-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: migrate tests to use node:test module for better test structure
- 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.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); |