Skip to content
This repository has been archived by the owner on Dec 12, 2024. It is now read-only.

Commit

Permalink
Align ts tests with production bundle
Browse files Browse the repository at this point in the history
  • Loading branch information
KendallWeihe committed Oct 9, 2024
1 parent ee2994a commit cae9ec0
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"enable-source-maps": true,
"exit": true,
"spec": ["tests/compiled/node/**/*.test.js"]
"spec": ["tests/compiled/cjs/**/*.test.js"]
}
5 changes: 5 additions & 0 deletions bound/typescript/.mocharc.esm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"enable-source-maps": true,
"exit": true,
"spec": ["tests/compiled/esm/**/*.test.js"]
}
6 changes: 4 additions & 2 deletions bound/typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@
"build:types": "tsc --declaration --emitDeclarationOnly --outFile dist/index.d.ts && ./declaration-hack.sh",
"build:wasm": "./bundle-wasm/build.sh && node ./bundle-wasm/bundle.js",
"build": "npm run build:wasm && npm run build:types && npm run build:browser && npm run build:esm && npm run build:cjs",
"test:node": "tsc -p tests/tsconfig.json && node tests/bundle-node.js && mocha",
"test:browser": "tsc -p tests/tsconfig.json && node tests/bundle-browser.js && web-test-runner",
"test:cjs": "tsc -p tests/tsconfig.json && node tests/bundle-cjs.js && mocha --config .mocharc.cjs.json",
"test:esm": "tsc -p tests/tsconfig.json && node tests/bundle-esm.js && mocha --config .mocharc.esm.json",
"test:browser:cjs": "tsc -p tests/tsconfig.json && node tests/bundle-browser.js && web-test-runner --config web-test-runner.cjs.config.mjs",
"test:browser:esm": "tsc -p tests/tsconfig.json && node tests/bundle-browser.js && web-test-runner --config web-test-runner.esm.config.mjs",
"test": "npm run test:node && npm run test:browser"
},
"dependencies": {}
Expand Down
15 changes: 14 additions & 1 deletion bound/typescript/tests/bundle-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,20 @@ esbuild.buildSync({
sourcemap : true,
platform : 'browser',
target : ['chrome101', 'firefox108', 'safari16'],
outdir : `${__dirname}/compiled/browser`,
outdir : `${__dirname}/compiled/browser/esm`,
define : {
'global': 'globalThis',
},
});

esbuild.buildSync({
entryPoints: [`${__dirname}/compiled/bound/typescript/tests/**/*.test.js`],
format : 'cjs',
bundle : true,
sourcemap : true,
platform : 'browser',
target : ['chrome101', 'firefox108', 'safari16'],
outdir : `${__dirname}/compiled/browser/cjs`,
define : {
'global': 'globalThis',
},
Expand Down
20 changes: 20 additions & 0 deletions bound/typescript/tests/bundle-cjs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { fileURLToPath } from 'node:url'
import esbuild from 'esbuild'
import path from 'node:path'
import fs from 'node:fs'

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

fs.copyFileSync(`${__dirname}/../src/wasm/generated.d.ts`, `${__dirname}/compiled/bound/typescript/src/wasm/generated.d.ts`)
fs.copyFileSync(`${__dirname}/../src/wasm/generated.js`, `${__dirname}/compiled/bound/typescript/src/wasm/generated.js`)

esbuild.buildSync({
entryPoints: [`${__dirname}/compiled/bound/typescript/tests/**/*.test.js`],
format: 'cjs',
bundle: true,
sourcemap: true,
platform: 'node',
target: ['node18'],
outdir: `${__dirname}/compiled/cjs`,
});
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ esbuild.buildSync({
sourcemap: true,
platform: 'node',
target: ['node18'],
outdir: `${__dirname}/compiled/node`,
outdir: `${__dirname}/compiled/esm`,
});
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { playwrightLauncher } from '@web/test-runner-playwright'
* @type {import('@web/test-runner').TestRunnerConfig}
*/
export default {
files : ['./tests/compiled/browser/**/*.test.js'],
files : ['./tests/compiled/browser/cjs/**/*.test.js'],
playwright : true,
browsers : [
playwrightLauncher({
Expand Down
27 changes: 27 additions & 0 deletions bound/typescript/web-test-runner.esm.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { playwrightLauncher } from '@web/test-runner-playwright'

/**
* @type {import('@web/test-runner').TestRunnerConfig}
*/
export default {
files : ['./tests/compiled/browser/esm/**/*.test.js'],
playwright : true,
browsers : [
playwrightLauncher({
product: 'chromium',
}),
playwrightLauncher({
product: 'firefox',
}),
playwrightLauncher({
product: 'webkit',
}),
],
testsFinishTimeout : 300000,
concurrentBrowsers : 1,
testFramework : {
config: {
timeout: '30000',
},
}
};

0 comments on commit cae9ec0

Please sign in to comment.