Skip to content

Commit 06b3b94

Browse files
committed
fixup! sqlite: restore changes from #55373
1 parent 2945e44 commit 06b3b94

File tree

4 files changed

+57
-2
lines changed

4 files changed

+57
-2
lines changed

lib/internal/test_runner/snapshot.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class SnapshotFile {
7777
}
7878

7979
setSnapshot(id, value) {
80-
this.snapshots[keyEscape(id)] = value;
80+
this.snapshots[escapeSnapshotKey(id)] = value;
8181
}
8282

8383
nextId(name) {
@@ -290,7 +290,7 @@ function validateFunctionArray(fns, name) {
290290
}
291291
}
292292

293-
function keyEscape(str) {
293+
function escapeSnapshotKey(str) {
294294
let result = JSONStringify(str, null, 2).slice(1, -1);
295295
result = StringPrototypeReplaceAll(result, '`', '\\`');
296296
result = StringPrototypeReplaceAll(result, '${', '\\${');
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
'use strict';
2+
const { test } = require('node:test');
3+
4+
test('\r', (t) => {
5+
t.assert.snapshot({ key: 'value' });
6+
});
7+
8+
test(String.fromCharCode(55296), t => {
9+
t.assert.snapshot({key: 'value'});
10+
});
11+
12+
test(String.fromCharCode(57343), t => {
13+
t.assert.snapshot({key: 'value'});
14+
});
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
exports[`\r 1`] = `
2+
{
3+
"key": "value"
4+
}
5+
`;
6+
7+
exports[`\ud800 1`] = `
8+
{
9+
"key": "value"
10+
}
11+
`;
12+
13+
exports[`\udfff 1`] = `
14+
{
15+
"key": "value"
16+
}
17+
`;

test/parallel/test-runner-snapshot-tests.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,30 @@ test('t.assert.snapshot()', async (t) => {
342342
});
343343
});
344344

345+
test('special characters are allowed', async (t) => {
346+
const fixture = fixtures.path(
347+
'test-runner', 'snapshots', 'special-character.js'
348+
);
349+
350+
await common.spawnPromisified(
351+
process.execPath,
352+
['--test-update-snapshots', fixture],
353+
{ cwd: tmpdir.path },
354+
);
355+
356+
const child = await common.spawnPromisified(
357+
process.execPath,
358+
[fixture],
359+
{ cwd: tmpdir.path },
360+
);
361+
362+
t.assert.strictEqual(child.code, 0);
363+
t.assert.strictEqual(child.signal, null);
364+
t.assert.match(child.stdout, /tests 3/);
365+
t.assert.match(child.stdout, /pass 3/);
366+
t.assert.match(child.stdout, /fail 0/);
367+
});
368+
345369
test('snapshots from multiple files (isolation=none)', async (t) => {
346370
tmpdir.refresh();
347371

0 commit comments

Comments
 (0)