mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
test_runner: fix escaping in snapshot tests
Snapshotted values are escaped after serialization. This happens when serializing a value for comparison when snapshots already exist, and also when updating them. That is, snapshots are escaped in the internal storage, but when written to disk, one "level" of escaping is removed. That escaping is never added back when reading the snapshots back. This makes even the simplest test trying to serialize a string with an escape code in it fail, like the one I added here. PR-URL: https://github.com/nodejs/node/pull/53833 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Moshe Atlow <moshe@atlow.co.il> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
86415e4688
commit
4b4a9319d9
@ -146,7 +146,9 @@ class SnapshotManager {
|
||||
);
|
||||
}
|
||||
|
||||
this.snapshots = context.exports;
|
||||
for (const key in context.exports) {
|
||||
this.snapshots[key] = templateEscape(context.exports[key]);
|
||||
}
|
||||
this.loaded = true;
|
||||
} catch (err) {
|
||||
let msg = `Cannot read snapshot file '${this.snapshotFile}.'`;
|
||||
|
4
test/fixtures/test-runner/snapshots/unit.js
vendored
4
test/fixtures/test-runner/snapshots/unit.js
vendored
@ -22,3 +22,7 @@ test('`${foo}`', async (t) => {
|
||||
const options = { serializers: [() => { return '***'; }]};
|
||||
t.assert.snapshot('snapshotted string', options);
|
||||
});
|
||||
|
||||
test('escapes in `\\${foo}`\n', async (t) => {
|
||||
t.assert.snapshot('`\\${foo}`\n');
|
||||
});
|
||||
|
@ -296,9 +296,9 @@ test('t.assert.snapshot()', async (t) => {
|
||||
|
||||
t.assert.strictEqual(child.code, 1);
|
||||
t.assert.strictEqual(child.signal, null);
|
||||
t.assert.match(child.stdout, /# tests 3/);
|
||||
t.assert.match(child.stdout, /# tests 4/);
|
||||
t.assert.match(child.stdout, /# pass 0/);
|
||||
t.assert.match(child.stdout, /# fail 3/);
|
||||
t.assert.match(child.stdout, /# fail 4/);
|
||||
t.assert.match(child.stdout, /Missing snapshots/);
|
||||
});
|
||||
|
||||
@ -311,8 +311,8 @@ test('t.assert.snapshot()', async (t) => {
|
||||
|
||||
t.assert.strictEqual(child.code, 0);
|
||||
t.assert.strictEqual(child.signal, null);
|
||||
t.assert.match(child.stdout, /tests 3/);
|
||||
t.assert.match(child.stdout, /pass 3/);
|
||||
t.assert.match(child.stdout, /tests 4/);
|
||||
t.assert.match(child.stdout, /pass 4/);
|
||||
t.assert.match(child.stdout, /fail 0/);
|
||||
});
|
||||
|
||||
@ -325,8 +325,8 @@ test('t.assert.snapshot()', async (t) => {
|
||||
|
||||
t.assert.strictEqual(child.code, 0);
|
||||
t.assert.strictEqual(child.signal, null);
|
||||
t.assert.match(child.stdout, /tests 3/);
|
||||
t.assert.match(child.stdout, /pass 3/);
|
||||
t.assert.match(child.stdout, /tests 4/);
|
||||
t.assert.match(child.stdout, /pass 4/);
|
||||
t.assert.match(child.stdout, /fail 0/);
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user