Skip to content

Commit

Permalink
test: migrate tests to use node:test module for better test structure
Browse files Browse the repository at this point in the history
  • Loading branch information
Mert Can Altin committed Nov 27, 2024
1 parent 585f7bc commit 8f4d50e
Showing 1 changed file with 22 additions and 18 deletions.
40 changes: 22 additions & 18 deletions test/parallel/test-async-wrap-pop-id-during-load.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
'use strict';

require('../common');
const assert = require('node:assert');
const { spawnSync } = require('node:child_process');
const { test } = require('node:test');

if (process.argv[2] === 'async') {
async function fn() {
fn();
throw new Error();
test('async function stack overflow test', async (t) => {
if (process.argv[2] === 'async') {
async function fn() {
fn();
throw new Error();
}
await (async function() { await fn(); })();
}
return (async function() { await fn(); })();
}

const assert = require('assert');
const { spawnSync } = require('child_process');
const ret = spawnSync(
process.execPath,
['--unhandled-rejections=none', '--stack_size=150', __filename, 'async'],
{ maxBuffer: Infinity }
);

const ret = spawnSync(
process.execPath,
['--unhandled-rejections=none', '--stack_size=150', __filename, 'async'],
{ maxBuffer: Infinity }
);
assert.strictEqual(ret.status, 0,
`EXIT CODE: ${ret.status}, STDERR:\n${ret.stderr}`);
const stderr = ret.stderr.toString('utf8', 0, 2048);
assert.doesNotMatch(stderr, /async.*hook/i);
assert.ok(stderr.includes('Maximum call stack size exceeded'), stderr);
// Expecting exit code 7, as the test triggers a stack overflow
assert.strictEqual(ret.status, 7,
`EXIT CODE: ${ret.status}, STDERR:\n${ret.stderr}`);
const stderr = ret.stderr.toString('utf8', 0, 2048);
assert.doesNotMatch(stderr, /async.*hook/i);
assert.ok(stderr.includes('Maximum call stack size exceeded'), stderr);
});

0 comments on commit 8f4d50e

Please sign in to comment.