Skip to content

Commit 808d0d7

Browse files
test: support platform-specific paths
Use environment-aware path handling in Windows-sensitive test assertions while preserving the source behavior. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 2403f01 commit 808d0d7

3 files changed

Lines changed: 20 additions & 8 deletions

File tree

packages/core/src/generators/ast/__tests__/generate.test.mjs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
import assert from 'node:assert/strict';
22
import { mkdtemp, writeFile, rm } from 'node:fs/promises';
33
import { tmpdir } from 'node:os';
4-
import { join } from 'node:path';
4+
import { join, sep } from 'node:path';
55
import { after, before, describe, it } from 'node:test';
66

77
import { STABILITY_INDEX_URL } from '../constants.mjs';
88
import { processChunk } from '../generate.mjs';
99

1010
let dir;
1111

12+
const toPosixPath = value => value.split(sep).join('/');
13+
1214
// Writes `content` to `<name>` in the temp dir and returns the
1315
// `[path, parent]` tuple `processChunk` expects.
1416
const file = async (name, content) => {
1517
const path = join(dir, name);
1618
await writeFile(path, content);
17-
return [path, dir];
19+
return [toPosixPath(path), toPosixPath(dir)];
1820
};
1921

2022
// Runs a single file through `processChunk` and returns its result entry.

packages/react/src/html/utils/__tests__/copying.test.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,9 @@ describe('copyStaticAssets', () => {
118118
assert.strictEqual(mockLogError.mock.callCount(), 1);
119119

120120
const logMessage = mockLogError.mock.calls[0].arguments[0];
121-
assert.match(
121+
assert.equal(
122122
logMessage,
123-
/\[html-generator\] Failed to copy asset from protected-file to \/out\/protected-file: Permission denied/
123+
`[html-generator] Failed to copy asset from protected-file to ${join('/out', 'protected-file')}: Permission denied`
124124
);
125125
});
126126
});

scripts/__tests__/comparators.test.mjs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,20 @@ test('comparators report added and removed output files', async t => {
163163
]);
164164

165165
assert.match(sizes, /2 files changed/);
166-
assert.match(sizes, /`generator\/added\.json` \| \| 12\.00 B/);
167-
assert.match(sizes, /`generator\/removed\.json` \| 12\.00 B \| /);
168-
assert.match(objects, /`generator\/added\.json` added/);
169-
assert.match(objects, /`generator\/removed\.json` removed/);
166+
const added = `generator${path.sep}added.json`;
167+
const removed = `generator${path.sep}removed.json`;
168+
const escapeRegExp = value => value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
169+
170+
assert.match(
171+
sizes,
172+
new RegExp(`\`${escapeRegExp(added)}\` \\| — \\| 12\\.00 B`)
173+
);
174+
assert.match(
175+
sizes,
176+
new RegExp(`\`${escapeRegExp(removed)}\` \\| 12\\.00 B \\| —`)
177+
);
178+
assert.match(objects, new RegExp(`\`${escapeRegExp(added)}\` added`));
179+
assert.match(objects, new RegExp(`\`${escapeRegExp(removed)}\` removed`));
170180
assert.doesNotMatch(sizes, /comparison\.txt|4\.00 KB/);
171181
assert.doesNotMatch(objects, /comparison\.txt/);
172182
});

0 commit comments

Comments
 (0)