From d6abf3a55d92c9ffe28395c67664ceaf631372cb Mon Sep 17 00:00:00 2001 From: Benny Powers Date: Mon, 1 Jun 2026 17:29:44 +0300 Subject: [PATCH] refactor(dev-server): migrate tests from mocha to node:test Replace mocha globals with node:test imports. No chai was used in this test file -- assertions use manual `throw new Error(...)`. - Add `import { describe, it, before, after, beforeEach, afterEach } from 'node:test'` - `this.timeout(30000)` -> `{ timeout: 30000 }` option on describe - `function test()` / `function it()` -> arrow functions - Replace `path.dirname(fileURLToPath(import.meta.url))` with `import.meta.dirname` - Add `--test-force-exit` to prevent test hangs from open handles Assisted-By: Claude Opus 4.6 (1M context) --- packages/dev-server/package.json | 4 ++-- packages/dev-server/test/integration.test.mjs | 11 ++++------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/packages/dev-server/package.json b/packages/dev-server/package.json index 1659a94710..a7f0535226 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-force-exit test/**/*.test.mjs", + "test:watch": "node --test --test-force-exit --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..d1e9c13b2c 100644 --- a/packages/dev-server/test/integration.test.mjs +++ b/packages/dev-server/test/integration.test.mjs @@ -1,11 +1,9 @@ +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'; -const dirname = path.dirname(fileURLToPath(import.meta.url)); - const testCases = [ { name: 'base-path', @@ -53,15 +51,14 @@ 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 () => { server = await startDevServer({ autoExitProcess: false, logStartMessage: false, - argv: ['--config', path.join(dirname, `../demo/${testCase.name}/config.mjs`)], + argv: ['--config', path.join(import.meta.dirname, `../demo/${testCase.name}/config.mjs`)], }); }); @@ -69,7 +66,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();