Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Migrate message error tests from Python to JS #49738

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

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

assert.throws(() => { throw new Error('foo'); }, { bar: true });
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
node:assert:*
node:assert*
throw err;
^

Expand All @@ -9,7 +9,7 @@ AssertionError [ERR_ASSERTION]: Expected values to be strictly deep-equal:
- Comparison {
- bar: true
- }
at Object.<anonymous> (*assert_throws_stack.js:*:*)
at *
at *
at *
at *
Expand All @@ -19,16 +19,16 @@ AssertionError [ERR_ASSERTION]: Expected values to be strictly deep-equal:
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:*:*)
Comment on lines -22 to -25
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't the test checking exactly for this stack?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the test should check for it exactly ?, current test generates:

  at * {
  generatedMessage: true,
  code: 'ERR_ASSERTION',
  actual: Error: foo
      at *
      at *
      at *
      at *
      at *
      at *
      at *
      at *
      at *
      at node:internal*main*run_main_module**,
  expected: { bar: true },
  operator: 'throws'
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the original PR adding this test: #27243
@BridgeAR is this test intended to snapshot the entire stack trace? is this change ok?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any idea or suggestions to close this PR ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe add another trasnform function to make this snapshot similar to the original one?

at *
at *
at *
at *
at *
at *,
at *
at *
at *
at *
at node:internal*main*run_main_module**,
expected: { bar: true },
operator: 'throws'
}
Expand Down
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);
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
node:internal/assert:*
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
Please open an issue with this stack trace at https:**github.com*nodejs*node*issues

at new NodeError (node:internal/errors:*:*)
at assert (node:internal/assert:*:*)
at * (*test*message*internal_assert.js:7:1)
at *
at *
at *
at *
at *
at *
Expand Down
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!');
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
node:internal/assert:*
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
Please open an issue with this stack trace at https:**github.com*nodejs*node*issues

at new NodeError (node:internal/errors:*:*)
at Function.fail (node:internal/assert:*:*)
at * (*test*message*internal_assert_fail.js:7:8)
at *
at *
at *
at *
at *
at *
Expand Down
33 changes: 33 additions & 0 deletions test/parallel/test-output-assert.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import '../common/index.mjs';
import * as fixtures from '../common/fixtures.mjs';
import * as snapshot from '../common/assertSnapshot.js';
import { describe, it } from 'node:test';

function replaceStackTrace(str) {
return snapshot.replaceStackTrace(str, '$1at *$7\n');
}
function normalize(str) {
return str
.replaceAll(snapshot.replaceWindowsPaths(process.cwd()), '')
.replaceAll('/', '*')
.replaceAll(process.version, '*')
.replaceAll(/:\d+/g, '*');
}
const common = snapshot
.transform(snapshot.replaceWindowsLineEndings, snapshot.replaceWindowsPaths);

const defaultTransform = snapshot.transform(common, replaceStackTrace, normalize);

const tests = [
{ name: 'assert/assert_throws_stack.js' },
{ name: 'assert/internal_assert_fail.js' },
{ name: 'assert/internal_assert.js' },
];

describe('assertion output', { concurrency: true }, () => {
for (const { name, transform } of tests) {
it(name, async () => {
await snapshot.spawnAndAssert(fixtures.path(name), transform ?? defaultTransform);
});
}
});