Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
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';
import { processChunk } from '../generate.mjs';

let dir;

const toPosixPath = value => value.split(sep).join('/');

// Writes `content` to `<name>` 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.
Expand Down
4 changes: 2 additions & 2 deletions packages/react/src/html/utils/__tests__/copying.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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`
);
});
});
18 changes: 14 additions & 4 deletions scripts/__tests__/comparators.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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/);
});
Loading