refactor(polyfills-loader): migrate tests to node:test#3086
Conversation
Replace mocha globals and chai assertions with node:test and
node:assert/strict across 3 test files.
- `import type { PolyfillsLoaderConfig, PolyfillFile }` (type-only imports)
- `../src/*.js` -> `../dist/*.js`
- `expect(x).to.eql(y)` -> `assert.deepEqual(x, y)`
- `expect(x).to.equal(y)` -> `assert.equal(x, y)`
- `expect(x).to.be.a('string', msg)` -> `assert.equal(typeof x, 'string', msg)`
- `this.timeout(5000)` -> `{ timeout: 5000 }` option on describe
- `__dirname` -> `import.meta.dirname`
- Removed `test:update-snapshots` script
- Add `--experimental-strip-types` to override CI NODE_OPTIONS workaround
Assisted-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
| "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", |
There was a problem hiding this comment.
just checking: since we don't have mocha snapshots anymore, we just need to update them manually?
I think we use snapshots in just 3 packages now, so it's not much work to update them
I also migrated 2 packages recently to a new solution where everything is managed in JS, becuase I found it really hard to extends tests with new use-case with folder-based approach, and debugging was very slow, so might be good to look into refactoring remaining tests to same approach
There was a problem hiding this comment.
node:test has --experimental-test-snapshots (landed in Node 22.3). It writes .snapshot files and supports assert.snapshot(). That's one option.
Summary
@web/polyfills-loadertests from mocha/chai tonode:test+node:assert/strictdist/, type-only imports for interfaces__dirname->import.meta.dirnameexpect(x).to.be.a('string')->assert.equal(typeof x, 'string')--experimental-strip-typesfor CI compatTest plan
NODE_OPTIONS='--no-experimental-strip-types'