Skip to content

Commit 7c5c4c0

Browse files
authored
test: migrate assertion tests from python to js
1 parent dd205c9 commit 7c5c4c0

7 files changed

Lines changed: 54 additions & 19 deletions
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
require('../common');
3+
require('../../common');
44
const assert = require('assert').strict;
55

66
assert.throws(() => { throw new Error('foo'); }, { bar: true });

test/message/assert_throws_stack.out renamed to test/fixtures/assertion/assert_throws_stack.snapshot

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ AssertionError [ERR_ASSERTION]: Expected values to be strictly deep-equal:
99
- Comparison {
1010
- bar: true
1111
- }
12-
at Object.<anonymous> (*assert_throws_stack.js:*:*)
12+
13+
at *
1314
at *
1415
at *
1516
at *
@@ -21,16 +22,16 @@ AssertionError [ERR_ASSERTION]: Expected values to be strictly deep-equal:
2122
generatedMessage: true,
2223
code: 'ERR_ASSERTION',
2324
actual: Error: foo
24-
at assert.throws.bar (*assert_throws_stack.js:*)
25-
at getActual (node:assert:*)
26-
at strict.throws (node:assert:*)
27-
at Object.<anonymous> (*assert_throws_stack.js:*:*)
2825
at *
2926
at *
3027
at *
3128
at *
3229
at *
33-
at *,
30+
at *
31+
at *
32+
at *
33+
at *
34+
at wrapModuleLoad (node:internal*modules*cjs*loader:*:*),
3435
expected: { bar: true },
3536
operator: 'throws'
3637
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
// Flags: --expose-internals
12
'use strict';
23

3-
// Flags: --expose-internals
4-
require('../common');
4+
require('../../common');
55

66
const assert = require('internal/assert');
77
assert(false);

test/message/internal_assert.out renamed to test/fixtures/assertion/internal_assert.snapshot

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
node:internal/assert:*
1+
node:internal*assert:*
22
throw new ERR_INTERNAL_ASSERTION(message);
33
^
44

55
Error [ERR_INTERNAL_ASSERTION]: This is caused by either a bug in Node.js or incorrect usage of Node.js internals.
6-
Please open an issue with this stack trace at https://github.com/nodejs/node/issues
6+
Please open an issue with this stack trace at https:**github.com*nodejs*node*issues
77

8-
at assert (node:internal/assert:*:*)
9-
at * (*test*message*internal_assert.js:7:1)
8+
at *
9+
at *
1010
at *
1111
at *
1212
at *
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
// Flags: --expose-internals
12
'use strict';
23

3-
// Flags: --expose-internals
4-
require('../common');
4+
require('../../common');
55

66
const assert = require('internal/assert');
77
assert.fail('Unreachable!');

test/message/internal_assert_fail.out renamed to test/fixtures/assertion/internal_assert_fail.snapshot

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
node:internal/assert:*
1+
node:internal*assert:*
22
throw new ERR_INTERNAL_ASSERTION(message);
33
^
44

55
Error [ERR_INTERNAL_ASSERTION]: Unreachable!
66
This is caused by either a bug in Node.js or incorrect usage of Node.js internals.
7-
Please open an issue with this stack trace at https://github.com/nodejs/node/issues
7+
Please open an issue with this stack trace at https:**github.com*nodejs*node*issues
88

9-
at assert.fail (node:internal/assert:*:*)
10-
at * (*test*message*internal_assert_fail.js:7:8)
9+
at *
10+
at *
1111
at *
1212
at *
1313
at *
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import '../common/index.mjs';
2+
import * as fixtures from '../common/fixtures.mjs';
3+
import * as snapshot from '../common/assertSnapshot.js';
4+
import { describe, it } from 'node:test';
5+
6+
function replaceStackTrace(str) {
7+
return snapshot.replaceStackTrace(str, '$1at *$7\n');
8+
}
9+
10+
describe('assertion output', { concurrency: true }, () => {
11+
function normalize(str) {
12+
return str
13+
.replaceAll(snapshot.replaceWindowsPaths(process.cwd()), '')
14+
.replaceAll('/', '*')
15+
.replaceAll(process.version, '*')
16+
.replaceAll(/:\d+/g, ':*')
17+
}
18+
19+
const common = snapshot
20+
.transform(snapshot.replaceWindowsLineEndings, snapshot.replaceWindowsPaths);
21+
const defaultTransform = snapshot.transform(common, replaceStackTrace, normalize);
22+
23+
const tests = [
24+
{ name: 'assertion/assert_throws_stack.js' },
25+
{ name: 'assertion/internal_assert_fail.js' },
26+
{ name: 'assertion/internal_assert.js' },
27+
];
28+
29+
for (const { name, transform } of tests) {
30+
it(name, async () => {
31+
await snapshot.spawnAndAssert(fixtures.path(name), transform ?? defaultTransform);
32+
});
33+
}
34+
});

0 commit comments

Comments
 (0)