Skip to content

Commit

Permalink
replace karma with web test runner (#316)
Browse files Browse the repository at this point in the history
* poc: web test runner

* add ci test

* webkit is hanging

* naming

* shutoff webkit

* unbump playwright

* remove manual timeouts

* use concurrency 1

* wrap up poc

* run CI for poc back to back with previous impl

* tie up loose ends

* let wtr run to compare

* add back webkit. apples to apples with karma.

* remove karma

* remove karma

* fix tbdocs (i assume)

* update ci config

* better naming of scripts

* fix node

* revert test config changes

* fix env var override

* cleanup ci config

* cleanup explicit deps

* add back playwright
  • Loading branch information
shamilovtim committed Dec 1, 2023
1 parent a23b49a commit ae975ea
Show file tree
Hide file tree
Showing 53 changed files with 3,142 additions and 2,060 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/tests-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,7 @@ jobs:
run: until curl -sf http://localhost:3000/health; do echo -n .; sleep .1; done

- name: Run tests for all packages
run: npm run test:browser --ws -- --color
env:
TEST_DWN_URL: http://localhost:3000
run: npm run test:browser --ws

web5-spec:
runs-on: ubuntu-latest
Expand Down
3,729 changes: 2,627 additions & 1,102 deletions package-lock.json

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions packages/agent/build/esbuild-tests.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/* eslint-disable @typescript-eslint/no-var-requires */
const esbuild = require('esbuild');
const browserConfig = require('./esbuild-browser-config.cjs');

esbuild.build({
...browserConfig,
format : 'esm',
entryPoints : ['./tests/*.spec.*'],
bundle : true,
minify : false,
outdir : 'tests/compiled',
define : {
...browserConfig.define,
'process.env.TEST_DWN_URL': JSON.stringify(process.env.TEST_DWN_URL ?? null),
},
});
87 changes: 0 additions & 87 deletions packages/agent/karma.conf.cjs

This file was deleted.

19 changes: 7 additions & 12 deletions packages/agent/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@
"build:cjs": "rimraf dist/cjs && tsc -p tsconfig.cjs.json && echo '{\"type\": \"commonjs\"}' > ./dist/cjs/package.json",
"build:browser": "rimraf dist/browser.mjs dist/browser.js && node build/bundles.js",
"build:tests:node": "rimraf tests/compiled && tsc -p tests/tsconfig.json",
"build:tests:browser": "rimraf tests/compiled && node build/esbuild-tests.cjs",
"build": "npm run clean && npm run build:esm && npm run build:cjs && npm run build:browser",
"lint": "eslint . --ext .ts --max-warnings 0",
"lint:fix": "eslint . --ext .ts --fix",
"test:node": "npm run build:tests:node && c8 mocha",
"test:browser": "karma start karma.conf.cjs"
"test:browser": "npm run build:tests:browser && web-test-runner"
},
"homepage": "https://github.com/TBD54566975/web5-js/tree/main/packages/agent#readme",
"bugs": "https://github.com/TBD54566975/web5-js/issues",
Expand Down Expand Up @@ -76,31 +77,25 @@
"readable-web-to-node-stream": "3.0.2"
},
"devDependencies": {
"@playwright/test": "1.36.2",
"@playwright/test": "1.40.1",
"@types/chai": "4.3.6",
"@types/chai-as-promised": "7.1.5",
"@types/eslint": "8.44.2",
"@types/mocha": "10.0.1",
"@types/readable-stream": "4.0.6",
"@typescript-eslint/eslint-plugin": "6.4.0",
"@typescript-eslint/parser": "6.4.0",
"@web/test-runner": "0.18.0",
"@web/test-runner-playwright": "0.11.0",
"c8": "8.0.1",
"chai": "4.3.10",
"chai-as-promised": "7.1.1",
"esbuild": "0.16.17",
"esbuild": "0.19.8",
"eslint": "8.47.0",
"eslint-plugin-mocha": "10.1.0",
"karma": "6.4.1",
"karma-chai": "0.1.0",
"karma-chrome-launcher": "3.1.1",
"karma-esbuild": "2.2.5",
"karma-firefox-launcher": "2.1.2",
"karma-mocha": "2.0.1",
"karma-mocha-reporter": "2.2.5",
"karma-webkit-launcher": "2.1.0",
"mocha": "10.2.0",
"node-stdlib-browser": "1.2.0",
"playwright": "1.36.2",
"playwright": "1.40.1",
"rimraf": "4.4.0",
"typescript": "5.1.6"
}
Expand Down
4 changes: 3 additions & 1 deletion packages/agent/tests/did-manager.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import chai, { expect } from 'chai';
import chaiAsPromised from 'chai-as-promised';
import type { PrivateKeyJwk, PublicKeyJwk, Web5Crypto } from '@web5/crypto';
import type { DidKeySet, PortableDid } from '@web5/dids';

import { expect } from 'chai';
import { DidKeyMethod } from '@web5/dids';
import { Jose, EdDsaAlgorithm } from '@web5/crypto';

Expand All @@ -13,6 +14,7 @@ import { DidManager } from '../src/did-manager.js';
import { TestManagedAgent } from '../src/test-managed-agent.js';
import { DidStoreDwn, DidStoreMemory } from '../src/store-managed-did.js';

