Skip to content

Commit a6a3b08

Browse files
committed
test: migrate message tests to use assertSnapshot
1 parent 57508fb commit a6a3b08

File tree

83 files changed

+267
-152
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+267
-152
lines changed

β€Žtest/common/assertSnapshot.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ const assert = require('node:assert/strict');
88
const stackFramesRegexp = /(\s+)((.+?)\s+\()?(?:\(?(.+?):(\d+)(?::(\d+))?)\)?(\s+\{)?(\n|$)/g;
99
const windowNewlineRegexp = /\r/g;
1010

11-
function replaceStackTrace(str) {
12-
return str.replace(stackFramesRegexp, '$1*$7\n');
11+
function replaceStackTrace(str, replacement = '$1*$7\n') {
12+
return str.replace(stackFramesRegexp, replacement);
1313
}
1414

1515
function replaceWindowsLineEndings(str) {
@@ -36,11 +36,9 @@ async function assertSnapshot(actual, filename = process.argv[1]) {
3636
}
3737

3838
async function spawnAndAssert(filename, transform = (x) => x) {
39-
// TODO: Add an option to this function to alternatively or additionally compare stderr.
40-
// For now, tests that want to check stderr or both stdout and stderr can use spawnPromisified.
4139
const flags = common.parseTestFlags(filename);
42-
const { stdout } = await common.spawnPromisified(process.execPath, [...flags, filename]);
43-
await assertSnapshot(transform(stdout), filename);
40+
const { stdout, stderr } = await common.spawnPromisified(process.execPath, [...flags, filename]);
41+
await assertSnapshot(transform(`${stdout}${stderr}`), filename);
4442
}
4543

4644
module.exports = {

β€Žtest/common/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ function parseTestFlags(filename = process.argv[1]) {
7070
fs.closeSync(fd);
7171
const source = buffer.toString('utf8', 0, bytesRead);
7272

73-
const flagStart = source.indexOf('// Flags: --') + 10;
73+
const flagStart = source.search(/\/\/ Flags:\s+--/) + 10;
7474

7575
if (flagStart === 9) {
7676
return [];
@@ -83,7 +83,8 @@ function parseTestFlags(filename = process.argv[1]) {
8383
return source
8484
.substring(flagStart, flagEnd)
8585
.replace(/_/g, '-')
86-
.split(' ');
86+
.split(/\s+/)
87+
.filter(Boolean);
8788
}
8889

8990
// Check for flags. Skip this for workers (both, the `cluster` module and

β€Žtest/message/2100bytes.js renamed to β€Žtest/fixtures/message/2100bytes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
// USE OR OTHER DEALINGS IN THE SOFTWARE.
2121

2222
'use strict';
23-
require('../common');
23+
require('../../common');
2424

2525
console.log([
2626
'_______________________________________________50',

β€Žtest/message/async_error_eval_cjs.js renamed to β€Žtest/fixtures/message/async_error_eval_cjs.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
'use strict';
22

3-
require('../common');
3+
require('../../common');
44
const { spawnSync } = require('child_process');
55

6-
const four = require('../common/fixtures')
6+
const four = require('../../common/fixtures')
77
.readSync('async-error.js')
88
.toString()
99
.split('\n')

β€Žtest/message/async_error_eval_cjs.out renamed to β€Žtest/fixtures/message/async_error_eval_cjs.snapshot

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ Error: test
33
at two ([eval]:15:9)
44
at async three ([eval]:18:3)
55
at async four ([eval]:22:3)
6-
at async main ([eval]:28:5)
6+
at async main ([eval]:28:5)
7+

β€Žtest/message/async_error_eval_esm.js renamed to β€Žtest/fixtures/message/async_error_eval_esm.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
'use strict';
22

3-
require('../common');
3+
require('../../common');
44
const { spawnSync } = require('child_process');
55

6-
const four = require('../common/fixtures')
6+
const four = require('../../common/fixtures')
77
.readSync('async-error.js')
88
.toString()
99
.split('\n')

β€Žtest/message/async_error_eval_esm.out renamed to β€Žtest/fixtures/message/async_error_eval_esm.snapshot

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ Error: test
44
at async three (file:*/[eval1]:18:3)
55
at async four (file:*/[eval1]:22:3)
66
at async main (file:*/[eval1]:28:5)
7+

β€Žtest/message/async_error_microtask_main.js renamed to β€Žtest/fixtures/message/async_error_microtask_main.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
2-
require('../common');
3-
const four = require('../fixtures/async-error');
2+
require('../../common');
3+
const four = require('../async-error');
44

55
async function main() {
66
try {

β€Žtest/message/async_error_sync_main.out renamed to β€Žtest/fixtures/message/async_error_microtask_main.snapshot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ Error: test
33
at two (*fixtures*async-error.js:17:9)
44
at async three (*fixtures*async-error.js:20:3)
55
at async four (*fixtures*async-error.js:24:3)
6-
at async main (*message*async_error_sync_main.js:7:5)
6+
at async main (*fixtures*message*async_error_microtask_main.js:7:5)

0 commit comments

Comments
Β (0)