Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace Karma with Web Test Runner #316

Merged
merged 27 commits into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
64843fc
poc: web test runner
shamilovtim Nov 27, 2023
7d96ca7
add ci test
shamilovtim Nov 27, 2023
ca19c8b
webkit is hanging
shamilovtim Nov 27, 2023
c43850a
naming
shamilovtim Nov 27, 2023
c09d2f7
shutoff webkit
shamilovtim Nov 27, 2023
a04ac05
unbump playwright
shamilovtim Nov 27, 2023
9e93208
remove manual timeouts
shamilovtim Nov 27, 2023
56cf9d0
use concurrency 1
shamilovtim Nov 27, 2023
b075b1c
wrap up poc
shamilovtim Nov 28, 2023
41ae6ec
run CI for poc back to back with previous impl
shamilovtim Nov 28, 2023
f48c325
tie up loose ends
shamilovtim Nov 29, 2023
aacf06c
let wtr run to compare
shamilovtim Nov 29, 2023
7566abc
Merge branch 'main' into tshamilov/web-test-runner
shamilovtim Nov 29, 2023
210b693
add back webkit. apples to apples with karma.
shamilovtim Nov 29, 2023
138c155
Merge branch 'main' into tshamilov/web-test-runner
shamilovtim Nov 29, 2023
cfdd6a3
remove karma
shamilovtim Nov 29, 2023
bb9d6ce
remove karma
shamilovtim Nov 29, 2023
1a374f3
fix tbdocs (i assume)
shamilovtim Nov 29, 2023
de7ee5d
update ci config
shamilovtim Nov 29, 2023
092f1b9
better naming of scripts
shamilovtim Nov 29, 2023
d99e6de
fix node
shamilovtim Nov 29, 2023
defbbf7
revert test config changes
shamilovtim Nov 30, 2023
1e861f6
fix env var override
shamilovtim Nov 30, 2023
1ee3e5a
cleanup ci config
shamilovtim Nov 30, 2023
df95935
cleanup explicit deps
shamilovtim Nov 30, 2023
489f2a5
Merge branch 'main' into tshamilov/web-test-runner
shamilovtim Nov 30, 2023
9902026
add back playwright
shamilovtim Dec 1, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the same URL as default. no value here.

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