Skip to content

Commit

Permalink
test: migrate messages v8 tests from Python to JS
Browse files Browse the repository at this point in the history
Migrated messages v8 tests from Python to JavaScript. This change is
part of an effort to enhance maintainability and consistency in the
test suite. All relevant test files and dependencies have been updated
accordingly.

Refs: nodejs#47707
  • Loading branch information
ognjenjevremovic committed Jan 20, 2024
1 parent fbf1fb3 commit 4bc9540
Show file tree
Hide file tree
Showing 17 changed files with 195 additions and 171 deletions.
11 changes: 11 additions & 0 deletions test/fixtures/errors/assert_throws_stack.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
'use strict';

require('../../common');
const assert = require('assert').strict;

assert.throws(
() => {
throw new Error('foo');
},
{ bar: true }
);
36 changes: 36 additions & 0 deletions test/fixtures/errors/assert_throws_stack.snapshot
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
node:assert:*
throw err;
^

AssertionError [ERR_ASSERTION]: Expected values to be strictly deep-equal:
+ actual - expected

+ Comparison {}
- Comparison {
- bar: true
- }
at Object.<anonymous> (*assert_throws_stack.js:*:*)
at Module._compile (node:internal*modules*cjs*loader:*:*)
at Module._extensions..js (node:internal*modules*cjs*loader:*:*)
at Module.load (node:internal*modules*cjs*loader:*:*)
at Module._load (node:internal*modules*cjs*loader:*:*)
at Function.executeUserEntryPoint [as runMain] (node:internal*modules*run_main:*:*)
at node:internal*main*run_main_module:*:* {
generatedMessage: true,
code: 'ERR_ASSERTION',
actual: Error: foo
at assert.throws.bar (*assert_throws_stack.js:*:*)
at getActual (node:assert:*:*)
at Function.throws (node:assert:*:*)
at Object.<anonymous> (*assert_throws_stack.js:*:*)
at Module._compile (node:internal*modules*cjs*loader:*:*)
at Module._extensions..js (node:internal*modules*cjs*loader:*:*)
at Module.load (node:internal*modules*cjs*loader:*:*)
at Module._load (node:internal*modules*cjs*loader:*:*)
at Function.executeUserEntryPoint [as runMain] (node:internal*modules*run_main:*:*)
at node:internal*main*run_main_module:*:*,
expected: { bar: true },
operator: 'throws'
}

Node.js *
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';

require('../common');
require('../../common');

console.assert(false, Symbol('hello'));
15 changes: 15 additions & 0 deletions test/fixtures/errors/console_assert.snapshot
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
node:internal*console*constructor:*
args[0] = `Assertion failed${args.length === 0 ? '' : `: ${args[0]}`}`;
^

TypeError: Cannot convert a Symbol value to a string
at console.assert (node:internal*console*constructor:*:*)
at Object.<anonymous> (*console_assert.js:*:*)
at Module._compile (node:internal*modules*cjs*loader:*:*)
at Module._extensions..js (node:internal*modules*cjs*loader:*:*)
at Module.load (node:internal*modules*cjs*loader:*:*)
at Module._load (node:internal*modules*cjs*loader:*:*)
at Function.executeUserEntryPoint [as runMain] (node:internal*modules*run_main:*:*)
at node:internal*main*run_main_module:*:*

Node.js *
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

'use strict';

require('../common');
require('../../common');

const spawn = require('child_process').spawn;

Expand All @@ -35,17 +35,18 @@ function run(cmd, strict, cb) {
child.on('close', cb);
}

const queue =
[ 'with(this){__filename}',
'42',
'throw new Error("hello")',
'var x = 100; y = x;',
'var ______________________________________________; throw 10' ];
const queue = [
'with(this){__filename}',
'42',
'throw new Error("hello")',
'var x = 100; y = x;',
'var ______________________________________________; throw 10',
];

