diff --git a/packages/core/src/generators/ast/__tests__/generate.test.mjs b/packages/core/src/generators/ast/__tests__/generate.test.mjs index 3f2e3b224..00e88cd50 100644 --- a/packages/core/src/generators/ast/__tests__/generate.test.mjs +++ b/packages/core/src/generators/ast/__tests__/generate.test.mjs @@ -1,7 +1,7 @@ import assert from 'node:assert/strict'; import { mkdtemp, writeFile, rm } from 'node:fs/promises'; import { tmpdir } from 'node:os'; -import { join } from 'node:path'; +import { join, sep } from 'node:path'; import { after, before, describe, it } from 'node:test'; import { STABILITY_INDEX_URL } from '../constants.mjs'; @@ -9,12 +9,14 @@ import { processChunk } from '../generate.mjs'; let dir; +const toPosixPath = value => value.split(sep).join('/'); + // Writes `content` to `` in the temp dir and returns the // `[path, parent]` tuple `processChunk` expects. const file = async (name, content) => { const path = join(dir, name); await writeFile(path, content); - return [path, dir]; + return [toPosixPath(path), toPosixPath(dir)]; }; // Runs a single file through `processChunk` and returns its result entry. diff --git a/packages/react/src/html/utils/__tests__/copying.test.mjs b/packages/react/src/html/utils/__tests__/copying.test.mjs index 7363dcd63..b18ec2d56 100644 --- a/packages/react/src/html/utils/__tests__/copying.test.mjs +++ b/packages/react/src/html/utils/__tests__/copying.test.mjs @@ -118,9 +118,9 @@ describe('copyStaticAssets', () => { assert.strictEqual(mockLogError.mock.callCount(), 1); const logMessage = mockLogError.mock.calls[0].arguments[0]; - assert.match( + assert.equal( logMessage, - /\[html-generator\] Failed to copy asset from protected-file to \/out\/protected-file: Permission denied/ + `[html-generator] Failed to copy asset from protected-file to ${join('/out', 'protected-file')}: Permission denied` ); }); }); diff --git a/scripts/__tests__/comparators.test.mjs b/scripts/__tests__/comparators.test.mjs index ddcde32d4..e398ae7da 100644 --- a/scripts/__tests__/comparators.test.mjs +++ b/scripts/__tests__/comparators.test.mjs @@ -163,10 +163,20 @@ test('comparators report added and removed output files', async t => { ]); assert.match(sizes, /2 files changed/); - assert.match(sizes, /`generator\/added\.json` \| — \| 12\.00 B/); - assert.match(sizes, /`generator\/removed\.json` \| 12\.00 B \| —/); - assert.match(objects, /`generator\/added\.json` added/); - assert.match(objects, /`generator\/removed\.json` removed/); + const added = `generator${path.sep}added.json`; + const removed = `generator${path.sep}removed.json`; + const escapeRegExp = value => value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); + + assert.match( + sizes, + new RegExp(`\`${escapeRegExp(added)}\` \\| — \\| 12\\.00 B`) + ); + assert.match( + sizes, + new RegExp(`\`${escapeRegExp(removed)}\` \\| 12\\.00 B \\| —`) + ); + assert.match(objects, new RegExp(`\`${escapeRegExp(added)}\` added`)); + assert.match(objects, new RegExp(`\`${escapeRegExp(removed)}\` removed`)); assert.doesNotMatch(sizes, /comparison\.txt|4\.00 KB/); assert.doesNotMatch(objects, /comparison\.txt/); });