Skip to content

Commit

Permalink
feat: move from CJS to ESM
Browse files Browse the repository at this point in the history
this is an unreasonably large change which does a few things:

- Moves all packages to `type: "module"`
- Removes `node-fetch` (ran into problems in ESM-land)
- Replaces all `__dirname` with an equivalent using `import.meta`
- Replaces all `require.resolve` with `import.meta.resolve`
- Update all imports to be ESM-compatible
- Move all `tsconfig` to use `nodenext` resolution

Probably some other stuff too.
  • Loading branch information
43081j committed Nov 21, 2023
1 parent d3ef523 commit 70dd2e3
Show file tree
Hide file tree
Showing 452 changed files with 7,785 additions and 4,736 deletions.
14 changes: 7 additions & 7 deletions integration/test-runner/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { BrowserLauncher, TestRunnerCoreConfig } from '@web/test-runner-core';
import { runBasicTest } from './tests/basic/runBasicTest';
import { runConfigGroupsTest } from './tests/config-groups/runConfigGroupsTest';
import { runParallelTest } from './tests/parallel/runParallelTest';
import { runTestFailureTest } from './tests/test-failure/runTestFailureTest';
import { runLocationChangeTest } from './tests/location-change/runLocationChangeTest';
import { runFocusTest } from './tests/focus/runFocusTest';
import { runManyTests } from './tests/many/runManyTests';
import { runBasicTest } from './tests/basic/runBasicTest.js';
import { runConfigGroupsTest } from './tests/config-groups/runConfigGroupsTest.js';
import { runParallelTest } from './tests/parallel/runParallelTest.js';
import { runTestFailureTest } from './tests/test-failure/runTestFailureTest.js';
import { runLocationChangeTest } from './tests/location-change/runLocationChangeTest.js';
import { runFocusTest } from './tests/focus/runFocusTest.js';
import { runManyTests } from './tests/many/runManyTests.js';

