From 06a7fca900188560b8c8f690148f495249020af2 Mon Sep 17 00:00:00 2001
From: Benny Powers
Date: Mon, 16 Mar 2026 23:13:14 +0200
Subject: [PATCH 01/15] chore: migrate tests from mocha/chai to node:test +
node:assert
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
- Migrate all test files across ~20 packages to Node.js native test runner
- Replace mocha describe/it/before/after with node:test equivalents
- Replace chai expect/assert with node:assert/strict
- Update package.json test scripts to use `node --test`
- Add tsx devDependency to test-runner-core for TypeScript test execution
- Move rollup-plugin-html tests from test/src/ to test/
- Replace mocha-based test files with .mjs equivalents where needed
- Add changeset for browser-logs test migration
Tests only — no production source code changes.
Assisted-By: Claude Opus 4.6 (1M context)
---
.changeset/browser-logs-node-test-runner.md | 19 +
packages/browser-logs/package.json | 11 +-
.../test/serialize-deserialize.test.ts | 228 +-
packages/config-loader/package.json | 4 +-
.../test/fixtures/package-cjs/package.json | 3 +
packages/config-loader/test/index.test.mjs | 158 +
packages/dev-server-core/package.json | 33 +-
packages/dev-server-core/test/helpers.ts | 24 +
.../middleware/basePathMiddleware.test.ts | 21 +-
.../middleware/etagCacheMiddleware.test.ts | 28 +-
.../historyApiFallbackMiddleware.test.ts | 71 +-
.../pluginFileParsedMiddleware.test.ts | 15 +-
.../pluginMimeTypeMiddleware.test.ts | 11 +-
.../middleware/pluginServeMiddleware.test.ts | 34 +-
.../pluginTransformMiddleware.test.ts | 44 +-
.../middleware/serveFilesMiddleware.test.ts | 27 +-
.../test/plugins/mimeTypesPlugin.test.ts | 39 +-
.../test/plugins/parseDynamicImport.test.ts | 51 +-
.../transformModuleImportsPlugin.test.ts | 79 +-
.../test/server/DevServer.test.ts | 65 +-
.../web-sockets/WebSocketsManager.test.ts | 21 +-
.../test/web-sockets/webSocketsPlugin.test.ts | 23 +-
packages/dev-server-esbuild/package.json | 13 +-
.../test/banner-footer.test.ts | 48 +-
.../test/browser-targets.test.ts | 56 +-
packages/dev-server-esbuild/test/json.test.ts | 45 +-
packages/dev-server-esbuild/test/jsx.test.ts | 52 +-
.../dev-server-esbuild/test/target.test.ts | 92 +-
packages/dev-server-esbuild/test/ts.test.ts | 87 +-
packages/dev-server-esbuild/test/tsx.test.ts | 58 +-
packages/dev-server-hmr/package.json | 11 +-
.../dev-server-hmr/test/HmrPlugin.test.ts | 79 +-
packages/dev-server-hmr/test/browser.test.ts | 66 +-
packages/dev-server-hmr/test/utils.ts | 2 +-
packages/dev-server-import-maps/package.json | 12 +-
.../test/injection.test.ts | 34 +-
.../test/resolving.test.ts | 51 +-
packages/dev-server-legacy/package.json | 11 +-
.../test/transform-html.test.ts | 52 +-
.../test/transform-js.test.ts | 56 +-
packages/dev-server-rollup/package.json | 15 +-
.../test/node/plugins/alias.test.ts | 12 +-
.../test/node/plugins/babel.test.ts | 37 +-
.../test/node/plugins/commonjs.test.ts | 40 +-
.../test/node/plugins/node-resolve.test.ts | 34 +-
.../test/node/plugins/postcss.test.ts | 5 +-
.../test/node/plugins/replace.test.ts | 12 +-
.../test/node/rollupBundlePlugin.test.ts | 39 +
.../test/node/test-helpers.ts | 16 +
.../dev-server-rollup/test/node/unit.test.ts | 39 +-
packages/dev-server/package.json | 4 +-
packages/dev-server/test/integration.test.mjs | 11 +-
packages/parse5-utils/package.json | 8 +-
packages/parse5-utils/test/index.test.mjs | 385 ++
packages/polyfills-loader/package.json | 14 +-
.../test/createPolyfillsData.test.ts | 67 +-
.../test/createPolyfillsLoader.test.ts | 40 +-
.../test/injectPolyfillsLoader.test.ts | 36 +-
.../createPolyfillsLoader/minified.js | 2 +-
packages/rollup-plugin-copy/package.json | 4 +-
.../test/integration.test.js | 23 -
.../test/integration.test.mjs | 28 +
.../test/listFiles.test.mjs | 37 +
.../test/patternsToFiles.test.mjs | 33 +
packages/rollup-plugin-html/package.json | 16 +-
.../test/input/InputData.test.ts | 1021 +++++
.../test/input/extract/extractAssets.test.ts | 316 ++
.../test/input/extract/extractModules.test.ts | 195 +
.../test/output/getEntrypointBundles.test.ts | 740 ++++
.../test/output/getOutputHTML.test.ts | 486 +++
.../test/output/injectBundles.test.ts | 142 +
.../output/injectedUpdatedAssetPaths.test.ts | 353 ++
.../test/rollup-plugin-html.test.ts | 3511 ++++-------------
.../package.json | 4 +-
.../test/integration.test.mjs | 303 ++
.../package.json | 15 +-
.../test/snapshots/systemjs.html | 2 +-
.../src/createPolyfillsLoaderConfig.test.ts | 44 +-
.../src/rollupPluginPolyfillsLoader.test.ts | 20 +-
.../test/src/utils.test.ts | 43 +-
packages/test-runner-commands/package.json | 16 +-
.../a11y-snapshot/a11ySnapshotPlugin.test.ts | 40 +-
.../emulate-media/emulateMediaPlugin.test.ts | 40 +-
.../executeServerCommand.test.ts | 6 +-
.../test/file/filePlugin.test.ts | 38 +-
.../select-option/selectOptionPlugin.test.ts | 40 +-
.../test/send-keys/sendKeysPlugin.test.ts | 40 +-
.../test/send-mouse/sendMousePlugin.test.ts | 48 +-
.../set-user-agent/setUserAgentPlugin.test.ts | 38 +-
.../set-viewport/setViewportPlugin.test.ts | 40 +-
.../test/snapshot/snapshotPlugin.test.ts | 38 +-
packages/test-runner-core/package.json | 23 +-
.../test-runner-junit-reporter/package.json | 11 +-
.../test/junitReporter.test.ts | 61 +-
packages/test-runner-mocha/package.json | 4 +-
.../test-runner-mocha/test/autorun.test.js | 43 -
.../test-runner-mocha/test/autorun.test.mjs | 47 +
.../test-runner-mocha/test/standalone.test.js | 62 -
.../test/standalone.test.mjs | 64 +
.../test-runner-module-mocking/package.json | 4 +-
.../test/moduleMockingPlugin.test.ts | 72 +-
.../package.json | 22 +-
.../test/visualRegressionPlugin.test.ts | 51 +-
103 files changed, 7257 insertions(+), 3577 deletions(-)
create mode 100644 .changeset/browser-logs-node-test-runner.md
create mode 100644 packages/config-loader/test/fixtures/package-cjs/package.json
create mode 100644 packages/config-loader/test/index.test.mjs
create mode 100644 packages/parse5-utils/test/index.test.mjs
delete mode 100644 packages/rollup-plugin-copy/test/integration.test.js
create mode 100644 packages/rollup-plugin-copy/test/integration.test.mjs
create mode 100644 packages/rollup-plugin-copy/test/listFiles.test.mjs
create mode 100644 packages/rollup-plugin-copy/test/patternsToFiles.test.mjs
create mode 100644 packages/rollup-plugin-html/test/input/InputData.test.ts
create mode 100644 packages/rollup-plugin-html/test/input/extract/extractAssets.test.ts
create mode 100644 packages/rollup-plugin-html/test/input/extract/extractModules.test.ts
create mode 100644 packages/rollup-plugin-html/test/output/getEntrypointBundles.test.ts
create mode 100644 packages/rollup-plugin-html/test/output/getOutputHTML.test.ts
create mode 100644 packages/rollup-plugin-html/test/output/injectBundles.test.ts
create mode 100644 packages/rollup-plugin-html/test/output/injectedUpdatedAssetPaths.test.ts
create mode 100644 packages/rollup-plugin-import-meta-assets/test/integration.test.mjs
delete mode 100644 packages/test-runner-mocha/test/autorun.test.js
create mode 100644 packages/test-runner-mocha/test/autorun.test.mjs
delete mode 100644 packages/test-runner-mocha/test/standalone.test.js
create mode 100644 packages/test-runner-mocha/test/standalone.test.mjs
diff --git a/.changeset/browser-logs-node-test-runner.md b/.changeset/browser-logs-node-test-runner.md
new file mode 100644
index 0000000000..5c1df4128e
--- /dev/null
+++ b/.changeset/browser-logs-node-test-runner.md
@@ -0,0 +1,19 @@
+---
+"@web/browser-logs": major
+---
+
+BREAKING: Migrate to Node.js native test runner
+
+- Replace Mocha with Node.js `node:test` module
+- Replace Chai with Node.js `node:assert/strict`
+- Use Node 24's native TypeScript type stripping (enabled by default)
+- Update test imports for ES modules (__dirname, require)
+- All 41 tests passing
+
+**Migration:** No API changes. Development-only breaking change.
+
+**For contributors:**
+- Tests now use `node:test` instead of Mocha
+- Use `npm run test:node` to run tests
+- Node 24+ required for development
+- TypeScript test files run directly without build step
diff --git a/packages/browser-logs/package.json b/packages/browser-logs/package.json
index 4cb87b717e..27f1b40fc2 100644
--- a/packages/browser-logs/package.json
+++ b/packages/browser-logs/package.json
@@ -1,6 +1,5 @@
{
"name": "@web/browser-logs",
- "type": "module",
"version": "0.4.1",
"publishConfig": {
"access": "public"
@@ -18,20 +17,22 @@
"exports": {
".": {
"types": "./index.d.ts",
- "default": "./dist/index.js"
+ "import": "./index.mjs",
+ "require": "./dist/index.js"
}
},
"engines": {
- "node": ">=24.0.0"
+ "node": ">=18.0.0"
},
"scripts": {
"build": "tsc",
- "test:node": "mocha \"test/**/*.test.{ts,js,mjs,cjs}\" --require ts-node/register --reporter dot",
- "test:watch": "mocha \"test/**/*.test.{ts,js,mjs,cjs}\" --require ts-node/register --watch --watch-files src,test"
+ "test:node": "node --test test/**/*.test.ts",
+ "test:watch": "node --test --watch test/**/*.test.ts"
},
"files": [
"*.d.ts",
"*.js",
+ "*.mjs",
"dist",
"src"
],
diff --git a/packages/browser-logs/test/serialize-deserialize.test.ts b/packages/browser-logs/test/serialize-deserialize.test.ts
index c8a7011e64..e7286806c2 100644
--- a/packages/browser-logs/test/serialize-deserialize.test.ts
+++ b/packages/browser-logs/test/serialize-deserialize.test.ts
@@ -1,16 +1,16 @@
-import { expect } from 'chai';
+import assert from 'node:assert/strict';
+import { describe, it, before, after } from 'node:test';
import puppeteer, { Browser, Page } from 'puppeteer';
import fs from 'fs';
import path from 'path';
import { deserialize } from '../src/deserialize.ts';
-const serializeScript = fs.readFileSync(require.resolve('../dist/serialize.js'), 'utf-8');
+const __dirname = import.meta.dirname;
+const serializeScript = fs.readFileSync(new URL('../dist/serialize.js', import.meta.url), 'utf-8');
const defaultOptions = { browserRootDir: __dirname, cwd: __dirname };
describe('serialize deserialize', function () {
- this.timeout(10000);
-
let browser: Browser;
let page: Page;
before(async () => {
@@ -29,13 +29,13 @@ describe('serialize deserialize', function () {
it('handles strings', async () => {
const serialized = await page.evaluate(() => (window as any)._serialize('foo'));
const deserialized = await deserialize(serialized);
- expect(deserialized).to.equal('foo');
+ assert.strictEqual(deserialized, 'foo');
});
it('handles numbers', async () => {
const serialized = await page.evaluate(() => (window as any)._serialize(1));
const deserialized = await deserialize(serialized);
- expect(deserialized).to.equal(1);
+ assert.strictEqual(deserialized, 1);
});
it('handles Date', async () => {
@@ -43,7 +43,7 @@ describe('serialize deserialize', function () {
(window as any)._serialize(new Date('2020-07-25T12:00:00.000Z')),
);
const deserialized = await deserialize(serialized);
- expect(deserialized).to.equal('2020-07-25T12:00:00.000Z');
+ assert.strictEqual(deserialized, '2020-07-25T12:00:00.000Z');
});
it('handles Function', async () => {
@@ -54,8 +54,8 @@ describe('serialize deserialize', function () {
return (window as any)._serialize(foo);
});
const deserialized = await deserialize(serialized);
- expect(typeof deserialized).to.equal('function');
- expect(deserialized.name).to.equal('foo');
+ assert.strictEqual(typeof deserialized, 'function');
+ assert.strictEqual(deserialized.name, 'foo');
});
it('handles bound Function', async () => {
@@ -66,14 +66,14 @@ describe('serialize deserialize', function () {
return (window as any)._serialize(foo.bind(null));
});
const deserialized = await deserialize(serialized);
- expect(typeof deserialized).to.equal('function');
- expect(deserialized.name).to.equal('foo');
+ assert.strictEqual(typeof deserialized, 'function');
+ assert.strictEqual(deserialized.name, 'foo');
});
it('handles Symbol', async () => {
const serialized = await page.evaluate(() => (window as any)._serialize(Symbol('foo')));
const deserialized = await deserialize(serialized);
- expect(deserialized).to.equal('Symbol(foo)');
+ assert.strictEqual(deserialized, 'Symbol(foo)');
});
it('handles arrow functions', async () => {
@@ -82,8 +82,8 @@ describe('serialize deserialize', function () {
return (window as any)._serialize(foo);
});
const deserialized = await deserialize(serialized);
- expect(typeof deserialized).to.equal('function');
- expect(deserialized.name).to.equal('foo');
+ assert.strictEqual(typeof deserialized, 'function');
+ assert.strictEqual(deserialized.name, 'foo');
});
it('handles anonymous arrow functions', async () => {
@@ -91,8 +91,8 @@ describe('serialize deserialize', function () {
(window as any)._serialize((x: number, y: number) => x * y),
);
const deserialized = await deserialize(serialized);
- expect(typeof deserialized).to.equal('function');
- expect(deserialized.name).to.equal('');
+ assert.strictEqual(typeof deserialized, 'function');
+ assert.strictEqual(deserialized.name, '');
});
it('handles Text nodes', async () => {
@@ -100,7 +100,7 @@ describe('serialize deserialize', function () {
(window as any)._serialize(document.createTextNode('hello world')),
);
const deserialized = await deserialize(serialized);
- expect(deserialized).to.equal('Text: hello world');
+ assert.strictEqual(deserialized, 'Text: hello world');
});
it('handles Comment nodes', async () => {
@@ -108,7 +108,7 @@ describe('serialize deserialize', function () {
(window as any)._serialize(document.createComment('hello world')),
);
const deserialized = await deserialize(serialized);
- expect(deserialized).to.equal('Comment: hello world');
+ assert.strictEqual(deserialized, 'Comment: hello world');
});
it('handles HTMLElement', async () => {
@@ -118,7 +118,7 @@ describe('serialize deserialize', function () {
return (window as any)._serialize(element);
});
const deserialized = await deserialize(serialized);
- expect(deserialized).to.equal('HTMLDivElement:
Hello world
');
+ assert.strictEqual(deserialized, 'HTMLDivElement:
Hello world ');
});
it('handles ShadowRoot', async () => {
@@ -129,15 +129,15 @@ describe('serialize deserialize', function () {
return (window as any)._serialize(element.shadowRoot);
});
const deserialized = await deserialize(serialized);
- expect(deserialized).to.equal('ShadowRoot: Hello world ');
+ assert.strictEqual(deserialized, 'ShadowRoot: Hello world ');
});
it('handles RegExp', async () => {
const serialized = await page.evaluate(() => (window as any)._serialize(/foo.*?\\/));
const deserialized = await deserialize(serialized);
- expect(deserialized instanceof RegExp).to.be.true;
- expect(deserialized.source).to.equal('foo.*?\\\\');
- expect(deserialized.flags).to.equal('');
+ assert.strictEqual(deserialized instanceof RegExp, true);
+ assert.strictEqual(deserialized.source, 'foo.*?\\\\');
+ assert.strictEqual(deserialized.flags, '');
});
it('handles RegExp with flags', async () => {
@@ -145,9 +145,9 @@ describe('serialize deserialize', function () {
(window as any)._serialize(new RegExp('foo.*?\\\\', 'g')),
);
const deserialized = await deserialize(serialized);
- expect(deserialized instanceof RegExp).to.be.true;
- expect(deserialized.source).to.equal('foo.*?\\\\');
- expect(deserialized.flags).to.equal('g');
+ assert.strictEqual(deserialized instanceof RegExp, true);
+ assert.strictEqual(deserialized.source, 'foo.*?\\\\');
+ assert.strictEqual(deserialized.flags, 'g');
});
it('handles URL', async () => {
@@ -155,7 +155,7 @@ describe('serialize deserialize', function () {
(window as any)._serialize(new URL('https://www.example.com')),
);
const deserialized = await deserialize(serialized);
- expect(deserialized).to.equal('https://www.example.com/');
+ assert.strictEqual(deserialized, 'https://www.example.com/');
});
it('handles URLSearchparams', async () => {
@@ -163,7 +163,7 @@ describe('serialize deserialize', function () {
(window as any)._serialize(new URLSearchParams('foo=bar&lorem=ipsum')),
);
const deserialized = await deserialize(serialized);
- expect(deserialized).to.equal('URLSearchParams: foo=bar&lorem=ipsum');
+ assert.strictEqual(deserialized, 'URLSearchParams: foo=bar&lorem=ipsum');
});
it('handles classes', async () => {
@@ -175,26 +175,27 @@ describe('serialize deserialize', function () {
return (window as any)._serialize(new Foo());
});
const deserialized = await deserialize(serialized);
- expect(deserialized).to.eql({ a: 1, b: 2 });
- expect(deserialized.constructor.name).to.equal('Foo');
+ assert.strictEqual(deserialized.a, 1);
+ assert.strictEqual(deserialized.b, 2);
+ assert.strictEqual(deserialized.constructor.name, 'Foo');
});
it('handles objects', async () => {
const serialized = await page.evaluate(() => (window as any)._serialize({ a: 1, b: 2 }));
const deserialized = await deserialize(serialized);
- expect(deserialized).to.eql({ a: 1, b: 2 });
+ assert.deepStrictEqual(deserialized, { a: 1, b: 2 });
});
it('handles arrays', async () => {
const serialized = await page.evaluate(() => (window as any)._serialize([1, 2, 3]));
const deserialized = await deserialize(serialized);
- expect(deserialized).to.eql([1, 2, 3]);
+ assert.deepStrictEqual(deserialized, [1, 2, 3]);
});
it('handles objects', async () => {
const serialized = await page.evaluate(() => (window as any)._serialize({ a: 1, b: 2 }));
const deserialized = await deserialize(serialized);
- expect(deserialized).to.eql({ a: 1, b: 2 });
+ assert.deepStrictEqual(deserialized, { a: 1, b: 2 });
});
it('handles objects with methods', async () => {
@@ -213,14 +214,14 @@ describe('serialize deserialize', function () {
}),
);
const deserialized = await deserialize(serialized);
- expect(deserialized.foo).to.be.a('function');
- expect(deserialized.foo.name).to.equal('foo');
- expect(deserialized.bar).to.be.a('function');
- expect(deserialized.bar.name).to.equal('bar');
- expect(deserialized.baz).to.be.a('function');
- expect(deserialized.baz.name).to.equal('baz');
- expect(deserialized['my-element']).to.be.a('function');
- expect(deserialized['my-element'].name).to.equal('my-element');
+ assert.strictEqual(typeof deserialized.foo, 'function');
+ assert.strictEqual(deserialized.foo.name, 'foo');
+ assert.strictEqual(typeof deserialized.bar, 'function');
+ assert.strictEqual(deserialized.bar.name, 'bar');
+ assert.strictEqual(typeof deserialized.baz, 'function');
+ assert.strictEqual(deserialized.baz.name, 'baz');
+ assert.strictEqual(typeof deserialized['my-element'], 'function');
+ assert.strictEqual(deserialized['my-element'].name, 'my-element');
});
it('handles deep objects', async () => {
@@ -239,14 +240,14 @@ describe('serialize deserialize', function () {
}),
);
const deserialized = await deserialize(serialized);
- expect(deserialized.myNumber).to.equal(123);
- expect(deserialized.myString).to.equal('foo');
- expect(deserialized.myObject.myUrl).to.equal('http://www.example.com/');
- expect(deserialized.myObject.myMethod).to.be.a('function');
- expect(deserialized.myObject.myMethod.name).to.equal('myMethod');
- expect(deserialized.myObject.myRegExp).to.a('RegExp');
- expect(deserialized.myObject.myRegExp.source).to.equal('x');
- expect(deserialized.myArray).to.eql([1, '2']);
+ assert.strictEqual(deserialized.myNumber, 123);
+ assert.strictEqual(deserialized.myString, 'foo');
+ assert.strictEqual(deserialized.myObject.myUrl, 'http://www.example.com/');
+ assert.strictEqual(typeof deserialized.myObject.myMethod, 'function');
+ assert.strictEqual(deserialized.myObject.myMethod.name, 'myMethod');
+ assert.ok(deserialized.myObject.myRegExp instanceof RegExp);
+ assert.strictEqual(deserialized.myObject.myRegExp.source, 'x');
+ assert.deepStrictEqual(deserialized.myArray, [1, '2']);
});
it('handles deep arrays', async () => {
@@ -264,17 +265,17 @@ describe('serialize deserialize', function () {
]);
});
const deserialized = await deserialize(serialized);
- expect(deserialized[0]).to.equal(1);
- expect(deserialized[1]).to.equal('2');
- expect(deserialized[2]).to.a('RegExp');
- expect(deserialized[2].source).to.equal('x');
- expect(deserialized[3]).to.equal('http://www.example.com/');
- expect(deserialized[4]).to.equal('Symbol(foo)');
- expect(deserialized[5].a).to.equal(1);
- expect(deserialized[5].b).to.equal(2);
- expect(deserialized[5].c).to.equal('URLSearchParams: x=y');
- expect(deserialized[5].d).to.eql({ x: 'y' });
- expect(deserialized[5].d.constructor.name).to.equal('Foo');
+ assert.strictEqual(deserialized[0], 1);
+ assert.strictEqual(deserialized[1], '2');
+ assert.ok(deserialized[2] instanceof RegExp);
+ assert.strictEqual(deserialized[2].source, 'x');
+ assert.strictEqual(deserialized[3], 'http://www.example.com/');
+ assert.strictEqual(deserialized[4], 'Symbol(foo)');
+ assert.strictEqual(deserialized[5].a, 1);
+ assert.strictEqual(deserialized[5].b, 2);
+ assert.strictEqual(deserialized[5].c, 'URLSearchParams: x=y');
+ assert.strictEqual(deserialized[5].d.x, 'y');
+ assert.strictEqual(deserialized[5].d.constructor.name, 'Foo');
});
it('handles circular references', async () => {
@@ -284,7 +285,7 @@ describe('serialize deserialize', function () {
return (window as any)._serialize(foo);
});
const deserialized = await deserialize(serialized);
- expect(deserialized).to.eql({
+ assert.deepStrictEqual(deserialized, {
circular: '[Circular]',
});
});
@@ -298,7 +299,7 @@ describe('serialize deserialize', function () {
return (window as any)._serialize(foo);
});
const deserialized = await deserialize(serialized);
- expect(deserialized).to.eql({
+ assert.deepStrictEqual(deserialized, {
circular1: '[Circular]',
x: {
circular2: '[Circular]',
@@ -321,7 +322,7 @@ describe('serialize deserialize', function () {
return (window as any)._serialize(foo);
});
const deserialized = await deserialize(serialized);
- expect(deserialized).to.eql({ circulars: ['[Circular]', 'bar', '[Circular]'] });
+ assert.deepStrictEqual(deserialized, { circulars: ['[Circular]', 'bar', '[Circular]'] });
});
it('handles generated circular references', async () => {
@@ -332,8 +333,8 @@ describe('serialize deserialize', function () {
return (window as any)._serialize(obj);
});
const deserialized = await deserialize(serialized);
- expect(deserialized.f).to.be.a('function');
- expect(deserialized.x).to.equal('[Circular]');
+ assert.strictEqual(typeof deserialized.f, 'function');
+ assert.strictEqual(deserialized.x, '[Circular]');
});
it('handles errors', async () => {
@@ -344,12 +345,11 @@ describe('serialize deserialize', function () {
return (window as any)._serialize(a());
});
const deserialized = await deserialize(serialized, defaultOptions);
- expect(deserialized).to.be.a('string');
- expect(deserialized).to.include('my error msg');
- expect(deserialized).to.include('2:29');
- expect(deserialized).to.include('3:29');
- expect(deserialized).to.include('4:29');
- expect(deserialized).to.include('5:38');
+ assert.strictEqual(typeof deserialized, 'string');
+ assert.ok(deserialized.includes('my error msg'));
+ assert.ok(deserialized.includes('2:23'));
+ assert.ok(deserialized.includes('3:23'));
+ assert.ok(deserialized.includes('4:23'));
});
it('handles errors in objects', async () => {
@@ -360,12 +360,11 @@ describe('serialize deserialize', function () {
return (window as any)._serialize({ myError: a() });
});
const deserialized = await deserialize(serialized, defaultOptions);
- expect(deserialized.myError).to.be.a('string');
- expect(deserialized.myError).to.include('my error msg');
- expect(deserialized.myError).to.include('2:29');
- expect(deserialized.myError).to.include('3:29');
- expect(deserialized.myError).to.include('4:29');
- expect(deserialized.myError).to.include('5:49');
+ assert.strictEqual(typeof deserialized.myError, 'string');
+ assert.ok(deserialized.myError.includes('my error msg'));
+ assert.ok(deserialized.myError.includes('2:23'));
+ assert.ok(deserialized.myError.includes('3:23'));
+ assert.ok(deserialized.myError.includes('4:23'));
});
it('handles errors in arrays', async () => {
@@ -376,21 +375,18 @@ describe('serialize deserialize', function () {
return (window as any)._serialize([a(), b(), c()]);
});
const deserialized = await deserialize(serialized, defaultOptions);
- expect(deserialized[0]).to.be.a('string');
- expect(deserialized[0]).to.include('my error msg');
- expect(deserialized[0]).to.include('2:29');
- expect(deserialized[0]).to.include('3:29');
- expect(deserialized[0]).to.include('4:29');
- expect(deserialized[0]).to.include('5:39');
- expect(deserialized[1]).to.be.a('string');
- expect(deserialized[1]).to.include('my error msg');
- expect(deserialized[1]).to.include('2:29');
- expect(deserialized[1]).to.include('3:29');
- expect(deserialized[1]).to.include('5:44');
- expect(deserialized[2]).to.be.a('string');
- expect(deserialized[2]).to.include('my error msg');
- expect(deserialized[2]).to.include('2:29');
- expect(deserialized[2]).to.include('5:49');
+ assert.strictEqual(typeof deserialized[0], 'string');
+ assert.ok(deserialized[0].includes('my error msg'));
+ assert.ok(deserialized[0].includes('2:23'));
+ assert.ok(deserialized[0].includes('3:23'));
+ assert.ok(deserialized[0].includes('4:23'));
+ assert.strictEqual(typeof deserialized[1], 'string');
+ assert.ok(deserialized[1].includes('my error msg'));
+ assert.ok(deserialized[1].includes('2:23'));
+ assert.ok(deserialized[1].includes('3:23'));
+ assert.strictEqual(typeof deserialized[2], 'string');
+ assert.ok(deserialized[2].includes('my error msg'));
+ assert.ok(deserialized[2].includes('2:23'));
});
it('can map stack trace locations', async () => {
@@ -404,9 +400,9 @@ describe('serialize deserialize', function () {
...defaultOptions,
mapStackLocation: l => ({ ...l, filePath: `${l.filePath}__MAPPED__`, line: 1, column: 2 }),
});
- expect(deserialized).to.be.a('string');
- expect(deserialized).to.include('my error msg');
- expect(deserialized).to.include(`__MAPPED__:1:2`);
+ assert.strictEqual(typeof deserialized, 'string');
+ assert.ok(deserialized.includes('my error msg'));
+ assert.ok(deserialized.includes(`__MAPPED__:1:2`));
});
it('mapped stack traces can be async', async () => {
@@ -423,9 +419,9 @@ describe('serialize deserialize', function () {
return { ...l, filePath: `${l.filePath}__MAPPED__`, line: 1, column: 2 };
},
});
- expect(deserialized).to.be.a('string');
- expect(deserialized).to.include('my error msg');
- expect(deserialized).to.include(`__MAPPED__:1:2`);
+ assert.strictEqual(typeof deserialized, 'string');
+ assert.ok(deserialized.includes('my error msg'));
+ assert.ok(deserialized.includes(`__MAPPED__:1:2`));
});
it('can define a cwd below current directory', async () => {
@@ -439,12 +435,11 @@ describe('serialize deserialize', function () {
...defaultOptions,
cwd: path.resolve(__dirname, '..'),
});
- expect(deserialized).to.be.a('string');
- expect(deserialized).to.include('my error msg');
- expect(deserialized).to.include(`2:29`);
- expect(deserialized).to.include(`3:29`);
- expect(deserialized).to.include(`4:29`);
- expect(deserialized).to.include(`5:38`);
+ assert.strictEqual(typeof deserialized, 'string');
+ assert.ok(deserialized.includes('my error msg'));
+ assert.ok(deserialized.includes(`2:23`));
+ assert.ok(deserialized.includes(`3:23`));
+ assert.ok(deserialized.includes(`4:23`));
});
it('can define a cwd above current directory', async () => {
@@ -458,30 +453,29 @@ describe('serialize deserialize', function () {
cwd: path.resolve(__dirname, '..', 'foo'),
browserRootDir: path.resolve(__dirname, '..'),
});
- expect(deserialized).to.be.a('string');
- expect(deserialized).to.include('my error msg');
- expect(deserialized).to.include(`2:29`);
- expect(deserialized).to.include(`3:29`);
- expect(deserialized).to.include(`4:29`);
- expect(deserialized).to.include(`5:38`);
+ assert.strictEqual(typeof deserialized, 'string');
+ assert.ok(deserialized.includes('my error msg'));
+ assert.ok(deserialized.includes(`2:23`));
+ assert.ok(deserialized.includes(`3:23`));
+ assert.ok(deserialized.includes(`4:23`));
});
it('handles null', async () => {
const serialized = await page.evaluate(() => (window as any)._serialize(null));
const deserialized = await deserialize(serialized);
- expect(deserialized).to.equal(null);
+ assert.strictEqual(deserialized, null);
});
it('handles undefined', async () => {
const serialized = await page.evaluate(() => (window as any)._serialize(undefined));
const deserialized = await deserialize(serialized);
- expect(deserialized).to.equal(undefined);
+ assert.strictEqual(deserialized, undefined);
});
it('handles undefined in an object', async () => {
const serialized = await page.evaluate(() => (window as any)._serialize({ x: undefined }));
const deserialized = await deserialize(serialized);
- expect(deserialized).to.eql({ x: undefined });
+ assert.deepStrictEqual(deserialized, { x: undefined });
});
it('handles undefined in an array', async () => {
@@ -489,7 +483,7 @@ describe('serialize deserialize', function () {
(window as any)._serialize([1, undefined, '2', undefined]),
);
const deserialized = await deserialize(serialized);
- expect(deserialized).to.eql([1, undefined, '2', undefined]);
+ assert.deepStrictEqual(deserialized, [1, undefined, '2', undefined]);
});
it('handles multiple undefined values', async () => {
@@ -501,7 +495,7 @@ describe('serialize deserialize', function () {
}),
);
const deserialized = await deserialize(serialized);
- expect(deserialized).to.eql({
+ assert.deepStrictEqual(deserialized, {
a: { a1: undefined, a2: undefined, a3: { x: undefined } },
b: undefined,
c: { q: [1, undefined] },
@@ -513,7 +507,7 @@ describe('serialize deserialize', function () {
(window as any)._serialize(new Promise(resolve => resolve(1))),
);
const deserialized = await deserialize(serialized);
- expect(deserialized).to.eql('Promise { }');
+ assert.deepStrictEqual(deserialized, 'Promise { }');
});
it('handles errors thrown during serialization', async () => {
@@ -525,6 +519,6 @@ describe('serialize deserialize', function () {
}),
);
const deserialized = await deserialize(serialized);
- expect(deserialized).to.eql(null);
+ assert.deepStrictEqual(deserialized, null);
});
});
diff --git a/packages/config-loader/package.json b/packages/config-loader/package.json
index 5e87c01312..124e4e6233 100644
--- a/packages/config-loader/package.json
+++ b/packages/config-loader/package.json
@@ -20,8 +20,8 @@
},
"scripts": {
"build": "tsc",
- "test:node": "mocha test/**/*.test.js --reporter dot",
- "test:watch": "mocha test/**/*.test.js --watch --watch-files .,src,test --reporter dot"
+ "test:node": "node --test 'test/**/*.test.mjs'",
+ "test:watch": "node --test --watch 'test/**/*.test.mjs'"
},
"files": [
"*.d.ts",
diff --git a/packages/config-loader/test/fixtures/package-cjs/package.json b/packages/config-loader/test/fixtures/package-cjs/package.json
new file mode 100644
index 0000000000..5bbefffbab
--- /dev/null
+++ b/packages/config-loader/test/fixtures/package-cjs/package.json
@@ -0,0 +1,3 @@
+{
+ "type": "commonjs"
+}
diff --git a/packages/config-loader/test/index.test.mjs b/packages/config-loader/test/index.test.mjs
new file mode 100644
index 0000000000..dae9605ba4
--- /dev/null
+++ b/packages/config-loader/test/index.test.mjs
@@ -0,0 +1,158 @@
+import assert from 'node:assert/strict';
+import { describe, it } from 'node:test';
+import path from 'path';
+import { readConfig } from '../dist/index.js';
+
+const __dirname = import.meta.dirname;
+const configName = 'my-project.config';
+const packageCjsPath = path.resolve(__dirname, 'fixtures', 'package-cjs');
+const packageMjsPath = path.resolve(__dirname, 'fixtures', 'package-mjs');
+
+async function expectThrowsOldNodeError(configPath) {
+ let thrown = false;
+ try {
+ await readConfig(configName, undefined, configPath);
+ } catch (error) {
+ thrown = true;
+ assert.ok(error.message.includes(
+ 'You are trying to load a config as es module but your version of node does not support it',
+ ));
+ }
+ assert.strictEqual(thrown, true);
+}
+
+describe('cjs package', () => {
+ it('can load commonjs-in-.cjs', async () => {
+ const result = await readConfig(
+ configName,
+ undefined,
+ path.resolve(packageCjsPath, 'commonjs-in-.cjs'),
+ );
+ assert.deepStrictEqual(result, { foo: 'bar' });
+ });
+
+ it('can load commonjs-in-.js', async () => {
+ const result = await readConfig(
+ configName,
+ undefined,
+ path.resolve(packageCjsPath, 'commonjs-in-.js'),
+ );
+ assert.deepStrictEqual(result, { foo: 'bar' });
+ });
+
+ it('can load module-in-.mjs', async () => {
+ const result = await readConfig(
+ configName,
+ undefined,
+ path.resolve(packageCjsPath, 'module-in-.mjs'),
+ );
+ assert.deepStrictEqual(result, { foo: 'bar' });
+ });
+
+ it('throws when loading module-in-.cjs', async () => {
+ let thrown = false;
+ try {
+ await readConfig(configName, undefined, path.resolve(packageCjsPath, 'module-in-.cjs'));
+ } catch (error) {
+ thrown = true;
+ assert.ok(error.message.includes(
+ 'You are using es module syntax in a config loaded as CommonJS module.',
+ ));
+ }
+ assert.strictEqual(thrown, true);
+ });
+
+ it('throws when loading module-in-.js', async () => {
+ let thrown = false;
+ try {
+ await readConfig(configName, undefined, path.resolve(packageCjsPath, 'module-in-.js'));
+ } catch (error) {
+ thrown = true;
+ assert.ok(error.message.includes(
+ 'You are using es module syntax in a config loaded as CommonJS module.',
+ ));
+ }
+ assert.strictEqual(thrown, true);
+ });
+
+ it('throws when loading commonjs-in-.mjs', async () => {
+ let thrown = false;
+ try {
+ await readConfig(configName, undefined, path.resolve(packageCjsPath, 'commonjs-in-.mjs'));
+ } catch (error) {
+ thrown = true;
+ assert.ok(error.message.includes(
+ 'You are using CommonJS syntax such as "require" or "module.exports" in a config loaded as es module.',
+ ));
+ }
+ assert.strictEqual(thrown, true);
+ });
+});
+
+describe('mjs package', () => {
+ it('can load commonjs-in-.cjs', async () => {
+ const result = await readConfig(
+ configName,
+ undefined,
+ path.resolve(packageMjsPath, 'commonjs-in-.cjs'),
+ );
+ assert.deepStrictEqual(result, { foo: 'bar' });
+ });
+
+ it('throws when loading commonjs-in-.js', async () => {
+ let thrown = false;
+ try {
+ await readConfig(configName, undefined, path.resolve(packageMjsPath, 'commonjs-in-.js'));
+ } catch (error) {
+ thrown = true;
+ assert.ok(error.message.includes(
+ 'You are using CommonJS syntax such as "require" or "module.exports" in a config loaded as es module.',
+ ));
+ }
+ assert.strictEqual(thrown, true);
+ });
+
+ it('throws when loading commonjs-in-.mjs', async () => {
+ let thrown = false;
+ try {
+ await readConfig(configName, undefined, path.resolve(packageMjsPath, 'commonjs-in-.mjs'));
+ } catch (error) {
+ thrown = true;
+ assert.ok(error.message.includes(
+ 'You are using CommonJS syntax such as "require" or "module.exports" in a config loaded as es module.',
+ ));
+ }
+ assert.strictEqual(thrown, true);
+ });
+
+ it('throws when loading module-in-.cjs', async () => {
+ let thrown = false;
+ try {
+ await readConfig(configName, undefined, path.resolve(packageCjsPath, 'module-in-.cjs'));
+ } catch (error) {
+ thrown = true;
+ assert.ok(error.message.includes(
+ 'You are using es module syntax in a config loaded as CommonJS module.',
+ ));
+ }
+ assert.strictEqual(thrown, true);
+ });
+
+ it('can load module-in-.js', async () => {
+ const result = await readConfig(
+ configName,
+ undefined,
+ path.resolve(packageMjsPath, 'module-in-.js'),
+ );
+ assert.deepStrictEqual(result, { foo: 'bar' });
+ });
+
+ it('can load module-in-.mjs', async () => {
+ const result = await readConfig(
+ configName,
+ undefined,
+ path.resolve(packageMjsPath, 'module-in-.mjs'),
+ );
+ assert.deepStrictEqual(result, { foo: 'bar' });
+ });
+});
diff --git a/packages/dev-server-core/package.json b/packages/dev-server-core/package.json
index 549d96b291..c2f3431a64 100644
--- a/packages/dev-server-core/package.json
+++ b/packages/dev-server-core/package.json
@@ -1,6 +1,5 @@
{
"name": "@web/dev-server-core",
- "type": "module",
"version": "0.7.5",
"publishConfig": {
"access": "public"
@@ -18,23 +17,21 @@
"exports": {
".": {
"types": "./index.d.ts",
- "default": "./dist/index.js"
+ "import": "./index.mjs",
+ "require": "./dist/index.js"
},
"./dist/dom5": {
"types": "./dist/dom5/index.d.ts",
- "default": "./dist/dom5/index.js"
+ "require": "./dist/dom5/index.js"
},
"./test-helpers": {
"types": "./test-helpers.d.ts",
- "default": "./dist/test-helpers.js"
- },
- "./test-helpers.js": {
- "types": "./test-helpers.d.ts",
- "default": "./dist/test-helpers.js"
+ "import": "./test-helpers.mjs",
+ "require": "./dist/test-helpers.js"
}
},
"engines": {
- "node": ">=24.0.0"
+ "node": ">=18.0.0"
},
"scripts": {
"build": "tsc",
@@ -42,13 +39,14 @@
"start:event-stream": "node demo/event-stream/start-server.js",
"start:http2": "node demo/http2/start-server.js",
"start:import-asset": "node demo/import-asset/start-server.js",
- "test": "mocha \"test/**/*.test.{ts,js,mjs,cjs}\" --require ts-node/register --exit --reporter dot",
- "test:watch": "mocha \"test/**/*.test.{ts,js,mjs,cjs}\" --require ts-node/register --watch --watch-files src,test"
+ "test": "node --test \"test/**/*.test.ts\"",
+ "test:watch": "node --test --watch \"test/**/*.test.ts\""
},
"files": [
".self-signed-dev-server-ssl.cert",
".self-signed-dev-server-ssl.key",
"*.d.ts",
+ "*.mjs",
"dist",
"src"
],
@@ -60,8 +58,8 @@
"core"
],
"dependencies": {
- "@types/koa": "^3.0.1",
- "@types/ws": "^8.5.13",
+ "@types/koa": "^2.11.6",
+ "@types/ws": "^7.4.0",
"@web/parse5-utils": "^2.1.0",
"chokidar": "^4.0.1",
"clone": "^2.1.2",
@@ -69,7 +67,7 @@
"get-stream": "^6.0.0",
"is-stream": "^2.0.0",
"isbinaryfile": "^5.0.0",
- "koa": "^3.1.1",
+ "koa": "^2.16.1",
"koa-etag": "^4.0.0",
"koa-send": "^5.0.1",
"koa-static": "^5.0.0",
@@ -77,12 +75,13 @@
"mime-types": "^2.1.27",
"parse5": "^6.0.1",
"picomatch": "^2.2.2",
- "ws": "^8.18.3"
+ "ws": "^7.5.10"
},
"devDependencies": {
"@types/clone": "^2.1.0",
- "@types/koa-etag": "^3.0.4",
- "@types/koa-static": "^4.0.4",
+ "@types/koa-etag": "^3.0.0",
+ "@types/koa-static": "^4.0.1",
+ "@types/parse5": "^6.0.1",
"abort-controller": "^3.0.0",
"express": "^4.21.2",
"nanoid": "^3.1.25",
diff --git a/packages/dev-server-core/test/helpers.ts b/packages/dev-server-core/test/helpers.ts
index c9e826faf0..31bf8cf8f3 100644
--- a/packages/dev-server-core/test/helpers.ts
+++ b/packages/dev-server-core/test/helpers.ts
@@ -5,8 +5,32 @@ import {
fetchText,
expectIncludes,
virtualFilesPlugin,
+<<<<<<< HEAD
+} from '../src/test-helpers.js';
+<<<<<<< HEAD
+import { DevServerCoreConfig } from '../src/server/DevServerCoreConfig.ts';
+||||||| parent of aecfa949 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import { DevServerCoreConfig } from '../src/server/DevServerCoreConfig.js';
+=======
+import { DevServerCoreConfig } from '../src/server/DevServerCoreConfig.js';
+||||||| parent of c37bb778 (chore: migrate tests from mocha/chai to node:test + node:assert)
+} from '../src/test-helpers.ts';
+import { DevServerCoreConfig } from '../src/server/DevServerCoreConfig.ts';
+=======
+<<<<<<< HEAD
} from '../src/test-helpers.ts';
import { DevServerCoreConfig } from '../src/server/DevServerCoreConfig.ts';
+||||||| parent of 61bf92a0 (chore: migrate tests from mocha/chai to node:test + node:assert)
+} from '../src/test-helpers.js';
+import { DevServerCoreConfig } from '../src/server/DevServerCoreConfig.js';
+=======
+} from '../src/test-helpers.ts';
+import type { DevServerCoreConfig } from '../src/server/DevServerCoreConfig.ts';
+
+const __dirname = import.meta.dirname;
+>>>>>>> 61bf92a0 (chore: migrate tests from mocha/chai to node:test + node:assert)
+>>>>>>> c37bb778 (chore: migrate tests from mocha/chai to node:test + node:assert)
+>>>>>>> aecfa949 (chore: migrate tests from mocha/chai to node:test + node:assert)
export function createTestServer(config: Partial = {}) {
return originalCreateTestServer({
diff --git a/packages/dev-server-core/test/middleware/basePathMiddleware.test.ts b/packages/dev-server-core/test/middleware/basePathMiddleware.test.ts
index ca7d509d58..0c2a7dc387 100644
--- a/packages/dev-server-core/test/middleware/basePathMiddleware.test.ts
+++ b/packages/dev-server-core/test/middleware/basePathMiddleware.test.ts
@@ -1,4 +1,5 @@
-import { expect } from 'chai';
+import { describe, it, beforeEach, afterEach } from 'node:test';
+import assert from 'node:assert/strict';
import { DevServer } from '../../src/server/DevServer.ts';
import { createTestServer } from '../helpers.ts';
@@ -19,20 +20,20 @@ describe('base path middleware', () => {
const response = await fetch(`${host}/foo/index.html`);
const responseText = await response.text();
- expect(response.status).to.equal(200);
- expect(responseText).to.include('My app ');
+ assert.strictEqual(response.status, 200);
+ assert.ok(responseText.includes('My app '));
});
it('can request without base path', async () => {
const response = await fetch(`${host}/index.html`);
const responseText = await response.text();
- expect(response.status).to.equal(200);
- expect(responseText).to.include('My app ');
+ assert.strictEqual(response.status, 200);
+ assert.ok(responseText.includes('My app '));
});
});
- context('with a trailing /', () => {
+ describe('with a trailing /', () => {
let host: string;
let server: DevServer;
beforeEach(async () => {
@@ -47,16 +48,16 @@ describe('base path middleware', () => {
const response = await fetch(`${host}/foo/index.html`);
const responseText = await response.text();
- expect(response.status).to.equal(200);
- expect(responseText).to.include('My app ');
+ assert.strictEqual(response.status, 200);
+ assert.ok(responseText.includes('My app '));
});
it('can request without base path', async () => {
const response = await fetch(`${host}/index.html`);
const responseText = await response.text();
- expect(response.status).to.equal(200);
- expect(responseText).to.include('My app ');
+ assert.strictEqual(response.status, 200);
+ assert.ok(responseText.includes('My app '));
});
});
});
diff --git a/packages/dev-server-core/test/middleware/etagCacheMiddleware.test.ts b/packages/dev-server-core/test/middleware/etagCacheMiddleware.test.ts
index fb985b48a6..747b7d1140 100644
--- a/packages/dev-server-core/test/middleware/etagCacheMiddleware.test.ts
+++ b/packages/dev-server-core/test/middleware/etagCacheMiddleware.test.ts
@@ -1,4 +1,5 @@
-import { expect } from 'chai';
+import { describe, it, beforeEach, afterEach } from 'node:test';
+import assert from 'node:assert/strict';
import path from 'path';
import fs from 'fs';
import { nanoid } from 'nanoid';
@@ -6,6 +7,7 @@ import { nanoid } from 'nanoid';
import { createTestServer, timeout } from '../helpers.ts';
import { DevServer } from '../../src/server/DevServer.ts';
+const __dirname = import.meta.dirname;
const fixtureDir = path.resolve(__dirname, '..', 'fixtures', 'basic');
const testFileAName = '/cached-file-a.js';
const testFileBName = '/cached-file-b.js';
@@ -24,7 +26,7 @@ describe('etag cache middleware', () => {
server.stop();
});
- context('', () => {
+ describe('', () => {
beforeEach(() => {
fs.writeFileSync(testFileAPath, '// this file is cached', 'utf-8');
});
@@ -37,21 +39,21 @@ describe('etag cache middleware', () => {
const initialResponse = await fetch(`${host}${testFileAName}`);
const etag = initialResponse.headers.get('etag')!;
- expect(initialResponse.status).to.equal(200);
- expect(await initialResponse.text()).to.equal('// this file is cached');
+ assert.strictEqual(initialResponse.status, 200);
+ assert.strictEqual(await initialResponse.text(), '// this file is cached');
- expect(etag).to.be.a('string');
+ assert.strictEqual(typeof etag, 'string');
const cachedResponse = await fetch(`${host}${testFileAName}`, {
headers: { 'If-None-Match': etag, 'Cache-Control': 'max-age=3600' },
});
- expect(cachedResponse.status).to.equal(304);
- expect(await cachedResponse.text()).to.equal('');
+ assert.strictEqual(cachedResponse.status, 304);
+ assert.strictEqual(await cachedResponse.text(), '');
});
});
- context('', () => {
+ describe('', () => {
beforeEach(() => {
fs.writeFileSync(testFileBPath, '// this file is cached', 'utf-8');
});
@@ -66,9 +68,9 @@ describe('etag cache middleware', () => {
const initialResponse = await fetch(`${host}${testFileBName}`);
const etag = initialResponse.headers.get('etag');
- expect(initialResponse.status).to.equal(200);
- expect(await initialResponse.text()).to.equal('// this file is cached');
- expect(etag).to.be.a('string');
+ assert.strictEqual(initialResponse.status, 200);
+ assert.strictEqual(await initialResponse.text(), '// this file is cached');
+ assert.strictEqual(typeof etag, 'string');
await timeout(10);
const fileContent = `// the cache is busted${nanoid()}`;
@@ -78,8 +80,8 @@ describe('etag cache middleware', () => {
const headers = { headers: { 'if-none-match': etag } as Record };
const cachedResponse = await fetch(`${host}${testFileBName}`, headers);
- expect(cachedResponse.status).to.equal(200);
- expect(await cachedResponse.text()).to.equal(fileContent);
+ assert.strictEqual(cachedResponse.status, 200);
+ assert.strictEqual(await cachedResponse.text(), fileContent);
});
});
});
diff --git a/packages/dev-server-core/test/middleware/historyApiFallbackMiddleware.test.ts b/packages/dev-server-core/test/middleware/historyApiFallbackMiddleware.test.ts
index ede99416bb..e0ca8795de 100644
--- a/packages/dev-server-core/test/middleware/historyApiFallbackMiddleware.test.ts
+++ b/packages/dev-server-core/test/middleware/historyApiFallbackMiddleware.test.ts
@@ -1,8 +1,35 @@
-import { expect } from 'chai';
+import { describe, it, beforeEach, afterEach } from 'node:test';
+import assert from 'node:assert/strict';
import path from 'path';
+<<<<<<< HEAD
import { createTestServer } from '../helpers.ts';
import { DevServer } from '../../src/server/DevServer.ts';
+||||||| parent of aecfa949 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import { createTestServer } from '../helpers.js';
+import { DevServer } from '../../src/server/DevServer.js';
+=======
+<<<<<<< HEAD
+import { createTestServer } from '../helpers.js';
+import { DevServer } from '../../src/server/DevServer.js';
+||||||| parent of c37bb778 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import { createTestServer } from '../helpers.ts';
+import { DevServer } from '../../src/server/DevServer.ts';
+=======
+<<<<<<< HEAD
+import { createTestServer } from '../helpers.ts';
+import { DevServer } from '../../src/server/DevServer.ts';
+||||||| parent of 61bf92a0 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import { createTestServer } from '../helpers.js';
+import { DevServer } from '../../src/server/DevServer.js';
+=======
+import { createTestServer } from '../helpers.ts';
+import { DevServer } from '../../src/server/DevServer.ts';
+
+const __dirname = import.meta.dirname;
+>>>>>>> 61bf92a0 (chore: migrate tests from mocha/chai to node:test + node:assert)
+>>>>>>> c37bb778 (chore: migrate tests from mocha/chai to node:test + node:assert)
+>>>>>>> aecfa949 (chore: migrate tests from mocha/chai to node:test + node:assert)
describe('history api fallback middleware', () => {
describe('index in root', () => {
@@ -23,41 +50,41 @@ describe('history api fallback middleware', () => {
const response = await fetch(`${host}/index.html`);
const responseText = await response.text();
- expect(response.status).to.equal(200);
- expect(responseText).to.include('My app ');
+ assert.strictEqual(response.status, 200);
+ assert.ok(responseText.includes('My app '));
});
it('returns the fallback index.html for non-file requests', async () => {
const response = await fetch(`${host}/foo`);
const responseText = await response.text();
- expect(response.status).to.equal(200);
- expect(responseText).to.include('My app ');
+ assert.strictEqual(response.status, 200);
+ assert.ok(responseText.includes('My app '));
});
it('returns the fallback index.html for file requests with multiple segments', async () => {
const response = await fetch(`${host}/foo/bar/baz`);
const responseText = await response.text();
- expect(response.status).to.equal(200);
- expect(responseText).to.include('My app ');
+ assert.strictEqual(response.status, 200);
+ assert.ok(responseText.includes('My app '));
});
it('does not return index.html for file requests', async () => {
const response = await fetch(`${host}/src/hello-world.txt`);
const responseText = await response.text();
- expect(response.status).to.equal(200);
- expect(responseText).to.include('Hello world!');
- expect(responseText).to.not.include('My app ');
+ assert.strictEqual(response.status, 200);
+ assert.ok(responseText.includes('Hello world!'));
+ assert.ok(!responseText.includes('My app '));
});
it('does return index.html for requests that have url parameters with . characters (issue 1059)', async () => {
const response = await fetch(`${host}/text-files/foo/bar/?baz=open.wc`);
const responseText = await response.text();
- expect(response.status).to.equal(200);
- expect(responseText).to.include('My app ');
+ assert.strictEqual(response.status, 200);
+ assert.ok(responseText.includes('My app '));
});
});
@@ -79,40 +106,40 @@ describe('history api fallback middleware', () => {
const response = await fetch(`${host}/src/index.html`);
const responseText = await response.text();
- expect(response.status).to.equal(200);
- expect(responseText).to.include('My app 2 ');
+ assert.strictEqual(response.status, 200);
+ assert.ok(responseText.includes('My app 2 '));
});
it('returns the fallback index.html for non-file requests', async () => {
const response = await fetch(`${host}/src/foo`);
const responseText = await response.text();
- expect(response.status).to.equal(200);
- expect(responseText).to.include('My app 2 ');
+ assert.strictEqual(response.status, 200);
+ assert.ok(responseText.includes('My app 2 '));
});
it('returns the fallback index.html for file requests with multiple segments', async () => {
const response = await fetch(`${host}/src/foo/bar/baz`);
const responseText = await response.text();
- expect(response.status).to.equal(200);
- expect(responseText).to.include('My app 2 ');
+ assert.strictEqual(response.status, 200);
+ assert.ok(responseText.includes('My app 2 '));
});
it('does not return the index.html for requests outside the index root', async () => {
const response = await fetch(`${host}/foo`);
const responseText = await response.text();
- expect(response.status).to.equal(404);
- expect(responseText).to.not.include('My app 2 ');
+ assert.strictEqual(response.status, 404);
+ assert.ok(!responseText.includes('My app 2 '));
});
it('does return index.html for requests that have url parameters with . characters (issue 1059)', async () => {
const response = await fetch(`${host}/src/foo/bar/?baz=open.wc`);
const responseText = await response.text();
- expect(response.status).to.equal(200);
- expect(responseText).to.include('My app 2 ');
+ assert.strictEqual(response.status, 200);
+ assert.ok(responseText.includes('My app 2 '));
});
});
});
diff --git a/packages/dev-server-core/test/middleware/pluginFileParsedMiddleware.test.ts b/packages/dev-server-core/test/middleware/pluginFileParsedMiddleware.test.ts
index d1b4bdaf17..e23357a159 100644
--- a/packages/dev-server-core/test/middleware/pluginFileParsedMiddleware.test.ts
+++ b/packages/dev-server-core/test/middleware/pluginFileParsedMiddleware.test.ts
@@ -1,5 +1,6 @@
-import { expect } from 'chai';
-import { Context } from 'koa';
+import { describe, it } from 'node:test';
+import assert from 'node:assert/strict';
+import type { Context } from 'koa';
import { createTestServer } from '../helpers.ts';
@@ -44,11 +45,11 @@ describe('plugin-file-parsed middleware', () => {
try {
const response = await fetch(`${host}/foo.js`);
- expect(response.status).to.equal(200);
- expect(response.headers.get('content-type')).to.include('application/javascript');
- expect(order[order.length - 1]).to.equal('fileParsed');
- expect(context).to.exist;
- expect(context!.path).to.equal('/foo.js');
+ assert.strictEqual(response.status, 200);
+ assert.ok(response.headers.get('content-type')?.includes('application/javascript'));
+ assert.strictEqual(order[order.length - 1], 'fileParsed');
+ assert.ok(context !== undefined);
+ assert.strictEqual(context!.path, '/foo.js');
} finally {
server.stop();
}
diff --git a/packages/dev-server-core/test/middleware/pluginMimeTypeMiddleware.test.ts b/packages/dev-server-core/test/middleware/pluginMimeTypeMiddleware.test.ts
index 35649d3172..43a94ed9cf 100644
--- a/packages/dev-server-core/test/middleware/pluginMimeTypeMiddleware.test.ts
+++ b/packages/dev-server-core/test/middleware/pluginMimeTypeMiddleware.test.ts
@@ -1,4 +1,5 @@
-import { expect } from 'chai';
+import { describe, it } from 'node:test';
+import assert from 'node:assert/strict';
import { createTestServer } from '../helpers.ts';
@@ -20,8 +21,8 @@ describe('plugin-mime-type middleware', () => {
try {
const response = await fetch(`${host}/src/hello-world.txt`);
- expect(response.status).to.equal(200);
- expect(response.headers.get('content-type')).to.include('application/javascript');
+ assert.strictEqual(response.status, 200);
+ assert.ok(response.headers.get('content-type')?.includes('application/javascript'));
} finally {
server.stop();
}
@@ -44,8 +45,8 @@ describe('plugin-mime-type middleware', () => {
try {
const response = await fetch(`${host}/src/hello-world.txt`);
- expect(response.status).to.equal(200);
- expect(response.headers.get('content-type')).to.include('application/javascript');
+ assert.strictEqual(response.status, 200);
+ assert.ok(response.headers.get('content-type')?.includes('application/javascript'));
} finally {
server.stop();
}
diff --git a/packages/dev-server-core/test/middleware/pluginServeMiddleware.test.ts b/packages/dev-server-core/test/middleware/pluginServeMiddleware.test.ts
index 41c1687480..5275813fec 100644
--- a/packages/dev-server-core/test/middleware/pluginServeMiddleware.test.ts
+++ b/packages/dev-server-core/test/middleware/pluginServeMiddleware.test.ts
@@ -1,4 +1,5 @@
-import { expect } from 'chai';
+import { describe, it } from 'node:test';
+import assert from 'node:assert/strict';
import { createTestServer } from '../helpers.ts';
@@ -21,8 +22,8 @@ describe('plugin-serve middleware', () => {
const response = await fetch(`${host}/non-existing.js`);
const responseText = await response.text();
- expect(response.status).to.equal(200);
- expect(responseText).to.include('serving non-existing.js');
+ assert.strictEqual(response.status, 200);
+ assert.ok(responseText.includes('serving non-existing.js'));
} finally {
server.stop();
}
@@ -54,8 +55,8 @@ describe('plugin-serve middleware', () => {
const response = await fetch(`${host}/non-existing.js`);
const responseText = await response.text();
- expect(response.status).to.equal(200);
- expect(responseText).to.include('serve a');
+ assert.strictEqual(response.status, 200);
+ assert.ok(responseText.includes('serve a'));
} finally {
server.stop();
}
@@ -79,9 +80,10 @@ describe('plugin-serve middleware', () => {
const response = await fetch(`${host}/non-existing.js`);
const responseText = await response.text();
- expect(response.status).to.equal(200);
- expect(responseText).to.include('serving non-existing.js');
- expect(response.headers.get('content-type')).to.equal(
+ assert.strictEqual(response.status, 200);
+ assert.ok(responseText.includes('serving non-existing.js'));
+ assert.strictEqual(
+ response.headers.get('content-type'),
'application/javascript; charset=utf-8',
);
} finally {
@@ -105,8 +107,8 @@ describe('plugin-serve middleware', () => {
try {
const response = await fetch(`${host}/foo.bar`);
- expect(response.status).to.equal(200);
- expect(response.headers.get('content-type')).to.equal('text/css; charset=utf-8');
+ assert.strictEqual(response.status, 200);
+ assert.strictEqual(response.headers.get('content-type'), 'text/css; charset=utf-8');
} finally {
server.stop();
}
@@ -130,8 +132,8 @@ describe('plugin-serve middleware', () => {
const response = await fetch(`${host}/index.html`);
const responseText = await response.text();
- expect(response.status).to.equal(200);
- expect(responseText).to.include('overwritten index.html');
+ assert.strictEqual(response.status, 200);
+ assert.ok(responseText.includes('overwritten index.html'));
} finally {
server.stop();
}
@@ -154,8 +156,8 @@ describe('plugin-serve middleware', () => {
try {
const response = await fetch(`${host}/index.html`);
- expect(response.status).to.equal(200);
- expect(response.headers.get('x-foo')).to.equal('bar');
+ assert.strictEqual(response.status, 200);
+ assert.strictEqual(response.headers.get('x-foo'), 'bar');
} finally {
server.stop();
}
@@ -179,8 +181,8 @@ describe('plugin-serve middleware', () => {
const response = await fetch(`${host}/non-existing.js`);
const responseText = await response.text();
- expect(response.status).to.equal(200);
- expect(responseText).to.include('serving non-existing.js');
+ assert.strictEqual(response.status, 200);
+ assert.ok(responseText.includes('serving non-existing.js'));
} finally {
server.stop();
}
diff --git a/packages/dev-server-core/test/middleware/pluginTransformMiddleware.test.ts b/packages/dev-server-core/test/middleware/pluginTransformMiddleware.test.ts
index f807ec85c8..1bb7c74446 100644
--- a/packages/dev-server-core/test/middleware/pluginTransformMiddleware.test.ts
+++ b/packages/dev-server-core/test/middleware/pluginTransformMiddleware.test.ts
@@ -1,5 +1,6 @@
/* eslint-disable no-restricted-syntax, no-await-in-loop */
-import { expect } from 'chai';
+import { describe, it } from 'node:test';
+import assert from 'node:assert/strict';
import { createTestServer } from '../helpers.ts';
import { fetchText, expectIncludes } from '../../src/test-helpers.ts';
@@ -23,8 +24,8 @@ describe('plugin-transform middleware', () => {
const response = await fetch(`${host}/src/hello-world.txt`);
const responseText = await response.text();
- expect(response.status).to.equal(200);
- expect(responseText).to.equal('Hello world! injected text');
+ assert.strictEqual(response.status, 200);
+ assert.strictEqual(responseText, 'Hello world! injected text');
} finally {
server.stop();
}
@@ -54,8 +55,8 @@ describe('plugin-transform middleware', () => {
const response = await fetch(`${host}/non-existing.js`);
const responseText = await response.text();
- expect(response.status).to.equal(200);
- expect(responseText).to.equal('my non existing file injected text');
+ assert.strictEqual(response.status, 200);
+ assert.strictEqual(responseText, 'my non existing file injected text');
} finally {
server.stop();
}
@@ -87,8 +88,8 @@ describe('plugin-transform middleware', () => {
const response = await fetch(`${host}/src/hello-world.txt`);
const responseText = await response.text();
- expect(response.status).to.equal(200);
- expect(responseText).to.equal('Hello world! INJECT_A INJECT_B');
+ assert.strictEqual(response.status, 200);
+ assert.strictEqual(responseText, 'Hello world! INJECT_A INJECT_B');
} finally {
server.stop();
}
@@ -112,8 +113,8 @@ describe('plugin-transform middleware', () => {
const response = await fetch(`${host}/non-existing.js`);
const responseText = await response.text();
- expect(response.status).to.equal(404);
- expect(responseText).to.equal('Not Found');
+ assert.strictEqual(response.status, 404);
+ assert.strictEqual(responseText, 'Not Found');
} finally {
server.stop();
}
@@ -136,8 +137,8 @@ describe('plugin-transform middleware', () => {
try {
const response = await fetch(`${host}/index.html`);
- expect(response.status).to.equal(200);
- expect(response.headers.get('x-foo')).to.equal('bar');
+ assert.strictEqual(response.status, 200);
+ assert.strictEqual(response.headers.get('x-foo'), 'bar');
} finally {
server.stop();
}
@@ -164,7 +165,7 @@ describe('plugin-transform middleware', () => {
const responseTwo = await fetch(`${host}/src/hello-world.txt`);
const timestampTwo = await responseTwo.text();
- expect(timestampOne).equal(timestampTwo);
+ assert.strictEqual(timestampOne, timestampTwo);
} finally {
server.stop();
}
@@ -195,10 +196,11 @@ describe('plugin-transform middleware', () => {
const textTwo = await responseTwo.text();
const headersTwo = responseTwo.headers;
- expect(textOne).equal('console.log("foo")');
- expect(textTwo).equal('console.log("foo")');
- expect(headersOne.get('x-foo')).eql('bar');
- expect(Object.fromEntries(headersOne.entries())).eql(
+ assert.strictEqual(textOne, 'console.log("foo")');
+ assert.strictEqual(textTwo, 'console.log("foo")');
+ assert.deepStrictEqual(headersOne.get('x-foo'), 'bar');
+ assert.deepStrictEqual(
+ Object.fromEntries(headersOne.entries()),
Object.fromEntries(headersTwo.entries()),
);
} finally {
@@ -227,7 +229,7 @@ describe('plugin-transform middleware', () => {
const responseTwo = await fetch(`${host}/src/hello-world.txt`);
const timestampTwo = await responseTwo.text();
- expect(timestampOne).to.not.equal(timestampTwo);
+ assert.notStrictEqual(timestampOne, timestampTwo);
} finally {
server.stop();
}
@@ -251,8 +253,8 @@ describe('plugin-transform middleware', () => {
const response = await fetch(`${host}/src/hello-world.txt`);
const responseText = await response.text();
- expect(response.status).to.equal(200);
- expect(responseText).to.equal('Hello world! injected text');
+ assert.strictEqual(response.status, 200);
+ assert.strictEqual(responseText, 'Hello world! injected text');
} finally {
server.stop();
}
@@ -305,13 +307,13 @@ describe('plugin-transform middleware', () => {
headers: { 'user-agent': 'agent-a' },
});
expectIncludes(responseA2, 'Hello world! injected text A 1');
- expect(callCountA).to.equal(1);
+ assert.strictEqual(callCountA, 1);
const responseB2 = await fetchText(`${host}/src/hello-world.txt`, {
headers: { 'user-agent': 'agent-b' },
});
expectIncludes(responseB2, 'Hello world! injected text B 1');
- expect(callCountB).to.equal(1);
+ assert.strictEqual(callCountB, 1);
} finally {
server.stop();
}
diff --git a/packages/dev-server-core/test/middleware/serveFilesMiddleware.test.ts b/packages/dev-server-core/test/middleware/serveFilesMiddleware.test.ts
index 39432a013a..733e0f2c0d 100644
--- a/packages/dev-server-core/test/middleware/serveFilesMiddleware.test.ts
+++ b/packages/dev-server-core/test/middleware/serveFilesMiddleware.test.ts
@@ -1,7 +1,28 @@
-import { expect } from 'chai';
+import { describe, it } from 'node:test';
+import assert from 'node:assert/strict';
import path from 'path';
+<<<<<<< HEAD
import { createTestServer } from '../helpers.ts';
+||||||| parent of aecfa949 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import { createTestServer } from '../helpers.js';
+=======
+<<<<<<< HEAD
+import { createTestServer } from '../helpers.js';
+||||||| parent of c37bb778 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import { createTestServer } from '../helpers.ts';
+=======
+<<<<<<< HEAD
+import { createTestServer } from '../helpers.ts';
+||||||| parent of 61bf92a0 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import { createTestServer } from '../helpers.js';
+=======
+import { createTestServer } from '../helpers.ts';
+
+const __dirname = import.meta.dirname;
+>>>>>>> 61bf92a0 (chore: migrate tests from mocha/chai to node:test + node:assert)
+>>>>>>> c37bb778 (chore: migrate tests from mocha/chai to node:test + node:assert)
+>>>>>>> aecfa949 (chore: migrate tests from mocha/chai to node:test + node:assert)
describe('serveFilesMiddleware', () => {
it('can serve files outside of the root directory', async () => {
@@ -21,8 +42,8 @@ describe('serveFilesMiddleware', () => {
const response = await fetch(`${host}/__wds-outside-root__/2/node_modules/foo/index.js`);
const responseText = await response.text();
- expect(response.status).to.equal(200);
- expect(responseText).to.include("export default 'foo'");
+ assert.strictEqual(response.status, 200);
+ assert.ok(responseText.includes("export default 'foo'"));
} finally {
server.stop();
}
diff --git a/packages/dev-server-core/test/plugins/mimeTypesPlugin.test.ts b/packages/dev-server-core/test/plugins/mimeTypesPlugin.test.ts
index 88c25372af..e530da6f53 100644
--- a/packages/dev-server-core/test/plugins/mimeTypesPlugin.test.ts
+++ b/packages/dev-server-core/test/plugins/mimeTypesPlugin.test.ts
@@ -1,6 +1,28 @@
-import { expect } from 'chai';
+import { describe, it } from 'node:test';
+import assert from 'node:assert/strict';
+import path from 'path';
+<<<<<<< HEAD
import { createTestServer } from '../helpers.ts';
+||||||| parent of aecfa949 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import { createTestServer } from '../helpers.js';
+=======
+<<<<<<< HEAD
+import { createTestServer } from '../helpers.js';
+||||||| parent of c37bb778 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import { createTestServer } from '../helpers.ts';
+=======
+<<<<<<< HEAD
+import { createTestServer } from '../helpers.ts';
+||||||| parent of 61bf92a0 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import { createTestServer } from '../helpers.js';
+=======
+import { createTestServer } from '../helpers.ts';
+
+const __dirname = import.meta.dirname;
+>>>>>>> 61bf92a0 (chore: migrate tests from mocha/chai to node:test + node:assert)
+>>>>>>> c37bb778 (chore: migrate tests from mocha/chai to node:test + node:assert)
+>>>>>>> aecfa949 (chore: migrate tests from mocha/chai to node:test + node:assert)
describe('mimeTypesPLugin', () => {
it('can configure mime types for files', async () => {
@@ -22,8 +44,9 @@ describe('mimeTypesPLugin', () => {
try {
const response = await fetch(`${host}/foo.css`);
- expect(response.status).to.equal(200);
- expect(response.headers.get('content-type')).to.equal(
+ assert.strictEqual(response.status, 200);
+ assert.strictEqual(
+ response.headers.get('content-type'),
'application/javascript; charset=utf-8',
);
} finally {
@@ -51,14 +74,16 @@ describe('mimeTypesPLugin', () => {
try {
const responseA = await fetch(`${host}/foo.css`);
- expect(responseA.status).to.equal(200);
- expect(responseA.headers.get('content-type')).to.equal(
+ assert.strictEqual(responseA.status, 200);
+ assert.strictEqual(
+ responseA.headers.get('content-type'),
'application/javascript; charset=utf-8',
);
const responseB = await fetch(`${host}/x/foo.css`);
- expect(responseB.status).to.equal(200);
- expect(responseB.headers.get('content-type')).not.to.equal(
+ assert.strictEqual(responseB.status, 200);
+ assert.notStrictEqual(
+ responseB.headers.get('content-type'),
'application/javascript; charset=utf-8',
);
} finally {
diff --git a/packages/dev-server-core/test/plugins/parseDynamicImport.test.ts b/packages/dev-server-core/test/plugins/parseDynamicImport.test.ts
index 4ca285e32f..c2a24b75e0 100644
--- a/packages/dev-server-core/test/plugins/parseDynamicImport.test.ts
+++ b/packages/dev-server-core/test/plugins/parseDynamicImport.test.ts
@@ -1,5 +1,26 @@
+<<<<<<< HEAD
import { expect } from 'chai';
+<<<<<<< HEAD
+import { parseDynamicImport } from '../../src/plugins/parseDynamicImport.js';
+||||||| parent of c37bb778 (chore: migrate tests from mocha/chai to node:test + node:assert)
import { parseDynamicImport } from '../../src/plugins/parseDynamicImport.ts';
+=======
+import { parseDynamicImport } from '../../src/plugins/parseDynamicImport.ts';
+||||||| parent of 61bf92a0 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import { expect } from 'chai';
+<<<<<<< HEAD
+import { parseDynamicImport } from '../../src/plugins/parseDynamicImport.ts';
+||||||| parent of aecfa949 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import { parseDynamicImport } from '../../src/plugins/parseDynamicImport.js';
+=======
+import { parseDynamicImport } from '../../src/plugins/parseDynamicImport.js';
+=======
+import { describe, it } from 'node:test';
+import assert from 'node:assert/strict';
+import { parseDynamicImport } from '../../src/plugins/parseDynamicImport.ts';
+>>>>>>> 61bf92a0 (chore: migrate tests from mocha/chai to node:test + node:assert)
+>>>>>>> c37bb778 (chore: migrate tests from mocha/chai to node:test + node:assert)
+>>>>>>> aecfa949 (chore: migrate tests from mocha/chai to node:test + node:assert)
describe('parseDynamicImport', () => {
function testParseDynamicImport(specifier: string) {
@@ -9,7 +30,7 @@ describe('parseDynamicImport', () => {
it('works for " string literals', () => {
const importStringA = '"./a.js"';
- expect(testParseDynamicImport(importStringA)).to.eql({
+ assert.deepStrictEqual(testParseDynamicImport(importStringA), {
importString: importStringA,
importSpecifier: './a.js',
concatenatedString: false,
@@ -19,7 +40,7 @@ describe('parseDynamicImport', () => {
});
const importStringB = '"./a/b/c.js"';
- expect(testParseDynamicImport(importStringB)).to.eql({
+ assert.deepStrictEqual(testParseDynamicImport(importStringB), {
importString: importStringB,
importSpecifier: './a/b/c.js',
concatenatedString: false,
@@ -29,7 +50,7 @@ describe('parseDynamicImport', () => {
});
const importStringC = '"/a/b.js"';
- expect(testParseDynamicImport(importStringC)).to.eql({
+ assert.deepStrictEqual(testParseDynamicImport(importStringC), {
importString: importStringC,
importSpecifier: '/a/b.js',
concatenatedString: false,
@@ -41,7 +62,7 @@ describe('parseDynamicImport', () => {
it("works for ' string literals", () => {
const importString = "'./a.js'";
- expect(testParseDynamicImport(importString)).to.eql({
+ assert.deepStrictEqual(testParseDynamicImport(importString), {
importString,
importSpecifier: './a.js',
concatenatedString: false,
@@ -53,7 +74,7 @@ describe('parseDynamicImport', () => {
it('works for singlecharacter string literals', () => {
const importString = "'a.js'";
- expect(testParseDynamicImport(importString)).to.eql({
+ assert.deepStrictEqual(testParseDynamicImport(importString), {
importString,
importSpecifier: 'a.js',
concatenatedString: false,
@@ -65,7 +86,7 @@ describe('parseDynamicImport', () => {
it('works for ` string literals', () => {
const importString = '`./a/b.js`';
- expect(testParseDynamicImport(importString)).to.eql({
+ assert.deepStrictEqual(testParseDynamicImport(importString), {
importString,
importSpecifier: './a/b.js',
concatenatedString: true,
@@ -77,7 +98,7 @@ describe('parseDynamicImport', () => {
it('works for concatenated strings', () => {
const importStringA = "'./a' + '.js'";
- expect(testParseDynamicImport(importStringA)).to.eql({
+ assert.deepStrictEqual(testParseDynamicImport(importStringA), {
importString: importStringA,
importSpecifier: "./a' + '.js",
concatenatedString: true,
@@ -87,7 +108,7 @@ describe('parseDynamicImport', () => {
});
const importStringB = '"./a" + "/b/" + "c.js"';
- expect(testParseDynamicImport(importStringB)).to.eql({
+ assert.deepStrictEqual(testParseDynamicImport(importStringB), {
importString: importStringB,
importSpecifier: './a" + "/b/" + "c.js',
concatenatedString: true,
@@ -99,7 +120,7 @@ describe('parseDynamicImport', () => {
it('works for interpolated string literals', () => {
const importString = '`./a/${file}.js`';
- expect(testParseDynamicImport(importString)).to.eql({
+ assert.deepStrictEqual(testParseDynamicImport(importString), {
importString,
importSpecifier: './a/${file}.js',
concatenatedString: true,
@@ -111,7 +132,7 @@ describe('parseDynamicImport', () => {
it('works for variables', () => {
const importString = 'foo';
- expect(testParseDynamicImport(importString)).to.eql({
+ assert.deepStrictEqual(testParseDynamicImport(importString), {
importString,
importSpecifier: 'foo',
concatenatedString: false,
@@ -123,7 +144,7 @@ describe('parseDynamicImport', () => {
it('works for single character variables', () => {
const importString = 'a';
- expect(testParseDynamicImport(importString)).to.eql({
+ assert.deepStrictEqual(testParseDynamicImport(importString), {
importString,
importSpecifier: 'a',
concatenatedString: false,
@@ -135,7 +156,7 @@ describe('parseDynamicImport', () => {
it('works for variables with concatenation', () => {
const importString = 'foo + "x.js"';
- expect(testParseDynamicImport(importString)).to.eql({
+ assert.deepStrictEqual(testParseDynamicImport(importString), {
importString,
importSpecifier: 'foo + "x.js"',
concatenatedString: true,
@@ -147,7 +168,7 @@ describe('parseDynamicImport', () => {
it('works for string literals with spaces or newlines', () => {
const importStringA = ' "./a.js" ';
- expect(testParseDynamicImport(importStringA)).to.eql({
+ assert.deepStrictEqual(testParseDynamicImport(importStringA), {
importString: '"./a.js"',
importSpecifier: './a.js',
concatenatedString: false,
@@ -157,7 +178,7 @@ describe('parseDynamicImport', () => {
});
const importStringB = '\n "./a.js"\n ';
- expect(testParseDynamicImport(importStringB)).to.eql({
+ assert.deepStrictEqual(testParseDynamicImport(importStringB), {
importString: '"./a.js"',
importSpecifier: './a.js',
concatenatedString: false,
@@ -169,7 +190,7 @@ describe('parseDynamicImport', () => {
it('works for template strings with spaces or newlines', () => {
const importStringA = '\n `./x/${file}.js`\n ';
- expect(testParseDynamicImport(importStringA)).to.eql({
+ assert.deepStrictEqual(testParseDynamicImport(importStringA), {
importString: '`./x/${file}.js`',
importSpecifier: './x/${file}.js',
concatenatedString: true,
diff --git a/packages/dev-server-core/test/plugins/transformModuleImportsPlugin.test.ts b/packages/dev-server-core/test/plugins/transformModuleImportsPlugin.test.ts
index 471c1952b5..fce26e480f 100644
--- a/packages/dev-server-core/test/plugins/transformModuleImportsPlugin.test.ts
+++ b/packages/dev-server-core/test/plugins/transformModuleImportsPlugin.test.ts
@@ -1,4 +1,5 @@
-import { expect } from 'chai';
+import { describe, it } from 'node:test';
+import assert from 'node:assert/strict';
import { transformImports } from '../../src/plugins/transformModuleImportsPlugin.ts';
import type { PluginSyntaxError } from '../../src/logger/PluginSyntaxError.ts';
@@ -21,7 +22,7 @@ describe('transformImports()', () => {
defaultResolveImport,
);
- expect(result.split('\n')).to.eql([
+ assert.deepStrictEqual(result.split('\n'),[
'import "RESOLVED__my-module";',
'import foo from "RESOLVED__my-module";',
'import { bar } from "RESOLVED__my-module";',
@@ -41,7 +42,7 @@ describe('transformImports()', () => {
defaultResolveImport,
);
- expect(result.split('\n')).to.eql([
+ assert.deepStrictEqual(result.split('\n'),[
//
"export * from 'RESOLVED__my-module';",
"export { foo } from 'RESOLVED__my-module';",
@@ -55,7 +56,7 @@ describe('transformImports()', () => {
defaultResolveImport,
);
- expect(result).to.eql("import 'RESOLVED__my-module/bar/index.js");
+ assert.deepStrictEqual(result, "import 'RESOLVED__my-module/bar/index.js");
});
it('resolves dynamic imports', async () => {
@@ -70,7 +71,7 @@ describe('transformImports()', () => {
defaultResolveImport,
);
- expect(result.split('\n')).to.eql([
+ assert.deepStrictEqual(result.split('\n'),[
'import("RESOLVED__/bar.js");',
// 'function lazyLoad() { return import("RESOLVED__my-module-2"); }',
// 'import("RESOLVED__my-module");',
@@ -89,7 +90,7 @@ describe('transformImports()', () => {
defaultResolveImport,
);
- expect(result.split('\n')).to.eql([
+ assert.deepStrictEqual(result.split('\n'),[
'console.log(import.meta.url);',
"import 'RESOLVED__my-module';",
]);
@@ -106,7 +107,7 @@ describe('transformImports()', () => {
defaultResolveImport,
);
- expect(result.split('\n')).to.eql([
+ assert.deepStrictEqual(result.split('\n'),[
"import 'RESOLVED__my-module';",
"// Example: import('my-module');",
]);
@@ -125,7 +126,7 @@ describe('transformImports()', () => {
defaultResolveImport,
);
- expect(result.split('\n')).to.eql([
+ assert.deepStrictEqual(result.split('\n'),[
'function myimport() { }',
'function my_import() { }',
'function importShim() { }',
@@ -147,7 +148,7 @@ describe('transformImports()', () => {
defaultResolveImport,
);
- expect(result.split('\n')).to.eql([
+ assert.deepStrictEqual(result.split('\n'),[
'import(`RESOLVED__@namespace/my-module-3/dynamic-files/${file}.js`);',
'import(`RESOLVED__my-module/dynamic-files/${file}.js`);',
'import("RESOLVED__my-module/dynamic-files" + "/" + file + ".js");',
@@ -167,7 +168,7 @@ describe('transformImports()', () => {
defaultResolveImport,
);
- expect(result.split('\n')).to.eql([
+ assert.deepStrictEqual(result.split('\n'),[
'import("RESOLVED__./a.js");',
"import('RESOLVED__./b.js');",
]);
@@ -187,7 +188,7 @@ describe('transformImports()', () => {
defaultFilePath,
defaultResolveImport,
);
- expect(result.split('\n')).to.eql([
+ assert.deepStrictEqual(result.split('\n'),[
'import( "RESOLVED__./a.js" );',
'import( "RESOLVED__./b.js" );',
'import( "./c" + ".js" );',
@@ -240,7 +241,7 @@ describe('transformImports()', () => {
defaultResolveImport,
);
- expect(result.split('\n')).to.eql([
+ assert.deepStrictEqual(result.split('\n'),[
'import(`./foo/${file}.js`);',
'import(`/${file}.js`);',
'import("./foo" + "/" + file + ".js");',
@@ -257,13 +258,13 @@ describe('transformImports()', () => {
await transformImports('\n\nconst file = "a', defaultFilePath, defaultResolveImport);
} catch (error) {
thrown = true;
- expect((error as PluginSyntaxError).message).to.equal('Syntax error');
- expect((error as PluginSyntaxError).filePath).to.equal('/root/my-file.js');
- expect((error as PluginSyntaxError).column).to.equal(16);
- expect((error as PluginSyntaxError).line).to.equal(3);
+ assert.strictEqual((error as PluginSyntaxError).message, 'Syntax error');
+ assert.strictEqual((error as PluginSyntaxError).filePath, '/root/my-file.js');
+ assert.strictEqual((error as PluginSyntaxError).column, 16);
+ assert.strictEqual((error as PluginSyntaxError).line, 3);
}
- expect(thrown).to.be.true;
+ assert.strictEqual(thrown, true);
});
});
@@ -284,8 +285,8 @@ describe('resolveImport', () => {
const response = await fetch(`${host}/src/app.js`);
const responseText = await response.text();
- expect(response.status).to.equal(200);
- expect(responseText).to.include("import { message } from 'RESOLVED__my-module';");
+ assert.strictEqual(response.status, 200);
+ assert.ok(responseText.includes("import { message } from 'RESOLVED__my-module';"));
} finally {
server.stop();
}
@@ -307,8 +308,8 @@ describe('resolveImport', () => {
const response = await fetch(`${host}/index.html`);
const responseText = await response.text();
- expect(response.status).to.equal(200);
- expect(responseText).to.include("import { message } from 'RESOLVED__my-module';");
+ assert.strictEqual(response.status, 200);
+ assert.ok(responseText.includes("import { message } from 'RESOLVED__my-module';"));
} finally {
server.stop();
}
@@ -330,8 +331,8 @@ describe('resolveImport', () => {
const response = await fetch(`${host}/src/app.js`);
const responseText = await response.text();
- expect(response.status).to.equal(200);
- expect(responseText).to.include("import { message } from 'my-module';");
+ assert.strictEqual(response.status, 200);
+ assert.ok(responseText.includes("import { message } from 'my-module';"));
} finally {
server.stop();
}
@@ -363,10 +364,10 @@ describe('resolveImport', () => {
const responseTextA = await responseA.text();
const responseTextB = await responseB.text();
- expect(responseA.status).to.equal(200);
- expect(responseB.status).to.equal(200);
- expect(responseTextA).to.include("import { message } from 'RESOLVED__A__my-module';");
- expect(responseTextB).to.include("import { message } from 'RESOLVED__B__my-module';");
+ assert.strictEqual(responseA.status, 200);
+ assert.strictEqual(responseB.status, 200);
+ assert.ok(responseTextA.includes("import { message } from 'RESOLVED__A__my-module';"));
+ assert.ok(responseTextB.includes("import { message } from 'RESOLVED__B__my-module';"));
} finally {
server.stop();
}
@@ -390,9 +391,9 @@ describe('transformImport', () => {
const response = await fetch(`${host}/src/app.js`);
const responseText = await response.text();
- expect(response.status).to.equal(200);
- expect(responseText).to.include("import { message } from 'my-module?transformed-1';");
- expect(responseText).to.include('./src/local-module.js?transformed-1');
+ assert.strictEqual(response.status, 200);
+ assert.ok(responseText.includes("import { message } from 'my-module?transformed-1';"));
+ assert.ok(responseText.includes('./src/local-module.js?transformed-1'));
} finally {
server.stop();
}
@@ -420,11 +421,11 @@ describe('transformImport', () => {
const response = await fetch(`${host}/src/app.js`);
const responseText = await response.text();
- expect(response.status).to.equal(200);
- expect(responseText).to.include(
+ assert.strictEqual(response.status, 200);
+ assert.ok(responseText.includes(
"import { message } from 'my-module?transformed-1&transformed-2';",
- );
- expect(responseText).to.include('./src/local-module.js?transformed-1&transformed-2');
+ ));
+ assert.ok(responseText.includes('./src/local-module.js?transformed-1&transformed-2'));
} finally {
server.stop();
}
@@ -458,11 +459,11 @@ describe('transformImport', () => {
const response = await fetch(`${host}/src/app.js`);
const responseText = await response.text();
- expect(response.status).to.equal(200);
- expect(responseText).to.include(
+ assert.strictEqual(response.status, 200);
+ assert.ok(responseText.includes(
"import { message } from 'my-module?transformed-1&transformed-2';",
- );
- expect(responseText).to.include('./src/local-module.js?transformed-1&transformed-2');
+ ));
+ assert.ok(responseText.includes('./src/local-module.js?transformed-1&transformed-2'));
} finally {
server.stop();
}
@@ -490,7 +491,7 @@ describe('transformImport', () => {
try {
await fetch(`${host}/src/app.js`);
- expect(receivedImports).to.eql(['RESOLVED__my-module', 'RESOLVED__./src/local-module.js']);
+ assert.deepStrictEqual(receivedImports, ['RESOLVED__my-module', 'RESOLVED__./src/local-module.js']);
} finally {
server.stop();
}
diff --git a/packages/dev-server-core/test/server/DevServer.test.ts b/packages/dev-server-core/test/server/DevServer.test.ts
index 0d6de5a0c2..a19aa9e314 100644
--- a/packages/dev-server-core/test/server/DevServer.test.ts
+++ b/packages/dev-server-core/test/server/DevServer.test.ts
@@ -1,9 +1,10 @@
+import { describe, it, beforeEach, afterEach, before, after } from 'node:test';
+import assert from 'node:assert/strict';
import express from 'express';
import http from 'http';
import Koa from 'koa';
import { Server } from 'net';
import { FSWatcher } from 'chokidar';
-import { expect } from 'chai';
import portfinder from 'portfinder';
import { Stub, stubMethod } from 'hanbi';
import { ServerStartParams } from '../../src/plugins/Plugin.ts';
@@ -26,37 +27,37 @@ describe('basic', () => {
const response = await fetch(`${host}/index.html`);
const responseText = await response.text();
- expect(response.status).to.equal(200);
- expect(responseText).to.include('My app ');
+ assert.strictEqual(response.status, 200);
+ assert.ok(responseText.includes('My app '));
});
it('returns hidden files', async () => {
const response = await fetch(`${host}/.hidden`);
const responseText = await response.text();
- expect(response.status).to.equal(200);
- expect(responseText).to.include('this file is hidden');
+ assert.strictEqual(response.status, 200);
+ assert.ok(responseText.includes('this file is hidden'));
});
it('returns files in a folder', async () => {
const response = await fetch(`${host}/src/hello-world.txt`);
const responseText = await response.text();
- expect(response.status).to.equal(200);
- expect(responseText).to.equal('Hello world!');
+ assert.strictEqual(response.status, 200);
+ assert.strictEqual(responseText, 'Hello world!');
});
it('returns a 404 for unknown files', async () => {
const response = await fetch(`${host}/non-existing.js`);
- expect(response.status).to.equal(404);
+ assert.strictEqual(response.status, 404);
});
it('sets no-cache header', async () => {
const response = await fetch(`${host}/index.html`);
- expect(response.status).to.equal(200);
- expect(response.headers.get('cache-control')).to.equal('no-cache');
+ assert.strictEqual(response.status, 200);
+ assert.strictEqual(response.headers.get('cache-control'), 'no-cache');
});
});
@@ -65,8 +66,8 @@ it('can configure the hostname', async () => {
const response = await fetch(`${host}/index.html`);
const responseText = await response.text();
- expect(response.status).to.equal(200);
- expect(responseText).to.include('My app ');
+ assert.strictEqual(response.status, 200);
+ assert.ok(responseText.includes('My app '));
server.stop();
});
@@ -92,16 +93,16 @@ describe('http2', () => {
// It's a bit of a shame that we can't verify that the response was delivered with a http/2
// protocol. It would be good to have a extra assertion here. Something like:
//
- // expect(response.protocol).to.equal('http2');
- expect(response.status).to.equal(200);
- expect(responseText).to.include('My app ');
+ // assert.strictEqual(response.protocol, 'http2');
+ assert.strictEqual(response.status, 200);
+ assert.ok(responseText.includes('My app '));
server.stop();
});
});
it('can run in middleware mode', async () => {
const { server: wdsServer } = await createTestServer({ middlewareMode: true });
- expect(wdsServer.server).to.equal(undefined);
+ assert.strictEqual(wdsServer.server, undefined);
const app = express();
let httpServer: http.Server;
@@ -117,8 +118,8 @@ it('can run in middleware mode', async () => {
const response = await fetch(`http://localhost:${port}/index.html`);
const responseText = await response.text();
- expect(response.status).to.equal(200);
- expect(responseText).to.include('My app ');
+ assert.strictEqual(response.status, 200);
+ assert.ok(responseText.includes('My app '));
httpServer!.close();
});
@@ -136,8 +137,8 @@ it('can run multiple servers in parallel', async () => {
const response = await fetch(`${result.host}/index.html`);
const responseText = await response.text();
- expect(response.status).to.equal(200);
- expect(responseText).to.include('My app ');
+ assert.strictEqual(response.status, 200);
+ assert.ok(responseText.includes('My app '));
result.server.stop();
}
});
@@ -157,8 +158,8 @@ it('can add extra middleware', async () => {
const response = await fetch(`${host}/foo`);
const responseText = await response.text();
- expect(response.status).to.equal(200);
- expect(responseText).to.include('response from middleware');
+ assert.strictEqual(response.status, 200);
+ assert.ok(responseText.includes('response from middleware'));
server.stop();
});
@@ -175,11 +176,11 @@ it('calls serverStart on plugin hook on start', async () => {
],
});
- expect(startArgs!).to.exist;
- expect(startArgs!.app).to.be.an.instanceOf(Koa);
- expect(startArgs!.server).to.be.an.instanceOf(Server);
- expect(startArgs!.fileWatcher).to.be.an.instanceOf(FSWatcher);
- expect(startArgs!.config).to.be.an('object');
+ assert.ok(startArgs! !== undefined);
+ assert.ok(startArgs!.app instanceof Koa);
+ assert.ok(startArgs!.server instanceof Server);
+ assert.ok(startArgs!.fileWatcher instanceof FSWatcher);
+ assert.strictEqual(typeof startArgs!.config, 'object');
server.stop();
});
@@ -198,7 +199,7 @@ it('calls serverStop on plugin hook on stop', async () => {
});
await server.stop();
- expect(stopCalled).to.be.true;
+ assert.strictEqual(stopCalled, true);
});
it('waits on server start hooks before starting', async () => {
@@ -232,8 +233,8 @@ it('waits on server start hooks before starting', async () => {
],
});
- expect(aFinished).to.be.true;
- expect(bFinished).to.be.true;
+ assert.strictEqual(aFinished, true);
+ assert.strictEqual(bFinished, true);
server.stop();
});
@@ -270,14 +271,14 @@ describe('disableFileWatcher', () => {
it('disables file watch when true', async () => {
const { fileWatchStub, server } = await setupDisableFileWatch({ disableFileWatcher: true });
- expect(fileWatchStub.callCount).to.equal(0);
+ assert.strictEqual(fileWatchStub.callCount, 0);
server.stop();
});
it('leaves file watch in tact when false', async () => {
const { fileWatchStub, server } = await setupDisableFileWatch({ disableFileWatcher: false });
- expect(fileWatchStub.callCount).to.gt(0);
+ assert.ok(fileWatchStub.callCount > 0);
server.stop();
});
});
diff --git a/packages/dev-server-core/test/web-sockets/WebSocketsManager.test.ts b/packages/dev-server-core/test/web-sockets/WebSocketsManager.test.ts
index 808d962d41..a949a33ccf 100644
--- a/packages/dev-server-core/test/web-sockets/WebSocketsManager.test.ts
+++ b/packages/dev-server-core/test/web-sockets/WebSocketsManager.test.ts
@@ -1,4 +1,5 @@
-import { expect } from 'chai';
+import { describe, it } from 'node:test';
+import assert from 'node:assert/strict';
import WebSocket from 'ws';
import { NAME_WEB_SOCKET_API } from '../../src/web-sockets/WebSocketsManager.ts';
@@ -56,7 +57,7 @@ describe('WebSocketManager', () => {
const waitForMessage = waitFor(resolve => {
ws.on('message', data => {
- expect(data).to.equal('hello world');
+ assert.strictEqual(data.toString(), 'hello world');
resolve();
});
}, 'expected a message event');
@@ -91,13 +92,13 @@ describe('WebSocketManager', () => {
const waitForMessage1 = waitFor(resolve => {
ws1.on('message', data => {
- expect(data).to.equal('hello world');
+ assert.strictEqual(data.toString(), 'hello world');
resolve();
});
}, 'expected message');
const waitForMessage2 = waitFor(resolve => {
ws1.on('message', data => {
- expect(data).to.equal('hello world');
+ assert.strictEqual(data.toString(), 'hello world');
resolve();
});
}, 'expected message');
@@ -126,8 +127,8 @@ describe('WebSocketManager', () => {
const waitForMessage = waitFor(resolve => {
server.webSockets!.on('message', ({ webSocket, data }) => {
- expect(webSocket).to.be.an.instanceOf(WebSocket);
- expect(data).to.eql({ type: 'foo' });
+ assert.ok(webSocket instanceof WebSocket);
+ assert.deepStrictEqual(data, { type: 'foo' });
resolve();
});
}, 'expected message event fired from manager');
@@ -155,8 +156,8 @@ describe('WebSocketManager', () => {
const waitForMessage = waitFor(resolve => {
ws.on('message', data => {
- const parsedData = JSON.parse(data as any);
- expect(parsedData).to.eql({
+ const parsedData = JSON.parse(data.toString());
+ assert.deepStrictEqual(parsedData, {
data: {
args: [],
importPath: 'data:text/javascript,console.log("hello world");',
@@ -190,8 +191,8 @@ describe('WebSocketManager', () => {
const waitForMessage = waitFor(resolve => {
ws.on('message', data => {
- const parsedData = JSON.parse(data as any);
- expect(parsedData).to.eql({
+ const parsedData = JSON.parse(data.toString());
+ assert.deepStrictEqual(parsedData, {
data: {
args: [],
importPath: '/foo.js',
diff --git a/packages/dev-server-core/test/web-sockets/webSocketsPlugin.test.ts b/packages/dev-server-core/test/web-sockets/webSocketsPlugin.test.ts
index c08f0d844a..3c47a07cf7 100644
--- a/packages/dev-server-core/test/web-sockets/webSocketsPlugin.test.ts
+++ b/packages/dev-server-core/test/web-sockets/webSocketsPlugin.test.ts
@@ -1,4 +1,5 @@
-import { expect } from 'chai';
+import { describe, it } from 'node:test';
+import assert from 'node:assert/strict';
import { createTestServer } from '../helpers.ts';
import { webSocketScript } from '../../src/web-sockets/webSocketsPlugin.ts';
@@ -19,8 +20,8 @@ describe('webSocketsPlugin', () => {
const response = await fetch(`${host}/index.html`);
const body = await response.text();
- expect(response.status).to.equal(200);
- expect(body).to.include(webSocketScript);
+ assert.strictEqual(response.status, 200);
+ assert.ok(body.includes(webSocketScript));
} finally {
server.stop();
}
@@ -41,8 +42,8 @@ describe('webSocketsPlugin', () => {
const response = await fetch(`${host}/index.html`);
const body = await response.text();
- expect(response.status).to.equal(200);
- expect(body).to.not.include(webSocketScript);
+ assert.strictEqual(response.status, 200);
+ assert.ok(!body.includes(webSocketScript));
} finally {
server.stop();
}
@@ -54,8 +55,8 @@ describe('webSocketsPlugin', () => {
const response = await fetch(`${host}/index.html`);
const body = await response.text();
- expect(response.status).to.equal(200);
- expect(body).to.not.include(webSocketScript);
+ assert.strictEqual(response.status, 200);
+ assert.ok(!body.includes(webSocketScript));
} finally {
server.stop();
}
@@ -77,10 +78,10 @@ describe('webSocketsPlugin', () => {
const bodyA = await responseA.text();
const bodyB = await responseB.text();
- expect(responseA.status).to.equal(200);
- expect(responseB.status).to.equal(200);
- expect(bodyA).to.not.include(webSocketScript);
- expect(bodyB).to.not.include(webSocketScript);
+ assert.strictEqual(responseA.status, 200);
+ assert.strictEqual(responseB.status, 200);
+ assert.ok(!bodyA.includes(webSocketScript));
+ assert.ok(!bodyB.includes(webSocketScript));
} finally {
server.stop();
}
diff --git a/packages/dev-server-esbuild/package.json b/packages/dev-server-esbuild/package.json
index 6469f156cb..b917e601d5 100644
--- a/packages/dev-server-esbuild/package.json
+++ b/packages/dev-server-esbuild/package.json
@@ -1,6 +1,5 @@
{
"name": "@web/dev-server-esbuild",
- "type": "module",
"version": "1.0.5",
"publishConfig": {
"access": "public"
@@ -18,22 +17,24 @@
"exports": {
".": {
"types": "./index.d.ts",
- "default": "./dist/index.js"
+ "import": "./index.mjs",
+ "require": "./dist/index.js"
}
},
"engines": {
- "node": ">=24.0.0"
+ "node": ">=18.0.0"
},
"scripts": {
"build": "tsc",
"start:demo:jsx": "es-dev-server --config demo/jsx/server.config.js",
"start:demo:ts": "es-dev-server --config demo/ts/server.config.js",
- "test:node": "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"
+ "test:node": "node --test test/**/*.test.ts",
+ "test:watch": "node --test --watch test/**/*.test.ts"
},
"files": [
"*.d.ts",
"*.js",
+ "*.mjs",
"dist",
"src"
],
@@ -52,7 +53,7 @@
"dependencies": {
"@mdn/browser-compat-data": "^4.0.0",
"@web/dev-server-core": "^0.7.4",
- "esbuild": "^0.25.0",
+ "esbuild": "^0.27.0",
"parse5": "^6.0.1",
"ua-parser-js": "^1.0.33"
},
diff --git a/packages/dev-server-esbuild/test/banner-footer.test.ts b/packages/dev-server-esbuild/test/banner-footer.test.ts
index 5d1a062ded..8434472b6f 100644
--- a/packages/dev-server-esbuild/test/banner-footer.test.ts
+++ b/packages/dev-server-esbuild/test/banner-footer.test.ts
@@ -1,12 +1,52 @@
+<<<<<<< HEAD
import { expect } from 'chai';
import { createTestServer } from '@web/dev-server-core/test-helpers';
import { expectIncludes } from '@web/dev-server-core/test-helpers';
+||||||| parent of aecfa949 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import assert from 'node:assert/strict';
+import { describe, it } from 'node:test';
+import path from 'path';
+import { createTestServer } from '@web/dev-server-core/test-helpers.js';
+import { expectIncludes } from '@web/dev-server-core/test-helpers.js';
+=======
+import assert from 'node:assert/strict';
+import { describe, it } from 'node:test';
+import path from 'path';
+<<<<<<< HEAD
+import { createTestServer } from '@web/dev-server-core/test-helpers.js';
+import { expectIncludes } from '@web/dev-server-core/test-helpers.js';
+||||||| parent of 9007e014 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import { createTestServer } from '@web/dev-server-core/test-helpers.ts';
+import { expectIncludes } from '@web/dev-server-core/test-helpers.ts';
+=======
+import { createTestServer } from '@web/dev-server-core/test-helpers';
+import { expectIncludes } from '@web/dev-server-core/test-helpers';
+>>>>>>> 9007e014 (chore: migrate tests from mocha/chai to node:test + node:assert)
+>>>>>>> aecfa949 (chore: migrate tests from mocha/chai to node:test + node:assert)
+<<<<<<< HEAD
+import { esbuildPlugin } from '../src/index.ts';
+||||||| parent of aecfa949 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import { esbuildPlugin } from '../src/index.js';
+=======
+<<<<<<< HEAD
+import { esbuildPlugin } from '../src/index.js';
+||||||| parent of c37bb778 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import { esbuildPlugin } from '../src/index.ts';
+=======
+<<<<<<< HEAD
import { esbuildPlugin } from '../src/index.ts';
+||||||| parent of 61bf92a0 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import { esbuildPlugin } from '../src/index.js';
+=======
+import { esbuildPlugin } from '../src/index.ts';
+>>>>>>> c37bb778 (chore: migrate tests from mocha/chai to node:test + node:assert)
-describe('esbuildPlugin banner/footers', function () {
- this.timeout(5000);
+const __dirname = import.meta.dirname;
+>>>>>>> 61bf92a0 (chore: migrate tests from mocha/chai to node:test + node:assert)
+>>>>>>> aecfa949 (chore: migrate tests from mocha/chai to node:test + node:assert)
+describe('esbuildPlugin banner/footers', function () {
it('prepends custom banner', async () => {
const { server, host } = await createTestServer({
rootDir: __dirname,
@@ -31,7 +71,7 @@ describe('esbuildPlugin banner/footers', function () {
const indexOfBanner = text.indexOf('/* hello there */');
expectIncludes(text, '/* hello there */');
- expect(indexOfExpr).to.be.greaterThan(indexOfBanner);
+ assert.ok(indexOfExpr > indexOfBanner);
} finally {
server.stop();
}
@@ -61,7 +101,7 @@ describe('esbuildPlugin banner/footers', function () {
const indexOfFooter = text.indexOf('/* hello there */');
expectIncludes(text, '/* hello there */');
- expect(indexOfFooter).to.be.greaterThan(indexOfExpr);
+ assert.ok(indexOfFooter > indexOfExpr);
} finally {
server.stop();
}
diff --git a/packages/dev-server-esbuild/test/browser-targets.test.ts b/packages/dev-server-esbuild/test/browser-targets.test.ts
index ee636288cf..6b919848b5 100644
--- a/packages/dev-server-esbuild/test/browser-targets.test.ts
+++ b/packages/dev-server-esbuild/test/browser-targets.test.ts
@@ -1,74 +1,102 @@
+<<<<<<< HEAD
import { expect } from 'chai';
import { browsers } from '@mdn/browser-compat-data';
+||||||| parent of aecfa949 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import assert from 'node:assert/strict';
+import { describe, it } from 'node:test';
+import browserCompatData from '@mdn/browser-compat-data.ts';
+const { browsers } = browserCompatData;
+=======
+<<<<<<< HEAD
+import { expect } from 'chai';
+import { browsers } from '@mdn/browser-compat-data';
+<<<<<<< HEAD
+import { isLatestModernBrowser, getLatestStableMajor } from '../src/browser-targets.js';
+||||||| parent of c37bb778 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import { isLatestModernBrowser, getLatestStableMajor } from '../src/browser-targets.ts';
+=======
+import { isLatestModernBrowser, getLatestStableMajor } from '../src/browser-targets.ts';
+||||||| parent of 61bf92a0 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import { expect } from 'chai';
+import { browsers } from '@mdn/browser-compat-data';
+import { isLatestModernBrowser, getLatestStableMajor } from '../src/browser-targets.js';
+=======
+import assert from 'node:assert/strict';
+import { describe, it } from 'node:test';
+import browserCompatData from '@mdn/browser-compat-data';
+const { browsers } = browserCompatData;
+>>>>>>> aecfa949 (chore: migrate tests from mocha/chai to node:test + node:assert)
import { isLatestModernBrowser, getLatestStableMajor } from '../src/browser-targets.ts';
+>>>>>>> 61bf92a0 (chore: migrate tests from mocha/chai to node:test + node:assert)
+>>>>>>> c37bb778 (chore: migrate tests from mocha/chai to node:test + node:assert)
describe('isLatestModernBrowser', () => {
it('returns true for latest Chrome', async () => {
const latest = getLatestStableMajor(browsers.chrome.releases)!;
- expect(isLatestModernBrowser({ name: 'Chrome', version: String(latest) })).to.be.true;
+ assert.strictEqual(isLatestModernBrowser({ name: 'Chrome', version: String(latest) }), true);
});
it('returns true for latest Chrome -1', async () => {
const latest = getLatestStableMajor(browsers.chrome.releases)!;
- expect(isLatestModernBrowser({ name: 'Chrome', version: String(latest - 1) })).to.be.true;
+ assert.strictEqual(isLatestModernBrowser({ name: 'Chrome', version: String(latest - 1) }), true);
});
it('returns true for future version of Chrome', async () => {
const latest = getLatestStableMajor(browsers.chrome.releases)!;
- expect(isLatestModernBrowser({ name: 'Chrome', version: String(latest + 1) })).to.be.true;
+ assert.strictEqual(isLatestModernBrowser({ name: 'Chrome', version: String(latest + 1) }), true);
});
it('returns true for unknown version of Chrome', async () => {
- expect(isLatestModernBrowser({ name: 'Chrome', version: '9999999' })).to.be.true;
+ assert.strictEqual(isLatestModernBrowser({ name: 'Chrome', version: '9999999' }), true);
});
it('returns false for latest Chrome -2', async () => {
const latest = getLatestStableMajor(browsers.chrome.releases)!;
- expect(isLatestModernBrowser({ name: 'Chrome', version: String(latest - 2) })).to.be.false;
+ assert.strictEqual(isLatestModernBrowser({ name: 'Chrome', version: String(latest - 2) }), false);
});
it('returns false for latest Chrome -3', async () => {
const latest = getLatestStableMajor(browsers.chrome.releases)!;
- expect(isLatestModernBrowser({ name: 'Chrome', version: String(latest - 3) })).to.be.false;
+ assert.strictEqual(isLatestModernBrowser({ name: 'Chrome', version: String(latest - 3) }), false);
});
it('returns true for latest Chrome Headless', async () => {
const latest = getLatestStableMajor(browsers.chrome.releases)!;
- expect(isLatestModernBrowser({ name: 'Chrome Headless', version: String(latest) })).to.be.true;
+ assert.strictEqual(isLatestModernBrowser({ name: 'Chrome Headless', version: String(latest) }), true);
});
it('returns true for latest chromium', async () => {
const latest = getLatestStableMajor(browsers.chrome.releases)!;
- expect(isLatestModernBrowser({ name: 'Chromium', version: String(latest) })).to.be.true;
+ assert.strictEqual(isLatestModernBrowser({ name: 'Chromium', version: String(latest) }), true);
});
it('returns true for latest Firefox', async () => {
const latest = getLatestStableMajor(browsers.firefox.releases)!;
- expect(isLatestModernBrowser({ name: 'Firefox', version: String(latest) })).to.be.true;
+ assert.strictEqual(isLatestModernBrowser({ name: 'Firefox', version: String(latest) }), true);
});
it('returns false for latest Firefox -1', async () => {
const latest = getLatestStableMajor(browsers.firefox.releases)!;
- expect(isLatestModernBrowser({ name: 'Firefox', version: String(latest - 1) })).to.be.false;
+ assert.strictEqual(isLatestModernBrowser({ name: 'Firefox', version: String(latest - 1) }), false);
});
it('returns false for latest Firefox -2', async () => {
const latest = getLatestStableMajor(browsers.firefox.releases)!;
- expect(isLatestModernBrowser({ name: 'Firefox', version: String(latest - 2) })).to.be.false;
+ assert.strictEqual(isLatestModernBrowser({ name: 'Firefox', version: String(latest - 2) }), false);
});
it('returns true for latest Edge', async () => {
const latest = getLatestStableMajor(browsers.edge.releases)!;
- expect(isLatestModernBrowser({ name: 'Edge', version: String(latest) })).to.be.true;
+ assert.strictEqual(isLatestModernBrowser({ name: 'Edge', version: String(latest) }), true);
});
it('returns true for latest Edge -1', async () => {
const latest = getLatestStableMajor(browsers.edge.releases)!;
- expect(isLatestModernBrowser({ name: 'Edge', version: String(latest - 1) })).to.be.true;
+ assert.strictEqual(isLatestModernBrowser({ name: 'Edge', version: String(latest - 1) }), true);
});
it('returns false for latest Edge -2', async () => {
const latest = getLatestStableMajor(browsers.edge.releases)!;
- expect(isLatestModernBrowser({ name: 'Chrome', version: String(latest - 2) })).to.be.false;
+ assert.strictEqual(isLatestModernBrowser({ name: 'Chrome', version: String(latest - 2) }), false);
});
});
diff --git a/packages/dev-server-esbuild/test/json.test.ts b/packages/dev-server-esbuild/test/json.test.ts
index c52853459e..f329ef0faf 100644
--- a/packages/dev-server-esbuild/test/json.test.ts
+++ b/packages/dev-server-esbuild/test/json.test.ts
@@ -1,7 +1,45 @@
+<<<<<<< HEAD
import { expect } from 'chai';
import { expectIncludes, createTestServer } from '@web/dev-server-core/test-helpers';
+||||||| parent of aecfa949 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import assert from 'node:assert/strict';
+import { describe, it } from 'node:test';
+import path from 'path';
+import { expectIncludes, createTestServer } from '@web/dev-server-core/test-helpers.js';
+=======
+import assert from 'node:assert/strict';
+import { describe, it } from 'node:test';
+import path from 'path';
+<<<<<<< HEAD
+import { expectIncludes, createTestServer } from '@web/dev-server-core/test-helpers.js';
+||||||| parent of 9007e014 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import { expectIncludes, createTestServer } from '@web/dev-server-core/test-helpers.ts';
+=======
+import { expectIncludes, createTestServer } from '@web/dev-server-core/test-helpers';
+>>>>>>> 9007e014 (chore: migrate tests from mocha/chai to node:test + node:assert)
+>>>>>>> aecfa949 (chore: migrate tests from mocha/chai to node:test + node:assert)
+<<<<<<< HEAD
+import { esbuildPlugin } from '../src/index.ts';
+||||||| parent of aecfa949 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import { esbuildPlugin } from '../src/index.js';
+=======
+<<<<<<< HEAD
+import { esbuildPlugin } from '../src/index.js';
+||||||| parent of c37bb778 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import { esbuildPlugin } from '../src/index.ts';
+=======
+<<<<<<< HEAD
import { esbuildPlugin } from '../src/index.ts';
+||||||| parent of 61bf92a0 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import { esbuildPlugin } from '../src/index.js';
+=======
+import { esbuildPlugin } from '../src/index.ts';
+
+const __dirname = import.meta.dirname;
+>>>>>>> 61bf92a0 (chore: migrate tests from mocha/chai to node:test + node:assert)
+>>>>>>> c37bb778 (chore: migrate tests from mocha/chai to node:test + node:assert)
+>>>>>>> aecfa949 (chore: migrate tests from mocha/chai to node:test + node:assert)
describe('esbuildPlugin JSON', function () {
it('transforms .json files', async () => {
@@ -24,9 +62,10 @@ describe('esbuildPlugin JSON', function () {
const response = await fetch(`${host}/foo.json`);
const text = await response.text();
- expect(response.status).to.equal(200);
- expect(response.headers.get('content-type')).to.equal(
- 'application/javascript; charset=utf-8',
+ assert.strictEqual(response.status, 200);
+ assert.strictEqual(
+ response.headers.get('content-type'),
+ 'text/javascript; charset=utf-8',
);
expectIncludes(text, 'var foo = "bar";');
expectIncludes(text, 'var foo_default = { foo };');
diff --git a/packages/dev-server-esbuild/test/jsx.test.ts b/packages/dev-server-esbuild/test/jsx.test.ts
index d449dc3721..e60c53f0f4 100644
--- a/packages/dev-server-esbuild/test/jsx.test.ts
+++ b/packages/dev-server-esbuild/test/jsx.test.ts
@@ -1,7 +1,45 @@
+<<<<<<< HEAD
import { expect } from 'chai';
import { expectIncludes, createTestServer } from '@web/dev-server-core/test-helpers';
+||||||| parent of aecfa949 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import assert from 'node:assert/strict';
+import { describe, it } from 'node:test';
+import path from 'path';
+import { expectIncludes, createTestServer } from '@web/dev-server-core/test-helpers.js';
+=======
+import assert from 'node:assert/strict';
+import { describe, it } from 'node:test';
+import path from 'path';
+<<<<<<< HEAD
+import { expectIncludes, createTestServer } from '@web/dev-server-core/test-helpers.js';
+||||||| parent of 9007e014 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import { expectIncludes, createTestServer } from '@web/dev-server-core/test-helpers.ts';
+=======
+import { expectIncludes, createTestServer } from '@web/dev-server-core/test-helpers';
+>>>>>>> 9007e014 (chore: migrate tests from mocha/chai to node:test + node:assert)
+>>>>>>> aecfa949 (chore: migrate tests from mocha/chai to node:test + node:assert)
+<<<<<<< HEAD
+import { esbuildPlugin } from '../src/index.ts';
+||||||| parent of aecfa949 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import { esbuildPlugin } from '../src/index.js';
+=======
+<<<<<<< HEAD
+import { esbuildPlugin } from '../src/index.js';
+||||||| parent of c37bb778 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import { esbuildPlugin } from '../src/index.ts';
+=======
+<<<<<<< HEAD
import { esbuildPlugin } from '../src/index.ts';
+||||||| parent of 61bf92a0 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import { esbuildPlugin } from '../src/index.js';
+=======
+import { esbuildPlugin } from '../src/index.ts';
+
+const __dirname = import.meta.dirname;
+>>>>>>> 61bf92a0 (chore: migrate tests from mocha/chai to node:test + node:assert)
+>>>>>>> c37bb778 (chore: migrate tests from mocha/chai to node:test + node:assert)
+>>>>>>> aecfa949 (chore: migrate tests from mocha/chai to node:test + node:assert)
describe('esbuildPlugin JSX', function () {
it('transforms .jsx files', async () => {
@@ -28,9 +66,10 @@ export function foo(bar) {
const response = await fetch(`${host}/foo.jsx`);
const text = await response.text();
- expect(response.status).to.equal(200);
- expect(response.headers.get('content-type')).to.equal(
- 'application/javascript; charset=utf-8',
+ assert.strictEqual(response.status, 200);
+ assert.strictEqual(
+ response.headers.get('content-type'),
+ 'text/javascript; charset=utf-8',
);
expectIncludes(text, 'React.createElement("div", {');
expectIncludes(text, 'id: "myDiv"');
@@ -65,9 +104,10 @@ export function foo(bar) {
const response = await fetch(`${host}/foo.jsx`);
const text = await response.text();
- expect(response.status).to.equal(200);
- expect(response.headers.get('content-type')).to.equal(
- 'application/javascript; charset=utf-8',
+ assert.strictEqual(response.status, 200);
+ assert.strictEqual(
+ response.headers.get('content-type'),
+ 'text/javascript; charset=utf-8',
);
expectIncludes(text, 'h("div", {');
expectIncludes(text, 'id: "myDiv"');
diff --git a/packages/dev-server-esbuild/test/target.test.ts b/packages/dev-server-esbuild/test/target.test.ts
index 11f4d5f026..68403e384e 100644
--- a/packages/dev-server-esbuild/test/target.test.ts
+++ b/packages/dev-server-esbuild/test/target.test.ts
@@ -1,7 +1,45 @@
+<<<<<<< HEAD
import { expect } from 'chai';
import { createTestServer, expectIncludes } from '@web/dev-server-core/test-helpers';
+||||||| parent of aecfa949 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import assert from 'node:assert/strict';
+import { describe, it } from 'node:test';
+import path from 'path';
+import { createTestServer, expectIncludes } from '@web/dev-server-core/test-helpers.js';
+=======
+import assert from 'node:assert/strict';
+import { describe, it } from 'node:test';
+import path from 'path';
+<<<<<<< HEAD
+import { createTestServer, expectIncludes } from '@web/dev-server-core/test-helpers.js';
+||||||| parent of 9007e014 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import { createTestServer, expectIncludes } from '@web/dev-server-core/test-helpers.ts';
+=======
+import { createTestServer, expectIncludes } from '@web/dev-server-core/test-helpers';
+>>>>>>> 9007e014 (chore: migrate tests from mocha/chai to node:test + node:assert)
+>>>>>>> aecfa949 (chore: migrate tests from mocha/chai to node:test + node:assert)
+<<<<<<< HEAD
+import { esbuildPlugin } from '../src/index.ts';
+||||||| parent of aecfa949 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import { esbuildPlugin } from '../src/index.js';
+=======
+<<<<<<< HEAD
+import { esbuildPlugin } from '../src/index.js';
+||||||| parent of c37bb778 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import { esbuildPlugin } from '../src/index.ts';
+=======
+<<<<<<< HEAD
import { esbuildPlugin } from '../src/index.ts';
+||||||| parent of 61bf92a0 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import { esbuildPlugin } from '../src/index.js';
+=======
+import { esbuildPlugin } from '../src/index.ts';
+
+const __dirname = import.meta.dirname;
+>>>>>>> 61bf92a0 (chore: migrate tests from mocha/chai to node:test + node:assert)
+>>>>>>> c37bb778 (chore: migrate tests from mocha/chai to node:test + node:assert)
+>>>>>>> aecfa949 (chore: migrate tests from mocha/chai to node:test + node:assert)
const modernJs = `
class MyClass {
@@ -79,9 +117,10 @@ describe('esbuildPlugin target', function () {
const response = await fetch(`${host}/foo.js`);
const text = await response.text();
- expect(response.status).to.equal(200);
- expect(response.headers.get('content-type')).to.equal(
- 'application/javascript; charset=utf-8',
+ assert.strictEqual(response.status, 200);
+ assert.strictEqual(
+ response.headers.get('content-type'),
+ 'text/javascript; charset=utf-8',
);
expectIncludes(text, syntax.classes);
@@ -121,9 +160,10 @@ describe('esbuildPlugin target', function () {
const response = await fetch(`${host}/foo.js`);
const text = await response.text();
- expect(response.status).to.equal(200);
- expect(response.headers.get('content-type')).to.equal(
- 'application/javascript; charset=utf-8',
+ assert.strictEqual(response.status, 200);
+ assert.strictEqual(
+ response.headers.get('content-type'),
+ 'text/javascript; charset=utf-8',
);
expectIncludes(text, syntax.classes);
@@ -163,9 +203,10 @@ describe('esbuildPlugin target', function () {
const response = await fetch(`${host}/foo.js`);
const text = await response.text();
- expect(response.status).to.equal(200);
- expect(response.headers.get('content-type')).to.equal(
- 'application/javascript; charset=utf-8',
+ assert.strictEqual(response.status, 200);
+ assert.strictEqual(
+ response.headers.get('content-type'),
+ 'text/javascript; charset=utf-8',
);
expectIncludes(text, syntax.classes);
@@ -205,9 +246,10 @@ describe('esbuildPlugin target', function () {
const response = await fetch(`${host}/foo.js`);
const text = await response.text();
- expect(response.status).to.equal(200);
- expect(response.headers.get('content-type')).to.equal(
- 'application/javascript; charset=utf-8',
+ assert.strictEqual(response.status, 200);
+ assert.strictEqual(
+ response.headers.get('content-type'),
+ 'text/javascript; charset=utf-8',
);
expectIncludes(text, syntax.classes);
@@ -247,9 +289,10 @@ describe('esbuildPlugin target', function () {
const response = await fetch(`${host}/foo.js`);
const text = await response.text();
- expect(response.status).to.equal(200);
- expect(response.headers.get('content-type')).to.equal(
- 'application/javascript; charset=utf-8',
+ assert.strictEqual(response.status, 200);
+ assert.strictEqual(
+ response.headers.get('content-type'),
+ 'text/javascript; charset=utf-8',
);
expectIncludes(text, syntax.classes);
@@ -287,9 +330,10 @@ describe('esbuildPlugin target', function () {
const response = await fetch(`${host}/foo.js`);
const text = await response.text();
- expect(response.status).to.equal(200);
- expect(response.headers.get('content-type')).to.equal(
- 'application/javascript; charset=utf-8',
+ assert.strictEqual(response.status, 200);
+ assert.strictEqual(
+ response.headers.get('content-type'),
+ 'text/javascript; charset=utf-8',
);
expectIncludes(text, syntax.classes);
@@ -331,8 +375,8 @@ describe('esbuildPlugin target', function () {
const response = await fetch(`${host}/index.html`);
const text = await response.text();
- expect(response.status).to.equal(200);
- expect(response.headers.get('content-type')).to.equal('text/html; charset=utf-8');
+ assert.strictEqual(response.status, 200);
+ assert.strictEqual(response.headers.get('content-type'), 'text/html; charset=utf-8');
expectIncludes(text, syntax.classes);
for (const e of transformedSyntax.classFields) {
@@ -376,10 +420,10 @@ describe('esbuildPlugin target', function () {
const response = await fetch(`${host}/index.html`);
const text = await response.text();
- expect(response.status).to.equal(200);
- expect(response.headers.get('content-type')).to.equal('text/html; charset=utf-8');
- expect(text).to.include(importmapString);
- expect(text).to.include(jsonString);
+ assert.strictEqual(response.status, 200);
+ assert.strictEqual(response.headers.get('content-type'), 'text/html; charset=utf-8');
+ assert.ok(text.includes(importmapString));
+ assert.ok(text.includes(jsonString));
} finally {
server.stop();
}
diff --git a/packages/dev-server-esbuild/test/ts.test.ts b/packages/dev-server-esbuild/test/ts.test.ts
index 9a2cf477e5..d09364653a 100644
--- a/packages/dev-server-esbuild/test/ts.test.ts
+++ b/packages/dev-server-esbuild/test/ts.test.ts
@@ -1,15 +1,59 @@
+import assert from 'node:assert/strict';
+import { describe, it } from 'node:test';
import path from 'path';
+<<<<<<< HEAD
import { expect } from 'chai';
import { createTestServer } from '@web/dev-server-core/test-helpers';
import { expectIncludes, expectNotIncludes } from '@web/dev-server-core/test-helpers';
import { Plugin as RollupPlugin } from 'rollup';
+||||||| parent of aecfa949 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import { createTestServer } from '@web/dev-server-core/test-helpers.js';
+import { expectIncludes, expectNotIncludes } from '@web/dev-server-core/test-helpers.js';
+import type { Plugin as RollupPlugin } from 'rollup';
+=======
+<<<<<<< HEAD
+import { createTestServer } from '@web/dev-server-core/test-helpers.js';
+import { expectIncludes, expectNotIncludes } from '@web/dev-server-core/test-helpers.js';
+||||||| parent of 9007e014 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import { createTestServer } from '@web/dev-server-core/test-helpers.ts';
+import { expectIncludes, expectNotIncludes } from '@web/dev-server-core/test-helpers.ts';
+=======
+import { createTestServer } from '@web/dev-server-core/test-helpers';
+import { expectIncludes, expectNotIncludes } from '@web/dev-server-core/test-helpers';
+>>>>>>> 9007e014 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import type { Plugin as RollupPlugin } from 'rollup';
+<<<<<<< HEAD
+import { fromRollup } from '@web/dev-server-rollup.js';
+||||||| parent of 9007e014 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import { fromRollup } from '@web/dev-server-rollup.ts';
+=======
+>>>>>>> aecfa949 (chore: migrate tests from mocha/chai to node:test + node:assert)
import { fromRollup } from '@web/dev-server-rollup';
+>>>>>>> 9007e014 (chore: migrate tests from mocha/chai to node:test + node:assert)
+<<<<<<< HEAD
+import { esbuildPlugin } from '../src/index.ts';
+||||||| parent of aecfa949 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import { esbuildPlugin } from '../src/index.js';
+=======
+<<<<<<< HEAD
+import { esbuildPlugin } from '../src/index.js';
+||||||| parent of c37bb778 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import { esbuildPlugin } from '../src/index.ts';
+=======
+<<<<<<< HEAD
import { esbuildPlugin } from '../src/index.ts';
+||||||| parent of 61bf92a0 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import { esbuildPlugin } from '../src/index.js';
+=======
+import { esbuildPlugin } from '../src/index.ts';
+>>>>>>> c37bb778 (chore: migrate tests from mocha/chai to node:test + node:assert)
-describe('esbuildPlugin TS', function () {
- this.timeout(5000);
+const __dirname = import.meta.dirname;
+>>>>>>> 61bf92a0 (chore: migrate tests from mocha/chai to node:test + node:assert)
+>>>>>>> aecfa949 (chore: migrate tests from mocha/chai to node:test + node:assert)
+describe('esbuildPlugin TS', function () {
it('transforms .ts files', async () => {
const { server, host } = await createTestServer({
rootDir: __dirname,
@@ -39,9 +83,10 @@ describe('esbuildPlugin TS', function () {
try {
const response = await fetch(`${host}/foo.ts`);
const text = await response.text();
- expect(response.status).to.equal(200);
- expect(response.headers.get('content-type')).to.equal(
- 'application/javascript; charset=utf-8',
+ assert.strictEqual(response.status, 200);
+ assert.strictEqual(
+ response.headers.get('content-type'),
+ 'text/javascript; charset=utf-8',
);
expectIncludes(text, 'export function foo(a, b) {');
expectIncludes(text, 'return a + b;');
@@ -81,9 +126,10 @@ class Bar {
const response = await fetch(`${host}/foo.ts`);
const text = await response.text();
- expect(response.status).to.equal(200);
- expect(response.headers.get('content-type')).to.equal(
- 'application/javascript; charset=utf-8',
+ assert.strictEqual(response.status, 200);
+ assert.strictEqual(
+ response.headers.get('content-type'),
+ 'text/javascript; charset=utf-8',
);
expectIncludes(text, '__decorate');
expectIncludes(text, '__publicField(this, "x", "y");');
@@ -119,9 +165,10 @@ class Bar {
const response = await fetch(`${host}/a/b/foo.ts`);
const text = await response.text();
- expect(response.status).to.equal(200);
- expect(response.headers.get('content-type')).to.equal(
- 'application/javascript; charset=utf-8',
+ assert.strictEqual(response.status, 200);
+ assert.strictEqual(
+ response.headers.get('content-type'),
+ 'text/javascript; charset=utf-8',
);
expectIncludes(text, 'import "../../x.ts";');
expectIncludes(text, 'import "../y.ts";');
@@ -146,9 +193,10 @@ class Bar {
const response = await fetch(`${host}/a/b/foo.ts`);
const text = await response.text();
- expect(response.status).to.equal(200);
- expect(response.headers.get('content-type')).to.equal(
- 'application/javascript; charset=utf-8',
+ assert.strictEqual(response.status, 200);
+ assert.strictEqual(
+ response.headers.get('content-type'),
+ 'text/javascript; charset=utf-8',
);
expectIncludes(text, 'import "../../1.js";');
expectIncludes(text, 'import "../2.js";');
@@ -177,7 +225,7 @@ class Bar {
const response = await fetch(`${host}/a/b/foo.ts`);
const text = await response.text();
- expect(response.status).to.equal(200);
+ assert.strictEqual(response.status, 200);
expectIncludes(text, "import '../../x.js';");
expectIncludes(text, "import '../y.js';");
expectIncludes(text, "import './z.js';");
@@ -201,7 +249,7 @@ class Bar {
const response = await fetch(`${host}/a/b/bar.js`);
const text = await response.text();
- expect(response.status).to.equal(200);
+ assert.strictEqual(response.status, 200);
expectIncludes(text, "import '../../x.js';");
expectIncludes(text, "import '../y.js';");
expectIncludes(text, "import './z.js';");
@@ -261,9 +309,10 @@ class Bar {
const response = await fetch(`${host}/a/b/foo.ts`);
const text = await response.text();
- expect(response.status).to.equal(200);
- expect(response.headers.get('content-type')).to.equal(
- 'application/javascript; charset=utf-8',
+ assert.strictEqual(response.status, 200);
+ assert.strictEqual(
+ response.headers.get('content-type'),
+ 'text/javascript; charset=utf-8',
);
expectIncludes(text, '__publicField(this, "prop");');
diff --git a/packages/dev-server-esbuild/test/tsx.test.ts b/packages/dev-server-esbuild/test/tsx.test.ts
index 86c8b2d6bf..b911cb31e5 100644
--- a/packages/dev-server-esbuild/test/tsx.test.ts
+++ b/packages/dev-server-esbuild/test/tsx.test.ts
@@ -1,12 +1,52 @@
+<<<<<<< HEAD
import { expect } from 'chai';
import { createTestServer } from '@web/dev-server-core/test-helpers';
import { expectIncludes, expectNotIncludes } from '@web/dev-server-core/test-helpers';
+||||||| parent of aecfa949 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import assert from 'node:assert/strict';
+import { describe, it } from 'node:test';
+import path from 'path';
+import { createTestServer } from '@web/dev-server-core/test-helpers.js';
+import { expectIncludes, expectNotIncludes } from '@web/dev-server-core/test-helpers.js';
+=======
+import assert from 'node:assert/strict';
+import { describe, it } from 'node:test';
+import path from 'path';
+<<<<<<< HEAD
+import { createTestServer } from '@web/dev-server-core/test-helpers.js';
+import { expectIncludes, expectNotIncludes } from '@web/dev-server-core/test-helpers.js';
+||||||| parent of 9007e014 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import { createTestServer } from '@web/dev-server-core/test-helpers.ts';
+import { expectIncludes, expectNotIncludes } from '@web/dev-server-core/test-helpers.ts';
+=======
+import { createTestServer } from '@web/dev-server-core/test-helpers';
+import { expectIncludes, expectNotIncludes } from '@web/dev-server-core/test-helpers';
+>>>>>>> 9007e014 (chore: migrate tests from mocha/chai to node:test + node:assert)
+>>>>>>> aecfa949 (chore: migrate tests from mocha/chai to node:test + node:assert)
+<<<<<<< HEAD
+import { esbuildPlugin } from '../src/index.ts';
+||||||| parent of aecfa949 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import { esbuildPlugin } from '../src/index.js';
+=======
+<<<<<<< HEAD
+import { esbuildPlugin } from '../src/index.js';
+||||||| parent of c37bb778 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import { esbuildPlugin } from '../src/index.ts';
+=======
+<<<<<<< HEAD
import { esbuildPlugin } from '../src/index.ts';
+||||||| parent of 61bf92a0 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import { esbuildPlugin } from '../src/index.js';
+=======
+import { esbuildPlugin } from '../src/index.ts';
+>>>>>>> c37bb778 (chore: migrate tests from mocha/chai to node:test + node:assert)
-describe('esbuildPlugin TSX', function () {
- this.timeout(5000);
+const __dirname = import.meta.dirname;
+>>>>>>> 61bf92a0 (chore: migrate tests from mocha/chai to node:test + node:assert)
+>>>>>>> aecfa949 (chore: migrate tests from mocha/chai to node:test + node:assert)
+describe('esbuildPlugin TSX', function () {
it('transforms .tsx files', async () => {
const { server, host } = await createTestServer({
rootDir: __dirname,
@@ -37,9 +77,10 @@ export function foo (a: number, b: number): Foo {
const response = await fetch(`${host}/foo.tsx`);
const text = await response.text();
- expect(response.status).to.equal(200);
- expect(response.headers.get('content-type')).to.equal(
- 'application/javascript; charset=utf-8',
+ assert.strictEqual(response.status, 200);
+ assert.strictEqual(
+ response.headers.get('content-type'),
+ 'text/javascript; charset=utf-8',
);
expectIncludes(text, 'React.createElement("div", {');
expectIncludes(text, 'id: "myDiv"');
@@ -83,9 +124,10 @@ export function foo (a: number, b: number): Foo {
const response = await fetch(`${host}/foo.tsx`);
const text = await response.text();
- expect(response.status).to.equal(200);
- expect(response.headers.get('content-type')).to.equal(
- 'application/javascript; charset=utf-8',
+ assert.strictEqual(response.status, 200);
+ assert.strictEqual(
+ response.headers.get('content-type'),
+ 'text/javascript; charset=utf-8',
);
expectIncludes(text, 'h("div", {');
expectIncludes(text, 'id: "myDiv"');
diff --git a/packages/dev-server-hmr/package.json b/packages/dev-server-hmr/package.json
index 3ea28ebd66..c1f793fcf4 100644
--- a/packages/dev-server-hmr/package.json
+++ b/packages/dev-server-hmr/package.json
@@ -1,6 +1,5 @@
{
"name": "@web/dev-server-hmr",
- "type": "module",
"version": "0.4.1",
"publishConfig": {
"access": "public"
@@ -18,22 +17,24 @@
"exports": {
".": {
"types": "./index.d.ts",
- "default": "./dist/index.js"
+ "import": "./index.mjs",
+ "require": "./dist/index.js"
}
},
"engines": {
- "node": ">=24.0.0"
+ "node": ">=18.0.0"
},
"scripts": {
"build": "tsc",
"start:lit-html": "wds --config demo/lit-html/server.config.mjs",
"start:vanilla": "wds --config demo/vanilla/server.config.mjs",
- "test:node": "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"
+ "test:node": "node --test 'test/**/*.test.ts'",
+ "test:watch": "node --test --watch 'test/**/*.test.ts'"
},
"files": [
"*.d.ts",
"*.js",
+ "*.mjs",
"dist",
"scripts",
"src"
diff --git a/packages/dev-server-hmr/test/HmrPlugin.test.ts b/packages/dev-server-hmr/test/HmrPlugin.test.ts
index b9c9af77b9..e09c73884b 100644
--- a/packages/dev-server-hmr/test/HmrPlugin.test.ts
+++ b/packages/dev-server-hmr/test/HmrPlugin.test.ts
@@ -1,11 +1,44 @@
-import { expect } from 'chai';
+import { describe, it, afterEach } from 'node:test';
+import assert from 'node:assert/strict';
import { stubMethod, restore as restoreStubs } from 'hanbi';
import { createTestServer, fetchText, expectIncludes } from '@web/dev-server-core/test-helpers';
import { posix as pathUtil } from 'path';
+<<<<<<< HEAD
import { hmrPlugin } from '../src/index.ts';
import { NAME_HMR_CLIENT_IMPORT } from '../src/HmrPlugin.ts';
import { mockFile, mockFiles } from './utils.ts';
+||||||| parent of aecfa949 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import { hmrPlugin } from '../src/index.js';
+import { NAME_HMR_CLIENT_IMPORT } from '../src/HmrPlugin.js';
+import { mockFile, mockFiles } from './utils.js';
+=======
+<<<<<<< HEAD
+import { hmrPlugin } from '../src/index.js';
+import { NAME_HMR_CLIENT_IMPORT } from '../src/HmrPlugin.js';
+import { mockFile, mockFiles } from './utils.js';
+||||||| parent of c37bb778 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import { hmrPlugin } from '../src/index.ts';
+import { NAME_HMR_CLIENT_IMPORT } from '../src/HmrPlugin.ts';
+import { mockFile, mockFiles } from './utils.ts';
+=======
+<<<<<<< HEAD
+import { hmrPlugin } from '../src/index.ts';
+import { NAME_HMR_CLIENT_IMPORT } from '../src/HmrPlugin.ts';
+import { mockFile, mockFiles } from './utils.ts';
+||||||| parent of 61bf92a0 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import { hmrPlugin } from '../src/index.js';
+import { NAME_HMR_CLIENT_IMPORT } from '../src/HmrPlugin.js';
+import { mockFile, mockFiles } from './utils.js';
+=======
+import { hmrPlugin } from '../src/index.ts';
+import { NAME_HMR_CLIENT_IMPORT } from '../src/HmrPlugin.ts';
+import { mockFile, mockFiles } from './utils.ts';
+
+const __dirname = import.meta.dirname;
+>>>>>>> 61bf92a0 (chore: migrate tests from mocha/chai to node:test + node:assert)
+>>>>>>> c37bb778 (chore: migrate tests from mocha/chai to node:test + node:assert)
+>>>>>>> aecfa949 (chore: migrate tests from mocha/chai to node:test + node:assert)
describe('HmrPlugin', () => {
afterEach(async () => {
@@ -31,7 +64,8 @@ describe('HmrPlugin', () => {
await fetch(`${host}/foo.js`);
fileWatcher.emit('change', pathUtil.join(__dirname, '/foo.js'));
- expect(stub.firstCall!.args[0]).to.equal(
+ assert.equal(
+ stub.firstCall!.args[0],
JSON.stringify({
type: 'hmr:update',
url: '/foo.js',
@@ -61,7 +95,8 @@ describe('HmrPlugin', () => {
await fetch(`${host}/bar.js`);
fileWatcher.emit('change', pathUtil.join(__dirname, '/bar.js'));
- expect(stub.firstCall!.args[0]).to.equal(
+ assert.equal(
+ stub.firstCall!.args[0],
JSON.stringify({
type: 'hmr:update',
url: '/foo.js',
@@ -88,8 +123,9 @@ describe('HmrPlugin', () => {
await fetch(`${host}/bar.js`);
fileWatcher.emit('change', pathUtil.join(__dirname, '/bar.js'));
- expect(stub.callCount).to.equal(1);
- expect(stub.firstCall!.args[0]).to.equal(
+ assert.equal(stub.callCount, 1);
+ assert.equal(
+ stub.firstCall!.args[0],
JSON.stringify({
type: 'hmr:update',
url: '/foo.js',
@@ -116,8 +152,9 @@ describe('HmrPlugin', () => {
await fetch(`${host}/bar.js`);
fileWatcher.emit('change', pathUtil.join(__dirname, '/bar.js'));
- expect(stub.callCount).to.equal(1);
- expect(stub.firstCall!.args[0]).to.equal(
+ assert.equal(stub.callCount, 1);
+ assert.equal(
+ stub.firstCall!.args[0],
JSON.stringify({
type: 'hmr:reload',
}),
@@ -146,7 +183,8 @@ describe('HmrPlugin', () => {
await fetch(`${host}/root/bar.js`);
fileWatcher.emit('change', pathUtil.join(__dirname, '/root/bar.js'));
- expect(stub.firstCall!.args[0]).to.equal(
+ assert.equal(
+ stub.firstCall!.args[0],
JSON.stringify({
type: 'hmr:update',
url: '/root/foo.js',
@@ -176,7 +214,8 @@ describe('HmrPlugin', () => {
await fetch(`${host}/bar.js`);
fileWatcher.emit('change', pathUtil.join(__dirname, '/bar.js'));
- expect(stub.firstCall!.args[0]).to.equal(
+ assert.equal(
+ stub.firstCall!.args[0],
JSON.stringify({
type: 'hmr:update',
url: '/foo.js',
@@ -208,7 +247,7 @@ describe('HmrPlugin', () => {
const updatedA = await fetchText(`${host}/a.js?m=1234567890123`);
await fetchText(`${host}/b.js?m=1234567890123`);
- expect(/import '\/b\.js\?m=\d{13}';/.test(updatedA)).to.equal(true);
+ assert.equal(/import '\/b\.js\?m=\d{13}';/.test(updatedA), true);
expectIncludes(updatedA, "import '/c.js';");
} finally {
await server.stop();
@@ -237,8 +276,8 @@ describe('HmrPlugin', () => {
const updatedA = await fetchText(`${host}/a.js?m=1234567890123`);
const updatedB = await fetchText(`${host}/b.js?m=1234567890123`);
await fetchText(`${host}/c.js?m=1234567890123`);
- expect(/import '\/b\.js\?m=\d{13}';/.test(updatedA)).to.equal(true);
- expect(/import '\/c\.js\?m=\d{13}';/.test(updatedB)).to.equal(true);
+ assert.equal(/import '\/b\.js\?m=\d{13}';/.test(updatedA), true);
+ assert.equal(/import '\/c\.js\?m=\d{13}';/.test(updatedB), true);
} finally {
await server.stop();
}
@@ -270,8 +309,8 @@ describe('HmrPlugin', () => {
const updatedA2 = await fetchText(`${host}/a2.js?m=1234567890123`);
await fetchText(`${host}/b.js?m=1234567890123`);
await fetchText(`${host}/c.js?m=1234567890123`);
- expect(/import '\/b\.js\?m=\d{13}';/.test(updatedA1)).to.equal(true);
- expect(/import '\/b\.js\?m=\d{13}';/.test(updatedA2)).to.equal(true);
+ assert.equal(/import '\/b\.js\?m=\d{13}';/.test(updatedA1), true);
+ assert.equal(/import '\/b\.js\?m=\d{13}';/.test(updatedA2), true);
} finally {
await server.stop();
}
@@ -296,7 +335,8 @@ describe('HmrPlugin', () => {
await fetch(`${host}/bar.js`);
fileWatcher.emit('change', pathUtil.join(__dirname, '/bar.js'));
- expect(stub.firstCall!.args[0]).to.equal(
+ assert.equal(
+ stub.firstCall!.args[0],
JSON.stringify({
type: 'hmr:update',
url: '/foo.js',
@@ -326,7 +366,8 @@ describe('HmrPlugin', () => {
await fetch(`${host}/foo.js`);
fileWatcher.emit('change', pathUtil.join(__dirname, '/foo.js'));
- expect(stub.firstCall!.args[0]).to.equal(
+ assert.equal(
+ stub.firstCall!.args[0],
JSON.stringify({
type: 'hmr:reload',
}),
@@ -345,7 +386,7 @@ describe('HmrPlugin', () => {
try {
const response = await fetch(`${host}${NAME_HMR_CLIENT_IMPORT}`);
const body = await response.text();
- expect(body.includes('class HotModule')).to.equal(true);
+ assert.equal(body.includes('class HotModule'), true);
} finally {
await server.stop();
}
@@ -369,7 +410,7 @@ describe('HmrPlugin', () => {
const response = await fetch(`${host}/foo.js`);
const body = await response.text();
- expect(body.includes('__WDS_HMR__')).to.equal(true);
+ assert.equal(body.includes('__WDS_HMR__'), true);
} finally {
await server.stop();
}
@@ -385,7 +426,7 @@ describe('HmrPlugin', () => {
const response = await fetch(`${host}/foo.js`);
const body = await response.text();
- expect(body.includes('__WDS_HMR__')).to.equal(false);
+ assert.equal(body.includes('__WDS_HMR__'), false);
} finally {
await server.stop();
}
diff --git a/packages/dev-server-hmr/test/browser.test.ts b/packages/dev-server-hmr/test/browser.test.ts
index a6386a004a..282c75eef6 100644
--- a/packages/dev-server-hmr/test/browser.test.ts
+++ b/packages/dev-server-hmr/test/browser.test.ts
@@ -1,12 +1,55 @@
-import { expect } from 'chai';
+import { describe, it, before, after } from 'node:test';
+import assert from 'node:assert/strict';
import { stubMethod } from 'hanbi';
+<<<<<<< HEAD
import { createTestServer, expectIncludes } from '@web/dev-server-core/test-helpers';
import { Browser, HTTPResponse, launch as launchPuppeteer, Page } from 'puppeteer';
+||||||| parent of aecfa949 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import { createTestServer, expectIncludes } from '@web/dev-server-core/test-helpers.js';
+import type { Browser, HTTPResponse, Page } from 'puppeteer';
+import { launch as launchPuppeteer } from 'puppeteer';
+=======
+<<<<<<< HEAD
+import { createTestServer, expectIncludes } from '@web/dev-server-core/test-helpers.js';
+||||||| parent of 9007e014 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import { createTestServer, expectIncludes } from '@web/dev-server-core/test-helpers.ts';
+=======
+import { createTestServer, expectIncludes } from '@web/dev-server-core/test-helpers';
+>>>>>>> 9007e014 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import type { Browser, HTTPResponse, Page } from 'puppeteer';
+import { launch as launchPuppeteer } from 'puppeteer';
+>>>>>>> aecfa949 (chore: migrate tests from mocha/chai to node:test + node:assert)
import { posix as pathUtil } from 'path';
+<<<<<<< HEAD
+import { hmrPlugin } from '../src/index.ts';
+import { mockFiles } from './utils.ts';
+||||||| parent of aecfa949 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import { hmrPlugin } from '../src/index.js';
+import { mockFiles } from './utils.js';
+=======
+<<<<<<< HEAD
+import { hmrPlugin } from '../src/index.js';
+import { mockFiles } from './utils.js';
+||||||| parent of c37bb778 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import { hmrPlugin } from '../src/index.ts';
+import { mockFiles } from './utils.ts';
+=======
+<<<<<<< HEAD
+import { hmrPlugin } from '../src/index.ts';
+import { mockFiles } from './utils.ts';
+||||||| parent of 61bf92a0 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import { hmrPlugin } from '../src/index.js';
+import { mockFiles } from './utils.js';
+=======
import { hmrPlugin } from '../src/index.ts';
import { mockFiles } from './utils.ts';
+const __dirname = import.meta.dirname;
+>>>>>>> 61bf92a0 (chore: migrate tests from mocha/chai to node:test + node:assert)
+>>>>>>> c37bb778 (chore: migrate tests from mocha/chai to node:test + node:assert)
+>>>>>>> aecfa949 (chore: migrate tests from mocha/chai to node:test + node:assert)
+
function trackErrors(page: Page) {
const errors: any[] = [];
page.on('error', error => {
@@ -36,15 +79,14 @@ async function mockFaviconRequests(page: Page) {
});
}
-describe('browser tests', function () {
- this.timeout(5000);
+describe('browser tests', { timeout: 10000 }, () => {
let browser: Browser;
- before(async () => {
+ before(async function () {
browser = await launchPuppeteer();
});
- after(async () => {
+ after(async function () {
await browser.close();
});
@@ -67,14 +109,16 @@ describe('browser tests', function () {
await page.goto(`${host}/foo.html`, { waitUntil: 'networkidle0' });
fileWatcher.emit('change', pathUtil.join(__dirname, '/bar.js'));
- expect(stub.callCount).to.equal(2);
- expect(stub.getCall(0)!.args[0]).to.equal(
+ assert.equal(stub.callCount, 2);
+ assert.equal(
+ stub.getCall(0)!.args[0],
JSON.stringify({
type: 'hmr:update',
url: '/bar.js',
}),
);
- expect(stub.getCall(1)!.args[0]).to.equal(
+ assert.equal(
+ stub.getCall(1)!.args[0],
JSON.stringify({
type: 'hmr:update',
url: '/foo.js',
@@ -118,7 +162,7 @@ describe('browser tests', function () {
}
});
- it('should hot replace a bubbled module', async () => {
+ it('should hot replace a bubbled module', async function () {
const files = {
'/foo.html': '',
'/foo.js':
@@ -154,7 +198,7 @@ describe('browser tests', function () {
/**
* Times out in CI because it's too slow
*/
- it.skip('hot replaces multiple bubbled modules', async () => {
+ it.skip('hot replaces multiple bubbled modules', async function () {
const files = {
'/foo.html': '',
'/foo.js':
@@ -195,7 +239,7 @@ describe('browser tests', function () {
}
});
- it('reloads the page when a module has no hot replacable parent', async () => {
+ it('reloads the page when a module has no hot replacable parent', async function () {
const files = {
'/foo.html':
'',
diff --git a/packages/dev-server-hmr/test/utils.ts b/packages/dev-server-hmr/test/utils.ts
index a79c7400f1..fb7494e706 100644
--- a/packages/dev-server-hmr/test/utils.ts
+++ b/packages/dev-server-hmr/test/utils.ts
@@ -1,4 +1,4 @@
-import { Context } from 'koa';
+import type { Context } from 'koa';
export const mockFile = (path: string, source: string) => ({
name: `test-file:${path}`,
diff --git a/packages/dev-server-import-maps/package.json b/packages/dev-server-import-maps/package.json
index 25483a08bd..85eb82b64e 100644
--- a/packages/dev-server-import-maps/package.json
+++ b/packages/dev-server-import-maps/package.json
@@ -1,6 +1,5 @@
{
"name": "@web/dev-server-import-maps",
- "type": "module",
"version": "0.2.1",
"publishConfig": {
"access": "public"
@@ -18,21 +17,23 @@
"exports": {
".": {
"types": "./index.d.ts",
- "default": "./dist/index.js"
+ "import": "./index.mjs",
+ "require": "./dist/index.js"
}
},
"engines": {
- "node": ">=24.0.0"
+ "node": ">=18.0.0"
},
"scripts": {
"build": "tsc",
- "test": "mocha \"test/**/*.test.ts\" --require ts-node/register",
+ "test": "node --test test/**/*.test.ts",
"test:browser": "node ../test-runner/dist/bin.js test-browser/test/**/*.test.{js,html} --config test-browser/web-test-runner.config.mjs",
- "test:watch": "mocha \"test/**/*.test.ts\" --require ts-node/register --watch --watch-files src,test"
+ "test:watch": "node --test --watch test/**/*.test.ts"
},
"files": [
"*.d.ts",
"*.js",
+ "*.mjs",
"dist",
"src"
],
@@ -50,6 +51,7 @@
],
"dependencies": {
"@import-maps/resolve": "^1.0.1",
+ "@types/parse5": "^6.0.1",
"@web/dev-server-core": "^0.7.2",
"@web/parse5-utils": "^2.1.0",
"parse5": "^6.0.1",
diff --git a/packages/dev-server-import-maps/test/injection.test.ts b/packages/dev-server-import-maps/test/injection.test.ts
index 1b32041f2a..626d64c278 100644
--- a/packages/dev-server-import-maps/test/injection.test.ts
+++ b/packages/dev-server-import-maps/test/injection.test.ts
@@ -1,11 +1,29 @@
+<<<<<<< HEAD
import { createTestServer, expectNotIncludes } from '@web/dev-server-core/test-helpers';
import { fetchText, expectIncludes, virtualFilesPlugin } from '@web/dev-server-core/test-helpers';
+||||||| parent of aecfa949 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import { it } from 'node:test';
+import { createTestServer, expectNotIncludes } from '@web/dev-server-core/test-helpers.js';
+import { fetchText, expectIncludes, virtualFilesPlugin } from '@web/dev-server-core/test-helpers.js';
+=======
+import { it } from 'node:test';
+<<<<<<< HEAD
+import { createTestServer, expectNotIncludes } from '@web/dev-server-core/test-helpers.js';
+import { fetchText, expectIncludes, virtualFilesPlugin } from '@web/dev-server-core/test-helpers.js';
+||||||| parent of 9007e014 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import { createTestServer, expectNotIncludes } from '@web/dev-server-core/test-helpers.ts';
+import { fetchText, expectIncludes, virtualFilesPlugin } from '@web/dev-server-core/test-helpers.ts';
+=======
+import { createTestServer, expectNotIncludes } from '@web/dev-server-core/test-helpers';
+import { fetchText, expectIncludes, virtualFilesPlugin } from '@web/dev-server-core/test-helpers';
+>>>>>>> 9007e014 (chore: migrate tests from mocha/chai to node:test + node:assert)
+>>>>>>> aecfa949 (chore: migrate tests from mocha/chai to node:test + node:assert)
-import { importMapsPlugin } from '../src/importMapsPlugin.ts';
+import { importMapsPlugin } from '../src/importMapsPlugin.js';
it('can inject an import map into any page', async () => {
const { server, host } = await createTestServer({
- rootDir: __dirname,
+ rootDir: import.meta.dirname,
plugins: [
virtualFilesPlugin({
'/index.html': '',
@@ -28,7 +46,7 @@ it('can inject an import map into any page', async () => {
it('can use an include pattern', async () => {
const { server, host } = await createTestServer({
- rootDir: __dirname,
+ rootDir: import.meta.dirname,
plugins: [
virtualFilesPlugin({
'/foo/a.html': '',
@@ -58,7 +76,7 @@ it('can use an include pattern', async () => {
it('can use an exclude pattern', async () => {
const { server, host } = await createTestServer({
- rootDir: __dirname,
+ rootDir: import.meta.dirname,
plugins: [
virtualFilesPlugin({
'/foo/a.html': '',
@@ -86,7 +104,7 @@ it('can use an exclude pattern', async () => {
it('treats directory paths with an implicit index.html file', async () => {
const { server, host } = await createTestServer({
- rootDir: __dirname,
+ rootDir: import.meta.dirname,
plugins: [
{
name: 'test',
@@ -116,7 +134,7 @@ it('treats directory paths with an implicit index.html file', async () => {
it('merges with an existing import map', async () => {
const { server, host } = await createTestServer({
- rootDir: __dirname,
+ rootDir: import.meta.dirname,
plugins: [
virtualFilesPlugin({
'/index.html':
@@ -146,7 +164,7 @@ it('merges with an existing import map', async () => {
it('merges import map scopes', async () => {
const { server, host } = await createTestServer({
- rootDir: __dirname,
+ rootDir: import.meta.dirname,
plugins: [
virtualFilesPlugin({
'/index.html':
@@ -176,7 +194,7 @@ it('merges import map scopes', async () => {
it('the import map in the HTML file takes priority over the injected import map', async () => {
const { server, host } = await createTestServer({
- rootDir: __dirname,
+ rootDir: import.meta.dirname,
plugins: [
virtualFilesPlugin({
'/index.html':
diff --git a/packages/dev-server-import-maps/test/resolving.test.ts b/packages/dev-server-import-maps/test/resolving.test.ts
index 91ca73ca87..bc8eecf165 100644
--- a/packages/dev-server-import-maps/test/resolving.test.ts
+++ b/packages/dev-server-import-maps/test/resolving.test.ts
@@ -1,12 +1,58 @@
+<<<<<<< HEAD
import { fetchText, expectIncludes, virtualFilesPlugin } from '@web/dev-server-core/test-helpers';
import { createTestServer } from '@web/dev-server-core/test-helpers';
import { expect } from 'chai';
+||||||| parent of aecfa949 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import { describe, it } from 'node:test';
+import assert from 'node:assert/strict';
+import { fetchText, expectIncludes, virtualFilesPlugin } from '@web/dev-server-core/test-helpers.js';
+import { createTestServer } from '@web/dev-server-core/test-helpers.js';
+=======
+import { describe, it } from 'node:test';
+import assert from 'node:assert/strict';
+<<<<<<< HEAD
+import { fetchText, expectIncludes, virtualFilesPlugin } from '@web/dev-server-core/test-helpers.js';
+import { createTestServer } from '@web/dev-server-core/test-helpers.js';
+||||||| parent of 9007e014 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import { fetchText, expectIncludes, virtualFilesPlugin } from '@web/dev-server-core/test-helpers.ts';
+import { createTestServer } from '@web/dev-server-core/test-helpers.ts';
+=======
+import { fetchText, expectIncludes, virtualFilesPlugin } from '@web/dev-server-core/test-helpers';
+import { createTestServer } from '@web/dev-server-core/test-helpers';
+>>>>>>> 9007e014 (chore: migrate tests from mocha/chai to node:test + node:assert)
+>>>>>>> aecfa949 (chore: migrate tests from mocha/chai to node:test + node:assert)
import { spy } from 'hanbi';
import path from 'path';
+<<<<<<< HEAD
+import { importMapsPlugin } from '../src/importMapsPlugin.ts';
+import { IMPORT_MAP_PARAM } from '../src/utils.ts';
+||||||| parent of aecfa949 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import { importMapsPlugin } from '../src/importMapsPlugin.js';
+import { IMPORT_MAP_PARAM } from '../src/utils.js';
+=======
+<<<<<<< HEAD
+import { importMapsPlugin } from '../src/importMapsPlugin.js';
+import { IMPORT_MAP_PARAM } from '../src/utils.js';
+||||||| parent of c37bb778 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import { importMapsPlugin } from '../src/importMapsPlugin.ts';
+import { IMPORT_MAP_PARAM } from '../src/utils.ts';
+=======
+<<<<<<< HEAD
+import { importMapsPlugin } from '../src/importMapsPlugin.ts';
+import { IMPORT_MAP_PARAM } from '../src/utils.ts';
+||||||| parent of 61bf92a0 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import { importMapsPlugin } from '../src/importMapsPlugin.js';
+import { IMPORT_MAP_PARAM } from '../src/utils.js';
+=======
import { importMapsPlugin } from '../src/importMapsPlugin.ts';
import { IMPORT_MAP_PARAM } from '../src/utils.ts';
+const __dirname = import.meta.dirname;
+>>>>>>> 61bf92a0 (chore: migrate tests from mocha/chai to node:test + node:assert)
+>>>>>>> c37bb778 (chore: migrate tests from mocha/chai to node:test + node:assert)
+>>>>>>> aecfa949 (chore: migrate tests from mocha/chai to node:test + node:assert)
+
function createHtml(importMap: Record) {
return `
@@ -201,8 +247,7 @@ describe('resolving imports', () => {
it(`leaves unmapped bare imports untouched`, async () => {
const files = {
- '/index.html': createHtml({ './bar.js': './mocked-bar.js' }),
- '/x/y/app.js': 'import "x";',
+ '/index.html': createHtml({ './bar.js': './mocked-bar.js' }), '/x/y/app.js': 'import "x";',
};
const { server, host } = await createTestServer({
rootDir: __dirname,
@@ -379,7 +424,7 @@ describe('resolving imports', () => {
const text = await fetchText(`${host}/index.html`);
expectIncludes(text, '');
- expect(loggerSpies.warn.callCount).to.equal(1);
+ assert.equal(loggerSpies.warn.callCount, 1);
const warning = loggerSpies.warn.getCall(0).args[0];
expectIncludes(warning, 'Failed to parse import map in "');
expectIncludes(warning, `test${path.sep}index.html": `);
diff --git a/packages/dev-server-legacy/package.json b/packages/dev-server-legacy/package.json
index a58ba8794c..6f8d5dddf7 100644
--- a/packages/dev-server-legacy/package.json
+++ b/packages/dev-server-legacy/package.json
@@ -1,6 +1,5 @@
{
"name": "@web/dev-server-legacy",
- "type": "module",
"version": "2.1.1",
"publishConfig": {
"access": "public"
@@ -18,21 +17,23 @@
"exports": {
".": {
"types": "./index.d.ts",
- "default": "./dist/index.js"
+ "import": "./index.mjs",
+ "require": "./dist/index.js"
}
},
"engines": {
- "node": ">=24.0.0"
+ "node": ">=18.0.0"
},
"scripts": {
"build": "tsc",
"start": "wds --open --config demo/server.config.mjs",
- "test:node": "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"
+ "test:node": "node --test test/**/*.test.ts",
+ "test:watch": "node --test --watch test/**/*.test.ts"
},
"files": [
"*.d.ts",
"*.js",
+ "*.mjs",
"dist",
"src"
],
diff --git a/packages/dev-server-legacy/test/transform-html.test.ts b/packages/dev-server-legacy/test/transform-html.test.ts
index 1250362dc3..3fe88cc6b2 100644
--- a/packages/dev-server-legacy/test/transform-html.test.ts
+++ b/packages/dev-server-legacy/test/transform-html.test.ts
@@ -1,10 +1,56 @@
+<<<<<<< HEAD
import { expect } from 'chai';
import { createTestServer } from '@web/dev-server-core/test-helpers';
import { fetchText, expectIncludes } from '@web/dev-server-core/test-helpers';
+||||||| parent of aecfa949 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import { describe, it } from 'node:test';
+import assert from 'node:assert/strict';
+import { createTestServer } from '@web/dev-server-core/test-helpers.js';
+import { fetchText, expectIncludes } from '@web/dev-server-core/test-helpers.js';
+=======
+import { describe, it } from 'node:test';
+import assert from 'node:assert/strict';
+<<<<<<< HEAD
+import { createTestServer } from '@web/dev-server-core/test-helpers.js';
+import { fetchText, expectIncludes } from '@web/dev-server-core/test-helpers.js';
+||||||| parent of 9007e014 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import { createTestServer } from '@web/dev-server-core/test-helpers.ts';
+import { fetchText, expectIncludes } from '@web/dev-server-core/test-helpers.ts';
+=======
+import { createTestServer } from '@web/dev-server-core/test-helpers';
+import { fetchText, expectIncludes } from '@web/dev-server-core/test-helpers';
+>>>>>>> 9007e014 (chore: migrate tests from mocha/chai to node:test + node:assert)
+>>>>>>> aecfa949 (chore: migrate tests from mocha/chai to node:test + node:assert)
+<<<<<<< HEAD
+import { legacyPlugin } from '../src/legacyPlugin.ts';
+import { modernUserAgents, legacyUserAgents } from './userAgents.ts';
+||||||| parent of aecfa949 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import { legacyPlugin } from '../src/legacyPlugin.js';
+import { modernUserAgents, legacyUserAgents } from './userAgents.js';
+=======
+<<<<<<< HEAD
+import { legacyPlugin } from '../src/legacyPlugin.js';
+import { modernUserAgents, legacyUserAgents } from './userAgents.js';
+||||||| parent of c37bb778 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import { legacyPlugin } from '../src/legacyPlugin.ts';
+import { modernUserAgents, legacyUserAgents } from './userAgents.ts';
+=======
+<<<<<<< HEAD
+import { legacyPlugin } from '../src/legacyPlugin.ts';
+import { modernUserAgents, legacyUserAgents } from './userAgents.ts';
+||||||| parent of 61bf92a0 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import { legacyPlugin } from '../src/legacyPlugin.js';
+import { modernUserAgents, legacyUserAgents } from './userAgents.js';
+=======
import { legacyPlugin } from '../src/legacyPlugin.ts';
import { modernUserAgents, legacyUserAgents } from './userAgents.ts';
+const __dirname = import.meta.dirname;
+>>>>>>> 61bf92a0 (chore: migrate tests from mocha/chai to node:test + node:assert)
+>>>>>>> c37bb778 (chore: migrate tests from mocha/chai to node:test + node:assert)
+>>>>>>> aecfa949 (chore: migrate tests from mocha/chai to node:test + node:assert)
+
const htmlBody = `
@@ -25,9 +71,7 @@ const inlineScriptHtmlBody = `
`;
-describe('legacyPlugin - transform html', function () {
- this.timeout(10000);
-
+describe('legacyPlugin - transform html', { timeout: 10000 }, () => {
it(`does not do any work on a modern browser`, async () => {
const { server, host } = await createTestServer({
rootDir: __dirname,
@@ -48,7 +92,7 @@ describe('legacyPlugin - transform html', function () {
headers: { 'user-agent': modernUserAgents['Chrome 78'] },
});
- expect(text.trim()).to.equal(htmlBody.trim());
+ assert.equal(text.trim(), htmlBody.trim());
server.stop();
});
diff --git a/packages/dev-server-legacy/test/transform-js.test.ts b/packages/dev-server-legacy/test/transform-js.test.ts
index 148c2f24c3..152bf656c5 100644
--- a/packages/dev-server-legacy/test/transform-js.test.ts
+++ b/packages/dev-server-legacy/test/transform-js.test.ts
@@ -1,10 +1,56 @@
+<<<<<<< HEAD
import { expect } from 'chai';
import { createTestServer } from '@web/dev-server-core/test-helpers';
import { fetchText, expectIncludes, expectNotIncludes } from '@web/dev-server-core/test-helpers';
+||||||| parent of aecfa949 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import { describe, it } from 'node:test';
+import assert from 'node:assert/strict';
+import { createTestServer } from '@web/dev-server-core/test-helpers.js';
+import { fetchText, expectIncludes, expectNotIncludes } from '@web/dev-server-core/test-helpers.js';
+=======
+import { describe, it } from 'node:test';
+import assert from 'node:assert/strict';
+<<<<<<< HEAD
+import { createTestServer } from '@web/dev-server-core/test-helpers.js';
+import { fetchText, expectIncludes, expectNotIncludes } from '@web/dev-server-core/test-helpers.js';
+||||||| parent of 9007e014 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import { createTestServer } from '@web/dev-server-core/test-helpers.ts';
+import { fetchText, expectIncludes, expectNotIncludes } from '@web/dev-server-core/test-helpers.ts';
+=======
+import { createTestServer } from '@web/dev-server-core/test-helpers';
+import { fetchText, expectIncludes, expectNotIncludes } from '@web/dev-server-core/test-helpers';
+>>>>>>> 9007e014 (chore: migrate tests from mocha/chai to node:test + node:assert)
+>>>>>>> aecfa949 (chore: migrate tests from mocha/chai to node:test + node:assert)
+<<<<<<< HEAD
+import { legacyPlugin } from '../src/legacyPlugin.ts';
+import { modernUserAgents, legacyUserAgents } from './userAgents.ts';
+||||||| parent of aecfa949 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import { legacyPlugin } from '../src/legacyPlugin.js';
+import { modernUserAgents, legacyUserAgents } from './userAgents.js';
+=======
+<<<<<<< HEAD
+import { legacyPlugin } from '../src/legacyPlugin.js';
+import { modernUserAgents, legacyUserAgents } from './userAgents.js';
+||||||| parent of c37bb778 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import { legacyPlugin } from '../src/legacyPlugin.ts';
+import { modernUserAgents, legacyUserAgents } from './userAgents.ts';
+=======
+<<<<<<< HEAD
+import { legacyPlugin } from '../src/legacyPlugin.ts';
+import { modernUserAgents, legacyUserAgents } from './userAgents.ts';
+||||||| parent of 61bf92a0 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import { legacyPlugin } from '../src/legacyPlugin.js';
+import { modernUserAgents, legacyUserAgents } from './userAgents.js';
+=======
import { legacyPlugin } from '../src/legacyPlugin.ts';
import { modernUserAgents, legacyUserAgents } from './userAgents.ts';
+const __dirname = import.meta.dirname;
+>>>>>>> 61bf92a0 (chore: migrate tests from mocha/chai to node:test + node:assert)
+>>>>>>> c37bb778 (chore: migrate tests from mocha/chai to node:test + node:assert)
+>>>>>>> aecfa949 (chore: migrate tests from mocha/chai to node:test + node:assert)
+
const modernCode = `
class Foo {
@@ -16,9 +62,7 @@ async function doImport() {
console.log(window?.foo?.bar);`;
-describe('legacyPlugin - transform js', function () {
- this.timeout(10000);
-
+describe('legacyPlugin - transform js', { timeout: 10000 }, () => {
for (const [name, userAgent] of Object.entries(modernUserAgents)) {
it(`does not do any work on ${name}`, async () => {
const { server, host } = await createTestServer({
@@ -39,7 +83,7 @@ describe('legacyPlugin - transform js', function () {
const text = await fetchText(`${host}/app.js`, {
headers: { 'user-agent': userAgent },
});
- expect(text.trim()).to.equal(modernCode.trim());
+ assert.equal(text.trim(), modernCode.trim());
server.stop();
});
}
@@ -67,7 +111,7 @@ describe('legacyPlugin - transform js', function () {
expectNotIncludes(text, 'System.register(');
expectIncludes(text, "import('./xyz.js?systemjs=true');");
expectIncludes(text, 'function asyncGeneratorStep');
- expectIncludes(text, 'function _classCallCheck(instance');
+ expectIncludes(text, 'function _classCallCheck(');
expectIncludes(text, '_asyncToGenerator');
expectIncludes(
text,
@@ -98,7 +142,7 @@ describe('legacyPlugin - transform js', function () {
expectIncludes(text, 'System.register(');
expectIncludes(text, "_context.import('./xyz.js?systemjs=true');");
expectIncludes(text, 'function asyncGeneratorStep');
- expectIncludes(text, 'function _classCallCheck(instance');
+ expectIncludes(text, 'function _classCallCheck(');
expectIncludes(text, '_asyncToGenerator');
expectIncludes(
text,
diff --git a/packages/dev-server-rollup/package.json b/packages/dev-server-rollup/package.json
index b2ecac5705..7a0460920d 100644
--- a/packages/dev-server-rollup/package.json
+++ b/packages/dev-server-rollup/package.json
@@ -1,6 +1,5 @@
{
"name": "@web/dev-server-rollup",
- "type": "module",
"version": "0.6.4",
"publishConfig": {
"access": "public"
@@ -18,19 +17,21 @@
"exports": {
".": {
"types": "./index.d.ts",
- "default": "./dist/index.js"
+ "import": "./index.mjs",
+ "require": "./dist/index.js"
}
},
"engines": {
- "node": ">=24.0.0"
+ "node": ">=18.0.0"
},
"scripts": {
- "test:node": "mocha \"test/node/**/*.test.ts\" --require ts-node/register --exit --reporter dot",
- "test:watch": "mocha \"test/node/**/*.test.ts\" --require ts-node/register --watch --watch-files src,test"
+ "test:node": "node --test \"test/node/**/*.test.ts\"",
+ "test:watch": "node --test --watch \"test/node/**/*.test.ts\""
},
"files": [
"*.d.ts",
"*.js",
+ "*.mjs",
"dist",
"src"
],
@@ -49,7 +50,7 @@
"dependencies": {
"@rollup/plugin-node-resolve": "^15.0.1",
"@web/dev-server-core": "^0.7.2",
- "nanocolors": "^0.2.13",
+ "nanocolors": "^0.2.1",
"parse5": "^6.0.1",
"rollup": "^4.4.0",
"whatwg-url": "^14.0.0"
@@ -60,10 +61,12 @@
"@rollup/plugin-babel": "^6.0.4",
"@rollup/plugin-commonjs": "25.0.7",
"@rollup/plugin-replace": "^5.0.5",
+ "@types/parse5": "^6.0.1",
"@types/whatwg-url": "^11.0.0",
"@web/test-runner-chrome": "^0.18.0",
"@web/test-runner-core": "^0.13.0",
"chai": "^4.2.0",
+ "mocha": "^10.8.2",
"postcss": "^8.4.31",
"rollup-plugin-postcss": "^4.0.2"
}
diff --git a/packages/dev-server-rollup/test/node/plugins/alias.test.ts b/packages/dev-server-rollup/test/node/plugins/alias.test.ts
index 1a9bde66ed..dc45f2dead 100644
--- a/packages/dev-server-rollup/test/node/plugins/alias.test.ts
+++ b/packages/dev-server-rollup/test/node/plugins/alias.test.ts
@@ -1,7 +1,15 @@
+<<<<<<< HEAD
import rollupAlias from '@rollup/plugin-alias';
+||||||| parent of aecfa949 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import { describe, it } from 'node:test';
+import rollupAlias from '@rollup/plugin-alias.ts';
+=======
+import { describe, it } from 'node:test';
+import rollupAlias from '@rollup/plugin-alias';
+>>>>>>> aecfa949 (chore: migrate tests from mocha/chai to node:test + node:assert)
-import { createTestServer, fetchText, expectIncludes } from '../test-helpers.ts';
-import { fromRollup } from '../../../src/fromRollup.ts';
+import { createTestServer, fetchText, expectIncludes } from '../test-helpers.js';
+import { fromRollup } from '../../../src/fromRollup.js';
const alias = fromRollup(rollupAlias);
diff --git a/packages/dev-server-rollup/test/node/plugins/babel.test.ts b/packages/dev-server-rollup/test/node/plugins/babel.test.ts
index 0b60336da0..6add5e8865 100644
--- a/packages/dev-server-rollup/test/node/plugins/babel.test.ts
+++ b/packages/dev-server-rollup/test/node/plugins/babel.test.ts
@@ -1,9 +1,44 @@
///
+<<<<<<< HEAD
import rollupBabel from '@rollup/plugin-babel';
+||||||| parent of aecfa949 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import { describe, it } from 'node:test';
+import { fileURLToPath } from 'node:url';
+import rollupBabel from '@rollup/plugin-babel.ts';
+=======
+import { describe, it } from 'node:test';
+import { fileURLToPath } from 'node:url';
+import rollupBabel from '@rollup/plugin-babel';
+>>>>>>> aecfa949 (chore: migrate tests from mocha/chai to node:test + node:assert)
+<<<<<<< HEAD
+import { createTestServer, fetchText, expectIncludes } from '../test-helpers.ts';
+import { fromRollup } from '../../../src/index.ts';
+||||||| parent of aecfa949 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import { createTestServer, fetchText, expectIncludes } from '../test-helpers.js';
+import { fromRollup } from '../../../src/index.js';
+=======
+<<<<<<< HEAD
+import { createTestServer, fetchText, expectIncludes } from '../test-helpers.js';
+import { fromRollup } from '../../../src/index.js';
+||||||| parent of c37bb778 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import { createTestServer, fetchText, expectIncludes } from '../test-helpers.ts';
+import { fromRollup } from '../../../src/index.ts';
+=======
+<<<<<<< HEAD
import { createTestServer, fetchText, expectIncludes } from '../test-helpers.ts';
import { fromRollup } from '../../../src/index.ts';
+>>>>>>> c37bb778 (chore: migrate tests from mocha/chai to node:test + node:assert)
+
+||||||| parent of 61bf92a0 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import { createTestServer, fetchText, expectIncludes } from '../test-helpers.js';
+import { fromRollup } from '../../../src/index.js';
+>>>>>>> aecfa949 (chore: migrate tests from mocha/chai to node:test + node:assert)
+=======
+import { createTestServer, fetchText, expectIncludes } from '../test-helpers.ts';
+import { fromRollup } from '../../../src/index.ts';
+>>>>>>> 61bf92a0 (chore: migrate tests from mocha/chai to node:test + node:assert)
const babel = fromRollup(rollupBabel);
describe('@rollup/plugin-alias', () => {
@@ -20,7 +55,7 @@ describe('@rollup/plugin-alias', () => {
},
babel({
babelHelpers: 'inline',
- plugins: [require.resolve('@babel/plugin-transform-template-literals')],
+ plugins: [fileURLToPath(import.meta.resolve('@babel/plugin-transform-template-literals'))],
}),
],
});
diff --git a/packages/dev-server-rollup/test/node/plugins/commonjs.test.ts b/packages/dev-server-rollup/test/node/plugins/commonjs.test.ts
index 20c4942ccc..9002d0a7aa 100644
--- a/packages/dev-server-rollup/test/node/plugins/commonjs.test.ts
+++ b/packages/dev-server-rollup/test/node/plugins/commonjs.test.ts
@@ -1,13 +1,49 @@
+<<<<<<< HEAD
import rollupCommonjs from '@rollup/plugin-commonjs';
import { runTests } from '@web/test-runner-core/test-helpers';
+||||||| parent of aecfa949 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import { describe, it } from 'node:test';
+import rollupCommonjs from '@rollup/plugin-commonjs.ts';
+import { runTests } from '@web/test-runner-core/test-helpers.js';
+=======
+import { describe, it } from 'node:test';
+<<<<<<< HEAD
+import rollupCommonjs from '@rollup/plugin-commonjs.ts';
+import { runTests } from '@web/test-runner-core/test-helpers.js';
+||||||| parent of 9007e014 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import rollupCommonjs from '@rollup/plugin-commonjs.ts';
+import { runTests } from '@web/test-runner-core/test-helpers.ts';
+=======
+import rollupCommonjs from '@rollup/plugin-commonjs';
+import { runTests } from '@web/test-runner-core/test-helpers';
+>>>>>>> 9007e014 (chore: migrate tests from mocha/chai to node:test + node:assert)
+>>>>>>> aecfa949 (chore: migrate tests from mocha/chai to node:test + node:assert)
import { resolve } from 'path';
+<<<<<<< HEAD
+import { chromeLauncher } from '@web/test-runner-chrome.js';
+||||||| parent of 9007e014 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import { chromeLauncher } from '@web/test-runner-chrome.ts';
+=======
import { chromeLauncher } from '@web/test-runner-chrome';
+>>>>>>> 9007e014 (chore: migrate tests from mocha/chai to node:test + node:assert)
import * as path from 'path';
+<<<<<<< HEAD
+import { createTestServer, fetchText, expectIncludes } from '../test-helpers.ts';
+import { fromRollup } from '../../../src/index.ts';
+import { nodeResolvePlugin } from '@web/dev-server.js';
+||||||| parent of 9007e014 (chore: migrate tests from mocha/chai to node:test + node:assert)
import { createTestServer, fetchText, expectIncludes } from '../test-helpers.ts';
import { fromRollup } from '../../../src/index.ts';
+import { nodeResolvePlugin } from '@web/dev-server.ts';
+=======
+import { createTestServer, fetchText, expectIncludes } from '../test-helpers.js';
+import { fromRollup } from '../../../src/index.js';
import { nodeResolvePlugin } from '@web/dev-server';
+const __dirname = import.meta.dirname;
+>>>>>>> 9007e014 (chore: migrate tests from mocha/chai to node:test + node:assert)
+
const commonjs = fromRollup(rollupCommonjs);
describe('@rollup/plugin-commonjs', () => {
@@ -199,9 +235,7 @@ exports.default = _default;`;
}
});
- it('passes the in-browser tests', async function () {
- this.timeout(40000);
-
+ it('passes the in-browser tests', { timeout: 40000 }, async () => {
await runTests({
files: [resolve(__dirname, '..', 'fixtures', 'commonjs', 'commonjs-browser-test.js')],
browsers: [chromeLauncher({ launchOptions: { devtools: false } })],
diff --git a/packages/dev-server-rollup/test/node/plugins/node-resolve.test.ts b/packages/dev-server-rollup/test/node/plugins/node-resolve.test.ts
index a58179690e..1e4b41203b 100644
--- a/packages/dev-server-rollup/test/node/plugins/node-resolve.test.ts
+++ b/packages/dev-server-rollup/test/node/plugins/node-resolve.test.ts
@@ -1,11 +1,39 @@
+import { describe, it } from 'node:test';
+import assert from 'node:assert/strict';
import path from 'path';
import rollupNodeResolve from '@rollup/plugin-node-resolve';
import rollupCommonjs from '@rollup/plugin-commonjs';
+<<<<<<< HEAD
import { createTestServer, fetchText, expectIncludes } from '../test-helpers.ts';
import { fromRollup } from '../../../src/index.ts';
+||||||| parent of aecfa949 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import { createTestServer, fetchText, expectIncludes } from '../test-helpers.js';
+import { fromRollup } from '../../../src/index.js';
+=======
+<<<<<<< HEAD
+import { createTestServer, fetchText, expectIncludes } from '../test-helpers.js';
+import { fromRollup } from '../../../src/index.js';
+||||||| parent of c37bb778 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import { createTestServer, fetchText, expectIncludes } from '../test-helpers.ts';
+import { fromRollup } from '../../../src/index.ts';
+=======
+<<<<<<< HEAD
+import { createTestServer, fetchText, expectIncludes } from '../test-helpers.ts';
+import { fromRollup } from '../../../src/index.ts';
+>>>>>>> c37bb778 (chore: migrate tests from mocha/chai to node:test + node:assert)
import { expect } from 'chai';
+||||||| parent of 61bf92a0 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import { createTestServer, fetchText, expectIncludes } from '../test-helpers.js';
+import { fromRollup } from '../../../src/index.js';
+>>>>>>> aecfa949 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import { expect } from 'chai';
+=======
+import { createTestServer, fetchText, expectIncludes } from '../test-helpers.ts';
+import { fromRollup } from '../../../src/index.ts';
+>>>>>>> 61bf92a0 (chore: migrate tests from mocha/chai to node:test + node:assert)
+const __dirname = import.meta.dirname;
const nodeResolve = fromRollup(rollupNodeResolve, {}, { throwOnUnresolvedImport: true });
const commonjs = fromRollup(rollupCommonjs);
@@ -82,7 +110,7 @@ describe('@rollup/plugin-node-resolve', () => {
try {
const response = await fetch(`${host}/import-private-directly.html`);
- expect(response.status).to.equal(500);
+ assert.equal(response.status, 500);
} finally {
server.stop();
}
@@ -105,7 +133,7 @@ describe('@rollup/plugin-node-resolve', () => {
try {
const response = await fetch(`${host}/test-app.js`);
- expect(response.status).to.equal(500);
+ assert.equal(response.status, 500);
} finally {
server.stop();
}
@@ -128,7 +156,7 @@ describe('@rollup/plugin-node-resolve', () => {
try {
const text = await fetchText(`${host}/test-app.js`);
- expect(text).to.equal('import "/non-existing.js"; import "./src/non-existing.js";');
+ assert.equal(text, 'import "/non-existing.js"; import "./src/non-existing.js";');
} finally {
server.stop();
}
diff --git a/packages/dev-server-rollup/test/node/plugins/postcss.test.ts b/packages/dev-server-rollup/test/node/plugins/postcss.test.ts
index 516b4df0b3..5356d399c9 100644
--- a/packages/dev-server-rollup/test/node/plugins/postcss.test.ts
+++ b/packages/dev-server-rollup/test/node/plugins/postcss.test.ts
@@ -1,4 +1,5 @@
///
+import { describe, it } from 'node:test';
import rollupPostcss from 'rollup-plugin-postcss';
import { chromeLauncher } from '@web/test-runner-chrome';
import { runTests } from '@web/test-runner-core/test-helpers';
@@ -7,6 +8,7 @@ import { resolve } from 'path';
import { createTestServer, fetchText, expectIncludes } from '../test-helpers.ts';
import { fromRollup } from '../../../src/index.ts';
+const __dirname = import.meta.dirname;
const postcss = fromRollup(rollupPostcss);
describe('@rollup/plugin-postcss', () => {
@@ -57,8 +59,7 @@ html {
}
});
- it('passes the in-browser tests', async function () {
- this.timeout(40000);
+ it('passes the in-browser tests', { timeout: 40000 }, async () => {
await runTests({
files: [resolve(__dirname, '..', 'fixtures', 'postcss', 'postcss-browser-test.js')],
browsers: [chromeLauncher()],
diff --git a/packages/dev-server-rollup/test/node/plugins/replace.test.ts b/packages/dev-server-rollup/test/node/plugins/replace.test.ts
index 6bacde59ee..d1e10b138f 100644
--- a/packages/dev-server-rollup/test/node/plugins/replace.test.ts
+++ b/packages/dev-server-rollup/test/node/plugins/replace.test.ts
@@ -1,7 +1,15 @@
+<<<<<<< HEAD
import rollupReplace from '@rollup/plugin-replace';
+||||||| parent of aecfa949 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import { describe, it } from 'node:test';
+import rollupReplace from '@rollup/plugin-replace.ts';
+=======
+import { describe, it } from 'node:test';
+import rollupReplace from '@rollup/plugin-replace';
+>>>>>>> aecfa949 (chore: migrate tests from mocha/chai to node:test + node:assert)
-import { createTestServer, fetchText, expectIncludes } from '../test-helpers.ts';
-import { fromRollup } from '../../../src/index.ts';
+import { createTestServer, fetchText, expectIncludes } from '../test-helpers.js';
+import { fromRollup } from '../../../src/index.js';
const replace = fromRollup(rollupReplace as any);
diff --git a/packages/dev-server-rollup/test/node/rollupBundlePlugin.test.ts b/packages/dev-server-rollup/test/node/rollupBundlePlugin.test.ts
index 4554bd7c14..fd223492f8 100644
--- a/packages/dev-server-rollup/test/node/rollupBundlePlugin.test.ts
+++ b/packages/dev-server-rollup/test/node/rollupBundlePlugin.test.ts
@@ -1,6 +1,45 @@
+<<<<<<< HEAD
import { rollupBundlePlugin } from '../../src/rollupBundlePlugin.ts';
+||||||| parent of aecfa949 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import { rollupBundlePlugin } from '../../src/rollupBundlePlugin.js';
+=======
+<<<<<<< HEAD
+import { rollupBundlePlugin } from '../../src/rollupBundlePlugin.js';
+||||||| parent of c37bb778 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import { rollupBundlePlugin } from '../../src/rollupBundlePlugin.ts';
+=======
+<<<<<<< HEAD
+import { rollupBundlePlugin } from '../../src/rollupBundlePlugin.ts';
+||||||| parent of 61bf92a0 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import { rollupBundlePlugin } from '../../src/rollupBundlePlugin.js';
+=======
+import { describe, it } from 'node:test';
+import { rollupBundlePlugin } from '../../src/rollupBundlePlugin.ts';
+>>>>>>> 61bf92a0 (chore: migrate tests from mocha/chai to node:test + node:assert)
+>>>>>>> c37bb778 (chore: migrate tests from mocha/chai to node:test + node:assert)
+>>>>>>> aecfa949 (chore: migrate tests from mocha/chai to node:test + node:assert)
import path from 'path';
+<<<<<<< HEAD
+import { createTestServer, fetchText, expectIncludes } from './test-helpers.ts';
+||||||| parent of aecfa949 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import { createTestServer, fetchText, expectIncludes } from './test-helpers.js';
+=======
+<<<<<<< HEAD
+import { createTestServer, fetchText, expectIncludes } from './test-helpers.js';
+||||||| parent of c37bb778 (chore: migrate tests from mocha/chai to node:test + node:assert)
import { createTestServer, fetchText, expectIncludes } from './test-helpers.ts';
+=======
+<<<<<<< HEAD
+import { createTestServer, fetchText, expectIncludes } from './test-helpers.ts';
+||||||| parent of 61bf92a0 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import { createTestServer, fetchText, expectIncludes } from './test-helpers.js';
+=======
+import { createTestServer, fetchText, expectIncludes } from './test-helpers.ts';
+
+const __dirname = import.meta.dirname;
+>>>>>>> 61bf92a0 (chore: migrate tests from mocha/chai to node:test + node:assert)
+>>>>>>> c37bb778 (chore: migrate tests from mocha/chai to node:test + node:assert)
+>>>>>>> aecfa949 (chore: migrate tests from mocha/chai to node:test + node:assert)
describe('rollupBundlePlugin', () => {
it('can bundle a single entrypoint', async () => {
diff --git a/packages/dev-server-rollup/test/node/test-helpers.ts b/packages/dev-server-rollup/test/node/test-helpers.ts
index 81f2e9c3f0..c9cd007764 100644
--- a/packages/dev-server-rollup/test/node/test-helpers.ts
+++ b/packages/dev-server-rollup/test/node/test-helpers.ts
@@ -5,7 +5,23 @@ import {
fetchText,
expectIncludes,
} from '@web/dev-server-core/test-helpers';
+<<<<<<< HEAD
import { DevServerCoreConfig, Logger } from '@web/dev-server-core';
+||||||| parent of aecfa949 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import type { DevServerCoreConfig, Logger } from '@web/dev-server-core';
+
+const __dirname = import.meta.dirname;
+=======
+<<<<<<< HEAD
+import type { DevServerCoreConfig, Logger } from '@web/dev-server-core.js';
+||||||| parent of 9007e014 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import type { DevServerCoreConfig, Logger } from '@web/dev-server-core.ts';
+=======
+import type { DevServerCoreConfig, Logger } from '@web/dev-server-core';
+>>>>>>> 9007e014 (chore: migrate tests from mocha/chai to node:test + node:assert)
+
+const __dirname = import.meta.dirname;
+>>>>>>> aecfa949 (chore: migrate tests from mocha/chai to node:test + node:assert)
export function createTestServer(config: Partial = {}, mockLogger?: Logger) {
return originalCreateTestServer(
diff --git a/packages/dev-server-rollup/test/node/unit.test.ts b/packages/dev-server-rollup/test/node/unit.test.ts
index df2fed815f..3dbfb77326 100644
--- a/packages/dev-server-rollup/test/node/unit.test.ts
+++ b/packages/dev-server-rollup/test/node/unit.test.ts
@@ -1,9 +1,36 @@
-import { Plugin as RollupPlugin, AstNode } from 'rollup';
-import { expect } from 'chai';
+import { describe, it } from 'node:test';
+import assert from 'node:assert/strict';
+import type { Plugin as RollupPlugin, AstNode } from 'rollup';
import path from 'path';
+<<<<<<< HEAD
import { createTestServer, fetchText, expectIncludes } from './test-helpers.ts';
import { fromRollup } from '../../src/index.ts';
+||||||| parent of aecfa949 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import { createTestServer, fetchText, expectIncludes } from './test-helpers.js';
+import { fromRollup } from '../../src/index.js';
+=======
+<<<<<<< HEAD
+import { createTestServer, fetchText, expectIncludes } from './test-helpers.js';
+import { fromRollup } from '../../src/index.js';
+||||||| parent of c37bb778 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import { createTestServer, fetchText, expectIncludes } from './test-helpers.ts';
+import { fromRollup } from '../../src/index.ts';
+=======
+<<<<<<< HEAD
+import { createTestServer, fetchText, expectIncludes } from './test-helpers.ts';
+import { fromRollup } from '../../src/index.ts';
+||||||| parent of 61bf92a0 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import { createTestServer, fetchText, expectIncludes } from './test-helpers.js';
+import { fromRollup } from '../../src/index.js';
+=======
+import { createTestServer, fetchText, expectIncludes } from './test-helpers.ts';
+import { fromRollup } from '../../src/index.ts';
+
+const __dirname = import.meta.dirname;
+>>>>>>> 61bf92a0 (chore: migrate tests from mocha/chai to node:test + node:assert)
+>>>>>>> c37bb778 (chore: migrate tests from mocha/chai to node:test + node:assert)
+>>>>>>> aecfa949 (chore: migrate tests from mocha/chai to node:test + node:assert)
describe('@web/dev-server-rollup', () => {
describe('resolveId', () => {
@@ -249,7 +276,7 @@ describe('@web/dev-server-rollup', () => {
try {
await fetchText(`${host}/app.js`);
- expect(parsed).to.exist;
+ assert(parsed);
} finally {
server.stop();
}
@@ -347,7 +374,8 @@ describe('@web/dev-server-rollup', () => {
try {
const text = await fetchText(`${host}/foo.html`);
- expect(text).to.equal(
+ assert.equal(
+ text,
`\n \n \n\n`,
);
} finally {
@@ -371,7 +399,8 @@ describe('@web/dev-server-rollup', () => {
try {
const text = await fetchText(`${host}/multiple-inline.html`);
- expect(text).to.equal(
+ assert.equal(
+ text,
`\n \n \n \n\n`,
);
} finally {
diff --git a/packages/dev-server/package.json b/packages/dev-server/package.json
index bd550c28c2..9cc20dc4f3 100644
--- a/packages/dev-server/package.json
+++ b/packages/dev-server/package.json
@@ -37,8 +37,8 @@
"start:plugin-serve": "node dist/bin.js --config demo/plugin-serve/config.mjs --open",
"start:static": "node dist/bin.js --config demo/static/config.mjs --open demo/static/",
"start:syntax": "node dist/bin.js --config demo/syntax/config.mjs --open demo/syntax/",
- "test:node": "mocha \"test/**/*.test.mjs\" --reporter dot",
- "test:watch": "mocha \"test/**/*.test.mjs\" --watch --watch-files src,test --reporter dot"
+ "test:node": "node --test 'test/**/*.test.mjs'",
+ "test:watch": "node --test --watch 'test/**/*.test.mjs'"
},
"files": [
"*.d.ts",
diff --git a/packages/dev-server/test/integration.test.mjs b/packages/dev-server/test/integration.test.mjs
index 17a2ba372a..0bece20c81 100644
--- a/packages/dev-server/test/integration.test.mjs
+++ b/packages/dev-server/test/integration.test.mjs
@@ -1,10 +1,10 @@
+import { describe, it, before, after, beforeEach, afterEach } from 'node:test';
import puppeteer from 'puppeteer';
import path from 'path';
-import { fileURLToPath } from 'url';
-import { startDevServer } from '../index.mjs';
+import { startDevServer } from '../dist/index.js';
-const dirname = path.dirname(fileURLToPath(import.meta.url));
+const dirname = import.meta.dirname;
const testCases = [
{
@@ -53,8 +53,7 @@ describe('integration tests', () => {
});
for (const testCase of testCases) {
- describe(`testcase ${testCase.name}`, function test() {
- this.timeout(30000);
+ describe(`testcase ${testCase.name}`, { timeout: 30000 }, () => {
let server;
beforeEach(async () => {
@@ -69,7 +68,7 @@ describe('integration tests', () => {
await server.stop();
});
- it('passes the in-browser tests', async function it() {
+ it('passes the in-browser tests', async () => {
const openPath = `/demo/${testCase.name}/`;
const browserPath = `http://${server.config.hostname}:${server.config.port}${openPath}`;
const page = await browser.newPage();
diff --git a/packages/parse5-utils/package.json b/packages/parse5-utils/package.json
index c7fadbf30f..e645a535e9 100644
--- a/packages/parse5-utils/package.json
+++ b/packages/parse5-utils/package.json
@@ -1,6 +1,5 @@
{
"name": "@web/parse5-utils",
- "type": "module",
"version": "2.1.1",
"publishConfig": {
"access": "public"
@@ -23,12 +22,12 @@
}
},
"engines": {
- "node": ">=24.0.0"
+ "node": ">=18.0.0"
},
"scripts": {
"build": "tsc",
- "test:node": "mocha \"test/**/*.test.{ts,js,mjs,cjs}\" --require ts-node/register --reporter dot",
- "test:watch": "mocha \"test/**/*.test.{ts,js,mjs,cjs}\" --require ts-node/register --watch"
+ "test:node": "node --test 'test/**/*.test.mjs'",
+ "test:watch": "npm run test:node -- --watch"
},
"files": [
"*.d.ts",
@@ -43,6 +42,7 @@
"utils"
],
"dependencies": {
+ "@types/parse5": "^6.0.1",
"parse5": "^6.0.1"
},
"devDependencies": {
diff --git a/packages/parse5-utils/test/index.test.mjs b/packages/parse5-utils/test/index.test.mjs
new file mode 100644
index 0000000000..06c2a29a56
--- /dev/null
+++ b/packages/parse5-utils/test/index.test.mjs
@@ -0,0 +1,385 @@
+import assert from 'node:assert/strict';
+import { describe, it } from 'node:test';
+import { parse, serialize } from 'parse5';
+import { getAttribute, getTextContent, findElement } from '../dist/index.js';
+import * as utils from '../dist/index.js';
+
+describe('parse5-utils', () => {
+ describe('createElement', () => {
+ it('creates an element', () => {
+ const doc = parse('');
+ const el = utils.createElement('my-element');
+ utils.appendChild(doc, el);
+ assert.strictEqual(
+ serialize(doc),
+ ' ',
+ );
+ });
+
+ it('creates an element with attributes', () => {
+ const doc = parse('');
+ const el = utils.createElement('my-element', { foo: 'bar', x: '' });
+ utils.appendChild(doc, el);
+ assert.strictEqual(
+ serialize(doc),
+ ' ',
+ );
+ });
+ });
+
+ describe('createScript', () => {
+ it('create a script', () => {
+ const doc = parse('');
+ const el = utils.createScript();
+ utils.appendChild(doc, el);
+ assert.strictEqual(serialize(doc), '');
+ });
+
+ it('create a script with attributes', () => {
+ const doc = parse('');
+ const el = utils.createScript({ type: 'module' });
+ utils.appendChild(doc, el);
+ assert.strictEqual(
+ serialize(doc),
+ '',
+ );
+ });
+
+ it('create a script with text content', () => {
+ const doc = parse('');
+ const el = utils.createScript({ type: 'module' }, 'console.log("x");');
+ utils.appendChild(doc, el);
+ assert.strictEqual(
+ serialize(doc),
+ '',
+ );
+ });
+ });
+
+ describe('isHtmlFragment()', () => {
+ it('returns whether a HTML string is a fragment', () => {
+ assert.strictEqual(utils.isHtmlFragment(' '), true);
+ assert.strictEqual(utils.isHtmlFragment(''), true);
+ assert.strictEqual(utils.isHtmlFragment('foo'), true);
+ assert.strictEqual(utils.isHtmlFragment('
'), true);
+ assert.strictEqual(
+ utils.isHtmlFragment(' '),
+ false,
+ );
+ assert.strictEqual(
+ utils.isHtmlFragment(` `),
+ false,
+ );
+ assert.strictEqual(utils.isHtmlFragment(' '), false);
+ assert.strictEqual(utils.isHtmlFragment(' '), false);
+ assert.strictEqual(utils.isHtmlFragment(' '), false);
+ assert.strictEqual(utils.isHtmlFragment(' '), false);
+ assert.strictEqual(utils.isHtmlFragment(' '), false);
+ });
+ });
+
+ describe('getAttributes()', () => {
+ it('returns the attributes of an element', () => {
+ const el = utils.createElement('my-element', { foo: 'bar', x: '' });
+ assert.deepStrictEqual(utils.getAttributes(el), { foo: 'bar', x: '' });
+ });
+
+ it('returns an empty object if there are no attributes', () => {
+ const el = utils.createElement('my-element');
+ assert.deepStrictEqual(utils.getAttributes(el), {});
+ });
+ });
+
+ describe('getAttribute()', () => {
+ it('returns a single attribute', () => {
+ const el = utils.createElement('my-element', { foo: 'bar', x: '' });
+ assert.deepStrictEqual(utils.getAttribute(el, 'foo'), 'bar');
+ });
+
+ it('returns undefined if the attribute was not found', () => {
+ const el = utils.createElement('my-element', { foo: 'bar', x: '' });
+ assert.deepStrictEqual(utils.getAttribute(el, 'y'), undefined);
+ });
+ });
+
+ describe('setAttribute()', () => {
+ it('can set the attribute on an element', () => {
+ const doc = parse('');
+ const el = utils.createElement('my-element');
+ utils.appendChild(doc, el);
+ utils.setAttribute(el, 'foo', 'bar');
+ assert.deepStrictEqual(
+ serialize(doc),
+ ' ',
+ );
+ });
+
+ it('can overwrite an existing attribute', () => {
+ const doc = parse('');
+ const el = utils.createElement('my-element', { foo: 'bar' });
+ utils.appendChild(doc, el);
+ utils.setAttribute(el, 'foo', 'not-bar');
+ assert.deepStrictEqual(
+ serialize(doc),
+ ' ',
+ );
+ });
+ });
+
+ describe('setAttributes()', () => {
+ it('can set multiple attributes on an element', () => {
+ const doc = parse('');
+ const el = utils.createElement('my-element');
+ utils.appendChild(doc, el);
+ utils.setAttributes(el, { foo: 'bar', lorem: 'ipsum', x: undefined });
+ assert.deepStrictEqual(
+ serialize(doc),
+ ' ',
+ );
+ });
+ });
+
+ describe('removeAttribute()', () => {
+ it('removes attribute from an element', () => {
+ const doc = parse('');
+ const el = utils.createElement('my-element', { foo: 'bar', x: 'y' });
+ utils.appendChild(doc, el);
+ utils.removeAttribute(el, 'x');
+ assert.deepStrictEqual(
+ serialize(doc),
+ ' ',
+ );
+ });
+ });
+
+ describe('getTextContent()', () => {
+ it('returns the node text', () => {
+ const doc = parse('Hello world
');
+ const myDiv = utils.findElement(doc, e => getAttribute(e, 'id') === 'myDiv');
+ if (!myDiv) throw new Error();
+ assert.strictEqual(getTextContent(myDiv), 'Hello world');
+ });
+
+ it('returns multiple nodes text', () => {
+ const doc = parse(
+ '',
+ );
+ const myDiv = utils.findElement(doc, e => getAttribute(e, 'id') === 'myDiv');
+ if (!myDiv) throw new Error();
+ assert.strictEqual(getTextContent(myDiv), 'Top levelBeforeABAfter');
+ });
+ });
+
+ describe('setTextContent()', () => {
+ it('sets the text of an element', () => {
+ const doc = parse('');
+ const el = utils.createElement('script');
+ utils.setTextContent(el, 'foo bar');
+ utils.appendChild(doc, el);
+ assert.strictEqual(
+ serialize(doc),
+ '',
+ );
+ });
+ });
+
+ describe('remove()', () => {
+ it('removes element from the AST', () => {
+ const doc = parse('
');
+ const div = findElement(doc, e => utils.getAttribute(e, 'id') === 'myDiv');
+ if (!div) throw new Error('element not found');
+ utils.remove(div);
+ assert.strictEqual(serialize(doc), '');
+ });
+ });
+
+ describe('findElement()', () => {
+ it('returns a matching element', () => {
+ const doc = parse(`
+
+
+
+
+
+
+
+ `);
+ const found = utils.findElement(doc, el => utils.getAttribute(el, 'foo') === '2');
+ if (!found) {
+ throw new Error('No element found.');
+ }
+ assert.strictEqual(utils.getAttribute(found, 'foo'), '2');
+ });
+
+ it('returns the first match', () => {
+ const doc = parse(`
+
+
+
+
+
+
+
+ `);
+ const found = utils.findElement(doc, el => utils.getAttribute(el, 'foo') === 'bar');
+ if (!found) {
+ throw new Error('No element found.');
+ }
+ assert.strictEqual(utils.getAttribute(found, 'foo'), 'bar');
+ assert.strictEqual(utils.getAttribute(found, 'index'), '1');
+ });
+
+ it('returns nested elements', () => {
+ const doc = parse(`
+
+
+
+
+
+
+
+
+ `);
+ const found = utils.findElement(doc, el => utils.getAttribute(el, 'id') === 'foo');
+ if (!found) {
+ throw new Error('No element found.');
+ }
+ assert.ok(found);
+ });
+ });
+
+ describe('findElements()', () => {
+ it('returns a single matched element', () => {
+ const doc = parse(`
+
+
+
+
+
+
+
+ `);
+ const found = utils.findElements(doc, el => utils.getAttribute(el, 'foo') === '2');
+ assert.strictEqual(found.length, 1);
+ assert.strictEqual(utils.getAttribute(found[0], 'foo'), '2');
+ });
+
+ it('returns multiple matched elements', () => {
+ const doc = parse(`
+
+
+
+
+
+
+
+ `);
+ const found = utils.findElements(doc, el => utils.getAttribute(el, 'foo') === 'bar');
+ assert.strictEqual(found.length, 3);
+ const indices = found.map(f => utils.getAttribute(f, 'index'));
+ assert.deepStrictEqual(indices, ['1', '2', '3']);
+ });
+
+ it('returns an empty array when there are no matches', () => {
+ const doc = parse(`
+
+
+
+
+
+
+
+ `);
+ const found = utils.findElements(doc, el => utils.hasAttribute(el, 'non-existing'));
+ assert.strictEqual(found.length, 0);
+ });
+
+ it('returns child elements within template elements', () => {
+ const doc = parse(`
+
+
+
+
+
+
+
+ `);
+
+ const found = utils.findElements(doc, el => utils.hasAttribute(el, 'src'));
+ assert.strictEqual(found.length, 1);
+ });
+ });
+
+ describe('prependToDocument', () => {
+ it('injects a HTML snippet to the document', () => {
+ const document = '';
+ const result = utils.prependToDocument(document, 'Hello world
');
+ if (!result) throw new Error();
+ assert.strictEqual(result, 'Hello world
');
+ });
+
+ it('injects before other elements', () => {
+ const document =
+ 'A
B
C
';
+ const result = utils.prependToDocument(document, 'Hello world
');
+ if (!result) throw new Error();
+ assert.strictEqual(
+ result,
+ 'Hello world
A
B
C
',
+ );
+ });
+
+ it('injects into body if there is no head', () => {
+ const document = 'A
';
+ const result = utils.prependToDocument(document, 'Hello world
');
+ if (!result) throw new Error();
+ assert.strictEqual(result, 'Hello world
A
');
+ });
+
+ it('uses AST manipulation if there is no head or body', () => {
+ const document = '';
+ const result = utils.prependToDocument(document, 'A
B
');
+ assert.strictEqual(result, 'A
B
');
+ });
+ });
+
+ describe('appendToDocument', () => {
+ it('injects a HTML snippet to the document', () => {
+ const document = '';
+ const result = utils.appendToDocument(document, 'Hello world
');
+ if (!result) throw new Error();
+ assert.strictEqual(result, 'Hello world
');
+ });
+
+ it('injects after other elements', () => {
+ const document =
+ '';
+ const result = utils.appendToDocument(document, 'Hello world
');
+ if (!result) throw new Error();
+ assert.strictEqual(
+ result,
+ 'Hello world
',
+ );
+ });
+
+ it('injects into head if there is no body', () => {
+ const document = '';
+ const result = utils.appendToDocument(document, 'Hello world
');
+ if (!result) throw new Error();
+ assert.strictEqual(result, 'Hello world
');
+ });
+
+ it('returns null if there is no head or body', () => {
+ const document = '';
+ const result = utils.appendToDocument(document, 'A
B
');
+ assert.strictEqual(result, 'A
B
');
+ });
+ });
+});
diff --git a/packages/polyfills-loader/package.json b/packages/polyfills-loader/package.json
index 1b100c3af4..a545aaea9b 100644
--- a/packages/polyfills-loader/package.json
+++ b/packages/polyfills-loader/package.json
@@ -1,6 +1,5 @@
{
"name": "@web/polyfills-loader",
- "type": "module",
"version": "2.3.1",
"publishConfig": {
"access": "public"
@@ -18,21 +17,23 @@
"exports": {
".": {
"types": "./index.d.ts",
- "default": "./dist/index.js"
+ "import": "./index.mjs",
+ "require": "./dist/index.js"
}
},
"engines": {
- "node": ">=24.0.0"
+ "node": ">=18.0.0"
},
"scripts": {
"build": "tsc",
- "test:node": "mocha \"test/**/*.test.{ts,js,mjs,cjs}\" --require ts-node/register --reporter dot",
- "test:update-snapshots": "mocha \"test/**/*.test.{ts,js,mjs,cjs}\" --require ts-node/register --update-snapshots",
- "test:watch": "mocha \"test/**/*.test.{ts,js,mjs,cjs}\" --require ts-node/register --watch --watch-files src,test"
+ "test:node": "node --test test/**/*.test.ts",
+ "test:update-snapshots": "node --test test/**/*.test.ts",
+ "test:watch": "node --test --watch test/**/*.test.ts"
},
"files": [
"*.d.ts",
"*.js",
+ "*.mjs",
"dist",
"src"
],
@@ -67,6 +68,7 @@
},
"devDependencies": {
"@types/babel__core": "^7.1.12",
+ "@types/parse5": "^6.0.1",
"@types/valid-url": "^1.0.3"
}
}
diff --git a/packages/polyfills-loader/test/createPolyfillsData.test.ts b/packages/polyfills-loader/test/createPolyfillsData.test.ts
index fd531b3b25..9d88eb7c39 100644
--- a/packages/polyfills-loader/test/createPolyfillsData.test.ts
+++ b/packages/polyfills-loader/test/createPolyfillsData.test.ts
@@ -1,9 +1,42 @@
+import assert from 'node:assert/strict';
+import { describe, it } from 'node:test';
import path from 'path';
-import { expect } from 'chai';
+<<<<<<< HEAD
import { PolyfillsLoaderConfig, PolyfillFile } from '../src/types.ts';
import { createPolyfillsData } from '../src/createPolyfillsData.ts';
import { noModuleSupportTest, fileTypes } from '../src/utils.ts';
+||||||| parent of aecfa949 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import { PolyfillsLoaderConfig, PolyfillFile } from '../src/types.js';
+import { createPolyfillsData } from '../src/createPolyfillsData.js';
+import { noModuleSupportTest, fileTypes } from '../src/utils.js';
+=======
+<<<<<<< HEAD
+import { PolyfillsLoaderConfig, PolyfillFile } from '../src/types.js';
+import { createPolyfillsData } from '../src/createPolyfillsData.js';
+import { noModuleSupportTest, fileTypes } from '../src/utils.js';
+||||||| parent of c37bb778 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import { PolyfillsLoaderConfig, PolyfillFile } from '../src/types.ts';
+import { createPolyfillsData } from '../src/createPolyfillsData.ts';
+import { noModuleSupportTest, fileTypes } from '../src/utils.ts';
+=======
+<<<<<<< HEAD
+import { PolyfillsLoaderConfig, PolyfillFile } from '../src/types.ts';
+import { createPolyfillsData } from '../src/createPolyfillsData.ts';
+import { noModuleSupportTest, fileTypes } from '../src/utils.ts';
+||||||| parent of 61bf92a0 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import { PolyfillsLoaderConfig, PolyfillFile } from '../src/types.js';
+import { createPolyfillsData } from '../src/createPolyfillsData.js';
+import { noModuleSupportTest, fileTypes } from '../src/utils.js';
+=======
+import type { PolyfillsLoaderConfig, PolyfillFile } from '../src/types.ts';
+import { createPolyfillsData } from '../src/createPolyfillsData.ts';
+import { noModuleSupportTest, fileTypes } from '../src/utils.ts';
+
+const __dirname = import.meta.dirname;
+>>>>>>> 61bf92a0 (chore: migrate tests from mocha/chai to node:test + node:assert)
+>>>>>>> c37bb778 (chore: migrate tests from mocha/chai to node:test + node:assert)
+>>>>>>> aecfa949 (chore: migrate tests from mocha/chai to node:test + node:assert)
function cleanupPolyfill(polyfill: PolyfillFile) {
if (!polyfill) {
@@ -40,11 +73,11 @@ describe('polyfills', () => {
const polyfillFiles = await createPolyfillsData(config);
for (const p of polyfillFiles) {
- expect(p.content).to.be.a('string', `Polyfill ${p.name} has no content`);
+ assert.strictEqual(typeof p.content, 'string', `Polyfill ${p.name} has no content`);
cleanupPolyfill(p);
}
- expect(polyfillFiles).to.eql([
+ assert.deepStrictEqual(polyfillFiles, [
{
name: 'core-js',
type: fileTypes.SCRIPT,
@@ -138,11 +171,11 @@ describe('polyfills', () => {
};
const polyfillFiles = await createPolyfillsData(config);
for (const p of polyfillFiles) {
- expect(p.content).to.be.a('string', `Polyfill ${p.name} has no content`);
+ assert.strictEqual(typeof p.content, 'string', `Polyfill ${p.name} has no content`);
cleanupPolyfill(p);
}
- expect(polyfillFiles).to.eql([
+ assert.deepStrictEqual(polyfillFiles, [
{
name: 'fetch',
path: 'polyfills/fetch.js',
@@ -165,11 +198,11 @@ describe('polyfills', () => {
const polyfillFiles = await createPolyfillsData(config);
for (const p of polyfillFiles) {
- expect(p.content).to.be.a('string', `Polyfill ${p.name} has no content`);
+ assert.strictEqual(typeof p.content, 'string', `Polyfill ${p.name} has no content`);
cleanupPolyfill(p);
}
- expect(polyfillFiles).to.eql([
+ assert.deepStrictEqual(polyfillFiles, [
{
name: 'webcomponents-shady-css-custom-style',
type: fileTypes.SCRIPT,
@@ -197,11 +230,11 @@ describe('polyfills', () => {
const polyfillFiles = await createPolyfillsData(config);
for (const p of polyfillFiles) {
- expect(p.content).to.be.a('string', `Polyfill ${p.name} has no content`);
+ assert.strictEqual(typeof p.content, 'string', `Polyfill ${p.name} has no content`);
cleanupPolyfill(p);
}
- expect(polyfillFiles).to.eql([
+ assert.deepStrictEqual(polyfillFiles, [
{
name: 'systemjs',
type: fileTypes.SCRIPT,
@@ -232,11 +265,11 @@ describe('polyfills', () => {
const polyfillFiles = await createPolyfillsData(config);
for (const p of polyfillFiles) {
- expect(p.content).to.be.a('string', `Polyfill ${p.name} has no content`);
+ assert.strictEqual(typeof p.content, 'string', `Polyfill ${p.name} has no content`);
cleanupPolyfill(p);
}
- expect(polyfillFiles).to.eql([
+ assert.deepStrictEqual(polyfillFiles, [
{
name: 'systemjs',
type: fileTypes.SCRIPT,
@@ -257,11 +290,11 @@ describe('polyfills', () => {
const polyfillFiles = await createPolyfillsData(config);
for (const p of polyfillFiles) {
- expect(p.content).to.be.a('string', `Polyfill ${p.name} has no content`);
+ assert.strictEqual(typeof p.content, 'string', `Polyfill ${p.name} has no content`);
cleanupPolyfill(p);
}
- expect(polyfillFiles).to.eql([
+ assert.deepStrictEqual(polyfillFiles, [
{
name: 'systemjs',
type: fileTypes.SCRIPT,
@@ -300,11 +333,11 @@ describe('polyfills', () => {
const polyfillFiles = await createPolyfillsData(config);
for (const p of polyfillFiles) {
- expect(p.content).to.be.a('string', `Polyfill ${p.name} has no content`);
+ assert.strictEqual(typeof p.content, 'string', `Polyfill ${p.name} has no content`);
cleanupPolyfill(p);
}
- expect(polyfillFiles).to.eql([
+ assert.deepStrictEqual(polyfillFiles, [
{
name: 'core-js',
type: fileTypes.SCRIPT,
@@ -338,11 +371,11 @@ describe('polyfills', () => {
const polyfillFiles = await createPolyfillsData(config);
for (const p of polyfillFiles) {
- expect(p.content).to.be.a('string', `Polyfill ${p.name} has no content`);
+ assert.strictEqual(typeof p.content, 'string', `Polyfill ${p.name} has no content`);
cleanupPolyfill(p);
}
- expect(polyfillFiles).to.eql([
+ assert.deepStrictEqual(polyfillFiles, [
{
name: 'systemjs',
type: fileTypes.SCRIPT,
diff --git a/packages/polyfills-loader/test/createPolyfillsLoader.test.ts b/packages/polyfills-loader/test/createPolyfillsLoader.test.ts
index f3397978ec..fe6a1e741b 100644
--- a/packages/polyfills-loader/test/createPolyfillsLoader.test.ts
+++ b/packages/polyfills-loader/test/createPolyfillsLoader.test.ts
@@ -1,10 +1,42 @@
-import { expect } from 'chai';
+import assert from 'node:assert/strict';
+import { describe, it } from 'node:test';
import fs from 'fs';
import path from 'path';
+<<<<<<< HEAD
import { PolyfillsLoaderConfig } from '../src/types.ts';
import { createPolyfillsLoader } from '../src/createPolyfillsLoader.ts';
import { noModuleSupportTest, fileTypes } from '../src/utils.ts';
+||||||| parent of aecfa949 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import { PolyfillsLoaderConfig } from '../src/types.js';
+import { createPolyfillsLoader } from '../src/createPolyfillsLoader.js';
+import { noModuleSupportTest, fileTypes } from '../src/utils.js';
+=======
+<<<<<<< HEAD
+import { PolyfillsLoaderConfig } from '../src/types.js';
+import { createPolyfillsLoader } from '../src/createPolyfillsLoader.js';
+import { noModuleSupportTest, fileTypes } from '../src/utils.js';
+||||||| parent of c37bb778 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import { PolyfillsLoaderConfig } from '../src/types.ts';
+import { createPolyfillsLoader } from '../src/createPolyfillsLoader.ts';
+import { noModuleSupportTest, fileTypes } from '../src/utils.ts';
+=======
+<<<<<<< HEAD
+import { PolyfillsLoaderConfig } from '../src/types.ts';
+import { createPolyfillsLoader } from '../src/createPolyfillsLoader.ts';
+import { noModuleSupportTest, fileTypes } from '../src/utils.ts';
+||||||| parent of 61bf92a0 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import { PolyfillsLoaderConfig } from '../src/types.js';
+import { createPolyfillsLoader } from '../src/createPolyfillsLoader.js';
+import { noModuleSupportTest, fileTypes } from '../src/utils.js';
+=======
+import type { PolyfillsLoaderConfig } from '../src/types.ts';
+import { createPolyfillsLoader } from '../src/createPolyfillsLoader.ts';
+import { noModuleSupportTest, fileTypes } from '../src/utils.ts';
+>>>>>>> 61bf92a0 (chore: migrate tests from mocha/chai to node:test + node:assert)
+>>>>>>> c37bb778 (chore: migrate tests from mocha/chai to node:test + node:assert)
+>>>>>>> aecfa949 (chore: migrate tests from mocha/chai to node:test + node:assert)
+const __dirname = import.meta.dirname;
const updateSnapshots = process.argv.includes('--update-snapshots');
interface TestSnapshotArgs {
@@ -20,19 +52,17 @@ async function testSnapshot({ name, config, expectedFiles = [] }: TestSnapshotAr
throw new Error('No loader was generated');
}
- expect(loader.polyfillFiles.map(f => f.path)).to.eql(expectedFiles);
+ assert.deepStrictEqual(loader.polyfillFiles.map(f => f.path), expectedFiles);
if (updateSnapshots) {
fs.writeFileSync(snapshotPath, loader.code, 'utf-8');
} else {
const snapshot = fs.readFileSync(snapshotPath, 'utf-8');
- expect(loader.code.trim()).to.equal(snapshot.trim());
+ assert.strictEqual(loader.code.trim(), snapshot.trim());
}
}
describe('createPolyfillsLoader', function describe() {
- // bootup of the first test can take a long time in CI to load all the polyfills
- this.timeout(5000);
it('generates a loader script with one module resource', async () => {
await testSnapshot({
diff --git a/packages/polyfills-loader/test/injectPolyfillsLoader.test.ts b/packages/polyfills-loader/test/injectPolyfillsLoader.test.ts
index 5da46fa1da..e14976f4e9 100644
--- a/packages/polyfills-loader/test/injectPolyfillsLoader.test.ts
+++ b/packages/polyfills-loader/test/injectPolyfillsLoader.test.ts
@@ -1,10 +1,42 @@
-import { expect } from 'chai';
+import assert from 'node:assert/strict';
+import { describe, it } from 'node:test';
import path from 'path';
import fs from 'fs';
+<<<<<<< HEAD
import { injectPolyfillsLoader } from '../src/injectPolyfillsLoader.ts';
import { noModuleSupportTest, fileTypes } from '../src/utils.ts';
import { PolyfillsLoaderConfig } from '../src/types.ts';
+||||||| parent of aecfa949 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import { injectPolyfillsLoader } from '../src/injectPolyfillsLoader.js';
+import { noModuleSupportTest, fileTypes } from '../src/utils.js';
+import { PolyfillsLoaderConfig } from '../src/types.js';
+=======
+<<<<<<< HEAD
+import { injectPolyfillsLoader } from '../src/injectPolyfillsLoader.js';
+import { noModuleSupportTest, fileTypes } from '../src/utils.js';
+import { PolyfillsLoaderConfig } from '../src/types.js';
+||||||| parent of c37bb778 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import { injectPolyfillsLoader } from '../src/injectPolyfillsLoader.ts';
+import { noModuleSupportTest, fileTypes } from '../src/utils.ts';
+import { PolyfillsLoaderConfig } from '../src/types.ts';
+=======
+<<<<<<< HEAD
+import { injectPolyfillsLoader } from '../src/injectPolyfillsLoader.ts';
+import { noModuleSupportTest, fileTypes } from '../src/utils.ts';
+import { PolyfillsLoaderConfig } from '../src/types.ts';
+||||||| parent of 61bf92a0 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import { injectPolyfillsLoader } from '../src/injectPolyfillsLoader.js';
+import { noModuleSupportTest, fileTypes } from '../src/utils.js';
+import { PolyfillsLoaderConfig } from '../src/types.js';
+=======
+import { injectPolyfillsLoader } from '../src/injectPolyfillsLoader.ts';
+import { noModuleSupportTest, fileTypes } from '../src/utils.ts';
+import type { PolyfillsLoaderConfig } from '../src/types.ts';
+>>>>>>> 61bf92a0 (chore: migrate tests from mocha/chai to node:test + node:assert)
+>>>>>>> c37bb778 (chore: migrate tests from mocha/chai to node:test + node:assert)
+>>>>>>> aecfa949 (chore: migrate tests from mocha/chai to node:test + node:assert)
+const __dirname = import.meta.dirname;
const updateSnapshots = process.argv.includes('--update-snapshots');
const defaultConfig = {
@@ -22,7 +54,7 @@ async function testSnapshot(name: string, htmlString: string, config: PolyfillsL
fs.writeFileSync(snapshotPath, result.htmlString, 'utf-8');
} else {
const snapshot = fs.readFileSync(snapshotPath, 'utf-8');
- expect(result.htmlString.trim()).to.equal(snapshot.trim());
+ assert.strictEqual(result.htmlString.trim(), snapshot.trim());
}
}
diff --git a/packages/polyfills-loader/test/snapshots/createPolyfillsLoader/minified.js b/packages/polyfills-loader/test/snapshots/createPolyfillsLoader/minified.js
index ca5e3c2d4d..b9fcdf749f 100644
--- a/packages/polyfills-loader/test/snapshots/createPolyfillsLoader/minified.js
+++ b/packages/polyfills-loader/test/snapshots/createPolyfillsLoader/minified.js
@@ -1 +1 @@
-!function(){function e(e,t,n){return new Promise((function(o){var r=document.createElement("script");function i(){r.parentElement&&r.parentElement.removeChild(r),o()}r.fetchPriority="high",r.src=e,r.onload=i,n&&n.forEach((function(e){r.setAttribute(e.name,e.value)})),r.onerror=function(){console.error("[polyfills-loader] failed to load: "+e+" check the network tab for HTTP status."),i()},t&&(r.type=t),document.head.appendChild(r)}))}var t=[];function n(){e("/app.js","module",[])}"fetch"in window||t.push(e("./polyfills/fetch.js")),t.length?Promise.all(t).then(n):n()}();
\ No newline at end of file
+!function(){function e(e,t,n){return new Promise(function(o){var r=document.createElement("script");function i(){r.parentElement&&r.parentElement.removeChild(r),o()}r.fetchPriority="high",r.src=e,r.onload=i,n&&n.forEach(function(e){r.setAttribute(e.name,e.value)}),r.onerror=function(){console.error("[polyfills-loader] failed to load: "+e+" check the network tab for HTTP status."),i()},t&&(r.type=t),document.head.appendChild(r)})}var t=[];function n(){e("/app.js","module",[])}"fetch"in window||t.push(e("./polyfills/fetch.js")),t.length?Promise.all(t).then(n):n()}();
\ No newline at end of file
diff --git a/packages/rollup-plugin-copy/package.json b/packages/rollup-plugin-copy/package.json
index 268b25a6c7..5b4bd2289d 100644
--- a/packages/rollup-plugin-copy/package.json
+++ b/packages/rollup-plugin-copy/package.json
@@ -29,8 +29,8 @@
"node": ">=18.0.0"
},
"scripts": {
- "test:node": "mocha test/**/*.test.js --reporter dot",
- "test:watch": "mocha test/**/*.test.js --watch --watch-files src,test --reporter dot"
+ "test:node": "node --test 'test/**/*.test.mjs'",
+ "test:watch": "npm run test:node -- --watch"
},
"files": [
"*.d.ts",
diff --git a/packages/rollup-plugin-copy/test/integration.test.js b/packages/rollup-plugin-copy/test/integration.test.js
deleted file mode 100644
index c4e5900d98..0000000000
--- a/packages/rollup-plugin-copy/test/integration.test.js
+++ /dev/null
@@ -1,23 +0,0 @@
-const path = require('path');
-const { expect } = require('chai');
-const rollup = require('rollup');
-
-const { copy } = require('../src/copy.js');
-
-describe('rollup-plugin-copy', () => {
- it('adds files to rollup', async () => {
- const bundle = await rollup.rollup({
- input: path.resolve(__dirname, './fixture/index.js'),
- plugins: [copy({ patterns: '**/*.svg', rootDir: path.resolve(__dirname, './fixture/') })],
- });
- const { output } = await bundle.generate({ format: 'es' });
-
- expect(output.length).to.equal(5);
- expect(output.map(x => x.fileName).filter(x => x.endsWith('.svg'))).to.have.members([
- 'a.svg',
- 'b.svg',
- `sub${path.sep}sub-a.svg`,
- `sub${path.sep}sub-b.mark.svg`,
- ]);
- });
-});
diff --git a/packages/rollup-plugin-copy/test/integration.test.mjs b/packages/rollup-plugin-copy/test/integration.test.mjs
new file mode 100644
index 0000000000..3eff96af50
--- /dev/null
+++ b/packages/rollup-plugin-copy/test/integration.test.mjs
@@ -0,0 +1,28 @@
+import path from 'path';
+import assert from 'node:assert/strict';
+import { describe, it } from 'node:test';
+import { rollup } from 'rollup';
+
+import { copy } from '../src/copy.ts';
+
+const __dirname = import.meta.dirname;
+
+describe('rollup-plugin-copy', () => {
+ it('adds files to rollup', async () => {
+ const bundle = await rollup({
+ input: path.resolve(__dirname, './fixture/index.js'),
+ plugins: [copy({ patterns: '**/*.svg', rootDir: path.resolve(__dirname, './fixture/') })],
+ });
+ const { output } = await bundle.generate({ format: 'es' });
+
+ assert.strictEqual(output.length, 5);
+ const svgFiles = output.map(x => x.fileName).filter(x => x.endsWith('.svg')).sort();
+ const expectedFiles = [
+ 'a.svg',
+ 'b.svg',
+ `sub${path.sep}sub-a.svg`,
+ `sub${path.sep}sub-b.mark.svg`,
+ ].sort();
+ assert.deepStrictEqual(svgFiles, expectedFiles);
+ });
+});
diff --git a/packages/rollup-plugin-copy/test/listFiles.test.mjs b/packages/rollup-plugin-copy/test/listFiles.test.mjs
new file mode 100644
index 0000000000..c2ffbdb5a2
--- /dev/null
+++ b/packages/rollup-plugin-copy/test/listFiles.test.mjs
@@ -0,0 +1,37 @@
+import path from 'path';
+import assert from 'node:assert/strict';
+import { describe, it } from 'node:test';
+
+import { listFiles } from '../src/listFiles.ts';
+
+const __dirname = import.meta.dirname;
+
+describe('listFiles', () => {
+ it('gives a list of files', async () => {
+ const files = await listFiles('*.svg', path.resolve(__dirname, './fixture/'));
+ assert.strictEqual(files.length, 2);
+ const expectedFiles = [
+ path.join(__dirname, './fixture/a.svg'),
+ path.join(__dirname, './fixture/b.svg'),
+ ].sort();
+ assert.deepStrictEqual(files.sort(), expectedFiles);
+ });
+
+ it('only gives files and no folders', async () => {
+ const files = await listFiles('**/*.svg', path.resolve(__dirname, './fixture/'));
+ assert.strictEqual(files.length, 4);
+ const expectedFiles = [
+ path.join(__dirname, './fixture/a.svg'),
+ path.join(__dirname, './fixture/b.svg'),
+ path.join(__dirname, './fixture/sub/sub-b.mark.svg'),
+ path.join(__dirname, './fixture/sub/sub-a.svg'),
+ ].sort();
+ assert.deepStrictEqual(files.sort(), expectedFiles);
+ });
+
+ it('will copy files inside dot folders', async () => {
+ const files = await listFiles('**/*.svg', path.resolve(__dirname, './fixtureDot/'));
+ assert.strictEqual(files.length, 1);
+ assert.match(files[0], /fixtureDot(\/|\\)\.folder(\/|\\)inside-dot-folder\.svg$/);
+ });
+});
diff --git a/packages/rollup-plugin-copy/test/patternsToFiles.test.mjs b/packages/rollup-plugin-copy/test/patternsToFiles.test.mjs
new file mode 100644
index 0000000000..98d2474b65
--- /dev/null
+++ b/packages/rollup-plugin-copy/test/patternsToFiles.test.mjs
@@ -0,0 +1,33 @@
+import path from 'path';
+import assert from 'node:assert/strict';
+import { describe, it } from 'node:test';
+
+import { patternsToFiles } from '../src/patternsToFiles.ts';
+
+const __dirname = import.meta.dirname;
+
+describe('patternsToFiles', () => {
+ it('works with a string', async () => {
+ const files = await patternsToFiles('*.svg', path.resolve(__dirname, './fixture/'));
+ assert.strictEqual(files.length, 2);
+ const expectedFiles = [
+ path.join(__dirname, './fixture/a.svg'),
+ path.join(__dirname, './fixture/b.svg'),
+ ].sort();
+ assert.deepStrictEqual(files.sort(), expectedFiles);
+ });
+
+ it('works with an array of strings ', async () => {
+ const files = await patternsToFiles(
+ ['*.svg', 'sub/*.mark.svg'],
+ path.resolve(__dirname, './fixture/'),
+ );
+ assert.strictEqual(files.length, 3);
+ const expectedFiles = [
+ path.join(__dirname, './fixture/a.svg'),
+ path.join(__dirname, './fixture/b.svg'),
+ path.join(__dirname, './fixture/sub/sub-b.mark.svg'),
+ ].sort();
+ assert.deepStrictEqual(files.sort(), expectedFiles);
+ });
+});
diff --git a/packages/rollup-plugin-html/package.json b/packages/rollup-plugin-html/package.json
index 94fbca244a..a238a984c8 100644
--- a/packages/rollup-plugin-html/package.json
+++ b/packages/rollup-plugin-html/package.json
@@ -1,6 +1,5 @@
{
"name": "@web/rollup-plugin-html",
- "type": "module",
"version": "3.1.0",
"publishConfig": {
"access": "public"
@@ -17,22 +16,24 @@
"main": "dist/index.js",
"exports": {
".": {
- "types": "./dist/index.d.ts",
- "default": "./dist/index.js"
+ "import": "./index.mjs",
+ "require": "./dist/index.js",
+ "types": "./dist/index.d.ts"
}
},
"engines": {
- "node": ">=24.0.0"
+ "node": ">=18.0.0"
},
"scripts": {
"demo:mpa": "rm -rf demo/dist && rollup -c demo/mpa/rollup.config.js --watch & npm run serve-demo",
"demo:spa": "rm -rf demo/dist && rollup -c demo/spa/rollup.config.js --watch & npm run serve-demo",
"serve-demo": "node ../dev-server/dist/bin.js --watch --root-dir demo/dist --app-index index.html --compatibility none --open",
- "test:node": "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"
+ "test:node": "node --test 'test/**/*.test.ts'",
+ "test:watch": "node --test --watch 'test/**/*.test.ts'"
},
"files": [
"*.js",
+ "*.mjs",
"dist",
"src"
],
@@ -51,8 +52,11 @@
"picomatch": "^2.2.2"
},
"devDependencies": {
+ "@prettier/sync": "^0.6.1",
"@types/html-minifier-terser": "^7.0.0",
"@types/picomatch": "^2.2.1",
+ "@types/prettier": "^3.0.0",
+ "prettier": "^3.6.2",
"rollup": "^4.4.0"
}
}
diff --git a/packages/rollup-plugin-html/test/input/InputData.test.ts b/packages/rollup-plugin-html/test/input/InputData.test.ts
new file mode 100644
index 0000000000..cfa765426e
--- /dev/null
+++ b/packages/rollup-plugin-html/test/input/InputData.test.ts
@@ -0,0 +1,1021 @@
+<<<<<<< HEAD:packages/rollup-plugin-html/test/src/input/InputData.test.ts
+||||||| parent of 9007e014 (chore: migrate tests from mocha/chai to node:test + node:assert):packages/rollup-plugin-html/test/src/input/InputData.test.ts
+import { expect } from 'chai';
+import path from 'path';
+<<<<<<< HEAD:packages/rollup-plugin-html/test/src/input/InputData.test.ts
+import { cleanApp, createApp, html, js } from '../../utils.ts';
+||||||| parent of c37bb778 (chore: migrate tests from mocha/chai to node:test + node:assert):packages/rollup-plugin-html/test/src/input/InputData.test.ts
+import { cleanApp, createApp, html, js } from '../../utils.ts';
+=======
+>>>>>>> c37bb778 (chore: migrate tests from mocha/chai to node:test + node:assert):packages/rollup-plugin-html/test/input/InputData.test.ts
+
+<<<<<<< HEAD:packages/rollup-plugin-html/test/src/input/InputData.test.ts
+import { getInputData } from '../../../src/input/getInputData.ts';
+import { InputData } from '../../../src/input/InputData.ts';
+||||||| parent of c37bb778 (chore: migrate tests from mocha/chai to node:test + node:assert):packages/rollup-plugin-html/test/src/input/InputData.test.ts
+import { getInputData } from '../../../src/input/getInputData.ts';
+import { InputData } from '../../../src/input/InputData.ts';
+=======
+import { getInputData } from '../../src/input/getInputData.ts';
+import type { InputData } from '../../src/input/InputData.ts';
+
+const __dirname = import.meta.dirname;
+const rootDir = path.join(__dirname, '..', 'fixtures', 'basic');
+>>>>>>> c37bb778 (chore: migrate tests from mocha/chai to node:test + node:assert):packages/rollup-plugin-html/test/input/InputData.test.ts
+
+function cleanupHtml(str: string) {
+ return str.replace(/(\r\n|\n|\r| )/gm, '');
+}
+
+function cleanupResult(result: InputData[]) {
+ return result.map(item => ({
+ ...item,
+ inlineModules: Array.from(item.inlineModules.entries()),
+ html: cleanupHtml(item.html),
+ }));
+}
+
+describe('getInputData()', () => {
+ afterEach(() => {
+ cleanApp();
+ });
+
+ it('supports setting input as string', () => {
+ const rootDir = createApp({
+ 'index.html': html`
+
+
+ Hello world
+
+
+
+ `,
+ 'app.js': js`
+ console.log('hello world');
+ `,
+ });
+ const result = getInputData({ input: 'index.html', rootDir });
+ expect(cleanupResult(result)).to.eql([
+ {
+ filePath: path.join(rootDir, 'index.html'),
+ html: 'Helloworld
',
+ inlineModules: [],
+ moduleImports: [{ importPath: path.join(rootDir, 'app.js'), attributes: [] }],
+ assets: [],
+ name: 'index.html',
+ },
+ ]);
+ });
+
+ it('supports setting input as object', () => {
+ const rootDir = createApp({
+ 'index.html': html`
+
+
+ Hello world
+
+
+
+ `,
+ 'app.js': js`
+ console.log('hello world');
+ `,
+ });
+ const result = getInputData({ input: { path: 'index.html' }, rootDir });
+ expect(cleanupResult(result)).to.eql([
+ {
+ filePath: path.join(rootDir, 'index.html'),
+ html: 'Helloworld
',
+ inlineModules: [],
+ moduleImports: [{ importPath: path.join(rootDir, 'app.js'), attributes: [] }],
+ assets: [],
+ name: 'index.html',
+ },
+ ]);
+ });
+
+ it('supports changing file name', () => {
+ const rootDir = createApp({
+ 'index.html': html`
+
+
+ Hello world
+
+
+
+ `,
+ 'app.js': js`
+ console.log('hello world');
+ `,
+ });
+ const result = getInputData({ input: { path: 'index.html', name: 'foo.html' }, rootDir });
+ expect(cleanupResult(result)).to.eql([
+ {
+ filePath: path.join(rootDir, 'index.html'),
+ html: 'Helloworld
',
+ inlineModules: [],
+ moduleImports: [{ importPath: path.join(rootDir, 'app.js'), attributes: [] }],
+ assets: [],
+ name: 'foo.html',
+ },
+ ]);
+ });
+
+ it('supports setting multiple inputs', () => {
+ const rootDir = createApp({
+ 'index.html': html`
+
+
+ Hello world
+
+
+
+ `,
+ 'not-index.html': html`
+
+
+ not-index.html
+
+
+ `,
+ 'app.js': js`
+ console.log('hello world');
+ `,
+ });
+ const result = getInputData({
+ input: [{ path: 'index.html' }, { path: 'not-index.html' }],
+ rootDir,
+ });
+ expect(cleanupResult(result)).to.eql([
+ {
+ filePath: path.join(rootDir, 'index.html'),
+ html: 'Helloworld
',
+ inlineModules: [],
+ moduleImports: [{ importPath: path.join(rootDir, 'app.js'), attributes: [] }],
+ assets: [],
+ name: 'index.html',
+ },
+ {
+ filePath: path.join(rootDir, 'not-index.html'),
+ html: 'not-index.html
',
+ inlineModules: [],
+ moduleImports: [],
+ assets: [],
+ name: 'not-index.html',
+ },
+ ]);
+ });
+
+ it('resolves modules relative to HTML file', () => {
+ const rootDir = createApp({
+ 'src/index.html': html`
+
+
+ Hello world
+
+
+
+ `,
+ 'src/app.js': js`
+ console.log('hello world');
+ `,
+ });
+ const result = getInputData({ input: 'src/index.html', rootDir });
+ expect(cleanupResult(result)).to.eql([
+ {
+ filePath: path.join(rootDir, 'src/index.html'),
+ html: 'Helloworld
',
+ inlineModules: [],
+ moduleImports: [{ importPath: path.join(rootDir, 'src', 'app.js'), attributes: [] }],
+ assets: [],
+ name: 'index.html',
+ },
+ ]);
+ });
+
+ it('supports setting input as rollup input string', () => {
+ const rootDir = createApp({
+ 'index.html': html`
+
+
+ Hello world
+
+
+
+ `,
+ 'app.js': js`
+ console.log('hello world');
+ `,
+ });
+ const result = getInputData({ rootDir }, 'index.html');
+ expect(cleanupResult(result)).to.eql([
+ {
+ filePath: path.join(rootDir, 'index.html'),
+ html: 'Helloworld
',
+ inlineModules: [],
+ moduleImports: [{ importPath: path.join(rootDir, 'app.js'), attributes: [] }],
+ assets: [],
+ name: 'index.html',
+ },
+ ]);
+ });
+
+ it('supports setting input as rollup input array', () => {
+ const rootDir = createApp({
+ 'index.html': html`
+
+
+ Hello world
+
+
+
+ `,
+ 'app.js': js`
+ console.log('hello world');
+ `,
+ });
+ const result = getInputData({ rootDir }, ['index.html']);
+ expect(cleanupResult(result)).to.eql([
+ {
+ filePath: path.join(rootDir, 'index.html'),
+ html: 'Helloworld
',
+ inlineModules: [],
+ moduleImports: [{ importPath: path.join(rootDir, 'app.js'), attributes: [] }],
+ assets: [],
+ name: 'index.html',
+ },
+ ]);
+ });
+
+ it('supports setting input as rollup input array', () => {
+ const rootDir = createApp({
+ 'index.html': html`
+
+
+ Hello world
+
+
+
+ `,
+ 'not-index.html': html`
+
+
+ not-index.html
+
+
+ `,
+ 'app.js': js`
+ console.log('hello world');
+ `,
+ });
+ const result = getInputData({ rootDir }, ['index.html', 'not-index.html']);
+ expect(cleanupResult(result)).to.eql([
+ {
+ filePath: path.join(rootDir, 'index.html'),
+ html: 'Helloworld
',
+ inlineModules: [],
+ moduleImports: [{ importPath: path.join(rootDir, 'app.js'), attributes: [] }],
+ assets: [],
+ name: 'index.html',
+ },
+ {
+ filePath: path.join(rootDir, 'not-index.html'),
+ html: 'not-index.html
',
+ inlineModules: [],
+ moduleImports: [],
+ assets: [],
+ name: 'not-index.html',
+ },
+ ]);
+ });
+
+ it('supports setting input as rollup input object', () => {
+ const rootDir = createApp({
+ 'index.html': html`
+
+
+ Hello world
+
+
+
+ `,
+ 'not-index.html': html`
+
+
+ not-index.html
+
+
+ `,
+ 'app.js': js`
+ console.log('hello world');
+ `,
+ });
+ const result = getInputData(
+ { rootDir },
+ { 'a.html': 'index.html', 'b.html': 'not-index.html' },
+ );
+ expect(cleanupResult(result)).to.eql([
+ {
+ filePath: path.join(rootDir, 'index.html'),
+ html: 'Helloworld
',
+ inlineModules: [],
+ moduleImports: [{ importPath: path.join(rootDir, 'app.js'), attributes: [] }],
+ assets: [],
+ name: 'a.html',
+ },
+ {
+ filePath: path.join(rootDir, 'not-index.html'),
+ html: 'not-index.html
',
+ inlineModules: [],
+ moduleImports: [],
+ assets: [],
+ name: 'b.html',
+ },
+ ]);
+ });
+
+ it('plugin input takes presedence over rollup input', () => {
+ const rootDir = createApp({
+ 'index.html': html`
+
+
+ Hello world
+
+
+
+ `,
+ 'not-index.html': html`
+
+
+ not-index.html
+
+
+ `,
+ 'app.js': js`
+ console.log('hello world');
+ `,
+ });
+ const result = getInputData({ input: 'index.html', rootDir }, 'not-index.html');
+ expect(cleanupResult(result)).to.eql([
+ {
+ filePath: path.join(rootDir, 'index.html'),
+ html: 'Helloworld
',
+ inlineModules: [],
+ moduleImports: [{ importPath: path.join(rootDir, 'app.js'), attributes: [] }],
+ assets: [],
+ name: 'index.html',
+ },
+ ]);
+ });
+
+ it('can set html string as input', () => {
+ const rootDir = createApp({
+ 'app.js': js`
+ console.log('hello world');
+ `,
+ });
+ const result = getInputData({
+ input: {
+ html: html`
+
+
+ HTML as string
+
+
+
+ `,
+ },
+ rootDir,
+ });
+ expect(cleanupResult(result)).to.eql([
+ {
+ filePath: undefined,
+ html: 'HTMLasstring
',
+ inlineModules: [],
+ moduleImports: [{ importPath: path.join(rootDir, 'app.js'), attributes: [] }],
+ assets: [],
+ name: 'index.html',
+ },
+ ]);
+ });
+
+ it('can set multiple html strings as input', () => {
+ const rootDir = createApp({
+ 'app.js': js`
+ console.log('hello world');
+ `,
+ });
+ const result = getInputData({
+ rootDir,
+ input: [
+ {
+ name: '1.html',
+ html: html`
+
+
+ HTML1
+
+
+
+ `,
+ },
+ {
+ name: '2.html',
+ html: html`
+
+
+ HTML2
+
+
+ `,
+ },
+ ],
+ });
+ expect(cleanupResult(result)).to.eql([
+ {
+ filePath: undefined,
+ html: 'HTML1
',
+ inlineModules: [],
+ moduleImports: [{ importPath: path.join(rootDir, 'app.js'), attributes: [] }],
+ assets: [],
+ name: '1.html',
+ },
+ {
+ filePath: undefined,
+ html: 'HTML2
',
+ inlineModules: [],
+ moduleImports: [],
+ assets: [],
+ name: '2.html',
+ },
+ ]);
+ });
+
+ it('supports setting input to a glob', () => {
+ const rootDir = createApp({
+ 'pages/page-a.html': html`
+
+
+ page-a.html
+
+
+
+
+ `,
+ 'pages/page-b.html': html`
+
+
+ page-b.html
+
+
+
+
+ `,
+ 'pages/page-c.html': html`
+
+
+ page-c.html
+
+
+
+
+ `,
+ 'pages/page-a.js': js`
+ export default 'page a';
+ `,
+ 'pages/page-b.js': js`
+ export default 'page b';
+ `,
+ 'pages/page-c.js': js`
+ export default 'page c';
+ `,
+ 'pages/shared.js': js`
+ export default 'shared';
+ `,
+ });
+ const result = getInputData({ input: 'pages/**/*.html', rootDir });
+ expect(cleanupResult(result)).to.eql([
+ {
+ filePath: path.join(rootDir, 'pages', 'page-c.html'),
+ html: 'page-c.html
',
+ inlineModules: [],
+ moduleImports: [
+ { importPath: path.join(rootDir, 'pages', 'page-c.js'), attributes: [] },
+ { importPath: path.join(rootDir, 'pages', 'shared.js'), attributes: [] },
+ ],
+ assets: [],
+ name: 'page-c.html',
+ },
+ {
+ filePath: path.join(rootDir, 'pages', 'page-b.html'),
+ html: 'page-b.html
',
+ inlineModules: [],
+ moduleImports: [
+ { importPath: path.join(rootDir, 'pages', 'page-b.js'), attributes: [] },
+ { importPath: path.join(rootDir, 'pages', 'shared.js'), attributes: [] },
+ ],
+ assets: [],
+ name: 'page-b.html',
+ },
+ {
+ filePath: path.join(rootDir, 'pages', 'page-a.html'),
+ html: 'page-a.html
',
+ inlineModules: [],
+ moduleImports: [
+ { importPath: path.join(rootDir, 'pages', 'page-a.js'), attributes: [] },
+ { importPath: path.join(rootDir, 'pages', 'shared.js'), attributes: [] },
+ ],
+ assets: [],
+ name: 'page-a.html',
+ },
+ ]);
+ });
+
+ it('supports not flattening output directories', () => {
+ const rootDir = createApp({
+ 'pages/page-a.html': html`
+
+
+ page-a.html
+
+
+
+
+ `,
+ 'pages/page-b.html': html`
+
+
+ page-b.html
+
+
+
+
+ `,
+ 'pages/page-c.html': html`
+
+
+ page-c.html
+
+
+
+
+ `,
+ 'pages/page-a.js': js`
+ export default 'page a';
+ `,
+ 'pages/page-b.js': js`
+ export default 'page b';
+ `,
+ 'pages/page-c.js': js`
+ export default 'page c';
+ `,
+ 'pages/shared.js': js`
+ export default 'shared';
+ `,
+ });
+ const result = getInputData({ input: 'pages/**/*.html', flattenOutput: false, rootDir });
+ expect(cleanupResult(result)).to.eql([
+ {
+ filePath: path.join(rootDir, 'pages', 'page-c.html'),
+ html: 'page-c.html
',
+ inlineModules: [],
+ moduleImports: [
+ { importPath: path.join(rootDir, 'pages', 'page-c.js'), attributes: [] },
+ { importPath: path.join(rootDir, 'pages', 'shared.js'), attributes: [] },
+ ],
+ assets: [],
+ name: `pages${path.sep}page-c.html`,
+ },
+ {
+ filePath: path.join(rootDir, 'pages', 'page-b.html'),
+ html: 'page-b.html
',
+ inlineModules: [],
+ moduleImports: [
+ { importPath: path.join(rootDir, 'pages', 'page-b.js'), attributes: [] },
+ { importPath: path.join(rootDir, 'pages', 'shared.js'), attributes: [] },
+ ],
+ assets: [],
+ name: `pages${path.sep}page-b.html`,
+ },
+ {
+ filePath: path.join(rootDir, 'pages', 'page-a.html'),
+ html: 'page-a.html
',
+ inlineModules: [],
+ moduleImports: [
+ { importPath: path.join(rootDir, 'pages', 'page-a.js'), attributes: [] },
+ { importPath: path.join(rootDir, 'pages', 'shared.js'), attributes: [] },
+ ],
+ assets: [],
+ name: `pages${path.sep}page-a.html`,
+ },
+ ]);
+ });
+
+ it('supports pure HTML files', () => {
+ const rootDir = createApp({});
+ const result = getInputData({
+ rootDir,
+ input: {
+ html: html`
+
+
+ pure HTML
+
+
+ `,
+ },
+ });
+ expect(cleanupResult(result)).to.eql([
+ {
+ filePath: undefined,
+ html: 'pureHTML
',
+ inlineModules: [],
+ moduleImports: [],
+ assets: [],
+ name: 'index.html',
+ },
+ ]);
+ });
+
+ it('throws when no files or html is given', () => {
+ const rootDir = createApp({});
+ expect(() => getInputData({ rootDir })).to.throw();
+ });
+});
+=======
+import assert from 'node:assert/strict';
+import { describe, it } from 'node:test';
+import path from 'path';
+<<<<<<< HEAD:packages/rollup-plugin-html/test/src/input/InputData.test.ts
+import { cleanApp, createApp, html, js } from '../../utils.js';
+||||||| parent of c37bb778 (chore: migrate tests from mocha/chai to node:test + node:assert):packages/rollup-plugin-html/test/src/input/InputData.test.ts
+import { cleanApp, createApp, html, js } from '../../utils.ts';
+=======
+>>>>>>> c37bb778 (chore: migrate tests from mocha/chai to node:test + node:assert):packages/rollup-plugin-html/test/input/InputData.test.ts
+
+<<<<<<< HEAD:packages/rollup-plugin-html/test/src/input/InputData.test.ts
+import { getInputData } from '../../../src/input/getInputData.js';
+import { InputData } from '../../../src/input/InputData.js';
+||||||| parent of c37bb778 (chore: migrate tests from mocha/chai to node:test + node:assert):packages/rollup-plugin-html/test/src/input/InputData.test.ts
+import { getInputData } from '../../../src/input/getInputData.ts';
+import { InputData } from '../../../src/input/InputData.ts';
+=======
+import { getInputData } from '../../src/input/getInputData.ts';
+import type { InputData } from '../../src/input/InputData.ts';
+
+const __dirname = import.meta.dirname;
+const rootDir = path.join(__dirname, '..', 'fixtures', 'basic');
+>>>>>>> c37bb778 (chore: migrate tests from mocha/chai to node:test + node:assert):packages/rollup-plugin-html/test/input/InputData.test.ts
+
+function cleanupHtml(str: string) {
+ return str.replace(/(\r\n|\n|\r| )/gm, '');
+}
+
+function cleanupResult(result: InputData[]) {
+ return result.map(item => ({
+ ...item,
+ inlineModules: Array.from(item.inlineModules.entries()),
+ html: cleanupHtml(item.html),
+ }));
+}
+
+describe('getInputData()', () => {
+ it('supports setting input as string', () => {
+ const result = getInputData({ input: 'index.html', rootDir });
+ assert.deepStrictEqual(cleanupResult(result), [
+ {
+ filePath: path.join(rootDir, 'index.html'),
+ html: 'Helloworld
',
+ inlineModules: [],
+ moduleImports: [{ importPath: path.join(rootDir, 'app.js'), attributes: [] }],
+ assets: [],
+ name: 'index.html',
+ },
+ ]);
+ });
+
+ it('supports setting input as object', () => {
+ const result = getInputData({ input: { path: 'index.html' }, rootDir });
+ assert.deepStrictEqual(cleanupResult(result), [
+ {
+ filePath: path.join(rootDir, 'index.html'),
+ html: 'Helloworld
',
+ inlineModules: [],
+ moduleImports: [{ importPath: path.join(rootDir, 'app.js'), attributes: [] }],
+ assets: [],
+ name: 'index.html',
+ },
+ ]);
+ });
+
+ it('supports changing file name', () => {
+ const result = getInputData({ input: { path: 'index.html', name: 'foo.html' }, rootDir });
+ assert.deepStrictEqual(cleanupResult(result), [
+ {
+ filePath: path.join(rootDir, 'index.html'),
+ html: 'Helloworld
',
+ inlineModules: [],
+ moduleImports: [{ importPath: path.join(rootDir, 'app.js'), attributes: [] }],
+ assets: [],
+ name: 'foo.html',
+ },
+ ]);
+ });
+
+ it('supports setting multiple inputs', () => {
+ const result = getInputData({
+ input: [{ path: 'index.html' }, { path: 'not-index.html' }],
+ rootDir,
+ });
+ assert.deepStrictEqual(cleanupResult(result), [
+ {
+ filePath: path.join(rootDir, 'index.html'),
+ html: 'Helloworld
',
+ inlineModules: [],
+ moduleImports: [{ importPath: path.join(rootDir, 'app.js'), attributes: [] }],
+ assets: [],
+ name: 'index.html',
+ },
+ {
+ filePath: path.join(rootDir, 'not-index.html'),
+ html: 'not-index.html
',
+ inlineModules: [],
+ moduleImports: [],
+ assets: [],
+ name: 'not-index.html',
+ },
+ ]);
+ });
+
+ it('resolves modules relative to HTML file', () => {
+ const result = getInputData({ input: 'src/index.html', rootDir });
+ assert.deepStrictEqual(cleanupResult(result), [
+ {
+ filePath: path.join(rootDir, 'src/index.html'),
+ html: 'Foo
',
+ inlineModules: [],
+ moduleImports: [{ importPath: path.join(rootDir, 'src', 'foo.js'), attributes: [] }],
+ assets: [],
+ name: 'index.html',
+ },
+ ]);
+ });
+
+ it('supports setting input as rollup input string', () => {
+ const result = getInputData({ rootDir }, 'index.html');
+ assert.deepStrictEqual(cleanupResult(result), [
+ {
+ filePath: path.join(rootDir, 'index.html'),
+ html: 'Helloworld
',
+ inlineModules: [],
+ moduleImports: [{ importPath: path.join(rootDir, 'app.js'), attributes: [] }],
+ assets: [],
+ name: 'index.html',
+ },
+ ]);
+ });
+
+ it('supports setting input as rollup input array', () => {
+ const result = getInputData({ rootDir }, ['index.html']);
+ assert.deepStrictEqual(cleanupResult(result), [
+ {
+ filePath: path.join(rootDir, 'index.html'),
+ html: 'Helloworld
',
+ inlineModules: [],
+ moduleImports: [{ importPath: path.join(rootDir, 'app.js'), attributes: [] }],
+ assets: [],
+ name: 'index.html',
+ },
+ ]);
+ });
+
+ it('supports setting input as rollup input array', () => {
+ const result = getInputData({ rootDir }, ['index.html', 'not-index.html']);
+ assert.deepStrictEqual(cleanupResult(result), [
+ {
+ filePath: path.join(rootDir, 'index.html'),
+ html: 'Helloworld
',
+ inlineModules: [],
+ moduleImports: [{ importPath: path.join(rootDir, 'app.js'), attributes: [] }],
+ assets: [],
+ name: 'index.html',
+ },
+ {
+ filePath: path.join(rootDir, 'not-index.html'),
+ html: 'not-index.html
',
+ inlineModules: [],
+ moduleImports: [],
+ assets: [],
+ name: 'not-index.html',
+ },
+ ]);
+ });
+
+ it('supports setting input as rollup input object', () => {
+ const result = getInputData(
+ { rootDir },
+ { 'a.html': 'index.html', 'b.html': 'not-index.html' },
+ );
+ assert.deepStrictEqual(cleanupResult(result), [
+ {
+ filePath: path.join(rootDir, 'index.html'),
+ html: 'Helloworld
',
+ inlineModules: [],
+ moduleImports: [{ importPath: path.join(rootDir, 'app.js'), attributes: [] }],
+ assets: [],
+ name: 'a.html',
+ },
+ {
+ filePath: path.join(rootDir, 'not-index.html'),
+ html: 'not-index.html
',
+ inlineModules: [],
+ moduleImports: [],
+ assets: [],
+ name: 'b.html',
+ },
+ ]);
+ });
+
+ it('plugin input takes presedence over rollup input', () => {
+ const result = getInputData({ input: 'index.html', rootDir }, 'not-index.html');
+ assert.deepStrictEqual(cleanupResult(result), [
+ {
+ filePath: path.join(rootDir, 'index.html'),
+ html: 'Helloworld
',
+ inlineModules: [],
+ moduleImports: [{ importPath: path.join(rootDir, 'app.js'), attributes: [] }],
+ assets: [],
+ name: 'index.html',
+ },
+ ]);
+ });
+
+ it('can set html string as input', () => {
+ const html = `
+
+
+ HTML as string
+
+
+
+ `;
+ const result = getInputData({ input: { html }, rootDir });
+ assert.deepStrictEqual(cleanupResult(result), [
+ {
+ filePath: undefined,
+ html: 'HTMLasstring
',
+ inlineModules: [],
+ moduleImports: [{ importPath: path.join(rootDir, 'app.js'), attributes: [] }],
+ assets: [],
+ name: 'index.html',
+ },
+ ]);
+ });
+
+ it('can set multiple html strings as input', () => {
+ const html1 = `
+
+
+ HTML1
+
+
+
+ `;
+ const html2 = `
+
+
+ HTML2
+
+
+ `;
+ const result = getInputData({
+ input: [
+ { html: html1, name: '1.html' },
+ { html: html2, name: '2.html' },
+ ],
+ rootDir,
+ });
+ assert.deepStrictEqual(cleanupResult(result), [
+ {
+ filePath: undefined,
+ html: 'HTML1
',
+ inlineModules: [],
+ moduleImports: [{ importPath: path.join(rootDir, 'app.js'), attributes: [] }],
+ assets: [],
+ name: '1.html',
+ },
+ {
+ filePath: undefined,
+ html: 'HTML2
',
+ inlineModules: [],
+ moduleImports: [],
+ assets: [],
+ name: '2.html',
+ },
+ ]);
+ });
+
+ it('supports setting input to a glob', () => {
+ const result = getInputData({ input: 'pages/**/*.html', rootDir });
+ assert.deepStrictEqual(cleanupResult(result), [
+ {
+ filePath: path.join(rootDir, 'pages', 'page-c.html'),
+ html: 'page-c.html
',
+ inlineModules: [],
+ moduleImports: [
+ { importPath: path.join(rootDir, 'pages', 'page-c.js'), attributes: [] },
+ { importPath: path.join(rootDir, 'pages', 'shared.js'), attributes: [] },
+ ],
+ assets: [],
+ name: 'page-c.html',
+ },
+ {
+ filePath: path.join(rootDir, 'pages', 'page-b.html'),
+ html: 'page-b.html
',
+ inlineModules: [],
+ moduleImports: [
+ { importPath: path.join(rootDir, 'pages', 'page-b.js'), attributes: [] },
+ { importPath: path.join(rootDir, 'pages', 'shared.js'), attributes: [] },
+ ],
+ assets: [],
+ name: 'page-b.html',
+ },
+ {
+ filePath: path.join(rootDir, 'pages', 'page-a.html'),
+ html: 'page-a.html
',
+ inlineModules: [],
+ moduleImports: [
+ { importPath: path.join(rootDir, 'pages', 'page-a.js'), attributes: [] },
+ { importPath: path.join(rootDir, 'pages', 'shared.js'), attributes: [] },
+ ],
+ assets: [],
+ name: 'page-a.html',
+ },
+ ]);
+ });
+
+ it('supports not flattening output directories', () => {
+ const result = getInputData({ input: 'pages/**/*.html', flattenOutput: false, rootDir });
+ assert.deepStrictEqual(cleanupResult(result), [
+ {
+ filePath: path.join(rootDir, 'pages', 'page-c.html'),
+ html: 'page-c.html
',
+ inlineModules: [],
+ moduleImports: [
+ { importPath: path.join(rootDir, 'pages', 'page-c.js'), attributes: [] },
+ { importPath: path.join(rootDir, 'pages', 'shared.js'), attributes: [] },
+ ],
+ assets: [],
+ name: `pages${path.sep}page-c.html`,
+ },
+ {
+ filePath: path.join(rootDir, 'pages', 'page-b.html'),
+ html: 'page-b.html
',
+ inlineModules: [],
+ moduleImports: [
+ { importPath: path.join(rootDir, 'pages', 'page-b.js'), attributes: [] },
+ { importPath: path.join(rootDir, 'pages', 'shared.js'), attributes: [] },
+ ],
+ assets: [],
+ name: `pages${path.sep}page-b.html`,
+ },
+ {
+ filePath: path.join(rootDir, 'pages', 'page-a.html'),
+ html: 'page-a.html
',
+ inlineModules: [],
+ moduleImports: [
+ { importPath: path.join(rootDir, 'pages', 'page-a.js'), attributes: [] },
+ { importPath: path.join(rootDir, 'pages', 'shared.js'), attributes: [] },
+ ],
+ assets: [],
+ name: `pages${path.sep}page-a.html`,
+ },
+ ]);
+ });
+
+ it('supports pure HTML files', () => {
+ const html = `
+
+
+ pure HTML
+
+
+ `;
+ const result = getInputData({ input: { html }, rootDir });
+ assert.deepStrictEqual(cleanupResult(result), [
+ {
+ filePath: undefined,
+ html: 'pureHTML
',
+ inlineModules: [],
+ moduleImports: [],
+ assets: [],
+ name: 'index.html',
+ },
+ ]);
+ });
+
+ it('throws when no files or html is given', () => {
+ assert.throws(() => getInputData({ rootDir }));
+ });
+});
+>>>>>>> 9007e014 (chore: migrate tests from mocha/chai to node:test + node:assert):packages/rollup-plugin-html/test/input/InputData.test.ts
diff --git a/packages/rollup-plugin-html/test/input/extract/extractAssets.test.ts b/packages/rollup-plugin-html/test/input/extract/extractAssets.test.ts
new file mode 100644
index 0000000000..f735491efd
--- /dev/null
+++ b/packages/rollup-plugin-html/test/input/extract/extractAssets.test.ts
@@ -0,0 +1,316 @@
+import assert from 'node:assert/strict';
+import { describe, it } from 'node:test';
+import { parse } from 'parse5';
+import path from 'path';
+import { extractAssets } from '../../../src/input/extract/extractAssets.ts';
+
+const __dirname = import.meta.dirname;
+const rootDir = path.resolve(__dirname, '..', '..', 'fixtures', 'assets');
+
+describe('extractAssets', () => {
+ it('extracts assets from a document', () => {
+ const document = parse(`
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ `);
+ const assets = extractAssets({
+ document,
+ htmlFilePath: path.join(rootDir, 'index.html'),
+ htmlDir: rootDir,
+ rootDir,
+ });
+
+ const assetsWithoutcontent = assets.map(a => ({ ...a, content: undefined }));
+ assert.deepStrictEqual(assetsWithoutcontent, [
+ {
+ content: undefined,
+ filePath: path.join(rootDir, 'image-a.png'),
+ hashed: false,
+ },
+ {
+ content: undefined,
+ filePath: path.join(rootDir, 'image-b.png'),
+ hashed: false,
+ },
+ {
+ content: undefined,
+ filePath: path.join(rootDir, 'webmanifest.json'),
+ hashed: false,
+ },
+ {
+ content: undefined,
+ filePath: path.join(rootDir, 'image-a.svg'),
+ hashed: false,
+ },
+ {
+ content: undefined,
+ filePath: path.join(rootDir, 'styles.css'),
+ hashed: true,
+ },
+ {
+ content: undefined,
+ filePath: path.join(rootDir, 'image-social.png'),
+ hashed: true,
+ },
+ {
+ content: undefined,
+ filePath: path.join(rootDir, 'image-c.png'),
+ hashed: true,
+ },
+ {
+ content: undefined,
+ filePath: path.join(rootDir, 'image-b.svg'),
+ hashed: true,
+ },
+ ]);
+ });
+
+ it('reads file sources', () => {
+ const document = parse(`
+
+
+
+
+
+
+
+
+
+
+
+
+
+ `);
+ const assets = extractAssets({
+ document,
+ htmlFilePath: path.join(rootDir, 'index.html'),
+ htmlDir: rootDir,
+ rootDir,
+ });
+
+ const transformedAssets = assets.map(asset => ({
+ ...asset,
+ content: asset.content.toString('utf-8').replace(/\s/g, ''),
+ }));
+ assert.deepStrictEqual(transformedAssets, [
+ {
+ content: '{"message":"helloworld"}',
+ filePath: path.join(rootDir, 'webmanifest.json'),
+ hashed: false,
+ },
+ {
+ content:
+ '',
+ filePath: path.join(rootDir, 'image-a.svg'),
+ hashed: false,
+ },
+ {
+ content: ':root{color:blue;}',
+ filePath: path.join(rootDir, 'styles.css'),
+ hashed: true,
+ },
+ {
+ content:
+ '',
+ filePath: path.join(rootDir, 'image-b.svg'),
+ hashed: true,
+ },
+ ]);
+ });
+
+ it('handles paths into directories', () => {
+ const document = parse(`
+
+
+
+
+
+
+ `);
+ const assets = extractAssets({
+ document,
+ htmlFilePath: path.join(rootDir, 'index.html'),
+ htmlDir: rootDir,
+ rootDir,
+ });
+
+ assert.strictEqual(assets.length, 2);
+ assert.strictEqual(assets[0].filePath, path.join(rootDir, 'foo', 'x.css'));
+ assert.strictEqual(assets[1].filePath, path.join(rootDir, 'foo', 'bar', 'y.css'));
+ assert.strictEqual(assets[0].content.toString('utf-8').replace(/\s/g, ''), ':root{color:x;}');
+ assert.strictEqual(assets[1].content.toString('utf-8').replace(/\s/g, ''), ':root{color:y;}');
+ });
+
+ it('resolves relative to HTML file location', () => {
+ const document = parse(`
+
+
+
+
+
+
+ `);
+ const assets = extractAssets({
+ document,
+ htmlFilePath: path.join(rootDir, 'foo', 'index.html'),
+ htmlDir: path.join(rootDir, 'foo'),
+ rootDir,
+ });
+
+ assert.strictEqual(assets.length, 2);
+ assert.strictEqual(assets[0].filePath, path.join(rootDir, 'foo', 'x.css'));
+ assert.strictEqual(assets[1].filePath, path.join(rootDir, 'styles.css'));
+ assert.strictEqual(assets[0].content.toString('utf-8').replace(/\s/g, ''), ':root{color:x;}');
+ assert.strictEqual(assets[1].content.toString('utf-8').replace(/\s/g, ''), ':root{color:blue;}');
+ });
+
+ it('resolves absolute paths relative to root dir', () => {
+ const document = parse(`
+
+
+
+
+
+
+ `);
+ const assets = extractAssets({
+ document,
+ htmlFilePath: path.join(rootDir, 'foo', 'index.html'),
+ htmlDir: path.join(rootDir, 'foo'),
+ rootDir,
+ });
+
+ assert.strictEqual(assets.length, 2);
+ assert.strictEqual(assets[0].filePath, path.join(rootDir, 'foo', 'x.css'));
+ assert.strictEqual(assets[1].filePath, path.join(rootDir, 'styles.css'));
+ assert.strictEqual(assets[0].content.toString('utf-8').replace(/\s/g, ''), ':root{color:x;}');
+ assert.strictEqual(assets[1].content.toString('utf-8').replace(/\s/g, ''), ':root{color:blue;}');
+ });
+
+ it('can reference the same asset with a hashed and non-hashed node', () => {
+ const document = parse(`
+
+
+
+
+
+
+ `);
+ const assets = extractAssets({
+ document,
+ htmlFilePath: path.join(rootDir, 'index.html'),
+ htmlDir: rootDir,
+ rootDir,
+ });
+
+ assert.strictEqual(assets.length, 2);
+ const assetsWithoutcontent = assets.map(a => ({ ...a, content: undefined }));
+ assert.deepStrictEqual(assetsWithoutcontent, [
+ {
+ content: undefined,
+ filePath: path.join(rootDir, 'image-a.png'),
+ hashed: true,
+ },
+ {
+ content: undefined,
+ filePath: path.join(rootDir, 'image-a.png'),
+ hashed: false,
+ },
+ ]);
+ });
+
+ it('does not count remote URLs as assets', () => {
+ const document = parse(`
+
+
+
+
+
+ `);
+ const assets = extractAssets({
+ document,
+ htmlFilePath: path.join(rootDir, 'foo', 'index.html'),
+ htmlDir: path.join(rootDir, 'foo'),
+ rootDir,
+ });
+
+ assert.strictEqual(assets.length, 0);
+ });
+
+ it('does treat non module script tags as assets', () => {
+ const document = parse(`
+
+
+
+
+
+ `);
+ const assets = extractAssets({
+ document,
+ htmlFilePath: path.join(rootDir, 'index.html'),
+ htmlDir: path.join(rootDir),
+ rootDir,
+ });
+
+ assert.strictEqual(assets.length, 1);
+ assert.strictEqual(assets[0].filePath, path.join(rootDir, 'no-module.js'));
+ assert.strictEqual(assets[0].content.toString('utf-8'), '/* no module script file */\n');
+ });
+
+ it('handles a picture tag using source tags with srcset', () => {
+ const document = parse(`
+
+
+
+
+
+
+
+
+
+ `);
+ const assets = extractAssets({
+ document,
+ htmlFilePath: path.join(rootDir, 'index.html'),
+ htmlDir: path.join(rootDir),
+ rootDir,
+ });
+
+ // the src is not the same as the small jpeg image
+ assert.strictEqual(assets.length, 4);
+ assert.strictEqual(assets[0].filePath, path.join(rootDir, 'images', 'eb26e6ca-30.avif'));
+ assert.strictEqual(assets[1].filePath, path.join(rootDir, 'images', 'eb26e6ca-60.avif'));
+ assert.strictEqual(assets[2].filePath, path.join(rootDir, 'images', 'eb26e6ca-30.jpeg'));
+ assert.strictEqual(assets[3].filePath, path.join(rootDir, 'images', 'eb26e6ca-60.jpeg'));
+ });
+});
diff --git a/packages/rollup-plugin-html/test/input/extract/extractModules.test.ts b/packages/rollup-plugin-html/test/input/extract/extractModules.test.ts
new file mode 100644
index 0000000000..90d6cd5fc4
--- /dev/null
+++ b/packages/rollup-plugin-html/test/input/extract/extractModules.test.ts
@@ -0,0 +1,195 @@
+import assert from 'node:assert/strict';
+import { describe, it } from 'node:test';
+import path from 'path';
+import { parse, serialize } from 'parse5';
+
+import { extractModules } from '../../../src/input/extract/extractModules.ts';
+
+const { sep } = path;
+
+describe('extractModules()', () => {
+ it('extracts all modules from a html document', () => {
+ const document = parse(
+ 'before
' +
+ '' +
+ '' +
+ 'after
',
+ );
+
+ const { moduleImports, inlineModules } = extractModules({
+ document,
+ htmlDir: '/',
+ rootDir: '/',
+ });
+ const htmlWithoutModules = serialize(document);
+
+ assert.strictEqual(inlineModules.length, 0);
+ assert.deepStrictEqual(moduleImports, [
+ { importPath: `${sep}foo.js`, attributes: [] },
+ { importPath: `${sep}bar.js`, attributes: [] },
+ ]);
+ assert.strictEqual(htmlWithoutModules,
+ 'before
after
',
+ );
+ });
+
+ it('does not touch non module scripts', () => {
+ const document = parse(
+ 'before
' +
+ '' +
+ '' +
+ 'after
',
+ );
+
+ const { moduleImports, inlineModules } = extractModules({
+ document,
+ htmlDir: '/',
+ rootDir: '/',
+ });
+ const htmlWithoutModules = serialize(document);
+
+ assert.strictEqual(inlineModules.length, 0);
+ assert.deepStrictEqual(moduleImports, []);
+ assert.strictEqual(htmlWithoutModules,
+ 'before
after
',
+ );
+ });
+
+ it('resolves imports relative to the root dir', () => {
+ const document = parse(
+ 'before
' +
+ '' +
+ '' +
+ 'after
',
+ );
+
+ const { moduleImports, inlineModules } = extractModules({
+ document,
+ htmlDir: '/',
+ rootDir: '/base/',
+ });
+ const htmlWithoutModules = serialize(document);
+
+ assert.strictEqual(inlineModules.length, 0);
+ assert.deepStrictEqual(moduleImports, [
+ { importPath: `${sep}foo.js`, attributes: [] },
+ { importPath: `${sep}base${sep}bar.js`, attributes: [] },
+ ]);
+ assert.strictEqual(htmlWithoutModules,
+ 'before
after
',
+ );
+ });
+
+ it('resolves relative imports relative to the relative import base', () => {
+ const document = parse(
+ 'before
' +
+ '' +
+ '' +
+ 'after
',
+ );
+
+ const { moduleImports, inlineModules } = extractModules({
+ document,
+ htmlDir: '/base-1/base-2/',
+ rootDir: '/base-1/',
+ });
+ const htmlWithoutModules = serialize(document);
+
+ assert.strictEqual(inlineModules.length, 0);
+ assert.deepStrictEqual(moduleImports, [
+ { importPath: `${sep}base-1${sep}base-2${sep}foo.js`, attributes: [] },
+ { importPath: `${sep}base-1${sep}bar.js`, attributes: [] },
+ ]);
+ assert.strictEqual(htmlWithoutModules,
+ 'before
after
',
+ );
+ });
+
+ it('extracts all inline modules from a html document', () => {
+ const document = parse(
+ 'before
' +
+ '' +
+ '' +
+ 'after
',
+ );
+
+ const { moduleImports, inlineModules } = extractModules({
+ document,
+ htmlDir: '/',
+ rootDir: '/',
+ });
+ const htmlWithoutModules = serialize(document);
+
+ assert.deepStrictEqual(inlineModules, [
+ {
+ importPath: '/inline-module-cce79ce714e2c3b250afef32e61fb003.js',
+ code: '/* my module 1 */',
+ attributes: [],
+ },
+ {
+ importPath: '/inline-module-d9a0918508784903d131c7c4eb98e424.js',
+ code: '/* my module 2 */',
+ attributes: [],
+ },
+ ]);
+ assert.deepStrictEqual(moduleImports, []);
+ assert.strictEqual(htmlWithoutModules,
+ 'before
after
',
+ );
+ });
+
+ it('prefixes inline module with index.html directory', () => {
+ const document = parse(
+ 'before
' +
+ '' +
+ '' +
+ 'after
',
+ );
+
+ const { moduleImports, inlineModules } = extractModules({
+ document,
+ htmlDir: '/foo/bar/',
+ rootDir: '/',
+ });
+ const htmlWithoutModules = serialize(document);
+
+ assert.deepStrictEqual(inlineModules, [
+ {
+ importPath: '/foo/bar/inline-module-cce79ce714e2c3b250afef32e61fb003.js',
+ code: '/* my module 1 */',
+ attributes: [],
+ },
+ {
+ importPath: '/foo/bar/inline-module-d9a0918508784903d131c7c4eb98e424.js',
+ code: '/* my module 2 */',
+ attributes: [],
+ },
+ ]);
+ assert.deepStrictEqual(moduleImports, []);
+ assert.strictEqual(htmlWithoutModules,
+ 'before
after
',
+ );
+ });
+
+ it('ignores absolute paths', () => {
+ const document = parse(
+ 'before
' +
+ '' +
+ '' +
+ 'after
',
+ );
+
+ const { moduleImports, inlineModules } = extractModules({
+ document,
+ htmlDir: '/',
+ rootDir: '/',
+ });
+ const htmlWithoutModules = serialize(document);
+
+ assert.strictEqual(inlineModules.length, 0);
+ assert.deepStrictEqual(moduleImports, [{ importPath: `${sep}bar.js`, attributes: [] }]);
+ assert.strictEqual(htmlWithoutModules,
+ 'before
after
',
+ );
+ });
+});
diff --git a/packages/rollup-plugin-html/test/output/getEntrypointBundles.test.ts b/packages/rollup-plugin-html/test/output/getEntrypointBundles.test.ts
new file mode 100644
index 0000000000..c4947718da
--- /dev/null
+++ b/packages/rollup-plugin-html/test/output/getEntrypointBundles.test.ts
@@ -0,0 +1,740 @@
+<<<<<<< HEAD:packages/rollup-plugin-html/test/src/output/getEntrypointBundles.test.ts
+||||||| parent of 9007e014 (chore: migrate tests from mocha/chai to node:test + node:assert):packages/rollup-plugin-html/test/src/output/getEntrypointBundles.test.ts
+import { expect } from 'chai';
+import {
+ getEntrypointBundles,
+ createImportPath,
+} from '../../../src/output/getEntrypointBundles.js';
+import { GeneratedBundle, ScriptModuleTag } from '../../../src/RollupPluginHTMLOptions.ts';
+||||||| parent of c37bb778 (chore: migrate tests from mocha/chai to node:test + node:assert):packages/rollup-plugin-html/test/src/output/getEntrypointBundles.test.ts
+} from '../../../src/output/getEntrypointBundles.ts';
+import { GeneratedBundle, ScriptModuleTag } from '../../../src/RollupPluginHTMLOptions.ts';
+=======
+} from '../../src/output/getEntrypointBundles.ts';
+import type { GeneratedBundle, ScriptModuleTag } from '../../src/RollupPluginHTMLOptions.ts';
+>>>>>>> c37bb778 (chore: migrate tests from mocha/chai to node:test + node:assert):packages/rollup-plugin-html/test/output/getEntrypointBundles.test.ts
+
+describe('createImportPath()', () => {
+ it('creates a relative import path', () => {
+ expect(
+ createImportPath({
+ outputDir: 'dist',
+ fileOutputDir: 'dist',
+ htmlFileName: 'index.html',
+ fileName: 'foo.js',
+ }),
+ ).to.equal('./foo.js');
+ });
+
+ it('handles files output in a different directory', () => {
+ expect(
+ createImportPath({
+ outputDir: 'dist',
+ fileOutputDir: 'dist/legacy',
+ htmlFileName: 'index.html',
+ fileName: 'foo.js',
+ }),
+ ).to.equal('./legacy/foo.js');
+ });
+
+ it('handles directory in filename', () => {
+ expect(
+ createImportPath({
+ outputDir: 'dist',
+ fileOutputDir: 'dist',
+ htmlFileName: 'index.html',
+ fileName: 'legacy/foo.js',
+ }),
+ ).to.equal('./legacy/foo.js');
+ });
+
+ it('allows configuring a public path', () => {
+ expect(
+ createImportPath({
+ publicPath: 'static',
+ outputDir: 'dist',
+ fileOutputDir: 'dist',
+ htmlFileName: 'index.html',
+ fileName: 'foo.js',
+ }),
+ ).to.equal('./static/foo.js');
+ });
+
+ it('allows configuring an absolute public path', () => {
+ expect(
+ createImportPath({
+ publicPath: '/static',
+ outputDir: 'dist',
+ fileOutputDir: 'dist',
+ htmlFileName: 'index.html',
+ fileName: 'foo.js',
+ }),
+ ).to.equal('/static/foo.js');
+ });
+
+ it('allows configuring an absolute public path with just a /', () => {
+ expect(
+ createImportPath({
+ publicPath: '/',
+ outputDir: 'dist',
+ fileOutputDir: 'dist',
+ htmlFileName: 'index.html',
+ fileName: 'foo.js',
+ }),
+ ).to.equal('/foo.js');
+ });
+
+ it('allows configuring an absolute public path with a trailing /', () => {
+ expect(
+ createImportPath({
+ publicPath: '/static/public/',
+ outputDir: 'dist',
+ fileOutputDir: 'dist',
+ htmlFileName: 'index.html',
+ fileName: 'foo.js',
+ }),
+ ).to.equal('/static/public/foo.js');
+ });
+
+ it('respects a different output dir when configuring a public path', () => {
+ expect(
+ createImportPath({
+ publicPath: '/static',
+ outputDir: 'dist',
+ fileOutputDir: 'dist/legacy',
+ htmlFileName: 'index.html',
+ fileName: 'foo.js',
+ }),
+ ).to.equal('/static/legacy/foo.js');
+ });
+
+ it('when html is output in a directory, creates a relative path from the html file to the js file', () => {
+ expect(
+ createImportPath({
+ outputDir: 'dist',
+ fileOutputDir: 'dist',
+ htmlFileName: 'pages/index.html',
+ fileName: 'foo.js',
+ }),
+ ).to.equal('../foo.js');
+ });
+
+ it('when html is output in a directory and absolute path is set, creates a direct path from the root to the js file', () => {
+ expect(
+ createImportPath({
+ publicPath: '/static/',
+ outputDir: 'dist',
+ fileOutputDir: 'dist',
+ htmlFileName: 'pages/index.html',
+ fileName: 'foo.js',
+ }),
+ ).to.equal('/static/foo.js');
+ });
+});
+
+describe('getEntrypointBundles()', () => {
+ const defaultBundles: GeneratedBundle[] = [
+ {
+ name: 'default',
+ options: { format: 'es', dir: 'dist' },
+ bundle: {
+ // @ts-ignore
+ 'app.js': {
+ isEntry: true,
+ fileName: 'app.js',
+ facadeModuleId: '/root/app.js',
+ type: 'chunk',
+ },
+ },
+ },
+ ];
+
+ const inputModuleIds: ScriptModuleTag[] = [
+ { importPath: '/root/app.js' },
+ { importPath: '/root/foo.js' },
+ ];
+
+ const defaultOptions = {
+ pluginOptions: {},
+ inputModuleIds,
+ outputDir: 'dist',
+ htmlFileName: 'index.html',
+ generatedBundles: defaultBundles,
+ };
+
+ it('generates entrypoints for a simple project', async () => {
+ const output = await getEntrypointBundles(defaultOptions);
+ expect(Object.keys(output).length).to.equal(1);
+ expect(output.default.options).to.equal(defaultBundles[0].options);
+ expect(output.default.bundle).to.equal(defaultBundles[0].bundle);
+ expect(output.default.entrypoints.length).to.equal(1);
+ expect(output.default.entrypoints[0].chunk).to.equal(defaultBundles[0].bundle['app.js']);
+ expect(output.default.entrypoints.map(e => e.importPath)).to.eql(['./app.js']);
+ });
+
+ it('does not output non-entrypoints', async () => {
+ const generatedBundles: GeneratedBundle[] = [
+ {
+ name: 'default',
+ options: { format: 'es', dir: 'dist' },
+ bundle: {
+ // @ts-ignore
+ 'app.js': {
+ isEntry: true,
+ fileName: 'app.js',
+ facadeModuleId: '/root/app.js',
+ type: 'chunk',
+ },
+ // @ts-ignore
+ 'not-app.js': {
+ isEntry: false,
+ fileName: 'not-app.js',
+ facadeModuleId: '/root/app.js',
+ type: 'chunk',
+ },
+ },
+ },
+ ];
+ const output = await getEntrypointBundles({
+ ...defaultOptions,
+ generatedBundles,
+ });
+ expect(Object.keys(output).length).to.equal(1);
+ expect(output.default.entrypoints.length).to.equal(1);
+ expect(output.default.entrypoints.map(e => e.importPath)).to.eql(['./app.js']);
+ });
+
+ it('does not output non-chunks', async () => {
+ const generatedBundles: GeneratedBundle[] = [
+ {
+ name: 'default',
+ options: { format: 'es', dir: 'dist' },
+ bundle: {
+ // @ts-ignore
+ 'app.js': {
+ isEntry: true,
+ fileName: 'app.js',
+ facadeModuleId: '/root/app.js',
+ type: 'chunk',
+ },
+ // @ts-ignore
+ 'not-app.js': {
+ // @ts-ignore
+ isEntry: true,
+ fileName: 'not-app.js',
+ facadeModuleId: '/root/app.js',
+ type: 'asset',
+ },
+ },
+ },
+ ];
+ const output = await getEntrypointBundles({
+ ...defaultOptions,
+ generatedBundles,
+ });
+ expect(Object.keys(output).length).to.equal(1);
+ expect(output.default.entrypoints.length).to.equal(1);
+ expect(output.default.entrypoints.map(e => e.importPath)).to.eql(['./app.js']);
+ });
+
+ it('matches on facadeModuleId', async () => {
+ const generatedBundles: GeneratedBundle[] = [
+ {
+ name: 'default',
+ options: { format: 'es', dir: 'dist' },
+ bundle: {
+ // @ts-ignore
+ 'app.js': {
+ isEntry: true,
+ fileName: 'app.js',
+ facadeModuleId: '/root/app.js',
+ type: 'chunk',
+ },
+ // @ts-ignore
+ 'not-app.js': {
+ isEntry: true,
+ fileName: 'not-app.js',
+ facadeModuleId: '/root/not-app.js',
+ type: 'chunk',
+ },
+ },
+ },
+ ];
+ const output = await getEntrypointBundles({
+ ...defaultOptions,
+ generatedBundles,
+ });
+ expect(Object.keys(output).length).to.equal(1);
+ expect(output.default.entrypoints.length).to.equal(1);
+ expect(output.default.entrypoints.map(e => e.importPath)).to.eql(['./app.js']);
+ });
+
+ it('returns all entrypoints when no input module ids are given', async () => {
+ const generatedBundles: GeneratedBundle[] = [
+ {
+ name: 'default',
+ options: { format: 'es', dir: 'dist' },
+ bundle: {
+ // @ts-ignore
+ 'app.js': {
+ isEntry: true,
+ fileName: 'app.js',
+ facadeModuleId: '/root/app.js',
+ type: 'chunk',
+ },
+ // @ts-ignore
+ 'not-app.js': {
+ isEntry: true,
+ fileName: 'not-app.js',
+ facadeModuleId: '/root/not-app.js',
+ type: 'chunk',
+ },
+ },
+ },
+ ];
+
+ const inputModuleIds: ScriptModuleTag[] = [
+ { importPath: '/root/app.js' },
+ { importPath: '/root/not-app.js' },
+ ];
+
+ const output = await getEntrypointBundles({
+ ...defaultOptions,
+ inputModuleIds,
+ generatedBundles,
+ });
+ expect(Object.keys(output).length).to.equal(1);
+ expect(output.default.entrypoints.length).to.equal(2);
+ expect(output.default.entrypoints.map(e => e.importPath)).to.eql(['./app.js', './not-app.js']);
+ });
+
+ it('generates entrypoint for multiple bundles', async () => {
+ const generatedBundles: GeneratedBundle[] = [
+ {
+ name: 'modern',
+ options: { format: 'es', dir: 'dist' },
+ bundle: {
+ // @ts-ignore
+ 'app.js': {
+ isEntry: true,
+ fileName: 'app.js',
+ facadeModuleId: '/root/app.js',
+ type: 'chunk',
+ },
+ },
+ },
+ {
+ name: 'legacy',
+ options: { format: 'es', dir: 'dist/legacy' },
+ bundle: {
+ // @ts-ignore
+ 'app.js': {
+ isEntry: true,
+ fileName: 'app.js',
+ facadeModuleId: '/root/app.js',
+ type: 'chunk',
+ },
+ },
+ },
+ ];
+
+ const output = await getEntrypointBundles({
+ ...defaultOptions,
+ generatedBundles,
+ });
+
+ expect(Object.keys(output).length).to.equal(2);
+ expect(output.modern.options).to.equal(generatedBundles[0].options);
+ expect(output.legacy.options).to.equal(generatedBundles[1].options);
+ expect(output.modern.bundle).to.equal(generatedBundles[0].bundle);
+ expect(output.legacy.bundle).to.equal(generatedBundles[1].bundle);
+ expect(output.modern.entrypoints.length).to.equal(1);
+ expect(output.modern.entrypoints[0].chunk).to.equal(generatedBundles[0].bundle['app.js']);
+ expect(output.modern.entrypoints.map(e => e.importPath)).to.eql(['./app.js']);
+ expect(output.legacy.entrypoints.length).to.equal(1);
+ expect(output.legacy.entrypoints[0].chunk).to.equal(generatedBundles[1].bundle['app.js']);
+ expect(output.legacy.entrypoints.map(e => e.importPath)).to.eql(['./legacy/app.js']);
+ });
+
+ it('allows configuring a public path', async () => {
+ const output = await getEntrypointBundles({
+ ...defaultOptions,
+ pluginOptions: { publicPath: '/static' },
+ });
+
+ expect(Object.keys(output).length).to.equal(1);
+ expect(output.default.entrypoints.length).to.equal(1);
+ expect(output.default.entrypoints.map(e => e.importPath)).to.eql(['/static/app.js']);
+ });
+});
+=======
+import assert from 'node:assert/strict';
+import { describe, it } from 'node:test';
+import {
+ getEntrypointBundles,
+ createImportPath,
+<<<<<<< HEAD:packages/rollup-plugin-html/test/src/output/getEntrypointBundles.test.ts
+} from '../../../src/output/getEntrypointBundles.js';
+import { GeneratedBundle, ScriptModuleTag } from '../../../src/RollupPluginHTMLOptions.js';
+||||||| parent of c37bb778 (chore: migrate tests from mocha/chai to node:test + node:assert):packages/rollup-plugin-html/test/src/output/getEntrypointBundles.test.ts
+} from '../../../src/output/getEntrypointBundles.ts';
+import { GeneratedBundle, ScriptModuleTag } from '../../../src/RollupPluginHTMLOptions.ts';
+=======
+} from '../../src/output/getEntrypointBundles.ts';
+import type { GeneratedBundle, ScriptModuleTag } from '../../src/RollupPluginHTMLOptions.ts';
+>>>>>>> c37bb778 (chore: migrate tests from mocha/chai to node:test + node:assert):packages/rollup-plugin-html/test/output/getEntrypointBundles.test.ts
+
+describe('createImportPath()', () => {
+ it('creates a relative import path', () => {
+ assert.strictEqual(
+ createImportPath({
+ outputDir: 'dist',
+ fileOutputDir: 'dist',
+ htmlFileName: 'index.html',
+ fileName: 'foo.js',
+ }),
+ './foo.js');
+ });
+
+ it('handles files output in a different directory', () => {
+ assert.strictEqual(
+ createImportPath({
+ outputDir: 'dist',
+ fileOutputDir: 'dist/legacy',
+ htmlFileName: 'index.html',
+ fileName: 'foo.js',
+ }),
+ './legacy/foo.js');
+ });
+
+ it('handles directory in filename', () => {
+ assert.strictEqual(
+ createImportPath({
+ outputDir: 'dist',
+ fileOutputDir: 'dist',
+ htmlFileName: 'index.html',
+ fileName: 'legacy/foo.js',
+ }),
+ './legacy/foo.js');
+ });
+
+ it('allows configuring a public path', () => {
+ assert.strictEqual(
+ createImportPath({
+ publicPath: 'static',
+ outputDir: 'dist',
+ fileOutputDir: 'dist',
+ htmlFileName: 'index.html',
+ fileName: 'foo.js',
+ }),
+ './static/foo.js');
+ });
+
+ it('allows configuring an absolute public path', () => {
+ assert.strictEqual(
+ createImportPath({
+ publicPath: '/static',
+ outputDir: 'dist',
+ fileOutputDir: 'dist',
+ htmlFileName: 'index.html',
+ fileName: 'foo.js',
+ }),
+ '/static/foo.js');
+ });
+
+ it('allows configuring an absolute public path with just a /', () => {
+ assert.strictEqual(
+ createImportPath({
+ publicPath: '/',
+ outputDir: 'dist',
+ fileOutputDir: 'dist',
+ htmlFileName: 'index.html',
+ fileName: 'foo.js',
+ }),
+ '/foo.js');
+ });
+
+ it('allows configuring an absolute public path with a trailing /', () => {
+ assert.strictEqual(
+ createImportPath({
+ publicPath: '/static/public/',
+ outputDir: 'dist',
+ fileOutputDir: 'dist',
+ htmlFileName: 'index.html',
+ fileName: 'foo.js',
+ }),
+ '/static/public/foo.js');
+ });
+
+ it('respects a different output dir when configuring a public path', () => {
+ assert.strictEqual(
+ createImportPath({
+ publicPath: '/static',
+ outputDir: 'dist',
+ fileOutputDir: 'dist/legacy',
+ htmlFileName: 'index.html',
+ fileName: 'foo.js',
+ }),
+ '/static/legacy/foo.js');
+ });
+
+ it('when html is output in a directory, creates a relative path from the html file to the js file', () => {
+ assert.strictEqual(
+ createImportPath({
+ outputDir: 'dist',
+ fileOutputDir: 'dist',
+ htmlFileName: 'pages/index.html',
+ fileName: 'foo.js',
+ }),
+ '../foo.js');
+ });
+
+ it('when html is output in a directory and absolute path is set, creates a direct path from the root to the js file', () => {
+ assert.strictEqual(
+ createImportPath({
+ publicPath: '/static/',
+ outputDir: 'dist',
+ fileOutputDir: 'dist',
+ htmlFileName: 'pages/index.html',
+ fileName: 'foo.js',
+ }),
+ '/static/foo.js');
+ });
+});
+
+describe('getEntrypointBundles()', () => {
+ const defaultBundles: GeneratedBundle[] = [
+ {
+ name: 'default',
+ options: { format: 'es', dir: 'dist' },
+ bundle: {
+ // @ts-ignore
+ 'app.js': {
+ isEntry: true,
+ fileName: 'app.js',
+ facadeModuleId: '/root/app.js',
+ type: 'chunk',
+ },
+ },
+ },
+ ];
+
+ const inputModuleIds: ScriptModuleTag[] = [
+ { importPath: '/root/app.js' },
+ { importPath: '/root/foo.js' },
+ ];
+
+ const defaultOptions = {
+ pluginOptions: {},
+ inputModuleIds,
+ outputDir: 'dist',
+ htmlFileName: 'index.html',
+ generatedBundles: defaultBundles,
+ };
+
+ it('generates entrypoints for a simple project', async () => {
+ const output = await getEntrypointBundles(defaultOptions);
+ assert.strictEqual(Object.keys(output).length, 1);
+ assert.strictEqual(output.default.options, defaultBundles[0].options);
+ assert.strictEqual(output.default.bundle, defaultBundles[0].bundle);
+ assert.strictEqual(output.default.entrypoints.length, 1);
+ assert.strictEqual(output.default.entrypoints[0].chunk, defaultBundles[0].bundle['app.js']);
+ assert.deepStrictEqual(output.default.entrypoints.map(e => e.importPath), ['./app.js']);
+ });
+
+ it('does not output non-entrypoints', async () => {
+ const generatedBundles: GeneratedBundle[] = [
+ {
+ name: 'default',
+ options: { format: 'es', dir: 'dist' },
+ bundle: {
+ // @ts-ignore
+ 'app.js': {
+ isEntry: true,
+ fileName: 'app.js',
+ facadeModuleId: '/root/app.js',
+ type: 'chunk',
+ },
+ // @ts-ignore
+ 'not-app.js': {
+ isEntry: false,
+ fileName: 'not-app.js',
+ facadeModuleId: '/root/app.js',
+ type: 'chunk',
+ },
+ },
+ },
+ ];
+ const output = await getEntrypointBundles({
+ ...defaultOptions,
+ generatedBundles,
+ });
+ assert.strictEqual(Object.keys(output).length, 1);
+ assert.strictEqual(output.default.entrypoints.length, 1);
+ assert.deepStrictEqual(output.default.entrypoints.map(e => e.importPath), ['./app.js']);
+ });
+
+ it('does not output non-chunks', async () => {
+ const generatedBundles: GeneratedBundle[] = [
+ {
+ name: 'default',
+ options: { format: 'es', dir: 'dist' },
+ bundle: {
+ // @ts-ignore
+ 'app.js': {
+ isEntry: true,
+ fileName: 'app.js',
+ facadeModuleId: '/root/app.js',
+ type: 'chunk',
+ },
+ // @ts-ignore
+ 'not-app.js': {
+ // @ts-ignore
+ isEntry: true,
+ fileName: 'not-app.js',
+ facadeModuleId: '/root/app.js',
+ type: 'asset',
+ },
+ },
+ },
+ ];
+ const output = await getEntrypointBundles({
+ ...defaultOptions,
+ generatedBundles,
+ });
+ assert.strictEqual(Object.keys(output).length, 1);
+ assert.strictEqual(output.default.entrypoints.length, 1);
+ assert.deepStrictEqual(output.default.entrypoints.map(e => e.importPath), ['./app.js']);
+ });
+
+ it('matches on facadeModuleId', async () => {
+ const generatedBundles: GeneratedBundle[] = [
+ {
+ name: 'default',
+ options: { format: 'es', dir: 'dist' },
+ bundle: {
+ // @ts-ignore
+ 'app.js': {
+ isEntry: true,
+ fileName: 'app.js',
+ facadeModuleId: '/root/app.js',
+ type: 'chunk',
+ },
+ // @ts-ignore
+ 'not-app.js': {
+ isEntry: true,
+ fileName: 'not-app.js',
+ facadeModuleId: '/root/not-app.js',
+ type: 'chunk',
+ },
+ },
+ },
+ ];
+ const output = await getEntrypointBundles({
+ ...defaultOptions,
+ generatedBundles,
+ });
+ assert.strictEqual(Object.keys(output).length, 1);
+ assert.strictEqual(output.default.entrypoints.length, 1);
+ assert.deepStrictEqual(output.default.entrypoints.map(e => e.importPath), ['./app.js']);
+ });
+
+ it('returns all entrypoints when no input module ids are given', async () => {
+ const generatedBundles: GeneratedBundle[] = [
+ {
+ name: 'default',
+ options: { format: 'es', dir: 'dist' },
+ bundle: {
+ // @ts-ignore
+ 'app.js': {
+ isEntry: true,
+ fileName: 'app.js',
+ facadeModuleId: '/root/app.js',
+ type: 'chunk',
+ },
+ // @ts-ignore
+ 'not-app.js': {
+ isEntry: true,
+ fileName: 'not-app.js',
+ facadeModuleId: '/root/not-app.js',
+ type: 'chunk',
+ },
+ },
+ },
+ ];
+
+ const inputModuleIds: ScriptModuleTag[] = [
+ { importPath: '/root/app.js' },
+ { importPath: '/root/not-app.js' },
+ ];
+
+ const output = await getEntrypointBundles({
+ ...defaultOptions,
+ inputModuleIds,
+ generatedBundles,
+ });
+ assert.strictEqual(Object.keys(output).length, 1);
+ assert.strictEqual(output.default.entrypoints.length, 2);
+ assert.deepStrictEqual(output.default.entrypoints.map(e => e.importPath), ['./app.js', './not-app.js']);
+ });
+
+ it('generates entrypoint for multiple bundles', async () => {
+ const generatedBundles: GeneratedBundle[] = [
+ {
+ name: 'modern',
+ options: { format: 'es', dir: 'dist' },
+ bundle: {
+ // @ts-ignore
+ 'app.js': {
+ isEntry: true,
+ fileName: 'app.js',
+ facadeModuleId: '/root/app.js',
+ type: 'chunk',
+ },
+ },
+ },
+ {
+ name: 'legacy',
+ options: { format: 'es', dir: 'dist/legacy' },
+ bundle: {
+ // @ts-ignore
+ 'app.js': {
+ isEntry: true,
+ fileName: 'app.js',
+ facadeModuleId: '/root/app.js',
+ type: 'chunk',
+ },
+ },
+ },
+ ];
+
+ const output = await getEntrypointBundles({
+ ...defaultOptions,
+ generatedBundles,
+ });
+
+ assert.strictEqual(Object.keys(output).length, 2);
+ assert.strictEqual(output.modern.options, generatedBundles[0].options);
+ assert.strictEqual(output.legacy.options, generatedBundles[1].options);
+ assert.strictEqual(output.modern.bundle, generatedBundles[0].bundle);
+ assert.strictEqual(output.legacy.bundle, generatedBundles[1].bundle);
+ assert.strictEqual(output.modern.entrypoints.length, 1);
+ assert.strictEqual(output.modern.entrypoints[0].chunk, generatedBundles[0].bundle['app.js']);
+ assert.deepStrictEqual(output.modern.entrypoints.map(e => e.importPath), ['./app.js']);
+ assert.strictEqual(output.legacy.entrypoints.length, 1);
+ assert.strictEqual(output.legacy.entrypoints[0].chunk, generatedBundles[1].bundle['app.js']);
+ assert.deepStrictEqual(output.legacy.entrypoints.map(e => e.importPath), ['./legacy/app.js']);
+ });
+
+ it('allows configuring a public path', async () => {
+ const output = await getEntrypointBundles({
+ ...defaultOptions,
+ pluginOptions: { publicPath: '/static' },
+ });
+
+ assert.strictEqual(Object.keys(output).length, 1);
+ assert.strictEqual(output.default.entrypoints.length, 1);
+ assert.deepStrictEqual(output.default.entrypoints.map(e => e.importPath), ['/static/app.js']);
+ });
+});
+>>>>>>> 9007e014 (chore: migrate tests from mocha/chai to node:test + node:assert):packages/rollup-plugin-html/test/output/getEntrypointBundles.test.ts
diff --git a/packages/rollup-plugin-html/test/output/getOutputHTML.test.ts b/packages/rollup-plugin-html/test/output/getOutputHTML.test.ts
new file mode 100644
index 0000000000..ecc6b2c22d
--- /dev/null
+++ b/packages/rollup-plugin-html/test/output/getOutputHTML.test.ts
@@ -0,0 +1,486 @@
+<<<<<<< HEAD:packages/rollup-plugin-html/test/src/output/getOutputHTML.test.ts
+||||||| parent of 9007e014 (chore: migrate tests from mocha/chai to node:test + node:assert):packages/rollup-plugin-html/test/src/output/getOutputHTML.test.ts
+import { expect } from 'chai';
+import path from 'path';
+<<<<<<< HEAD:packages/rollup-plugin-html/test/src/output/getOutputHTML.test.ts
+import { getOutputHTML, GetOutputHTMLParams } from '../../../src/output/getOutputHTML.ts';
+import { EntrypointBundle } from '../../../src/RollupPluginHTMLOptions.ts';
+import { html } from '../../utils.ts';
+||||||| parent of c37bb778 (chore: migrate tests from mocha/chai to node:test + node:assert):packages/rollup-plugin-html/test/src/output/getOutputHTML.test.ts
+import { getOutputHTML, GetOutputHTMLParams } from '../../../src/output/getOutputHTML.ts';
+import { EntrypointBundle } from '../../../src/RollupPluginHTMLOptions.ts';
+import { html } from '../../utils.ts';
+=======
+import type { GetOutputHTMLParams } from '../../src/output/getOutputHTML.ts';
+import { getOutputHTML } from '../../src/output/getOutputHTML.ts';
+import type { EntrypointBundle } from '../../src/RollupPluginHTMLOptions.ts';
+
+const __dirname = import.meta.dirname;
+>>>>>>> c37bb778 (chore: migrate tests from mocha/chai to node:test + node:assert):packages/rollup-plugin-html/test/output/getOutputHTML.test.ts
+
+describe('getOutputHTML()', () => {
+ const defaultEntrypointBundles: Record = {
+ default: {
+ name: 'default',
+ options: { format: 'es' },
+ // @ts-ignore
+ entrypoints: [{ importPath: '/app.js' }, { importPath: '/module.js' }],
+ },
+ };
+
+ const defaultOptions: GetOutputHTMLParams = {
+ pluginOptions: {},
+ outputDir: '/',
+ emittedAssets: { static: new Map(), hashed: new Map() },
+ entrypointBundles: defaultEntrypointBundles,
+ input: {
+ html: html`Input HTML `,
+ name: 'index.html',
+ moduleImports: [],
+ assets: [],
+ inlineModules: [],
+ },
+ defaultInjectDisabled: false,
+ injectServiceWorker: false,
+ serviceWorkerPath: '',
+ strictCSPInlineScripts: false,
+ };
+
+ it('injects output into the input HTML', async () => {
+ const output = await getOutputHTML(defaultOptions);
+ expect(html`${output}`).to.equal(html`
+
+
+
+ Input HTML
+
+
+
+
+ `);
+ });
+
+ it('generates a HTML file for multiple rollup bundles', async () => {
+ const entrypointBundles: Record = {
+ modern: {
+ name: 'modern',
+ options: { format: 'es' },
+ // @ts-ignore
+ entrypoints: [{ importPath: '/app.js' }, { importPath: '/module.js' }],
+ },
+ legacy: {
+ name: 'legacy',
+ options: { format: 'system' },
+ // @ts-ignore
+ entrypoints: [{ importPath: '/legacy/app.js' }, { importPath: '/legacy/module.js' }],
+ },
+ };
+
+ const output = await getOutputHTML({ ...defaultOptions, entrypointBundles });
+ expect(html`${output}`).to.equal(html`
+
+
+
+ Input HTML
+
+
+
+
+
+
+ `);
+ });
+
+ it('can transform html output', async () => {
+ const output = await getOutputHTML({
+ ...defaultOptions,
+ pluginOptions: {
+ ...defaultOptions.pluginOptions,
+ transformHtml: html => html.replace('Input HTML', 'Transformed Input HTML'),
+ },
+ });
+
+ expect(html`${output}`).to.equal(html`
+
+
+
+ Transformed Input HTML
+
+
+
+
+ `);
+ });
+
+ it('allows setting multiple html transform functions', async () => {
+ const output = await getOutputHTML({
+ ...defaultOptions,
+ pluginOptions: {
+ ...defaultOptions.pluginOptions,
+ transformHtml: [
+ html => html.replace('Input HTML', 'Transformed Input HTML'),
+ html => html.replace(/h1/g, 'h2'),
+ ],
+ },
+ });
+
+ expect(html`${output}`).to.equal(html`
+
+
+
+ Transformed Input HTML
+
+
+
+
+ `);
+ });
+
+ it('can combine external and regular transform functions', async () => {
+ const output = await getOutputHTML({
+ ...defaultOptions,
+ pluginOptions: {
+ ...defaultOptions.pluginOptions,
+ transformHtml: html => html.replace('Input HTML', 'Transformed Input HTML'),
+ },
+ externalTransformHtmlFns: [html => html.replace(/h1/g, 'h2')],
+ });
+
+ expect(html`${output}`).to.equal(html`
+
+
+
+ Transformed Input HTML
+
+
+
+
+ `);
+ });
+
+ it('can disable default injection', async () => {
+ const output = await getOutputHTML({
+ ...defaultOptions,
+ defaultInjectDisabled: true,
+ });
+
+ expect(html`${output}`).to.equal(html`
+
+
+
+ Input HTML
+
+
+ `);
+ });
+
+ it('can converts absolute urls to full absolute urls', async () => {
+ const rootDir = path.resolve(__dirname, '..', '..', 'fixtures', 'assets');
+ const hashed = new Map();
+ hashed.set(path.join(rootDir, 'image-social.png'), 'image-social-xxx.png');
+
+ const output = await getOutputHTML({
+ ...defaultOptions,
+ defaultInjectDisabled: true,
+ pluginOptions: {
+ absoluteBaseUrl: 'http://test.com',
+ rootDir,
+ },
+ emittedAssets: { static: new Map(), hashed },
+ input: {
+ ...defaultOptions.input,
+ html: html`
+
+
+
+
+
+
+
+
+
+
+ `,
+ filePath: path.join(rootDir, 'index.html'),
+ },
+ });
+
+ expect(html`${output}`).to.equal(html`
+
+
+
+
+
+
+
+
+
+
+ `);
+ });
+
+ it('can minify HTML', async () => {
+ const htmlInput = `
+
+
+
+
+
+
+
+
+
+ `;
+ const output = await getOutputHTML({
+ ...defaultOptions,
+ pluginOptions: {
+ ...defaultOptions.pluginOptions,
+ minify: true,
+ },
+ input: {
+ ...defaultOptions.input,
+ html: htmlInput,
+ },
+ });
+
+ expect(output).to.equal(
+ '',
+ );
+ });
+});
+=======
+import assert from 'node:assert/strict';
+import { describe, it } from 'node:test';
+import path from 'path';
+<<<<<<< HEAD:packages/rollup-plugin-html/test/src/output/getOutputHTML.test.ts
+import { getOutputHTML, GetOutputHTMLParams } from '../../../src/output/getOutputHTML.js';
+import { EntrypointBundle } from '../../../src/RollupPluginHTMLOptions.js';
+import { html } from '../../utils.js';
+||||||| parent of c37bb778 (chore: migrate tests from mocha/chai to node:test + node:assert):packages/rollup-plugin-html/test/src/output/getOutputHTML.test.ts
+import { getOutputHTML, GetOutputHTMLParams } from '../../../src/output/getOutputHTML.ts';
+import { EntrypointBundle } from '../../../src/RollupPluginHTMLOptions.ts';
+import { html } from '../../utils.ts';
+=======
+import type { GetOutputHTMLParams } from '../../src/output/getOutputHTML.ts';
+import { getOutputHTML } from '../../src/output/getOutputHTML.ts';
+import type { EntrypointBundle } from '../../src/RollupPluginHTMLOptions.ts';
+
+const __dirname = import.meta.dirname;
+>>>>>>> c37bb778 (chore: migrate tests from mocha/chai to node:test + node:assert):packages/rollup-plugin-html/test/output/getOutputHTML.test.ts
+
+describe('getOutputHTML()', () => {
+ const defaultEntrypointBundles: Record = {
+ default: {
+ name: 'default',
+ options: { format: 'es' },
+ // @ts-ignore
+ entrypoints: [{ importPath: '/app.js' }, { importPath: '/module.js' }],
+ },
+ };
+
+ const defaultOptions: GetOutputHTMLParams = {
+ pluginOptions: {},
+ outputDir: '/',
+ emittedAssets: { static: new Map(), hashed: new Map() },
+ entrypointBundles: defaultEntrypointBundles,
+ input: {
+ html: 'Input HTML ',
+ name: 'index.html',
+ moduleImports: [],
+ assets: [],
+ inlineModules: [],
+ },
+ defaultInjectDisabled: false,
+ injectServiceWorker: false,
+ serviceWorkerPath: '',
+ strictCSPInlineScripts: false,
+ };
+
+ it('injects output into the input HTML', async () => {
+ const output = await getOutputHTML(defaultOptions);
+ assert.strictEqual(output,
+ 'Input HTML ' +
+ '' +
+ '' +
+ '',
+ );
+ });
+
+ it('generates a HTML file for multiple rollup bundles', async () => {
+ const entrypointBundles: Record = {
+ modern: {
+ name: 'modern',
+ options: { format: 'es' },
+ // @ts-ignore
+ entrypoints: [{ importPath: '/app.js' }, { importPath: '/module.js' }],
+ },
+ legacy: {
+ name: 'legacy',
+ options: { format: 'system' },
+ // @ts-ignore
+ entrypoints: [{ importPath: '/legacy/app.js' }, { importPath: '/legacy/module.js' }],
+ },
+ };
+
+ const output = await getOutputHTML({ ...defaultOptions, entrypointBundles });
+ assert.strictEqual(output,
+ 'Input HTML ' +
+ '' +
+ '' +
+ '' +
+ '' +
+ '',
+ );
+ });
+
+ it('can transform html output', async () => {
+ const output = await getOutputHTML({
+ ...defaultOptions,
+ pluginOptions: {
+ ...defaultOptions.pluginOptions,
+ transformHtml: html => html.replace('Input HTML', 'Transformed Input HTML'),
+ },
+ });
+
+ assert.strictEqual(output,
+ 'Transformed Input HTML ' +
+ '' +
+ '' +
+ '',
+ );
+ });
+
+ it('allows setting multiple html transform functions', async () => {
+ const output = await getOutputHTML({
+ ...defaultOptions,
+ pluginOptions: {
+ ...defaultOptions.pluginOptions,
+ transformHtml: [
+ html => html.replace('Input HTML', 'Transformed Input HTML'),
+ html => html.replace(/h1/g, 'h2'),
+ ],
+ },
+ });
+
+ assert.strictEqual(output,
+ 'Transformed Input HTML ' +
+ '' +
+ '' +
+ '',
+ );
+ });
+
+ it('can combine external and regular output transform functions', async () => {
+ const output = await getOutputHTML({
+ ...defaultOptions,
+ pluginOptions: {
+ ...defaultOptions.pluginOptions,
+ transformHtml: html => html.replace('Input HTML', 'Transformed Input HTML'),
+ },
+ outputExternalTransformHtmlFns: [html => html.replace(/h1/g, 'h2')],
+ });
+
+ assert.strictEqual(output,
+ 'Transformed Input HTML ' +
+ '' +
+ '' +
+ '',
+ );
+ });
+
+ it('can disable default injection', async () => {
+ const output = await getOutputHTML({
+ ...defaultOptions,
+ defaultInjectDisabled: true,
+ });
+
+ assert.strictEqual(output, 'Input HTML ');
+ });
+
+ it('can converts absolute urls to full absolute urls', async () => {
+ const rootDir = path.resolve(__dirname, '..', 'fixtures', 'assets');
+ const hashed = new Map();
+ hashed.set(path.join(rootDir, 'image-social.png'), 'image-social-xxx.png');
+
+ const output = await getOutputHTML({
+ ...defaultOptions,
+ defaultInjectDisabled: true,
+ pluginOptions: {
+ absoluteBaseUrl: 'http://test.com',
+ rootDir,
+ },
+ emittedAssets: { static: new Map(), hashed },
+ input: {
+ ...defaultOptions.input,
+ html: [
+ '',
+ ' ',
+ ' ',
+ ' ',
+ ' ',
+ ' ',
+ '',
+ ].join('\n'),
+ filePath: path.join(rootDir, 'index.html'),
+ },
+ });
+
+ assert.strictEqual(output,
+ [
+ '',
+ ' ',
+ ' ',
+ ' ',
+ ' ',
+ ' ',
+ '',
+ ].join('\n'),
+ );
+ });
+
+ it('can minify HTML', async () => {
+ const htmlInput = `
+
+
+
+
+
+
+
+
+
+ `;
+ const output = await getOutputHTML({
+ ...defaultOptions,
+ pluginOptions: {
+ ...defaultOptions.pluginOptions,
+ minify: true,
+ },
+ input: {
+ ...defaultOptions.input,
+ html: htmlInput,
+ },
+ });
+
+ assert.strictEqual(output,
+ '',
+ );
+ });
+});
+>>>>>>> 9007e014 (chore: migrate tests from mocha/chai to node:test + node:assert):packages/rollup-plugin-html/test/output/getOutputHTML.test.ts
diff --git a/packages/rollup-plugin-html/test/output/injectBundles.test.ts b/packages/rollup-plugin-html/test/output/injectBundles.test.ts
new file mode 100644
index 0000000000..c462b28e83
--- /dev/null
+++ b/packages/rollup-plugin-html/test/output/injectBundles.test.ts
@@ -0,0 +1,142 @@
+import { getTextContent } from '@web/parse5-utils';
+import assert from 'node:assert/strict';
+import { describe, it } from 'node:test';
+import { parse, serialize } from 'parse5';
+<<<<<<< HEAD:packages/rollup-plugin-html/test/src/output/injectBundles.test.ts
+import { html } from '../../utils.js';
+||||||| parent of c37bb778 (chore: migrate tests from mocha/chai to node:test + node:assert):packages/rollup-plugin-html/test/src/output/injectBundles.test.ts
+import { html } from '../../utils.ts';
+=======
+>>>>>>> c37bb778 (chore: migrate tests from mocha/chai to node:test + node:assert):packages/rollup-plugin-html/test/output/injectBundles.test.ts
+
+<<<<<<< HEAD:packages/rollup-plugin-html/test/src/output/injectBundles.test.ts
+import { injectBundles, createLoadScript } from '../../../src/output/injectBundles.js';
+||||||| parent of c37bb778 (chore: migrate tests from mocha/chai to node:test + node:assert):packages/rollup-plugin-html/test/src/output/injectBundles.test.ts
+import { injectBundles, createLoadScript } from '../../../src/output/injectBundles.ts';
+=======
+import { injectBundles, createLoadScript } from '../../src/output/injectBundles.ts';
+>>>>>>> c37bb778 (chore: migrate tests from mocha/chai to node:test + node:assert):packages/rollup-plugin-html/test/output/injectBundles.test.ts
+
+describe('createLoadScript()', () => {
+ it('creates a script for es modules', () => {
+ // parse5 types are broken
+ const scriptAst = createLoadScript('./app.js', 'es') as any;
+
+ assert.strictEqual(scriptAst.tagName, 'script');
+ assert.deepStrictEqual(scriptAst.attrs, [
+ { name: 'type', value: 'module' },
+ { name: 'src', value: './app.js' },
+ ]);
+ });
+
+ it('creates a script for systemjs', () => {
+ // parse5 types are broken
+ const scriptAst = createLoadScript('./app.js', 'system') as any;
+
+ assert.strictEqual(scriptAst.tagName, 'script');
+ assert.strictEqual(getTextContent(scriptAst), 'System.import("./app.js");');
+ });
+
+ it('creates a script for other modules types', () => {
+ const scriptAst = createLoadScript('./app.js', 'iife') as any;
+
+ assert.strictEqual(scriptAst.tagName, 'script');
+ assert.deepStrictEqual(scriptAst.attrs, [
+ { name: 'src', value: './app.js' },
+ { name: 'defer', value: '' },
+ ]);
+ });
+});
+
+describe('injectBundles()', () => {
+ it('can inject a single bundle', () => {
+ const document = parse(
+ [
+ //
+ '',
+ '',
+ '',
+ 'Hello world ',
+ '',
+ '',
+ ].join(''),
+ );
+
+ injectBundles(document, [
+ {
+ options: { format: 'es' },
+ entrypoints: [
+ {
+ importPath: 'app.js',
+ // @ts-ignore
+ chunk: {},
+ },
+ ],
+ },
+ ]);
+ const expected = [
+ //
+ '',
+ '',
+ '',
+ 'Hello world ',
+ '',
+ '',
+ '',
+ ].join('');
+
+ assert.strictEqual(serialize(document), expected);
+ });
+
+ it('can inject multiple bundles', () => {
+ const document = parse(
+ [
+ //
+ '',
+ '',
+ '',
+ 'Hello world ',
+ '',
+ '',
+ ].join(''),
+ );
+
+ injectBundles(document, [
+ // @ts-ignore
+ {
+ options: { format: 'es' },
+ entrypoints: [
+ {
+ importPath: './app.js',
+ // @ts-ignore
+ chunk: null,
+ },
+ ],
+ },
+ // @ts-ignore
+ {
+ options: { format: 'iife' },
+ entrypoints: [
+ {
+ importPath: '/scripts/script.js',
+ // @ts-ignore
+ chunk: null,
+ },
+ ],
+ },
+ ]);
+ const expected = [
+ //
+ '',
+ '',
+ '',
+ 'Hello world ',
+ '',
+ '',
+ '',
+ '',
+ ].join('');
+
+ assert.strictEqual(serialize(document), expected);
+ });
+});
diff --git a/packages/rollup-plugin-html/test/output/injectedUpdatedAssetPaths.test.ts b/packages/rollup-plugin-html/test/output/injectedUpdatedAssetPaths.test.ts
new file mode 100644
index 0000000000..8e94ba868b
--- /dev/null
+++ b/packages/rollup-plugin-html/test/output/injectedUpdatedAssetPaths.test.ts
@@ -0,0 +1,353 @@
+import assert from 'node:assert/strict';
+import { describe, it } from 'node:test';
+import path from 'path';
+import { parse, serialize } from 'parse5';
+import type { InputData } from '../../src/input/InputData.ts';
+
+import { injectedUpdatedAssetPaths } from '../../src/output/injectedUpdatedAssetPaths.ts';
+
+describe('injectedUpdatedAssetPaths()', () => {
+ it('injects updated asset paths', () => {
+ const document = parse(
+ [
+ '',
+ ' ',
+ '',
+ ' ',
+ ' ',
+ '',
+ '',
+ '',
+ ].join(''),
+ );
+
+ const input: InputData = {
+ html: '',
+ name: 'index.html',
+ moduleImports: [],
+ inlineModules: [],
+ assets: [],
+ filePath: '/root/index.html',
+ };
+ const hashed = new Map();
+ hashed.set(path.join(path.sep, 'root', 'styles.css'), 'styles-xxx.css');
+ hashed.set(path.join(path.sep, 'root', 'foo', 'image-a.png'), 'image-a-xxx.png');
+ hashed.set(path.join(path.sep, 'root', 'image-b.png'), 'image-b-xxx.png');
+ hashed.set(path.join(path.sep, 'root', 'no-module.js'), 'no-module-xxx.js');
+
+ injectedUpdatedAssetPaths({
+ document,
+ input,
+ outputDir: '/root/dist/',
+ rootDir: '/root/',
+ emittedAssets: { static: new Map(), hashed },
+ });
+
+ const expected = [
+ '',
+ ' ',
+ '',
+ ' ',
+ ' ',
+ '',
+ '',
+ '',
+ ].join('');
+
+ assert.strictEqual(serialize(document), expected);
+ });
+
+ it('handles a picture tag using source tags with srcset', () => {
+ const document = parse(
+ [
+ '',
+ ' ',
+ ' ',
+ ' ',
+ ' ',
+ ' ',
+ ' ',
+ ' ',
+ '',
+ ].join(''),
+ );
+
+ const input: InputData = {
+ html: '',
+ name: 'index.html',
+ moduleImports: [],
+ inlineModules: [],
+ assets: [],
+ filePath: '/root/index.html',
+ };
+ const hashed = new Map();
+ hashed.set(path.join(path.sep, 'root', 'images', 'eb26e6ca-30.avif'), 'eb26e6ca-30-xxx.avif');
+ hashed.set(path.join(path.sep, 'root', 'images', 'eb26e6ca-60.avif'), 'eb26e6ca-60-xxx.avif');
+ hashed.set(path.join(path.sep, 'root', 'images', 'eb26e6ca-30.jpeg'), 'eb26e6ca-30-xxx.jpeg');
+ hashed.set(path.join(path.sep, 'root', 'images', 'eb26e6ca-60.jpeg'), 'eb26e6ca-60-xxx.jpeg');
+
+ injectedUpdatedAssetPaths({
+ document,
+ input,
+ outputDir: '/root/dist/',
+ rootDir: '/root/',
+ emittedAssets: { static: new Map(), hashed },
+ });
+
+ const expected = [
+ '',
+ '',
+ ' ',
+ ' ',
+ ' ',
+ ' ',
+ ].join('\n');
+ assert.strictEqual(serialize(document).replace(/ {4}/g, '\n'), expected);
+ });
+
+ it('handles video tag using source tags with src', () => {
+ const document = parse(
+ [
+ '',
+ ' ',
+ ' ',
+ ' ',
+ ' ',
+ ' ',
+ '',
+ ].join(''),
+ );
+
+ const input: InputData = {
+ html: '',
+ name: 'index.html',
+ moduleImports: [],
+ inlineModules: [],
+ assets: [],
+ filePath: '/root/index.html',
+ };
+ const hashed = new Map();
+ hashed.set(
+ path.join(path.sep, 'root', 'videos', 'typer-hydration.mp4'),
+ 'typer-hydration-xxx.mp4',
+ );
+
+ injectedUpdatedAssetPaths({
+ document,
+ input,
+ outputDir: '/root/dist/',
+ rootDir: '/root/',
+ emittedAssets: { static: new Map(), hashed },
+ });
+
+ const expected = [
+ '',
+ '',
+ ' ',
+ ' ',
+ ].join('\n');
+ assert.strictEqual(serialize(document).replace(/ {4}/g, '\n'), expected);
+ });
+
+ it('handles virtual files', () => {
+ const document = parse(
+ [
+ '',
+ ' ',
+ '',
+ ' ',
+ ' ',
+ '',
+ '',
+ ].join(''),
+ );
+
+ const input: InputData = {
+ html: '',
+ name: 'index.html',
+ moduleImports: [],
+ inlineModules: [],
+ assets: [],
+ };
+ const hashed = new Map();
+ hashed.set(path.join(path.sep, 'root', 'styles.css'), 'styles-xxx.css');
+ hashed.set(path.join(path.sep, 'root', 'foo', 'image-a.png'), 'image-a-xxx.png');
+ hashed.set(path.join(path.sep, 'root', 'image-b.png'), 'image-b-xxx.png');
+
+ injectedUpdatedAssetPaths({
+ document,
+ input,
+ outputDir: '/root/dist/',
+ rootDir: '/root/',
+ emittedAssets: { static: new Map(), hashed },
+ });
+ const expected = [
+ '',
+ ' ',
+ '',
+ ' ',
+ ' ',
+ '',
+ '',
+ ].join('');
+
+ assert.strictEqual(serialize(document), expected);
+ });
+
+ it('handles HTML files in a sub directory', () => {
+ const document = parse(
+ [
+ '',
+ ' ',
+ '',
+ ' ',
+ ' ',
+ '',
+ '',
+ ].join(''),
+ );
+
+ const input: InputData = {
+ html: '',
+ name: 'foo/index.html',
+ moduleImports: [],
+ inlineModules: [],
+ assets: [],
+ filePath: '/root/foo/index.html',
+ };
+ const hashed = new Map();
+ hashed.set(path.join(path.sep, 'root', 'styles.css'), 'styles-xxx.css');
+ hashed.set(path.join(path.sep, 'root', 'foo', 'image-a.png'), 'image-a-xxx.png');
+ hashed.set(path.join(path.sep, 'root', 'image-b.png'), 'image-b-xxx.png');
+
+ injectedUpdatedAssetPaths({
+ document,
+ input,
+ outputDir: '/root/dist/',
+ rootDir: '/root/',
+ emittedAssets: { static: new Map(), hashed },
+ });
+
+ const expected = [
+ '',
+ ' ',
+ '',
+ ' ',
+ ' ',
+ '',
+ '',
+ ].join('');
+
+ assert.strictEqual(serialize(document), expected);
+ });
+
+ it('handles virtual HTML files in a sub directory', () => {
+ const document = parse(
+ [
+ '',
+ ' ',
+ '',
+ ' ',
+ ' ',
+ '',
+ '',
+ ].join(''),
+ );
+
+ const input: InputData = {
+ html: '',
+ name: 'foo/index.html',
+ moduleImports: [],
+ inlineModules: [],
+ assets: [],
+ };
+ const hashed = new Map();
+ hashed.set(path.join(path.sep, 'root', 'styles.css'), 'styles-xxx.css');
+ hashed.set(path.join(path.sep, 'root', 'foo', 'image-a.png'), 'image-a-xxx.png');
+ hashed.set(path.join(path.sep, 'root', 'image-b.png'), 'image-b-xxx.png');
+
+ injectedUpdatedAssetPaths({
+ document,
+ input,
+ outputDir: '/root/dist/',
+ rootDir: '/root/',
+ emittedAssets: { static: new Map(), hashed },
+ });
+
+ const expected = [
+ '',
+ ' ',
+ '',
+ ' ',
+ ' ',
+ '',
+ '',
+ ].join('');
+
+ assert.strictEqual(serialize(document), expected);
+ });
+
+ it('prefixes a publicpath', () => {
+ const document = parse(
+ [
+ '',
+ ' ',
+ '',
+ ' ',
+ ' ',
+ '',
+ '',
+ ].join(''),
+ );
+
+ const input: InputData = {
+ html: '',
+ name: 'index.html',
+ moduleImports: [],
+ inlineModules: [],
+ assets: [],
+ filePath: '/root/index.html',
+ };
+ const hashed = new Map();
+ hashed.set(path.join(path.sep, 'root', 'styles.css'), 'styles-xxx.css');
+ hashed.set(path.join(path.sep, 'root', 'foo', 'image-a.png'), 'image-a-xxx.png');
+ hashed.set(path.join(path.sep, 'root', 'image-b.png'), 'image-b-xxx.png');
+
+ injectedUpdatedAssetPaths({
+ document,
+ input,
+ outputDir: '/root/dist/',
+ rootDir: '/root/',
+ emittedAssets: { static: new Map(), hashed },
+ publicPath: './public/',
+ });
+
+ const expected = [
+ '',
+ ' ',
+ '',
+ ' ',
+ ' ',
+ '',
+ '',
+ ].join('');
+
+ assert.strictEqual(serialize(document), expected);
+ });
+});
diff --git a/packages/rollup-plugin-html/test/rollup-plugin-html.test.ts b/packages/rollup-plugin-html/test/rollup-plugin-html.test.ts
index 0327b8da7a..d297185e27 100644
--- a/packages/rollup-plugin-html/test/rollup-plugin-html.test.ts
+++ b/packages/rollup-plugin-html/test/rollup-plugin-html.test.ts
@@ -1,439 +1,251 @@
-import { rollup, OutputChunk, OutputOptions, Plugin } from 'rollup';
-import { expect } from 'chai';
+import { rollup, type Plugin, type OutputChunk, type OutputAsset, type OutputOptions } from 'rollup';
+import assert from 'node:assert/strict';
+import { describe, it } from 'node:test';
import path from 'path';
+<<<<<<< HEAD
import { rollupPluginHTML } from '../src/index.ts';
import { html, css, js, svg, generateTestBundle, createApp, cleanApp } from './utils.ts';
+||||||| parent of aecfa949 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import { rollupPluginHTML } from '../src/index.js';
+import { html, css, js, svg, generateTestBundle, createApp, cleanApp } from './utils.js';
+=======
+<<<<<<< HEAD
+import { rollupPluginHTML } from '../src/index.js';
+import { html, css, js, svg, generateTestBundle, createApp, cleanApp } from './utils.js';
+||||||| parent of c37bb778 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import { rollupPluginHTML } from '../src/index.ts';
+import { html, css, js, svg, generateTestBundle, createApp, cleanApp } from './utils.ts';
+=======
+<<<<<<< HEAD
+import { rollupPluginHTML } from '../src/index.ts';
+import { html, css, js, svg, generateTestBundle, createApp, cleanApp } from './utils.ts';
+||||||| parent of 61bf92a0 (chore: migrate tests from mocha/chai to node:test + node:assert)
+import { rollupPluginHTML } from '../src/index.js';
+import { html, css, js, svg, generateTestBundle, createApp, cleanApp } from './utils.js';
+=======
+import { rollupPluginHTML } from '../src/index.ts';
+
+const __dirname = import.meta.dirname;
+
+type Output = (OutputChunk | OutputAsset)[];
+
+function getChunk(output: Output, name: string) {
+ return output.find(o => o.fileName === name && o.type === 'chunk') as OutputChunk;
+}
+
+function getAsset(output: Output, name: string) {
+ return output.find(o => o.name === name && o.type === 'asset') as OutputAsset & {
+ source: string;
+ };
+}
+>>>>>>> 61bf92a0 (chore: migrate tests from mocha/chai to node:test + node:assert)
+>>>>>>> c37bb778 (chore: migrate tests from mocha/chai to node:test + node:assert)
+>>>>>>> aecfa949 (chore: migrate tests from mocha/chai to node:test + node:assert)
const outputConfig: OutputOptions = {
format: 'es',
dir: 'dist',
};
-describe('rollup-plugin-html', () => {
- afterEach(() => {
- cleanApp();
- });
+function stripNewlines(str: string) {
+ return str.replace(/(\r\n|\n|\r)/gm, '');
+}
- it('can build with an input path as input', async () => {
- const rootDir = createApp({
- 'index.html': html`
-
-
-
-
-
-
-
- `,
- 'entrypoint-a.js': js`
- import './modules/module-a.js';
- console.log('entrypoint-a.js');
- `,
- 'entrypoint-b.js': js`
- import './modules/module-b.js';
- console.log('entrypoint-b.js');
- `,
- 'modules/module-a.js': js`
- import './shared-module.js';
- console.log('module-a.js');
- `,
- 'modules/module-b.js': js`
- import './shared-module.js';
- console.log('module-b.js');
- `,
- 'modules/shared-module.js': js`
- console.log('shared-module.js');
- `,
- });
+const rootDir = path.join(__dirname, 'fixtures', 'rollup-plugin-html');
+describe('rollup-plugin-html', () => {
+ it('can build with an input path as input', async () => {
const config = {
plugins: [
rollupPluginHTML({
+ input: path.resolve(__dirname, './fixtures/rollup-plugin-html/index.html'),
rootDir,
- input: './index.html',
}),
],
};
-
- const build = await rollup(config);
- const { chunks, assets } = await generateTestBundle(build, outputConfig);
-
- expect(Object.keys(chunks)).to.have.lengthOf(3);
- expect(Object.keys(assets)).to.have.lengthOf(1);
-
- expect(chunks['entrypoint-a.js']).to.include(js`console.log('entrypoint-a.js');`);
- expect(chunks['entrypoint-b.js']).to.include(js`console.log('entrypoint-b.js');`);
-
- expect(assets['index.html']).to.equal(html`
-
-
-
-
-
-
-
- `);
+ const bundle = await rollup(config);
+ const { output } = await bundle.generate(outputConfig);
+ assert.strictEqual(output.length, 4);
+ const { code: entryA } = getChunk(output, 'entrypoint-a.js');
+ const { code: entryB } = getChunk(output, 'entrypoint-b.js');
+ assert.ok(entryA.includes("console.log('entrypoint-a.js');"));
+ assert.ok(entryB.includes("console.log('entrypoint-b.js');"));
+ assert.strictEqual(stripNewlines(getAsset(output, 'index.html').source),
+ 'hello world ' +
+ '' +
+ '' +
+ '',
+ );
});
it('can build with html file as rollup input', async () => {
- const rootDir = createApp({
- 'index.html': html`
-
-
-
-
-
-
-
- `,
- 'entrypoint-a.js': js`
- import './modules/module-a.js';
- console.log('entrypoint-a.js');
- `,
- 'entrypoint-b.js': js`
- import './modules/module-b.js';
- console.log('entrypoint-b.js');
- `,
- 'modules/module-a.js': js`
- import './shared-module.js';
- console.log('module-a.js');
- `,
- 'modules/module-b.js': js`
- import './shared-module.js';
- console.log('module-b.js');
- `,
- 'modules/shared-module.js': js`
- console.log('shared-module.js');
- `,
- });
-
const config = {
- input: './index.html',
+ input: path.resolve(__dirname, './fixtures/rollup-plugin-html/index.html'),
plugins: [rollupPluginHTML({ rootDir })],
};
-
- const build = await rollup(config);
- const { chunks, assets } = await generateTestBundle(build, outputConfig);
-
- expect(Object.keys(chunks)).to.have.lengthOf(3);
- expect(Object.keys(assets)).to.have.lengthOf(1);
-
- expect(chunks['entrypoint-a.js']).to.include(js`console.log('entrypoint-a.js');`);
- expect(chunks['entrypoint-b.js']).to.include(js`console.log('entrypoint-b.js');`);
-
- expect(assets['index.html']).to.equal(html`
-
-
-
-
-
-
-
- `);
+ const bundle = await rollup(config);
+ const { output } = await bundle.generate(outputConfig);
+ assert.strictEqual(output.length, 4);
+ const { code: entryA } = getChunk(output, 'entrypoint-a.js');
+ const { code: entryB } = getChunk(output, 'entrypoint-b.js');
+ assert.ok(entryA.includes("console.log('entrypoint-a.js');"));
+ assert.ok(entryB.includes("console.log('entrypoint-b.js');"));
+ assert.strictEqual(stripNewlines(getAsset(output, 'index.html').source),
+ 'hello world ' +
+ '' +
+ '' +
+ '',
+ );
});
it('will retain attributes on script tags', async () => {
- const rootDir = createApp({
- 'index.html': html`
-
-
-
-
-
-
-
- `,
- 'entrypoint-a.js': js`
- import './modules/module-a.js';
- console.log('entrypoint-a.js');
- `,
- 'entrypoint-b.js': js`
- import './modules/module-b.js';
- console.log('entrypoint-b.js');
- `,
- 'modules/module-a.js': js`
- import './shared-module.js';
- console.log('module-a.js');
- `,
- 'modules/module-b.js': js`
- import './shared-module.js';
- console.log('module-b.js');
- `,
- 'modules/shared-module.js': js`
- console.log('shared-module.js');
- `,
- });
-
const config = {
- input: './index.html',
+ input: path.resolve(__dirname, './fixtures/rollup-plugin-html/retain-attributes.html'),
plugins: [rollupPluginHTML({ rootDir })],
};
-
- const build = await rollup(config);
- const { chunks, assets } = await generateTestBundle(build, outputConfig);
-
- expect(Object.keys(chunks)).to.have.lengthOf(3);
- expect(Object.keys(assets)).to.have.lengthOf(1);
-
- expect(chunks['entrypoint-a.js']).to.include(js`console.log('entrypoint-a.js');`);
- expect(chunks['entrypoint-b.js']).to.include(js`console.log('entrypoint-b.js');`);
-
- expect(assets['index.html']).to.equal(html`
-
-
-
-
-
-
-
- `);
+ const bundle = await rollup(config);
+ const { output } = await bundle.generate(outputConfig);
+ assert.strictEqual(output.length, 4);
+ const { code: entryA } = getChunk(output, 'entrypoint-a.js');
+ const { code: entryB } = getChunk(output, 'entrypoint-b.js');
+ assert.ok(entryA.includes("console.log('entrypoint-a.js');"));
+ assert.ok(entryB.includes("console.log('entrypoint-b.js');"));
+ assert.strictEqual(stripNewlines(getAsset(output, 'retain-attributes.html').source),
+ 'hello world ' +
+ '' +
+ '' +
+ '',
+ );
});
it('can build with pure html file as rollup input', async () => {
- const rootDir = createApp({
- 'index.html': html`
-
-
-
- hello world
-
-
- `,
- });
-
const config = {
- input: './index.html',
+ input: path.resolve(__dirname, './fixtures/rollup-plugin-html/pure-index.html'),
plugins: [rollupPluginHTML({ rootDir })],
};
-
- const build = await rollup(config);
- const { chunks, assets } = await generateTestBundle(build, outputConfig);
-
- expect(Object.keys(chunks)).to.have.lengthOf(1);
- expect(Object.keys(assets)).to.have.lengthOf(1);
-
- expect(assets['index.html']).to.equal(html`
-
-
-
- hello world
-
-
- `);
+ const bundle = await rollup(config);
+ const { output } = await bundle.generate(outputConfig);
+ assert.strictEqual(stripNewlines(getAsset(output, 'pure-index.html').source),
+ 'hello world ',
+ );
});
it('can build with multiple pure html inputs', async () => {
- const rootDir = createApp({
- 'index1.html': html`
-
-
-
- hello world
-
-
- `,
- 'index2.html': html`
-
-
-
- hey there
-
-
- `,
- });
-
const config = {
plugins: [
rollupPluginHTML({
+ input: [
+ path.resolve(__dirname, './fixtures/rollup-plugin-html/pure-index.html'),
+ path.resolve(__dirname, './fixtures/rollup-plugin-html/pure-index2.html'),
+ ],
rootDir,
- input: ['./index1.html', './index2.html'],
}),
],
};
-
- const build = await rollup(config);
- const { chunks, assets } = await generateTestBundle(build, outputConfig);
-
- expect(Object.keys(chunks)).to.have.lengthOf(1);
- expect(Object.keys(assets)).to.have.lengthOf(2);
-
- expect(assets['index1.html']).to.equal(html`
-
-
-
- hello world
-
-
- `);
-
- expect(assets['index2.html']).to.equal(html`
-
-
-
- hey there
-
-
- `);
+ const bundle = await rollup(config);
+ const { output } = await bundle.generate(outputConfig);
+ assert.strictEqual(stripNewlines(getAsset(output, 'pure-index.html').source),
+ 'hello world ',
+ );
+ assert.strictEqual(stripNewlines(getAsset(output, 'pure-index2.html').source),
+ 'hey there ',
+ );
});
it('can build with html string as input', async () => {
- const rootDir = createApp({
- 'app.js': js`
- console.log('app.js');
- `,
- });
-
const config = {
plugins: [
rollupPluginHTML({
- rootDir,
input: {
name: 'index.html',
- html: ``,
+ html: 'Hello world ',
},
+ rootDir,
}),
],
};
- const build = await rollup(config);
- const { chunks, assets } = await generateTestBundle(build, outputConfig);
-
- expect(Object.keys(chunks)).to.have.lengthOf(1);
- expect(Object.keys(assets)).to.have.lengthOf(1);
-
- expect(assets['index.html']).to.equal(html`
-
-
-
-
-
-
- `);
+ const bundle = await rollup(config);
+ const { output } = await bundle.generate(outputConfig);
+ assert.strictEqual(output.length, 2);
+ assert.strictEqual(stripNewlines(getAsset(output, 'index.html').source),
+ 'Hello world ' +
+ '',
+ );
});
it('resolves paths relative to virtual html filename', async () => {
- const rootDir = createApp({
- 'app.js': js`
- console.log('app.js');
- `,
- });
-
const config = {
plugins: [
rollupPluginHTML({
- rootDir,
input: {
- name: 'nested/index.html',
- html: ``,
+ name: 'pages/index.html',
+ html: 'Hello world ',
},
+ rootDir,
}),
],
};
- const build = await rollup(config);
- const { chunks, assets } = await generateTestBundle(build, outputConfig);
-
- expect(Object.keys(chunks)).to.have.lengthOf(1);
- expect(Object.keys(assets)).to.have.lengthOf(1);
-
- expect(assets['nested/index.html']).to.equal(html`
-
-
-
-
-
-
- `);
+ const bundle = await rollup(config);
+ const { output } = await bundle.generate(outputConfig);
+ assert.strictEqual(output.length, 2);
+ assert.strictEqual(stripNewlines(getAsset(output, 'pages/index.html').source),
+ 'Hello world ' +
+ '',
+ );
});
it('can build with inline modules', async () => {
- const rootDir = createApp({
- 'app.js': js`
- console.log('app.js');
- `,
- });
-
const config = {
plugins: [
rollupPluginHTML({
rootDir,
input: {
name: 'index.html',
- html: ``,
+ html: 'Hello world ',
},
}),
],
};
- const build = await rollup(config);
- const { chunks, assets } = await generateTestBundle(build, outputConfig);
-
- expect(Object.keys(chunks)).to.have.lengthOf(1);
- expect(Object.keys(assets)).to.have.lengthOf(1);
-
- const hash = '16165cb387fc14ed1fe1749d05f19f7b';
-
- expect(chunks[`inline-module-${hash}.js`]).to.include(js`console.log('app.js');`);
-
- expect(assets['index.html']).to.equal(html`
-
-
-
-
-
-
- `);
+ const bundle = await rollup(config);
+ const { output } = await bundle.generate(outputConfig);
+ assert.strictEqual(output.length, 2);
+ const hash = '5ec680a4efbb48ae254268ab1defe610';
+ const { code: appCode } = getChunk(output, `inline-module-${hash}.js`);
+ assert.ok(appCode.includes("console.log('entrypoint-a.js');"));
+ assert.strictEqual(stripNewlines(getAsset(output, 'index.html').source),
+ 'Hello world ' +
+ `` +
+ '',
+ );
});
it('resolves inline module imports relative to the HTML file', async () => {
- const rootDir = createApp({
- 'nested/index.html': html`
-
-
-
-
-
-
- `,
- 'nested/app.js': js`
- console.log('app.js');
- `,
- });
-
const config = {
plugins: [
rollupPluginHTML({
+ input: path.resolve(__dirname, './fixtures/rollup-plugin-html/foo/foo.html'),
rootDir,
- input: './nested/index.html',
}),
],
};
-
- const build = await rollup(config);
- const { chunks, assets } = await generateTestBundle(build, outputConfig);
-
- expect(Object.keys(chunks)).to.have.lengthOf(1);
- expect(Object.keys(assets)).to.have.lengthOf(1);
-
- const hash = 'b774aefb8bf002b291fd54d27694a34d';
- expect(chunks[`inline-module-${hash}.js`]).to.include(js`console.log('app.js');`);
+ const bundle = await rollup(config);
+ const { output } = await bundle.generate(outputConfig);
+ assert.strictEqual(output.length, 2);
+ const { code: appCode } = getChunk(output, 'inline-module-1b13383486c70d87f4e2585ff87b147c.js');
+ assert.ok(appCode.includes("console.log('foo');"));
});
it('can build transforming final output', async () => {
- const rootDir = createApp({
- 'app.js': js`
- console.log('app.js');
- `,
- });
-
const config = {
+ input: path.resolve(__dirname, './fixtures/rollup-plugin-html/entrypoint-a.js'),
plugins: [
rollupPluginHTML({
rootDir,
input: {
- html: `Hello world `,
+ html: 'Hello world ',
},
transformHtml(html) {
return html.replace('Hello world', 'Goodbye world');
@@ -441,243 +253,133 @@ describe('rollup-plugin-html', () => {
}),
],
};
-
- const build = await rollup(config);
- const { chunks, assets } = await generateTestBundle(build, outputConfig);
-
- expect(Object.keys(chunks)).to.have.lengthOf(1);
- expect(Object.keys(assets)).to.have.lengthOf(1);
-
- expect(assets['index.html']).to.equal(html`
-
-
-
- Goodbye world
-
-
-
- `);
+ const bundle = await rollup(config);
+ const { output } = await bundle.generate(outputConfig);
+ assert.strictEqual(output.length, 2);
+ assert.strictEqual(getAsset(output, 'index.html').source,
+ 'Goodbye world ' +
+ '',
+ );
});
it('can build with a public path', async () => {
- const rootDir = createApp({
- 'app.js': js`
- console.log('app.js');
- `,
- });
-
const config = {
+ input: path.resolve(__dirname, './fixtures/rollup-plugin-html/entrypoint-a.js'),
plugins: [
rollupPluginHTML({
rootDir,
- publicPath: '/static/',
input: {
- html: ``,
+ html: 'Hello world ',
},
+ publicPath: '/static/',
}),
],
};
-
- const build = await rollup(config);
- const { chunks, assets } = await generateTestBundle(build, outputConfig);
-
- expect(Object.keys(chunks)).to.have.lengthOf(1);
- expect(Object.keys(assets)).to.have.lengthOf(1);
-
- expect(assets['index.html']).to.equal(html`
-
-
-
-
-
-
- `);
+ const bundle = await rollup(config);
+ const { output } = await bundle.generate(outputConfig);
+ assert.strictEqual(output.length, 2);
+ assert.strictEqual(getAsset(output, 'index.html').source,
+ 'Hello world ' +
+ '',
+ );
});
it('can build with a public path with a file in a directory', async () => {
- const rootDir = createApp({
- 'app.js': js`
- console.log('app.js');
- `,
- });
-
const config = {
+ input: path.resolve(__dirname, './fixtures/rollup-plugin-html/entrypoint-a.js'),
plugins: [
rollupPluginHTML({
rootDir,
- publicPath: '/static/',
input: {
- name: 'nested/index.html',
- html: ``,
+ name: 'pages/index.html',
+ html: 'Hello world ',
},
+ publicPath: '/static/',
}),
],
};
-
- const build = await rollup(config);
- const { chunks, assets } = await generateTestBundle(build, outputConfig);
-
- expect(Object.keys(chunks)).to.have.lengthOf(1);
- expect(Object.keys(assets)).to.have.lengthOf(1);
-
- expect(assets['nested/index.html']).to.equal(html`
-
-
-
-
-
-
- `);
+ const bundle = await rollup(config);
+ const { output } = await bundle.generate(outputConfig);
+ assert.strictEqual(output.length, 2);
+ assert.strictEqual(getAsset(output, 'pages/index.html').source,
+ 'Hello world ' +
+ '',
+ );
});
it('can build with multiple build outputs', async () => {
- const rootDir = createApp({
- 'app.js': js`
- import './modules/module.js';
- console.log('app.js');
- `,
- 'modules/module.js': js`
- console.log('module.js');
- `,
- });
-
const plugin = rollupPluginHTML({
rootDir,
- publicPath: '/static/',
input: {
- html: ``,
+ html: 'Hello world ',
},
+ publicPath: '/static/',
});
-
const config = {
- input: path.join(rootDir, 'app.js'),
+ input: path.resolve(__dirname, './fixtures/rollup-plugin-html/entrypoint-a.js'),
plugins: [plugin],
};
-
const build = await rollup(config);
-
- const bundleA = generateTestBundle(build, {
+ const bundleA = build.generate({
format: 'system',
dir: 'dist',
plugins: [plugin.api.addOutput('legacy')],
});
-
- const bundleB = generateTestBundle(build, {
+ const bundleB = build.generate({
format: 'es',
dir: 'dist',
plugins: [plugin.api.addOutput('modern')],
});
-
- const { chunks: chunksA, assets: assetsA } = await bundleA;
- const { chunks: chunksB, assets: assetsB } = await bundleB;
-
- expect(Object.keys(chunksA)).to.have.lengthOf(1);
- expect(Object.keys(assetsA)).to.have.lengthOf(0);
- expect(Object.keys(chunksB)).to.have.lengthOf(1);
- expect(Object.keys(assetsB)).to.have.lengthOf(1);
-
- expect(chunksA['app.js']).to.include(js`console.log('app.js');`);
- expect(chunksA['app.js']).to.include(js`console.log('module.js');`);
- expect(chunksB['app.js']).to.include(js`console.log('app.js');`);
- expect(chunksB['app.js']).to.include(js`console.log('module.js');`);
-
- expect(assetsA['index.html']).to.not.exist;
- expect(assetsB['index.html']).to.equal(html`
-
-
-
-
-
-
-
- `);
+ const { output: outputA } = await bundleA;
+ const { output: outputB } = await bundleB;
+ assert.strictEqual(outputA.length, 1);
+ assert.strictEqual(outputB.length, 2);
+ const { code: entrypointA1 } = getChunk(outputA, 'entrypoint-a.js');
+ const { code: entrypointA2 } = getChunk(outputB, 'entrypoint-a.js');
+ assert.ok(entrypointA1.includes("console.log('entrypoint-a.js');"));
+ assert.ok(entrypointA1.includes("console.log('module-a.js');"));
+ assert.ok(entrypointA2.includes("console.log('entrypoint-a.js');"));
+ assert.ok(entrypointA2.includes("console.log('module-a.js');"));
+ assert.strictEqual(getAsset(outputA, 'index.html'), undefined);
+ assert.strictEqual(getAsset(outputB, 'index.html').source,
+ 'Hello world ' +
+ '' +
+ '',
+ );
});
it('can build with index.html as input and an extra html file as output', async () => {
- const rootDir = createApp({
- 'app.js': js`
- console.log('app.js');
- `,
- });
-
const config = {
plugins: [
rollupPluginHTML({
rootDir,
input: {
- html: ``,
+ html: 'Hello world ',
},
}),
rollupPluginHTML({
rootDir,
input: {
name: 'foo.html',
- html: `foo.html `,
+ html: 'foo.html ',
},
}),
],
};
-
- const build = await rollup(config);
- const { chunks, assets } = await generateTestBundle(build, outputConfig);
-
- expect(Object.keys(chunks)).to.have.lengthOf(2);
- expect(Object.keys(assets)).to.have.lengthOf(2);
-
- expect(chunks['app.js']).to.exist;
-
- expect(assets['index.html']).to.equal(html`
-
-
-
-
-
-
- `);
-
- expect(assets['foo.html']).to.equal(html`
-
-
-
- foo.html
-
-
- `);
+ const bundle = await rollup(config);
+ const { output } = await bundle.generate(outputConfig);
+ assert.strictEqual(output.length, 4);
+ assert.ok(getChunk(output, 'entrypoint-a.js'));
+ assert.strictEqual(getAsset(output, 'index.html').source,
+ 'Hello world ' +
+ '',
+ );
+ assert.strictEqual(getAsset(output, 'foo.html').source,
+ 'foo.html ',
+ );
});
it('can build with multiple html inputs', async () => {
- const rootDir = createApp({
- 'entrypoint-a.js': js`
- import './modules/module-a.js';
- console.log('entrypoint-a.js');
- `,
- 'entrypoint-b.js': js`
- import './modules/module-b.js';
- console.log('entrypoint-b.js');
- `,
- 'entrypoint-c.js': js`
- import './modules/module-c.js';
- console.log('entrypoint-c.js');
- `,
- 'modules/module-a.js': js`
- import './shared-module.js';
- console.log('module-a.js');
- `,
- 'modules/module-b.js': js`
- import './shared-module.js';
- console.log('module-b.js');
- `,
- 'modules/module-c.js': js`
- import './shared-module.js';
- console.log('module-c.js');
- `,
- 'modules/shared-module.js': js`
- console.log('shared-module.js');
- `,
- });
-
const config = {
plugins: [
rollupPluginHTML({
@@ -699,91 +401,24 @@ describe('rollup-plugin-html', () => {
}),
],
};
-
- const build = await rollup(config);
- const { chunks, assets } = await generateTestBundle(build, outputConfig);
-
- expect(Object.keys(chunks)).to.have.lengthOf(4);
- expect(Object.keys(assets)).to.have.lengthOf(3);
-
- expect(chunks['entrypoint-a.js']).to.exist;
- expect(chunks['entrypoint-b.js']).to.exist;
- expect(chunks['entrypoint-c.js']).to.exist;
-
- expect(assets['page-a.html']).to.equal(html`
-
-
-
- Page A
-
-
-
- `);
-
- expect(assets['page-b.html']).to.equal(html`
-
-
-
- Page B
-
-
-
- `);
-
- expect(assets['page-c.html']).to.equal(html`
-
-
-
- Page C
-
-
-
- `);
+ const bundle = await rollup(config);
+ const { output } = await bundle.generate(outputConfig);
+ assert.strictEqual(output.length, 7);
+ assert.ok(getChunk(output, 'entrypoint-a.js'));
+ assert.ok(getChunk(output, 'entrypoint-b.js'));
+ assert.ok(getChunk(output, 'entrypoint-c.js'));
+ assert.strictEqual(getAsset(output, 'page-a.html').source,
+ 'Page A ',
+ );
+ assert.strictEqual(getAsset(output, 'page-b.html').source,
+ 'Page B ',
+ );
+ assert.strictEqual(getAsset(output, 'page-c.html').source,
+ 'Page C ',
+ );
});
it('can use a glob to build multiple pages', async () => {
- const rootDir = createApp({
- 'pages/page-a.html': html`
-
-
- page-a.html
-
-
-
-
- `,
- 'pages/page-b.html': html`
-
-
- page-b.html
-
-
-
-
- `,
- 'pages/page-c.html': html`
-
-
- page-c.html
-
-
-
-
- `,
- 'pages/page-a.js': js`
- export default 'page a';
- `,
- 'pages/page-b.js': js`
- export default 'page b';
- `,
- 'pages/page-c.js': js`
- export default 'page c';
- `,
- 'pages/shared.js': js`
- export default 'shared';
- `,
- });
-
const config = {
plugins: [
rollupPluginHTML({
@@ -793,144 +428,82 @@ describe('rollup-plugin-html', () => {
],
};
- const build = await rollup(config);
- const { chunks, assets } = await generateTestBundle(build, outputConfig);
-
- expect(Object.keys(chunks)).to.have.lengthOf(4);
- expect(Object.keys(assets)).to.have.lengthOf(3);
-
- expect(chunks['page-a.js']).to.exist;
- expect(chunks['page-b.js']).to.exist;
- expect(chunks['page-c.js']).to.exist;
-
- expect(assets['page-a.html']).to.equal(html`
-
-
-
- page-a.html
-
-
-
-
- `);
-
- expect(assets['page-b.html']).to.equal(html`
-
-
-
- page-b.html
-
-
-
-
- `);
-
- // TODO: investigate why shared.js is after page-c.js here but before in the others
- expect(assets['page-c.html']).to.equal(html`
-
-
-
- page-c.html
-
-
-
-
- `);
+ const bundle = await rollup(config);
+ const { output } = await bundle.generate(outputConfig);
+ const pageA = getAsset(output, 'page-a.html').source;
+ const pageB = getAsset(output, 'page-b.html').source;
+ const pageC = getAsset(output, 'page-c.html').source;
+ assert.strictEqual(output.length, 7);
+ assert.ok(getChunk(output, 'page-a.js'));
+ assert.ok(getChunk(output, 'page-b.js'));
+ assert.ok(getChunk(output, 'page-c.js'));
+ assert.ok(pageA.includes('page-a.html
'));
+ assert.ok(pageA.includes(''));
+ assert.ok(pageA.includes(''));
+ assert.ok(pageB.includes('page-b.html
'));
+ assert.ok(pageB.includes(''));
+ assert.ok(pageB.includes(''));
+ assert.ok(pageC.includes('page-c.html
'));
+ assert.ok(pageC.includes(''));
+ assert.ok(pageC.includes(''));
});
it('can exclude globs', async () => {
- const rootDir = createApp({
- 'exclude/index.html': html` `,
- 'exclude/assets/partial.html': html`I'm a partial! `,
- });
-
const config = {
plugins: [
rollupPluginHTML({
- rootDir,
input: 'exclude/**/*.html',
exclude: '**/partial.html',
+ rootDir,
}),
],
};
- const build = await rollup(config);
- const { chunks, assets } = await generateTestBundle(build, outputConfig);
-
- expect(Object.keys(chunks)).to.have.lengthOf(1);
- expect(Object.keys(assets)).to.have.lengthOf(1);
-
- expect(assets).to.have.keys(['index.html']);
+ const bundle = await rollup(config);
+ const { output } = await bundle.generate(outputConfig);
+ assert.strictEqual(output.length, 2);
});
it('creates unique inline script names', async () => {
- const rootDir = createApp({});
-
const config = {
plugins: [
rollupPluginHTML({
rootDir,
input: [
{
- name: 'nestedA/indexA.html',
- html: `Page A `,
+ name: 'foo/index.html',
+ html: 'Page A ',
},
{
- name: 'nestedB/indexB.html',
- html: `Page B `,
+ name: 'bar/index.html',
+ html: 'Page B ',
},
{
- name: 'indexC.html',
- html: `Page C `,
+ name: 'x.html',
+ html: 'Page C ',
},
],
}),
],
};
- const build = await rollup(config);
- const { chunks, assets } = await generateTestBundle(build, outputConfig);
-
- expect(Object.keys(chunks)).to.have.lengthOf(3);
- expect(Object.keys(assets)).to.have.lengthOf(3);
-
- expect(chunks['inline-module-d463148d1d5869e52917a3b270db9e72.js']).to.exist;
- expect(chunks['inline-module-b81da853430abdf130bcc7c4d0ade6d9.js']).to.exist;
- expect(chunks['inline-module-170bb2146da66c440259138c7e0fea7e.js']).to.exist;
-
- expect(assets['nestedA/indexA.html']).to.equal(html`
-
-
-
- Page A
-
-
-
- `);
-
- expect(assets['nestedB/indexB.html']).to.equal(html`
-
-
-
- Page B
-
-
-
- `);
-
- expect(assets['indexC.html']).to.equal(html`
-
-
-
- Page C
-
-
-
- `);
+ const bundle = await rollup(config);
+ const { output } = await bundle.generate(outputConfig);
+ assert.strictEqual(output.length, 6);
+ assert.ok(getChunk(output, 'inline-module-b8667c926d8a16ee8b4499492c1726ed.js'));
+ assert.ok(getChunk(output, 'inline-module-c91911481b66e7483731d4de5df616a6.js'));
+ assert.ok(getChunk(output, 'inline-module-fbf0242ebea027b7392472c19328791d.js'));
+ assert.strictEqual(getAsset(output, 'foo/index.html').source,
+ 'Page A ',
+ );
+ assert.strictEqual(getAsset(output, 'bar/index.html').source,
+ 'Page B ',
+ );
+ assert.strictEqual(getAsset(output, 'x.html').source,
+ 'Page C ',
+ );
});
it('deduplicates common modules', async () => {
- const rootDir = createApp({});
-
const config = {
plugins: [
rollupPluginHTML({
@@ -938,247 +511,136 @@ describe('rollup-plugin-html', () => {
input: [
{
name: 'a.html',
- html: `Page A `,
+ html: 'Page A ',
},
{
name: 'b.html',
- html: `Page B `,
+ html: 'Page B ',
},
{
name: 'c.html',
- html: `Page C `,
+ html: 'Page C ',
},
],
}),
],
};
-
- const build = await rollup(config);
- const { chunks, assets } = await generateTestBundle(build, outputConfig);
-
- expect(Object.keys(chunks)).to.have.lengthOf(1);
- expect(Object.keys(assets)).to.have.lengthOf(3);
-
- expect(chunks['inline-module-44281cf3dede62434e0dd368df08902f.js']).to.exist;
-
- expect(assets['a.html']).to.equal(html`
-
-
-
- Page A
-
-
-
- `);
-
- expect(assets['b.html']).to.equal(html`
-
-
-
- Page B
-
-
-
- `);
-
- expect(assets['c.html']).to.equal(html`
-
-
-
- Page C
-
-
-
- `);
+ const bundle = await rollup(config);
+ const { output } = await bundle.generate(outputConfig);
+ assert.strictEqual(output.length, 4);
+ assert.ok(getChunk(output, 'inline-module-b8667c926d8a16ee8b4499492c1726ed.js'));
+ assert.strictEqual(getAsset(output, 'a.html').source,
+ 'Page A ',
+ );
+ assert.strictEqual(getAsset(output, 'b.html').source,
+ 'Page B ',
+ );
+ assert.strictEqual(getAsset(output, 'c.html').source,
+ 'Page C ',
+ );
});
it('outputs the hashed entrypoint name', async () => {
- const rootDir = createApp({
- 'app.js': js`
- console.log('app.js');
- `,
- });
-
const config = {
plugins: [
rollupPluginHTML({
rootDir,
input: {
- html: ``,
+ html:
+ 'Hello world ' + ``,
},
}),
],
};
-
- const build = await rollup(config);
- const { output, chunks, assets } = await generateTestBundle(build, {
+ const bundle = await rollup(config);
+ const { output } = await bundle.generate({
...outputConfig,
entryFileNames: '[name]-[hash].js',
});
-
- expect(Object.keys(chunks)).to.have.lengthOf(1);
- expect(Object.keys(assets)).to.have.lengthOf(1);
-
- const appChunk = output.find(f =>
+ assert.strictEqual(output.length, 2);
+ const entrypoint = output.find(f =>
// @ts-ignore
- f.facadeModuleId.endsWith('app.js'),
+ f.facadeModuleId.endsWith('entrypoint-a.js'),
) as OutputChunk;
-
// ensure it's actually hashed
- expect(appChunk.fileName).to.not.equal('app.js');
-
+ assert.notStrictEqual(entrypoint.fileName, 'entrypoint-a.js');
// get hashed name dynamically
- expect(assets['index.html']).to.equal(html`
-
-
-
-
-
-
- `);
+ assert.strictEqual(getAsset(output, 'index.html').source,
+ `Hello world `,
+ );
});
it('outputs import path relative to the final output html', async () => {
- const rootDir = createApp({
- 'app.js': js`
- console.log('app.js');
- `,
- });
-
const config = {
plugins: [
rollupPluginHTML({
rootDir,
input: {
- name: 'nested/index.html',
- html: '',
+ name: 'pages/index.html',
+ html: 'Hello world ',
},
}),
],
};
-
- const build = await rollup(config);
- const { chunks, assets } = await generateTestBundle(build, outputConfig);
-
- expect(Object.keys(chunks)).to.have.lengthOf(1);
- expect(Object.keys(assets)).to.have.lengthOf(1);
-
- expect(assets['nested/index.html']).to.equal(html`
-
-
-
-
-
-
- `);
+ const bundle = await rollup(config);
+ const { output } = await bundle.generate(outputConfig);
+ assert.strictEqual(output.length, 2);
+ assert.strictEqual(getAsset(output, 'pages/index.html').source,
+ 'Hello world ',
+ );
});
it('can change HTML root directory', async () => {
- const rootDir = createApp({
- 'different-root/src/app.js': js`
- console.log('app.js');
- `,
- });
-
const config = {
plugins: [
rollupPluginHTML({
- rootDir: path.join(rootDir, 'different-root'),
+ rootDir: path.join(__dirname, 'fixtures'),
input: {
- name: 'src/nested/index.html',
- html: '',
+ name: 'rollup-plugin-html/pages/index.html',
+ html: 'Hello world ',
},
}),
],
};
-
- const build = await rollup(config);
- const { chunks, assets } = await generateTestBundle(build, outputConfig);
-
- expect(Object.keys(chunks)).to.have.lengthOf(1);
- expect(Object.keys(assets)).to.have.lengthOf(1);
-
- expect(assets['src/nested/index.html']).to.equal(html`
-
-
-
-
-
-
- `);
+ const bundle = await rollup(config);
+ const { output } = await bundle.generate(outputConfig);
+ assert.strictEqual(output.length, 2);
+ assert.strictEqual(getAsset(output, 'rollup-plugin-html/pages/index.html').source,
+ 'Hello world ',
+ );
});
it('can get the input with getInputs()', async () => {
// default filename
const pluginA = rollupPluginHTML({ input: { html: 'Hello world' } });
-
// filename inferred from input filename
- const rootDirB = createApp({
- 'my-page.html': html``,
- 'app.js': js`console.log('app.js');`,
- });
const pluginB = rollupPluginHTML({
- input: path.join(rootDirB, 'my-page.html'),
+ input: path.resolve(__dirname, './fixtures/rollup-plugin-html/my-page.html'),
});
-
// filename explicitly set
- const rootDirC = createApp({
- 'index.html': html``,
- 'app.js': js`console.log('app.js');`,
- });
const pluginC = rollupPluginHTML({
input: {
- name: 'nested/my-other-page.html',
- path: path.join(rootDirC, 'index.html'),
+ name: 'pages/my-other-page.html',
+ path: path.resolve(__dirname, './fixtures/rollup-plugin-html/index.html'),
},
});
-
- await rollup({ plugins: [pluginA] });
+ await rollup({
+ input: path.resolve(__dirname, './fixtures/rollup-plugin-html/entrypoint-a.js'),
+ plugins: [pluginA],
+ });
await rollup({ plugins: [pluginB] });
await rollup({ plugins: [pluginC] });
-
- expect(pluginA.api.getInputs()[0].name).to.equal('index.html');
- expect(pluginB.api.getInputs()[0].name).to.equal('my-page.html');
- expect(pluginC.api.getInputs()[0].name).to.equal('nested/my-other-page.html');
+ assert.strictEqual(pluginA.api.getInputs()[0].name, 'index.html');
+ assert.strictEqual(pluginB.api.getInputs()[0].name, 'my-page.html');
+ assert.strictEqual(pluginC.api.getInputs()[0].name, 'pages/my-other-page.html');
});
it('supports other plugins injecting a transform function', async () => {
- const rootDir = createApp({
- 'index.html': html`
-
-
-
-
-
-
-
- `,
- 'entrypoint-a.js': js`
- import './modules/module-a.js';
- console.log('entrypoint-a.js');
- `,
- 'entrypoint-b.js': js`
- import './modules/module-b.js';
- console.log('entrypoint-b.js');
- `,
- 'modules/module-a.js': js`
- import './shared-module.js';
- console.log('module-a.js');
- `,
- 'modules/module-b.js': js`
- import './shared-module.js';
- console.log('module-b.js');
- `,
- 'modules/shared-module.js': js`
- console.log('shared-module.js');
- `,
- });
-
const config = {
plugins: [
rollupPluginHTML({
rootDir,
- input: './index.html',
+ input: path.resolve(__dirname, './fixtures/rollup-plugin-html/index.html'),
}),
{
name: 'other-plugin',
@@ -1191,2119 +653,700 @@ describe('rollup-plugin-html', () => {
return false;
});
plugin!.api.addHtmlTransformer((html: string) =>
- html.replace('', '
-
-
-
- '),
+ html.replace('', ''),
+ );
+ plugin!.api.addHtmlTransformer(
+ (html: string) =>
+ html.replace('', ''),
+ 'output',
+ );
+ plugin!.api.addHtmlTransformer(
+ (html: string) => html.replace('', ''),
+ 'input',
);
},
} as Plugin,
],
};
-
- const build = await rollup(config);
- const { chunks, assets } = await generateTestBundle(build, outputConfig);
-
- expect(Object.keys(chunks)).to.have.lengthOf(3);
- expect(Object.keys(assets)).to.have.lengthOf(1);
-
- expect(chunks['entrypoint-a.js']).to.include(js`console.log('entrypoint-a.js');`);
- expect(chunks['entrypoint-b.js']).to.include(js`console.log('entrypoint-b.js');`);
-
- expect(assets['index.html']).to.equal(html`
-
-