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 #133

Merged
merged 9 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 6 additions & 0 deletions .changeset/famous-llamas-sit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@tbdex/http-client": patch
"@tbdex/protocol": patch
---

Replaces karma testing library with web-test-runner
87 changes: 0 additions & 87 deletions packages/http-client/karma.conf.cjs

This file was deleted.

17 changes: 6 additions & 11 deletions packages/http-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,41 +59,36 @@
"typeid-js": "0.3.0"
},
"devDependencies": {
"@playwright/test": "1.34.3",
"@types/chai": "4.3.5",
"@types/eslint": "8.37.0",
"@types/mocha": "10.0.1",
"@types/ms": "0.7.34",
"@types/sinon": "17.0.1",
"@typescript-eslint/eslint-plugin": "5.59.0",
"@typescript-eslint/parser": "5.59.0",
"@web/test-runner": "^0.18.0",
"@web/test-runner-playwright": "^0.11.0",
"buffer": "^6.0.3",
"chai": "4.3.10",
"esbuild": "0.16.17",
"eslint": "8.43.0",
"get-func-name": "2.0.1",
"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",
"mkdirp": "3.0.1",
"mocha": "10.2.0",
"rimraf": "4.4.0",
"sinon": "17.0.1",
"typedoc": "0.25.0",
"typedoc-plugin-markdown": "3.16.0",
"typescript": "5.2.2"
"typescript": "5.2.2",
"tiny-glob": "0.2.9"
},
"scripts": {
"clean": "rimraf dist tests/compiled",
"build:esm": "rimraf dist/esm dist/types && tsc",
"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",
"test:node": "rimraf tests/compiled && tsc -p tests/tsconfig.json && c8 mocha",
"test:browser": "karma start karma.conf.cjs",
"test:browser": "rimraf tests/compiled && node tests/bundle-tests.mjs && web-test-runner",
"build": "pnpm clean && pnpm build:esm && pnpm build:cjs && pnpm build:browser",
"lint": "eslint . --ext .ts --max-warnings 0",
"lint:fix": "eslint . --ext .ts --fix",
Expand Down
4 changes: 4 additions & 0 deletions packages/http-client/tests/buffer-polyfill.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/* eslint-disable @typescript-eslint/no-var-requires */
const Buffer = require('buffer/').Buffer

globalThis.Buffer = Buffer
22 changes: 22 additions & 0 deletions packages/http-client/tests/bundle-tests.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { fileURLToPath } from 'node:url'

import esbuild from 'esbuild'
import path from 'node:path'
import glob from 'tiny-glob'

const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)

esbuild.buildSync({
entryPoints : await glob(`${__dirname}/*.spec.ts`),
format : 'esm',
bundle : true,
sourcemap : true,
platform : 'browser',
target : ['chrome101', 'firefox108', 'safari16'],
outdir : `${__dirname}/compiled`,
define : {
'global': 'globalThis',
},
inject: [`${__dirname}/buffer-polyfill.cjs`],
})
28 changes: 28 additions & 0 deletions packages/http-client/web-test-runner.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { playwrightLauncher } from '@web/test-runner-playwright'

/**
* @type {import('@web/test-runner').TestRunnerConfig}
*/
export default {
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',
},
},
}
87 changes: 0 additions & 87 deletions packages/protocol/karma.conf.cjs

This file was deleted.

14 changes: 4 additions & 10 deletions packages/protocol/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,23 +61,17 @@
"typeid-js": "0.3.0"
},
"devDependencies": {
"@playwright/test": "1.34.3",
"@types/sinon": "17.0.2",
"@web/test-runner": "^0.18.0",
"@web/test-runner-playwright": "^0.11.0",
"chai": "4.3.10",
"esbuild": "0.16.17",
"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",
"mkdirp": "3.0.1",
"mocha": "10.2.0",
"node-stdlib-browser": "1.2.0",
"rimraf": "4.4.0",
"sinon": "17.0.1",
"tiny-glob": "0.2.9",
"typedoc": "0.25.0",
"typedoc-plugin-markdown": "3.16.0",
"typescript": "5.2.2"
Expand All @@ -89,7 +83,7 @@
"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",
"test:node": "rimraf tests/compiled && pnpm compile-validators && tsc -p tests/tsconfig.json && mocha",
"test:browser": "pnpm compile-validators && karma start karma.conf.cjs",
"test:browser": "rimraf tests/compiled && pnpm compile-validators && node tests/bundle-tests.mjs && web-test-runner",
kirahsapong marked this conversation as resolved.
Show resolved Hide resolved
"generate-test-vectors": "tsc -p tests/tsconfig.json && node tests/compiled/packages/protocol/tests/generate-test-vectors.js",
"build": "pnpm clean && pnpm compile-validators && pnpm build:esm && pnpm build:cjs && pnpm build:browser",
"lint": "eslint . --ext .ts --max-warnings 0",
Expand Down
6 changes: 3 additions & 3 deletions packages/protocol/src/dev-tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ export class DevTools {
/**
* creates and returns an example offering. Useful for testing purposes
*/
static createOffering(offeringData?: OfferingData): Offering {
static createOffering(opts?: { from?: string, offeringData?: OfferingData }): Offering {
return Offering.create({
metadata : { from: 'did:ex:pfi' },
data : offeringData ?? DevTools.createOfferingData()
metadata : { from: opts?.from ?? 'did:ex:pfi' },
data : opts?.offeringData ?? DevTools.createOfferingData()
})
}

Expand Down
21 changes: 21 additions & 0 deletions packages/protocol/tests/bundle-tests.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { fileURLToPath } from 'node:url'

import esbuild from 'esbuild'
import path from 'node:path'
import glob from 'tiny-glob'

const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)

esbuild.buildSync({
entryPoints : await glob(`${__dirname}/*.spec.ts`),
format : 'esm',
bundle : true,
sourcemap : true,
platform : 'browser',
target : ['chrome101', 'firefox108', 'safari16'],
outdir : `${__dirname}/compiled`,
define : {
'global': 'globalThis',
}
})
2 changes: 1 addition & 1 deletion packages/protocol/tests/generate-test-vectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type TestVector = {

const generateParseOfferingVector = async () => {
const did = await DidKeyMethod.create()
const offering = DevTools.createOffering()
const offering = DevTools.createOffering({ from: did.did })

await offering.sign(did)

Expand Down
6 changes: 6 additions & 0 deletions packages/protocol/tests/test-vectors.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ import ParseOrder from '../../../tbdex/hosted/test-vectors/protocol/vectors/pars
import ParseOrderStatus from '../../../tbdex/hosted/test-vectors/protocol/vectors/parse-orderstatus.json' assert { type: 'json' }
import ParseQuote from '../../../tbdex/hosted/test-vectors/protocol/vectors/parse-quote.json' assert { type: 'json' }
import ParseRfq from '../../../tbdex/hosted/test-vectors/protocol/vectors/parse-rfq.json' assert { type: 'json' }
import { messageFactory, resourceFactory } from '../src/utils.js'
import { Resource } from '../src/resource.js'
import { Message } from '../src/message.js'

Message.factory = messageFactory
Resource.factory = resourceFactory

describe('TbdexTestVectorsProtocol', () => {
it('parse_close', async () => {
Expand Down
Loading
Loading