chai.use(chaiAsPromised);
describe('DidManager', () => {

describe('constructor', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/agent/tests/dwn-manager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
ProtocolsConfigureMessage,
} from '@tbd54566975/dwn-sdk-js';

import { testDwnUrl } from './test-config.js';
import { testDwnUrl } from './utils/test-config.js';
import { TestAgent } from './utils/test-agent.js';
import { DwnManager } from '../src/dwn-manager.js';
import { ManagedIdentity } from '../src/identity-manager.js';
Expand Down
5 changes: 4 additions & 1 deletion packages/agent/tests/identity-manager.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { expect } from 'chai';
import chai, { expect } from 'chai';
import chaiAsPromised from 'chai-as-promised';
import { DidKeyMethod } from '@web5/dids';

import type { ManagedDid } from '../src/did-manager.js';
Expand All @@ -10,6 +11,8 @@ import { IdentityManager } from '../src/identity-manager.js';
import { TestManagedAgent } from '../src/test-managed-agent.js';
import { IdentityStoreDwn, IdentityStoreMemory } from '../src/store-managed-identity.js';

chai.use(chaiAsPromised);

describe('IdentityManager', () => {
describe('get agent', () => {
it(`returns the 'agent' instance property`, async () => {
Expand Down
6 changes: 4 additions & 2 deletions packages/agent/tests/key-manager.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { Web5Crypto } from '@web5/crypto';

import sinon from 'sinon';
import { expect } from 'chai';

import chai, { expect } from 'chai';
import chaiAsPromised from 'chai-as-promised';
import type { KeyManagerOptions } from '../src/key-manager.js';
import type { ManagedKey, ManagedKeyPair } from '../src/types/managed-key.js';

Expand All @@ -11,6 +11,8 @@ import { TestAgent } from './utils/test-agent.js';
import { KeyManager } from '../src/key-manager.js';
import { KeyStoreMemory } from '../src/store-managed-key.js';

chai.use(chaiAsPromised);

describe('KeyManager', () => {
let keyManager: KeyManager;
let localKms: LocalKms;
Expand Down
6 changes: 3 additions & 3 deletions packages/agent/tests/sync-manager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { RecordsQueryReply, RecordsWriteMessage } from '@tbd54566975/dwn-sdk-js'

import type { ManagedIdentity } from '../src/identity-manager.js';

import { testDwnUrl } from './test-config.js';
import { testDwnUrl } from './utils/test-config.js';
import { TestAgent } from './utils/test-agent.js';
import { SyncManagerLevel } from '../src/sync-manager.js';
import { TestManagedAgent } from '../src/test-managed-agent.js';
Expand Down Expand Up @@ -268,7 +268,7 @@ describe('SyncManagerLevel', () => {
localDwnQueryReply = queryResponse.reply as RecordsQueryReply;
expect(localDwnQueryReply.status.code).to.equal(200); // Query was successfully executed.
expect(localDwnQueryReply.entries).to.have.length(1); // Record does exist on local DWN.
}).timeout(5000);
});
});

describe('push()', () => {
Expand Down Expand Up @@ -464,7 +464,7 @@ describe('SyncManagerLevel', () => {
remoteDwnQueryReply = queryResponse.reply as RecordsQueryReply;
expect(remoteDwnQueryReply.status.code).to.equal(200); // Query was successfully executed.
expect(remoteDwnQueryReply.entries).to.have.length(1); // Record does exist on remote DWN.
}).timeout(5000);
});
});
});
});
24 changes: 0 additions & 24 deletions packages/agent/tests/test-config.ts

This file was deleted.

5 changes: 5 additions & 0 deletions packages/agent/tests/utils/test-config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const DEFAULT_TEST_DWN_URL = 'http://localhost:3000';

const getTestDwnUrl = () => process.env.TEST_DWN_URL || DEFAULT_TEST_DWN_URL;

export const testDwnUrl = getTestDwnUrl();
30 changes: 30 additions & 0 deletions packages/agent/web-test-runner.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/* eslint-disable @typescript-eslint/no-var-requires */
const playwrightLauncher =
require('@web/test-runner-playwright').playwrightLauncher;

/**
* @type {import('@web/test-runner').TestRunnerConfig}
*/
module.exports = {
files : 'tests/compiled/**/*.spec.js',
playwright : true,
nodeResolve : true,
browsers : [
playwrightLauncher({
product: 'chromium',
}),
playwrightLauncher({
product: 'firefox',
}),
playwrightLauncher({
product: 'webkit',
}),
],
testsFinishTimeout : 300000,
concurrentBrowsers : 2,
testFramework : {
config: {
timeout: '15000',
},
},
};
3 changes: 2 additions & 1 deletion packages/api/.mocharc.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"enable-source-maps": true,
"exit": true,
"spec": ["tests/compiled/**/*.spec.js"]
"spec": ["tests/compiled/**/*.spec.js"],
"timeout": 5000
}
16 changes: 16 additions & 0 deletions packages/api/build/esbuild-tests.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/* eslint-disable @typescript-eslint/no-var-requires */
const esbuild = require('esbuild');
const browserConfig = require('./esbuild-browser-config.cjs');

esbuild.build({
...browserConfig,
format : 'esm',
entryPoints : ['./tests/*.spec.*'],
bundle : true,
minify : false,
outdir : 'tests/compiled',
define : {
...browserConfig.define,
'process.env.TEST_DWN_URL': JSON.stringify(process.env.TEST_DWN_URL ?? null),
},
});
Loading

0 comments on commit ae975ea

Please sign in to comment.