export interface Tests {
basic: boolean;
Expand Down
1 change: 1 addition & 0 deletions integration/test-runner/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"author": "modern-web",
"homepage": "https://github.com/modernweb-dev/web/tree/master/packages/test-runner-integration-tests",
"main": "index.js",
"type": "module",
"scripts": {
"test": "mocha test/**/*.test.ts --require ts-node/register --reporter dot",
"test:watch": "mocha test/**/*.test.ts --require ts-node/register --watch --watch-files src,test --reporter dot"
Expand Down
7 changes: 5 additions & 2 deletions integration/test-runner/tests/basic/runBasicTest.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { BrowserLauncher, TestRunnerCoreConfig, TestSession } from '@web/test-runner-core';
import { runTests } from '@web/test-runner-core/test-helpers';
import { runTests } from '@web/test-runner-core/dist/test-helpers.js';
import { legacyPlugin } from '@web/dev-server-legacy';
import { resolve } from 'path';
import { expect } from 'chai';
import { fileURLToPath } from 'node:url';

const dirname = fileURLToPath(new URL('.', import.meta.url));

export function runBasicTest(
config: Partial<TestRunnerCoreConfig> & { browsers: BrowserLauncher[] },
Expand All @@ -14,7 +17,7 @@ export function runBasicTest(
before(async () => {
const result = await runTests({
...config,
files: [...(config.files ?? []), resolve(__dirname, 'browser-tests', '*.test.js')],
files: [...(config.files ?? []), resolve(dirname, 'browser-tests', '*.test.js')],
plugins: [...(config.plugins ?? []), legacyPlugin()],
});
allSessions = result.sessions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ import {
TestRunnerCoreConfig,
TestRunnerGroupConfig,
} from '@web/test-runner-core';
import { runTests } from '@web/test-runner-core/test-helpers';
import { runTests } from '@web/test-runner-core/dist/test-helpers.js';
import { legacyPlugin } from '@web/dev-server-legacy';
import { resolve } from 'path';
import { expect } from 'chai';
import { fileURLToPath } from 'node:url';

const dirname = fileURLToPath(new URL('.', import.meta.url));

export function runConfigGroupsTest(
config: Partial<TestRunnerCoreConfig> & { browsers: BrowserLauncher[] },
Expand All @@ -18,13 +21,13 @@ export function runConfigGroupsTest(
name: 'a',
testRunnerHtml: path =>
`<html><body><script>window.__group__ = "a";</script><script type="module" src=${path}></script></body></html>`,
files: [resolve(__dirname, 'browser-tests', 'test-runner-html-a.test.js')],
files: [resolve(dirname, 'browser-tests', 'test-runner-html-a.test.js')],
},
{
name: 'b',
testRunnerHtml: path =>
`<html><body><script>window.__group__ = "b";</script><script type="module" src=${path}></script></body></html>`,
files: [resolve(__dirname, 'browser-tests', 'test-runner-html-b.test.js')],
files: [resolve(dirname, 'browser-tests', 'test-runner-html-b.test.js')],
},
];
const result = await runTests(
Expand Down
7 changes: 5 additions & 2 deletions integration/test-runner/tests/focus/runFocusTest.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { BrowserLauncher, TestRunnerCoreConfig, TestSession } from '@web/test-runner-core';
import { runTests } from '@web/test-runner-core/test-helpers';
import { runTests } from '@web/test-runner-core/dist/test-helpers.js';
import { legacyPlugin } from '@web/dev-server-legacy';
import { resolve } from 'path';
import { expect } from 'chai';
import { fileURLToPath } from 'node:url';

const dirname = fileURLToPath(new URL('.', import.meta.url));

export function runFocusTest(
config: Partial<TestRunnerCoreConfig> & { browsers: BrowserLauncher[] },
Expand All @@ -15,7 +18,7 @@ export function runFocusTest(
...config,
// 2 means some are executed concurrently, and some sequentially
concurrency: 2,
files: [...(config.files ?? []), resolve(__dirname, 'browser-tests', '*.test.js')],
files: [...(config.files ?? []), resolve(dirname, 'browser-tests', '*.test.js')],
plugins: [...(config.plugins ?? []), legacyPlugin()],
});
allSessions = result.sessions;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { BrowserLauncher, TestRunnerCoreConfig, TestSession } from '@web/test-runner-core';
import { runTests } from '@web/test-runner-core/test-helpers';
import { runTests } from '@web/test-runner-core/dist/test-helpers.js';
import { legacyPlugin } from '@web/dev-server-legacy';
import { resolve } from 'path';
import { expect } from 'chai';
import { fileURLToPath } from 'node:url';

const dirname = fileURLToPath(new URL('.', import.meta.url));

export function runLocationChangeTest(
config: Partial<TestRunnerCoreConfig> & { browsers: BrowserLauncher[] },
Expand All @@ -15,7 +18,7 @@ export function runLocationChangeTest(
const result = await runTests(
{
...config,
files: [...(config.files ?? []), resolve(__dirname, 'browser-tests', '*.test.js')],
files: [...(config.files ?? []), resolve(dirname, 'browser-tests', '*.test.js')],
plugins: [...(config.plugins ?? []), legacyPlugin()],
},
undefined,
Expand Down
7 changes: 5 additions & 2 deletions integration/test-runner/tests/many/runManyTests.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { BrowserLauncher, TestRunnerCoreConfig } from '@web/test-runner-core';
import { runTests } from '@web/test-runner-core/test-helpers';
import { runTests } from '@web/test-runner-core/dist/test-helpers.js';
import { legacyPlugin } from '@web/dev-server-legacy';
import { resolve } from 'path';
import { fileURLToPath } from 'node:url';

const dirname = fileURLToPath(new URL('.', import.meta.url));

export function runManyTests(
config: Partial<TestRunnerCoreConfig> & { browsers: BrowserLauncher[] },
Expand All @@ -11,7 +14,7 @@ export function runManyTests(
await Promise.all([
runTests({
...config,
files: [...(config.files ?? []), resolve(__dirname, 'browser-tests', '*.test.js')],
files: [...(config.files ?? []), resolve(dirname, 'browser-tests', '*.test.js')],
plugins: [...(config.plugins ?? []), legacyPlugin()],
}),
]);
Expand Down
9 changes: 6 additions & 3 deletions integration/test-runner/tests/parallel/runParallelTest.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { BrowserLauncher, TestRunnerCoreConfig } from '@web/test-runner-core';
import { runTests } from '@web/test-runner-core/test-helpers';
import { runTests } from '@web/test-runner-core/dist/test-helpers.js';
import { legacyPlugin } from '@web/dev-server-legacy';
import { resolve } from 'path';
import { fileURLToPath } from 'node:url';

const dirname = fileURLToPath(new URL('.', import.meta.url));

export function runParallelTest(
createConfig: () => Partial<TestRunnerCoreConfig> & { browsers: BrowserLauncher[] },
Expand All @@ -14,13 +17,13 @@ export function runParallelTest(
await Promise.all([
runTests({
...configA,
files: [...(configA.files ?? []), resolve(__dirname, 'browser-tests', '*.test.js')],
files: [...(configA.files ?? []), resolve(dirname, 'browser-tests', '*.test.js')],
plugins: [...(configA.plugins ?? []), legacyPlugin()],
}),

runTests({
...configB,
files: [...(configB.files ?? []), resolve(__dirname, 'browser-tests', '*.test.js')],
files: [...(configB.files ?? []), resolve(dirname, 'browser-tests', '*.test.js')],
plugins: [...(configB.plugins ?? []), legacyPlugin()],
}),
]);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { BrowserLauncher, TestRunnerCoreConfig, TestSession } from '@web/test-runner-core';
import { runTests } from '@web/test-runner-core/test-helpers';
import { runTests } from '@web/test-runner-core/dist/test-helpers.js';
import { legacyPlugin } from '@web/dev-server-legacy';
import { resolve, sep } from 'path';
import { expect } from 'chai';
import { fileURLToPath } from 'node:url';

const dirname = fileURLToPath(new URL('.', import.meta.url));

const ERROR_NOT_IMPORTABLE = {
message:
Expand Down Expand Up @@ -34,7 +37,7 @@ export function runTestFailureTest(
const result = await runTests(
{
...config,
files: [...(config.files ?? []), resolve(__dirname, 'browser-tests', '*.test.js')],
files: [...(config.files ?? []), resolve(dirname, 'browser-tests', '*.test.js')],
plugins: [...(config.plugins ?? []), legacyPlugin()],
},
undefined,
Expand Down

0 comments on commit 70dd2e3

Please sign in to comment.