Skip to content

Commit

Permalink
Bun get tests working
Browse files Browse the repository at this point in the history
  • Loading branch information
joepio committed Jan 16, 2024
1 parent 3b3f862 commit f7c695a
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 37 deletions.
4 changes: 0 additions & 4 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"editor.formatOnSave": true,
"files.autoSave": "onFocusChange",
"rust-analyzer.checkOnSave.command": "clippy",

"search.exclude": {
"**/.git": true,
"**/node_modules": true,
Expand All @@ -26,9 +25,6 @@
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "explicit"
},
"jest.enableInlineErrorMessages": true,
"jest.showCoverageOnLoad": true,
"jest.runAllTestsFirst": false,
"eslint.workingDirectories": [
"./data-browser",
"./react",
Expand Down
1 change: 0 additions & 1 deletion browser/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ module.exports = {
env: {
browser: true,
es6: true,
jest: true,
node: true,
},
parserOptions: {
Expand Down
Binary file added browser/bun.lockb
Binary file not shown.
4 changes: 2 additions & 2 deletions browser/data-browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"homepage": "https://atomicdata.dev/",
"husky": {
"hooks": {
"pre-push": "pnpm lint && pnpm test"
"pre-push": "bun run lint && bun test"
}
},
"license": "MIT",
Expand All @@ -74,7 +74,7 @@
"predeploy": "build && touch build/.nojekyll",
"preview": "vite preview",
"start": "vite",
"test": "jest",
"test": "bun test",
"typecheck": "tsc --noEmit"
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { reorderArray } from './reorderArray';
import { expect } from 'chai';
import { expect, describe, it } from 'bun:test';

describe('reorderArray', () => {
it('reorders ', async () => {
const start = [0, 1, 2, 3, 4];
const out = reorderArray(start, 2, 3);
const expected = [0, 1, 3, 2, 4];
expect(out).to.deep.equal(expected);
expect(out).toStrictEqual(expected);
});
});
2 changes: 1 addition & 1 deletion browser/lib/src/EventManager.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { jest } from '@jest/globals';
import { jest, describe, it, expect } from 'bun:test';
import { EventManager } from './EventManager.js';
enum Events {
Click = 'click',
Expand Down
11 changes: 5 additions & 6 deletions browser/lib/src/commit.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { expect } from 'chai';
import { CommitBuilder } from './commit.js';
import {
generatePublicKeyFromPrivate,
Expand All @@ -20,7 +19,7 @@ describe('Commit signing and keys', () => {

it('creates the right public key', async () => {
const generatedPublickey = await generatePublicKeyFromPrivate(privateKey);
expect(generatedPublickey).to.equal(publicKey);
expect(generatedPublickey).toEqual(publicKey);
});

it('signs a commit with the right signature', async () => {
Expand All @@ -45,16 +44,16 @@ describe('Commit signing and keys', () => {
);
const sig = commit.signature;
const serialized = serializeDeterministically(commit);
expect(serialized).to.equal(serializedCommitRust);
expect(sig).to.equal(signatureCorrect);
expect(serialized).toEqual(serializedCommitRust);
expect(sig).toEqual(signatureCorrect);
});

it('signs any string correctly', async () => {
const input = 'val';
const correct_signature_rust =
'YtDR/xo0272LHNBQtDer4LekzdkfUANFTI0eHxZhITXnbC3j0LCqDWhr6itNvo4tFnep6DCbev5OKAHH89+TDA==';
const signature = await signToBase64(input, privateKey);
expect(signature).to.equal(correct_signature_rust);
expect(signature).toEqual(correct_signature_rust);
});
});

Expand Down Expand Up @@ -82,6 +81,6 @@ describe('Commit parse and apply', () => {
const description = resource
.get('https://atomicdata.dev/properties/description')!
.toString();
expect(description).to.equal('My new string');
expect(description).toEqual('My new string');
});
});
23 changes: 11 additions & 12 deletions browser/lib/src/store.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { expect } from 'chai';
import { jest } from '@jest/globals';
import { jest, describe, it, expect } from 'bun:test';
import { Resource, urls, Store, core, Core } from './index.js';

describe('Store', () => {
Expand All @@ -14,7 +13,7 @@ describe('Store', () => {
const atomString = gotResource!
.get(urls.properties.description)!
.toString();
expect(atomString).to.equal(testval);
expect(atomString).toEqual(testval);
});

it('fetches a resource', async () => {
Expand All @@ -28,7 +27,7 @@ describe('Store', () => {
}

const atomString = resource.get(urls.properties.shortname)!.toString();
expect(atomString).to.equal('created-at');
expect(atomString).toEqual('created-at');
});

it('accepts a custom fetch implementation', async () => {
Expand All @@ -46,15 +45,15 @@ describe('Store', () => {
noWebSocket: true,
});

expect(customFetch.mock.calls).to.have.length(0);
expect(customFetch.mock.calls).toHaveLength(0);

store.injectFetch(customFetch);

await store.fetchResourceFromServer(testResourceSubject, {
noWebSocket: true,
});

expect(customFetch.mock.calls).to.have.length(1);
expect(customFetch.mock.calls).toHaveLength(1);
});

it('creates new resources using store.newResource()', async () => {
Expand All @@ -70,14 +69,14 @@ describe('Store', () => {
},
});

expect(resource1.props.parent).to.equal('https://myserver.dev/properties');
expect(resource1.props.datatype).to.equal(urls.datatypes.slug);
expect(resource1.props.shortname).to.equal('testthing');
expect(resource1.hasClasses(core.classes.property)).to.equal(true);
expect(resource1.props.parent).toEqual('https://myserver.dev/properties');
expect(resource1.props.datatype).toEqual(urls.datatypes.slug);
expect(resource1.props.shortname).toEqual('testthing');
expect(resource1.hasClasses(core.classes.property)).toEqual(true);

const resource2 = await store.newResource();

expect(resource2.props.parent).to.equal(store.getServerUrl());
expect(resource2.get(core.properties.isA)).to.equal(undefined);
expect(resource2.props.parent).toEqual(store.getServerUrl());
expect(resource2.get(core.properties.isA)).toEqual(undefined);
});
});
10 changes: 2 additions & 8 deletions browser/package.json
Original file line number Diff line number Diff line change
@@ -1,30 +1,24 @@
{
"devDependencies": {
"@esm-bundle/chai": "4.3.4",
"@jest/globals": "^29.3.1",
"@types/chai": "^4.2.22",
"@types/jest": "^27.0.2",
"@types/bun": "^1.0.1",
"@types/node": "^16.11.4",
"@types/react": "^18.2.34",
"@types/react-dom": "^18.2.14",
"@types/react-router-dom": "^5.3.3",
"@typescript-eslint/eslint-plugin": "^5.9.0",
"@typescript-eslint/parser": "^5.9.0",
"@vitejs/plugin-react": "^1.3.0",
"chai": "^4.3.4",
"eslint": "8.23.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-jsx-a11y": "^6.6.1",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-react": "^7.28.0",
"eslint-plugin-react-hooks": "^4.3.0",
"husky": "^8.0.3",
"jest": "^29.0.2",
"netlify-cli": "16.2.0",
"prettier": "2.4.1",
"prettier-plugin-jsdoc": "^0.3.24",
"react": "^18.2.0",
"ts-jest": "^29.0.1",
"typedoc": "^0.25.3",
"typedoc-plugin-missing-exports": "^2.1.0",
"typescript": "^5.3.2",
Expand All @@ -39,7 +33,7 @@
"lint": "pnpm run -r lint",
"lint-fix": "pnpm run -r lint-fix",
"build": "pnpm --filter \"@tomic/lib\" run build && pnpm --filter=!./lib run -r build ",
"test": "pnpm run -r test",
"test": "bun test .test.ts",
"test-e2e": "pnpm run --filter @tomic/e2e test-e2e",
"test-query": "pnpm run --filter @tomic/e2e test-query",
"start": "pnpm run -r --parallel start",
Expand Down
2 changes: 1 addition & 1 deletion server/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ fn should_build(dirs: &Dirs) -> bool {

/// Runs JS package manager to install packages and build the JS bundle
fn build_js(dirs: &Dirs) {
let pkg_manager = "pnpm";
let pkg_manager = "bun";

p!("install js packages...");

Expand Down

0 comments on commit f7c695a

Please sign in to comment.