function go() {
const c = queue.shift();
if (!c) return console.log('done');
run(c, false, function() {
run(c, false, function () {
run(c, true, go);
});
}
Expand Down
76 changes: 76 additions & 0 deletions test/fixtures/errors/eval_messages.snapshot
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
[eval]
[eval]:*
with(this){__filename}
^^^^

SyntaxError: Strict mode code may not include a with statement
at makeContextifyScript (node:internal*vm:*:*)
at node:internal*process*execution:*:*
at [eval]-wrapper:*:*
at runScript (node:internal*process*execution:*:*)
at evalScript (node:internal*process*execution:*:*)
at node:internal*main*eval_string:*:*

Node.js *
42
42
[eval]:*
throw new Error("hello")
^

Error: hello
at [eval]:*:*
at runScriptInThisContext (node:internal*vm:*:*)
at node:internal*process*execution:*:*
at [eval]-wrapper:*:*
at runScript (node:internal*process*execution:*:*)
at evalScript (node:internal*process*execution:*:*)
at node:internal*main*eval_string:*:*

Node.js *
[eval]:*
throw new Error("hello")
^

Error: hello
at [eval]:*:*
at runScriptInThisContext (node:internal*vm:*:*)
at node:internal*process*execution:*:*
at [eval]-wrapper:*:*
at runScript (node:internal*process*execution:*:*)
at evalScript (node:internal*process*execution:*:*)
at node:internal*main*eval_string:*:*

Node.js *
100
[eval]:*
var x = 100; y = x;
^

ReferenceError: y is not defined
at [eval]:*:*
at runScriptInThisContext (node:internal*vm:*:*)
at node:internal*process*execution:*:*
at [eval]-wrapper:*:*
at runScript (node:internal*process*execution:*:*)
at evalScript (node:internal*process*execution:*:*)
at node:internal*main*eval_string:*:*

Node.js *

[eval]:*
var ______________________________________________; throw 10
^
10
(Use `node --trace-uncaught ...` to show where the exception was thrown)

Node.js *

[eval]:*
var ______________________________________________; throw 10
^
10
(Use `node --trace-uncaught ...` to show where the exception was thrown)

Node.js *
done
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

// Flags: --expose-internals
require('../common');
require('../../common');

const assert = require('internal/assert');
assert(false);
19 changes: 19 additions & 0 deletions test/fixtures/errors/internal_assert.snapshot
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
node:internal*assert:*
throw new ERR_INTERNAL_ASSERTION(message);
^

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

at assert (node:internal*assert:*:*)
at Object.<anonymous> (*internal_assert.js:*:*)
at Module._compile (node:internal*modules*cjs*loader:*:*)
at Module._extensions..js (node:internal*modules*cjs*loader:*:*)
at Module.load (node:internal*modules*cjs*loader:*:*)
at Module._load (node:internal*modules*cjs*loader:*:*)
at Function.executeUserEntryPoint [as runMain] (node:internal*modules*run_main:*:*)
at node:internal*main*run_main_module:*:* {
code: 'ERR_INTERNAL_ASSERTION'
}

Node.js *
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

// Flags: --expose-internals
require('../common');
require('../../common');

const assert = require('internal/assert');
assert.fail('Unreachable!');
20 changes: 20 additions & 0 deletions test/fixtures/errors/internal_assert_fail.snapshot
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
node:internal*assert:*
throw new ERR_INTERNAL_ASSERTION(message);
^

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

at Function.fail (node:internal*assert:*:*)
at Object.<anonymous> (*internal_assert_fail.js:*:*)
at Module._compile (node:internal*modules*cjs*loader:*:*)
at Module._extensions..js (node:internal*modules*cjs*loader:*:*)
at Module.load (node:internal*modules*cjs*loader:*:*)
at Module._load (node:internal*modules*cjs*loader:*:*)
at Function.executeUserEntryPoint [as runMain] (node:internal*modules*run_main:*:*)
at node:internal*main*run_main_module:*:* {
code: 'ERR_INTERNAL_ASSERTION'
}

Node.js *
6 changes: 0 additions & 6 deletions test/message/assert_throws_stack.js

This file was deleted.

36 changes: 0 additions & 36 deletions test/message/assert_throws_stack.out

This file was deleted.

1 change: 0 additions & 1 deletion test/message/console_assert.out

This file was deleted.

77 changes: 0 additions & 77 deletions test/message/eval_messages.out

This file was deleted.

19 changes: 0 additions & 19 deletions test/message/internal_assert.out

This file was deleted.

Loading

0 comments on commit 4bc9540

Please sign in to comment.