Upload Kmake

This commit is contained in:
Gorochu
2026-05-26 23:36:42 -07:00
parent ba051b2f74
commit 555ec72358
41615 changed files with 13344630 additions and 1 deletions

View File

@ -0,0 +1,25 @@
const {test, afterEach} = require('node:test');
const assert = require('node:assert');
const { waitForAbort } = require('./wait-for-abort-helper');
let testCount = 0;
let signal;
afterEach(() => {
assert.equal(signal.aborted, false);
waitForAbort({ testNumber: ++testCount, signal });
});
test("sync", (t) => {
signal = t.signal;
assert.equal(signal.aborted, false);
throw new Error('failing the sync test');
});
test("async", async (t) => {
await null;
signal = t.signal;
assert.equal(signal.aborted, false);
throw new Error('failing the async test');
});

View File

@ -0,0 +1,23 @@
const {test, afterEach} = require('node:test');
const assert = require('node:assert');
const {waitForAbort} = require("./wait-for-abort-helper");
let testCount = 0;
let signal;
afterEach(() => {
assert.equal(signal.aborted, false);
waitForAbort({ testNumber: ++testCount, signal });
});
test("sync", (t) => {
signal = t.signal;
assert.equal(signal.aborted, false);
});
test("async", async (t) => {
await null;
signal = t.signal;
assert.equal(signal.aborted, false);
});

View File

@ -0,0 +1,19 @@
module.exports = {
waitForAbort: function ({ testNumber, signal }) {
let retries = 0;
const interval = setInterval(() => {
retries++;
if(signal.aborted) {
console.log(`abort called for test ${testNumber}`);
clearInterval(interval);
return;
}
if(retries > 100) {
clearInterval(interval);
throw new Error(`abort was not called for test ${testNumber}`);
}
}, 10);
}
}

View File

@ -0,0 +1,27 @@
import { after, afterEach, before, beforeEach, test } from 'node:test'
before(() => {
setTimeout(() => {
throw new Error('before')
}, 100)
})
beforeEach(() => {
setTimeout(() => {
throw new Error('beforeEach')
}, 100)
})
after(() => {
setTimeout(() => {
throw new Error('after')
}, 100)
})
afterEach(() => {
setTimeout(() => {
throw new Error('afterEach')
}, 100)
})
test('ok', () => {})

View File

@ -0,0 +1,13 @@
import tmpdir from '../../../common/tmpdir.js';
import { setTimeout } from 'node:timers/promises';
import fs from 'node:fs/promises';
import path from 'node:path';
await fs.writeFile(tmpdir.resolve('test-runner-concurrency'), 'a.mjs');
while (true) {
const file = await fs.readFile(tmpdir.resolve('test-runner-concurrency'), 'utf8');
if (file === 'b.mjs') {
break;
}
await setTimeout(10);
}

View File

@ -0,0 +1,13 @@
import tmpdir from '../../../common/tmpdir.js';
import { setTimeout } from 'node:timers/promises';
import fs from 'node:fs/promises';
import path from 'node:path';
while (true) {
const file = await fs.readFile(tmpdir.resolve('test-runner-concurrency'), 'utf8');
if (file === 'a.mjs') {
await fs.writeFile(tmpdir.resolve('test-runner-concurrency'), 'b.mjs');
break;
}
await setTimeout(10);
}

View File

@ -0,0 +1,7 @@
const test = require('node:test');
const assert = require('node:assert');
const { foo } = require('./logic-file');
test('foo returns 1', () => {
assert.strictEqual(foo(), 1);
});

View File

@ -0,0 +1,7 @@
import test from 'node:test';
import assert from 'node:assert';
import { foo } from './logic-file.js';
test('foo returns 1', () => {
assert.strictEqual(foo(), 1);
});

View File

@ -0,0 +1,7 @@
import test from 'node:test';
import assert from 'node:assert';
import { foo } from './logic-file.js';
test('foo returns 1', () => {
assert.strictEqual(foo(), 1);
});

View File

@ -0,0 +1,9 @@
function foo() {
return 1;
}
function bar() {
return 'bar';
}
module.exports = { foo, bar };

View File

@ -0,0 +1,7 @@
const test = require('node:test');
const assert = require('node:assert');
const { foo } = require('./logic-file.js');
test('foo returns 1', () => {
assert.strictEqual(foo(), 1);
});

View File

@ -0,0 +1,7 @@
const test = require('node:test');
const assert = require('node:assert');
const { foo } = require('../logic-file.js');
test('foo returns 1', () => {
assert.strictEqual(foo(), 1);
});

View File

@ -0,0 +1,25 @@
const sources = {
// Virtual file. Doesn't exist on disk
"virtual.js": `
import { test } from 'node:test';
test('test', async () => {});
`,
// file with source map. this emulates the behavior of tsx
"sum.test.ts": `\
import{describe,it}from"node:test";import assert from"node:assert";import{sum}from"./sum.ts";describe("sum",()=>{it("should sum two numbers",()=>{assert.deepStrictEqual(sum(1,2),3)});it("should error out if one is not a number",()=>{assert.throws(()=>sum(1,"b"),Error)})});
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJtYXBwaW5ncyI6IkFBQUEsT0FBUyxTQUFVLE9BQVUsWUFDN0IsT0FBTyxXQUFZLGNBQ25CLE9BQVMsUUFBVyxRQUVwQixTQUFTLE1BQU8sSUFBTSxDQUNwQixHQUFHLHlCQUEwQixJQUFNLENBQy9CLE9BQU8sZ0JBQWdCLElBQUksRUFBRSxDQUFDLEVBQUcsQ0FBQyxDQUN0QyxDQUFDLEVBRUQsR0FBRywwQ0FBMkMsSUFBTSxDQUNsRCxPQUFPLE9BQU8sSUFBTSxJQUFJLEVBQUcsR0FBRyxFQUFHLEtBQUssQ0FDeEMsQ0FBQyxDQUNILENBQUMiLCJuYW1lcyI6W10sImlnbm9yZUxpc3QiOltdLCJzb3VyY2VzIjpbIi4vc3VtLnRlc3QudHMiXSwic291cmNlc0NvbnRlbnQiOltudWxsXX0=`,
// file with source map. this emulates the behavior of tsx
"sum.ts": `\
var __defProp=Object.defineProperty;var __name=(target,value)=>__defProp(target,"name",{value,configurable:true});function sum(...n){if(!n.every(num=>typeof num==="number"))throw new Error("Not a number");return n.reduce((acc,cur)=>acc+cur)}__name(sum,"sum");export{sum};
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJtYXBwaW5ncyI6ImtIQUFPLFNBQVMsT0FBUSxFQUFHLENBQ3pCLEdBQUksQ0FBQyxFQUFFLE1BQU8sS0FBUSxPQUFPLE1BQVEsUUFBUSxFQUFHLE1BQU0sSUFBSSxNQUFNLGNBQWMsRUFDOUUsT0FBTyxFQUFFLE9BQU8sQ0FBQyxJQUFLLE1BQVEsSUFBTSxHQUFHLENBQ3pDLENBSGdCIiwibmFtZXMiOltdLCJpZ25vcmVMaXN0IjpbXSwic291cmNlcyI6WyIuL3N1bS50cyJdLCJzb3VyY2VzQ29udGVudCI6W251bGxdfQ==`,
};
export async function load(url, context, nextLoad) {
const file = url.split('/').at(-1);
if (sources[file] !== undefined) {
return { format: "module", source: sources[file], shortCircuit: true };
}
return nextLoad(url, context);
}

View File

@ -0,0 +1,4 @@
const { register } = require('node:module');
const { pathToFileURL } = require('node:url');
register('./hooks.mjs', pathToFileURL(__filename));

View File

@ -0,0 +1,13 @@
import { describe, it } from 'node:test'
import assert from 'node:assert'
import { sum } from './sum'
describe('sum', () => {
it('should sum two numbers', () => {
assert.deepStrictEqual(sum(1, 2), 3)
})
it('should error out if one is not a number', () => {
assert.throws(() => sum(1, 'b'), Error)
})
})

View File

@ -0,0 +1,4 @@
export function sum (...n) {
if (!n.every((num) => typeof num === 'number')) throw new Error('Not a number')
return n.reduce((acc, cur) => acc + cur)
}

View File

View File

@ -0,0 +1,52 @@
'use strict';
// Here we can't import common module as the coverage will be different based on the system
// Empty functions that don't do anything
function doNothing1() {
// Not implemented
}
function doNothing2() {
// No logic here
}
function unusedFunction1() {
// Intentionally left empty
}
function unusedFunction2() {
// Another empty function
}
// Unused variables
const unusedVariable1 = 'This is never used';
const unusedVariable2 = 42;
let unusedVariable3;
// Empty class with no methods
class UnusedClass {
constructor() {
// Constructor does nothing
}
}
// Empty object literal
const emptyObject = {};
// Empty array
const emptyArray = [];
// Function with parameters but no body
function doNothingWithParams(param1, param2) {
// No implementation
}
// Function that returns nothing
function returnsNothing() {
// No return statement
}
// Another unused function
function unusedFunction3() {
// More empty code
}

View File

@ -0,0 +1,52 @@
'use strict';
// Here we can't import common module as the coverage will be different based on the system
// Empty functions that don't do anything
function doNothing1() {
// Not implemented
}
function doNothing2() {
// No logic here
}
function unusedFunction1() {
// Intentionally left empty
}
function unusedFunction2() {
// Another empty function
}
// Unused variables
const unusedVariable1 = 'This is never used';
const unusedVariable2 = 42;
let unusedVariable3;
// Empty class with no methods
class UnusedClass {
constructor() {
// Constructor does nothing
}
}
// Empty object literal
const emptyObject = {};
// Empty array
const emptyArray = [];
// Function with parameters but no body
function doNothingWithParams(param1, param2) {
// No implementation
}
// Function that returns nothing
function returnsNothing() {
// No return statement
}
// Another unused function
function unusedFunction3() {
// More empty code
}

View File

@ -0,0 +1,11 @@
'use strict';
// Here we can't import common module as the coverage will be different based on the system
// Empty functions that don't do anything
function doNothing1() {
// Not implemented
}
function doNothing2() {
// No logic here
}

View File

@ -0,0 +1,353 @@
'use strict';
// Here we can't import common module as the coverage will be different based on the system
// Empty functions that don't do anything
function doNothing1() {
// Not implemented
}
function doNothing2() {
// No logic here
}
function unusedFunction1() {
// Intentionally left empty
}
function unusedFunction2() {
// Another empty function
}
// Unused variables
const unusedVariable1 = 'This is never used';
const unusedVariable2 = 42;
let unusedVariable3;
// Empty class with no methods
class UnusedClass {
constructor() {
// Constructor does nothing
}
}
// Empty object literal
const emptyObject = {};
// Empty array
const emptyArray = [];
// Function with parameters but no body
function doNothingWithParams(param1, param2) {
// No implementation
}
// Function that returns nothing
function returnsNothing() {
// No return statement
}
// Another unused function
function unusedFunction3() {
// More empty code
}
// Empty functions with different signatures
function doNothing4() {
// No logic here
}
function doNothing5() {
// Another placeholder
}
function doNothingWithRestParams(...args) {
// Function with rest parameters but no logic
}
function doNothingWithCallback(callback) {
// Callback not called
}
// Unused variables of different types
const unusedVariable7 = null;
const unusedVariable8 = undefined;
const unusedVariable9 = Symbol('unused');
let unusedVariable10;
// Another empty class
class YetAnotherUnusedClass {
// No properties or methods
}
// Unused object with nested array
const unusedObjectWithArray = {
innerArray: [],
};
// Another empty array
const anotherEmptyArray = [];
// Function with default and rest parameters
function anotherComplexFunction(param1 = 10, ...rest) {
// No implementation
}
// More unused functions
function unusedFunction5() {
// Placeholder
}
function unusedFunction6() {
// Empty again
}
function unusedFunction7() {
// Still nothing here
}
// Empty static method in class
class UnusedClassWithStaticMethod {
static unusedStaticMethod() {
// No logic inside static method
}
}
// Empty getter and setter in a class
class ClassWithGetterSetter {
get unusedGetter() {
// Empty getter
}
set unusedSetter(value) {
// Empty setter
}
}
// Unused function returning undefined
function returnsUndefined() {
return undefined;
}
// Empty promise-returning function
function emptyPromiseFunction() {
return new Promise((resolve, reject) => {
// No promise logic
});
}
// Empty immediately-invoked function expression (IIFE)
(function emptyIIFE() {
// No implementation
})();
// Unused generator function with parameters
function* unusedGeneratorFunctionWithParams(param1, param2) {
// No yielding of values
}
// Unused async arrow function
const unusedAsyncArrowFunction = async () => {
// No async logic here
};
// Unused map function with no logic
const unusedMapFunction = new Map();
// Unused set function with no logic
const unusedSetFunction = new Set();
// Empty for loop
for (let i = 0; i < 10; i++) {
// Loop does nothing
}
// Empty while loop
while (false) {
// Never executes
}
// Empty try-catch-finally block
try {
// Nothing to try
} catch (error) {
// No error handling
} finally {
// Nothing to finalize
}
// Empty if-else block
if (false) {
// No logic here
} else {
// Nothing here either
}
// Empty switch statement
switch (false) {
case true:
// No case logic
break;
default:
// Default does nothing
break;
}
// Empty nested function
function outerFunction() {
function innerFunction() {
// Empty inner function
}
}
// More unused arrow functions
const unusedArrowFunction1 = () => {};
const unusedArrowFunction2 = (param) => {};
// Empty function with a try-catch block
function emptyTryCatchFunction() {
try {
// Nothing to try
} catch (error) {
// No error handling
}
}
// Unused async generator function
async function* unusedAsyncGenerator() {
// No async yielding
}
// Unused function returning an empty array
function returnsEmptyArray() {
return [];
}
// Unused function returning an empty object
function returnsEmptyObject() {
return {};
}
// Empty arrow function with destructuring
const unusedArrowFunctionWithDestructuring = ({ key1, key2 }) => {
// No logic here
};
// Unused function with default parameters
function unusedFunctionWithDefaults(param1 = 'default', param2 = 100) {
// No implementation
}
// Unused function returning an empty Map
function returnsEmptyMap() {
return new Map();
}
// Unused function returning an empty Set
function returnsEmptySet() {
return new Set();
}
// Unused async function with try-catch
async function unusedAsyncFunctionWithTryCatch() {
try {
// Nothing to try
} catch (error) {
// No error handling
}
}
// Function with spread operator but no logic
function unusedFunctionWithSpread(...args) {
// No implementation
}
// Function with object spread but no logic
function unusedFunctionWithObjectSpread(obj) {
const newObj = { ...obj };
// No logic here
}
// Empty function that takes an array and does nothing
function unusedFunctionWithArrayParam(arr) {
// No logic here
}
// Empty function that returns a function
function unusedFunctionReturningFunction() {
return function() {
// Empty function returned
};
}
// Empty function with destructuring and rest parameters
function unusedFunctionWithDestructuringAndRest({ a, b, ...rest }) {
// No logic here
}
// Unused async function that returns a promise
async function unusedAsyncFunctionReturningPromise() {
return Promise.resolve();
}
// Empty recursive function
function unusedRecursiveFunction() {
// No recursive logic
}
// Empty function using template literals
function unusedFunctionWithTemplateLiterals(param) {
const message = `Message: ${param}`;
// No further logic
}
// Function with complex destructuring and no logic
function unusedComplexDestructuringFunction({ a: { b, c }, d }) {
// No logic here
}
// Empty function that uses bitwise operations
function unusedFunctionWithBitwiseOperations(num) {
const result = num & 0xff;
// No further logic
}
// Unused function with optional chaining
function unusedFunctionWithOptionalChaining(obj) {
const value = obj?.property?.nestedProperty;
// No further logic
}
// Unused function with nullish coalescing operator
function unusedFunctionWithNullishCoalescing(param) {
const value = param ?? 'default';
// No further logic
}
// Unused generator function returning nothing
function* unusedGeneratorFunction() {
// No yielding
}
// Function using try-catch with finally, but no logic
function unusedFunctionWithTryCatchFinally() {
try {
// Nothing to try
} catch (e) {
// No error handling
} finally {
// Nothing in finally
}
}
// Function with chaining but no logic
function unusedFunctionWithChaining() {
const obj = {
method1: () => ({ method2: () => {} }),
};
obj.method1().method2();
}
// Empty function returning a new Date object
function unusedFunctionReturningDate() {
return new Date();
}

89
test/fixtures/test-runner/coverage.js vendored Normal file
View File

@ -0,0 +1,89 @@
'use strict';
const http = require('node:http'); // node:* should be filtered out.
try {
// This block does not throw.
} catch { /* node:coverage ignore next 3 */
// So this block is uncovered.
/* node:coverage disable */
/* node:coverage enable */
/* node:coverage ignore next */
}
function uncalledTopLevelFunction() {
if (true) {
return 5;
}
return 9;
}
const test = require('node:test');
if (false) {
console.log('this does not execute');
} else {
require('./invalid-tap.js');
}
test('a test', () => {
const uncalled = () => {};
function fnWithControlFlow(val) {
if (val < 0) {
return -1;
} else if (val === 0) {
return 0;
} else if (val < 100) {
return 1;
} else {
return Infinity;
}
}
fnWithControlFlow(-10);
fnWithControlFlow(99);
});
try {
require('test-nm'); // node_modules should be filtered out.
} catch {
}
async function main() {
if (false) { console.log('boo'); } else { /* console.log('yay'); */ }
if (false) {
console.log('not happening');
}
if (true) {
if (false) {
console.log('not printed');
}
// Nothing to see here.
} else {
console.log('also not printed');
}
try {
const foo = {};
foo.x = 1;
require('../v8-coverage/throw.js');
foo.y = 2;
return foo;
} catch (err) {
let bar = [];
bar.push(5);
} finally {
const baz = 1;
}
}
main();

View File

@ -0,0 +1,13 @@
The files in the directory are generated by the
following commands:
```sh
npx esbuild a.test.ts --sourcemap --outdir=. --out-extension:.js=.mjs --sources-content=false --minify --bundle --platform=node --format=esm
echo "import { test } from 'node:test';
test('ok', () => {});
function uncovered() {
return 'uncovered';
}
" | npx esbuild --sourcemap --sourcefile=stdin.test.ts --sources-content=true --bundle --platform=node --outfile="stdin.test.js"
```

View File

@ -0,0 +1,2 @@
import{test as o}from"node:test";import{strictEqual as r}from"node:assert";function e(){r(1,2)}o("fails",()=>{e()});
//# sourceMappingURL=a.test.mjs.map

View File

@ -0,0 +1,6 @@
{
"version": 3,
"sources": ["a.test.ts", "b.test.ts"],
"mappings": "AAAA,OAAS,QAAAA,MAAY,YCArB,OAAS,eAAAC,MAAmB,cAErB,SAASC,GAAU,CACxBD,EAAY,EAAG,CAAC,CAClB,CDDAE,EAAK,QAAS,IAAM,CAClBC,EAAQ,CACV,CAAC",
"names": ["test", "strictEqual", "covered", "test", "covered"]
}

View File

@ -0,0 +1,13 @@
import { test } from 'node:test';
import { covered } from './b.test';
test('fails', () => {
covered();
});
function uncovered() {
return 'uncovered';
}
if (false) {
uncovered();
}

View File

@ -0,0 +1,9 @@
import { strictEqual } from 'node:assert';
export function covered() {
strictEqual(1, 2);
}
export function uncovered() {
return 'uncovered';
}

View File

@ -0,0 +1,3 @@
export default function bar() {
return 'original bar';
}

View File

@ -0,0 +1,3 @@
import bar from './bar.mts';
export const foo = () => bar();

View File

@ -0,0 +1,7 @@
'use strict';
const test = require('node:test');
test('no source map', () => {});
if (false) {
console.log('this does not execute');
}

View File

@ -0,0 +1,5 @@
// stdin.test.ts
var import_node_test = require("node:test");
(0, import_node_test.test)("ok", () => {
});
//# sourceMappingURL=stdin.test.js.map

View File

@ -0,0 +1,7 @@
{
"version": 3,
"sources": ["stdin.test.ts"],
"sourcesContent": ["import { test } from 'node:test';\ntest('ok', () => {});\n\nfunction uncovered() {\n return 'uncovered';\n}\n\n"],
"mappings": ";AAAA,uBAAqB;AAAA,IACrB,uBAAK,MAAM,MAAM;AAAC,CAAC;",
"names": []
}

View File

@ -0,0 +1,15 @@
import { Transform } from 'node:stream';
export default class CoverageReporter extends Transform {
constructor(options) {
super({ ...options, writableObjectMode: true });
}
_transform(event, _encoding, callback) {
if (event.type === 'test:coverage') {
callback(null, JSON.stringify(event.data, null, 2));
} else {
callback(null);
}
}
}

View File

@ -0,0 +1,17 @@
const { Transform } = require('node:stream');
const customReporter = new Transform({
writableObjectMode: true,
transform(event, encoding, callback) {
this.counters ??= {};
this.counters[event.type] = (this.counters[event.type] ?? 0) + 1;
callback();
},
flush(callback) {
this.push('custom.cjs ')
this.push(JSON.stringify(this.counters));
callback();
}
});
module.exports = customReporter;

View File

@ -0,0 +1,14 @@
const assert = require('assert');
const path = require('path');
module.exports = async function * customReporter(source) {
const counters = {};
for await (const event of source) {
if (event.data.file) {
assert.strictEqual(event.data.file, path.resolve(__dirname, '../reporters.js'));
}
counters[event.type] = (counters[event.type] ?? 0) + 1;
}
yield "custom.js ";
yield JSON.stringify(counters);
};

View File

@ -0,0 +1,8 @@
export default async function * customReporter(source) {
const counters = {};
for await (const event of source) {
counters[event.type] = (counters[event.type] ?? 0) + 1;
}
yield "custom.mjs ";
yield JSON.stringify(counters);
}

View File

@ -0,0 +1,8 @@
'use strict';
module.exports = async function * customReporter() {
yield 'Going to throw an error\n';
setImmediate(() => {
throw new Error('Reporting error');
});
};

View File

@ -0,0 +1,6 @@
'use strict';
module.exports = async function * customReporter() {
yield 'Going to throw an error\n';
throw new Error('Reporting error');
};

View File

@ -0,0 +1,4 @@
'use strict';
const test = require('node:test');
test('this should pass');

View File

@ -0,0 +1,4 @@
'use strict';
const test = require('node:test');
test('this should pass');

View File

@ -0,0 +1,2 @@
'use strict';
throw new Error('thrown from node_modules');

View File

@ -0,0 +1,5 @@
import test from 'node:test';
test('this should fail', () => {
throw new Error('this is a failing test');
});

View File

@ -0,0 +1,4 @@
'use strict';
const test = require('node:test');
test('this should pass');

View File

@ -0,0 +1,5 @@
'use strict';
const test = require('node:test');
test('this should be skipped');
test('this should be executed');

View File

@ -0,0 +1,5 @@
'use strict';
const {test, suite} = require('node:test');
suite('this is a suite');
test('this is a test');

View File

@ -0,0 +1,6 @@
const assert = require('node:assert');
const { test } = require('node:test');
test('fail', () => {
assert.fail('a.mjs fail');
});

View File

@ -0,0 +1,6 @@
const assert = require('node:assert');
const { test } = require('node:test');
test('fail', () => {
assert.fail('b.mjs fail');
});

View File

@ -0,0 +1,5 @@
import test from 'node:test';
test('extraneous async activity test', () => {
setImmediate(() => { throw new Error(); });
});

View File

@ -0,0 +1,5 @@
import test from 'node:test';
test('extraneous async activity test', () => {
setTimeout(() => { throw new Error(); }, 100);
});

View File

@ -0,0 +1,13 @@
'use strict';
const test = require('node:test');
const assert = require('node:assert');
const fs = require('node:fs');
test('Another test that verifies setup flag existance', (t) => {
const setupFlagPath = process.env.SETUP_FLAG_PATH;
assert.ok(fs.existsSync(setupFlagPath), 'Setup flag file should exist');
const content = fs.readFileSync(setupFlagPath, 'utf8');
assert.strictEqual(content, 'Setup was executed');
});

View File

@ -0,0 +1,26 @@
'use strict';
const fs = require('node:fs');
const { setTimeout } = require('node:timers/promises');
const asyncFlagPath = process.env.ASYNC_FLAG_PATH;
async function globalSetup() {
console.log('Async setup starting');
await setTimeout(500);
fs.writeFileSync(asyncFlagPath, 'Setup part');
console.log('Async setup completed');
}
async function globalTeardown() {
console.log('Async teardown starting');
await setTimeout(100);
fs.appendFileSync(asyncFlagPath, ', Teardown part');
console.log('Async teardown completed');
}
module.exports = { globalSetup, globalTeardown };

View File

@ -0,0 +1,20 @@
'use strict';
const fs = require('node:fs');
// Path for temporary file to track execution
const setupFlagPath = process.env.SETUP_FLAG_PATH;
const teardownFlagPath = process.env.TEARDOWN_FLAG_PATH;
async function globalSetup() {
console.log('Global setup executed');
fs.writeFileSync(setupFlagPath, 'Setup was executed');
}
async function globalTeardown() {
console.log('Global teardown executed');
fs.writeFileSync(teardownFlagPath, 'Teardown was executed');
fs.rmSync(setupFlagPath, { force: true });
}
module.exports = { globalSetup, globalTeardown };

View File

@ -0,0 +1,18 @@
import * as fs from 'node:fs';
// Path for temporary file to track execution
const setupFlagPath = process.env.SETUP_FLAG_PATH;
const teardownFlagPath = process.env.TEARDOWN_FLAG_PATH;
async function globalSetup() {
console.log('Global setup executed');
fs.writeFileSync(setupFlagPath, 'Setup was executed');
}
async function globalTeardown() {
console.log('Global teardown executed');
fs.writeFileSync(teardownFlagPath, 'Teardown was executed');
fs.rmSync(setupFlagPath, { force: true });
}
export { globalSetup, globalTeardown };

View File

@ -0,0 +1,24 @@
import * as fs from 'node:fs';
// Path for temporary file to track execution
const setupFlagPath = process.env.SETUP_FLAG_PATH;
const teardownFlagPath = process.env.TEARDOWN_FLAG_PATH;
async function globalSetup(): Promise<void> {
console.log('Global setup executed');
if (setupFlagPath) {
fs.writeFileSync(setupFlagPath, 'Setup was executed');
}
}
async function globalTeardown(): Promise<void> {
console.log('Global teardown executed');
if (teardownFlagPath) {
fs.writeFileSync(teardownFlagPath, 'Teardown was executed');
}
if (setupFlagPath) {
fs.rmSync(setupFlagPath, { force: true });
}
}
export { globalSetup, globalTeardown };

View File

@ -0,0 +1,11 @@
'use strict';
async function globalSetup() {
throw new Error('Deliberate error in global setup');
}
async function globalTeardown() {
console.log('Teardown should not run if setup fails');
}
module.exports = { globalSetup, globalTeardown };

View File

@ -0,0 +1,4 @@
import { test } from 'node:test';
test('Imported module Ok', () => {});
test('Imported module Fail', () => { throw new Error('fail'); });

View File

@ -0,0 +1 @@
console.log('Imported module executed');

View File

@ -0,0 +1 @@
console.log('Required module executed');

View File

@ -0,0 +1,12 @@
'use strict';
const fs = require('node:fs');
const setupFlagPath = process.env.SETUP_ONLY_FLAG_PATH;
async function globalSetup() {
console.log('Setup-only module executed');
fs.writeFileSync(setupFlagPath, 'Setup-only was executed');
}
module.exports = { globalSetup };

View File

@ -0,0 +1,12 @@
'use strict';
const fs = require('node:fs');
const teardownFlagPath = process.env.TEARDOWN_ONLY_FLAG_PATH;
async function globalTeardown() {
console.log('Teardown-only module executed');
fs.writeFileSync(teardownFlagPath, 'Teardown-only was executed');
}
module.exports = { globalTeardown };

View File

@ -0,0 +1,17 @@
'use strict';
const test = require('node:test');
const assert = require('node:assert');
const fs = require('node:fs');
test('verify setup was executed', (t) => {
const setupFlagPath = process.env.SETUP_FLAG_PATH;
assert.ok(fs.existsSync(setupFlagPath), 'Setup flag file should exist');
const content = fs.readFileSync(setupFlagPath, 'utf8');
assert.strictEqual(content, 'Setup was executed');
});
test('another simple test', (t) => {
assert.ok(true);
});

2
test/fixtures/test-runner/index.js vendored Normal file
View File

@ -0,0 +1,2 @@
'use strict';
throw new Error('thrown from index.js');

View File

@ -0,0 +1 @@
console.log('invalid tap output');

View File

View File

View File

@ -0,0 +1,4 @@
'use strict';
const test = require('node:test');
test('this should pass');

View File

@ -0,0 +1,4 @@
'use strict';
const test = require('node:test');
test('this should pass');

View File

@ -0,0 +1,4 @@
'use strict';
import test from 'node:test';
test('this should pass');

View File

@ -0,0 +1,4 @@
const test = require('node:test');
// 'as string' ensures that type stripping actually occurs
test('this should pass' as string);

View File

@ -0,0 +1,4 @@
import { test } from 'node:test';
// 'as string' ensures that type stripping actually occurs
test('this should pass' as string);

View File

@ -0,0 +1,4 @@
const test = require('node:test');
// 'as string' ensures that type stripping actually occurs
test('this should pass' as string);

21
test/fixtures/test-runner/mock-nm.js vendored Normal file
View File

@ -0,0 +1,21 @@
'use strict';
const assert = require('node:assert');
const { test } = require('node:test');
const fixture = 'reporter-cjs';
test('mock node_modules dependency', async (t) => {
const mock = t.mock.module(fixture, {
namedExports: { fn() { return 42; } },
});
let cjsImpl = require(fixture);
let esmImpl = await import(fixture);
assert.strictEqual(cjsImpl.fn(), 42);
assert.strictEqual(esmImpl.fn(), 42);
mock.restore();
cjsImpl = require(fixture);
esmImpl = await import(fixture);
assert.strictEqual(cjsImpl.fn, undefined);
assert.strictEqual(esmImpl.fn, undefined);
});

24
test/fixtures/test-runner/nested.js vendored Normal file
View File

@ -0,0 +1,24 @@
'use strict';
const test = require('node:test');
test('level 0a', { concurrency: 4 }, async (t) => {
t.test('level 1a', async (t) => {
});
t.test('level 1b', async (t) => {
throw new Error('level 1b error');
});
t.test('level 1c', { skip: 'aaa' }, async (t) => {
});
t.test('level 1d', async (t) => {
t.diagnostic('level 1d diagnostic');
});
});
test('level 0b', async (t) => {
throw new Error('level 0b error');
});

View File

@ -0,0 +1,6 @@
const test = require('node:test');
const { setTimeout } = require('timers/promises');
// We are using a very large timeout value to ensure that the parent process
// will have time to send a SIGINT signal to cancel the test.
test('never ending test', () => setTimeout(100_000_000));

View File

@ -0,0 +1,5 @@
const test = require('node:test');
test('never ending test', () => {
while (true);
});

View File

@ -0,0 +1,6 @@
const test = require('node:test');
test.before(() => console.log('before(): global'));
test.beforeEach(() => console.log('beforeEach(): global'));
test.after(() => console.log('after(): global'));
test.afterEach(() => console.log('afterEach(): global'));

View File

@ -0,0 +1,6 @@
import test from 'node:test';
test.before(() => console.log('before(): global'));
test.beforeEach(() => console.log('beforeEach(): global'));
test.after(() => console.log('after(): global'));
test.afterEach(() => console.log('afterEach(): global'));

View File

@ -0,0 +1,37 @@
'use strict';
const { before, beforeEach, after, afterEach, test, suite } = require('node:test');
globalThis.GLOBAL_ORDER = [];
function record(data) {
globalThis.GLOBAL_ORDER.push(data);
console.log(data);
}
before(function() {
record(`before one: ${this.name}`);
});
beforeEach(function() {
record(`beforeEach one: ${this.name}`);
});
after(function() {
record(`after one: ${this.name}`);
});
afterEach(function() {
record(`afterEach one: ${this.name}`);
});
suite('suite one', function() {
record(this.name);
test('suite one - test', { only: true }, function() {
record(this.name);
});
});
test('test one', function() {
record(this.name);
});

View File

@ -0,0 +1,35 @@
'use strict';
const { before, beforeEach, after, afterEach, test, suite } = require('node:test');
function record(data) {
globalThis.GLOBAL_ORDER.push(data);
console.log(data);
}
before(function() {
record(`before two: ${this.name}`);
});
beforeEach(function() {
record(`beforeEach two: ${this.name}`);
});
after(function() {
record(`after two: ${this.name}`);
});
afterEach(function() {
record(`afterEach two: ${this.name}`);
});
suite('suite two', function() {
record(this.name);
before(function() {
record(`before suite two: ${this.name}`);
});
test('suite two - test', { only: true }, function() {
record(this.name);
});
});

View File

@ -0,0 +1,8 @@
module.exports = async function * customReporter(source) {
const counters = {};
for await (const event of source) {
counters[event.type] = (counters[event.type] ?? 0) + 1;
}
yield "package: reporter-cjs";
yield JSON.stringify(counters);
};

View File

@ -0,0 +1,4 @@
{
"name": "reporter-cjs",
"main": "index.js"
}

View File

@ -0,0 +1,8 @@
export default async function * customReporter(source) {
const counters = {};
for await (const event of source) {
counters[event.type] = (counters[event.type] ?? 0) + 1;
}
yield "package: reporter-esm";
yield JSON.stringify(counters);
};

View File

@ -0,0 +1,4 @@
{
"name": "reporter-esm",
"exports": "./index.mjs"
}

View File

@ -0,0 +1,14 @@
'use strict';
const { test } = require('node:test');
test('test that aborts', (t, done) => {
t.after(() => {
// This should still run.
console.log('AFTER');
});
setImmediate(() => {
// This creates an uncaughtException, which aborts the test.
throw new Error('boom');
});
});

View File

@ -0,0 +1,24 @@
TAP version 13
AFTER
# Subtest: test that aborts
not ok 1 - test that aborts
---
duration_ms: *
type: 'test'
location: '/test/fixtures/test-runner/output/abort-runs-after-hook.js:(LINE):1'
failureType: 'uncaughtException'
error: 'boom'
code: 'ERR_TEST_FAILURE'
stack: |-
*
*
...
1..1
# tests 1
# suites 0
# pass 0
# fail 1
# cancelled 0
# skipped 0
# todo 0
# duration_ms *

View File

@ -0,0 +1,46 @@
'use strict';
require('../../../common');
const test = require('node:test');
test('promise timeout signal', { signal: AbortSignal.timeout(1) }, async (t) => {
await Promise.all([
t.test('ok 1', async () => {}),
t.test('ok 2', () => {}),
t.test('ok 3', { signal: t.signal }, async () => {}),
t.test('ok 4', { signal: t.signal }, () => {}),
t.test('not ok 1', () => new Promise(() => {})),
t.test('not ok 2', (t, done) => {}),
t.test('not ok 3', { signal: t.signal }, () => new Promise(() => {})),
t.test('not ok 4', { signal: t.signal }, (t, done) => {}),
t.test('not ok 5', { signal: t.signal }, (t, done) => {
t.signal.addEventListener('abort', done);
}),
]);
});
test('promise abort signal', { signal: AbortSignal.abort() }, async (t) => {
await t.test('should not appear', () => {});
});
test('callback timeout signal', { signal: AbortSignal.timeout(1) }, (t, done) => {
t.test('ok 1', async () => {});
t.test('ok 2', () => {});
t.test('ok 3', { signal: t.signal }, async () => {});
t.test('ok 4', { signal: t.signal }, () => {});
t.test('not ok 1', () => new Promise(() => {}));
t.test('not ok 2', (t, done) => {});
t.test('not ok 3', { signal: t.signal }, () => new Promise(() => {}));
t.test('not ok 4', { signal: t.signal }, (t, done) => {});
t.test('not ok 5', { signal: t.signal }, (t, done) => {
t.signal.addEventListener('abort', done);
});
});
test('callback abort signal', { signal: AbortSignal.abort() }, (t, done) => {
t.test('should not appear', done);
});
// AbortSignal.timeout(1) doesn't prevent process from closing
// thus we have to keep the process open to prevent cancelation
// of the entire test tree
setTimeout(() => {}, 1000);

View File

@ -0,0 +1,308 @@
TAP version 13
# Subtest: promise timeout signal
# Subtest: ok 1
ok 1 - ok 1
---
duration_ms: *
type: 'test'
...
# Subtest: ok 2
ok 2 - ok 2
---
duration_ms: *
type: 'test'
...
# Subtest: ok 3
ok 3 - ok 3
---
duration_ms: *
type: 'test'
...
# Subtest: ok 4
ok 4 - ok 4
---
duration_ms: *
type: 'test'
...
# Subtest: not ok 1
not ok 5 - not ok 1
---
duration_ms: *
type: 'test'
location: '/test/fixtures/test-runner/output/abort.js:(LINE):7'
failureType: 'cancelledByParent'
error: 'test did not finish before its parent and was cancelled'
code: 'ERR_TEST_FAILURE'
...
# Subtest: not ok 2
not ok 6 - not ok 2
---
duration_ms: *
type: 'test'
location: '/test/fixtures/test-runner/output/abort.js:(LINE):7'
failureType: 'cancelledByParent'
error: 'test did not finish before its parent and was cancelled'
code: 'ERR_TEST_FAILURE'
...
# Subtest: not ok 3
not ok 7 - not ok 3
---
duration_ms: *
type: 'test'
location: '/test/fixtures/test-runner/output/abort.js:(LINE):7'
failureType: 'testAborted'
error: 'This operation was aborted'
code: 20
name: 'AbortError'
stack: |-
*
*
*
*
*
*
*
*
*
*
...
# Subtest: not ok 4
not ok 8 - not ok 4
---
duration_ms: *
type: 'test'
location: '/test/fixtures/test-runner/output/abort.js:(LINE):7'
failureType: 'testAborted'
error: 'This operation was aborted'
code: 20
name: 'AbortError'
stack: |-
*
*
*
*
*
*
*
*
*
*
...
# Subtest: not ok 5
not ok 9 - not ok 5
---
duration_ms: *
type: 'test'
location: '/test/fixtures/test-runner/output/abort.js:(LINE):7'
failureType: 'testAborted'
error: 'This operation was aborted'
code: 20
name: 'AbortError'
stack: |-
*
*
*
*
*
*
*
*
*
*
...
1..9
not ok 1 - promise timeout signal
---
duration_ms: *
type: 'test'
location: '/test/fixtures/test-runner/output/abort.js:(LINE):1'
failureType: 'testAborted'
error: 'The operation was aborted due to timeout'
code: 23
name: 'TimeoutError'
stack: |-
*
*
*
*
...
# Subtest: promise abort signal
not ok 2 - promise abort signal
---
duration_ms: *
type: 'test'
location: '/test/fixtures/test-runner/output/abort.js:(LINE):1'
failureType: 'testAborted'
error: 'This operation was aborted'
code: 20
name: 'AbortError'
stack: |-
*
*
*
*
*
*
*
*
*
*
...
# Subtest: callback timeout signal
# Subtest: ok 1
ok 1 - ok 1
---
duration_ms: *
type: 'test'
...
# Subtest: ok 2
ok 2 - ok 2
---
duration_ms: *
type: 'test'
...
# Subtest: ok 3
ok 3 - ok 3
---
duration_ms: *
type: 'test'
...
# Subtest: ok 4
ok 4 - ok 4
---
duration_ms: *
type: 'test'
...
# Subtest: not ok 1
not ok 5 - not ok 1
---
duration_ms: *
type: 'test'
location: '/test/fixtures/test-runner/output/abort.js:(LINE):5'
failureType: 'cancelledByParent'
error: 'test did not finish before its parent and was cancelled'
code: 'ERR_TEST_FAILURE'
...
# Subtest: not ok 2
not ok 6 - not ok 2
---
duration_ms: *
type: 'test'
location: '/test/fixtures/test-runner/output/abort.js:(LINE):5'
failureType: 'cancelledByParent'
error: 'test did not finish before its parent and was cancelled'
code: 'ERR_TEST_FAILURE'
...
# Subtest: not ok 3
not ok 7 - not ok 3
---
duration_ms: *
type: 'test'
location: '/test/fixtures/test-runner/output/abort.js:(LINE):5'
failureType: 'testAborted'
error: 'This operation was aborted'
code: 20
name: 'AbortError'
stack: |-
*
*
*
*
*
*
*
*
*
*
...
# Subtest: not ok 4
not ok 8 - not ok 4
---
duration_ms: *
type: 'test'
location: '/test/fixtures/test-runner/output/abort.js:(LINE):5'
failureType: 'testAborted'
error: 'This operation was aborted'
code: 20
name: 'AbortError'
stack: |-
*
*
*
*
*
*
*
*
*
*
...
# Subtest: not ok 5
not ok 9 - not ok 5
---
duration_ms: *
type: 'test'
location: '/test/fixtures/test-runner/output/abort.js:(LINE):5'
failureType: 'testAborted'
error: 'This operation was aborted'
code: 20
name: 'AbortError'
stack: |-
*
*
*
*
*
*
*
*
*
*
...
1..9
not ok 3 - callback timeout signal
---
duration_ms: *
type: 'test'
location: '/test/fixtures/test-runner/output/abort.js:(LINE):1'
failureType: 'testAborted'
error: 'The operation was aborted due to timeout'
code: 23
name: 'TimeoutError'
stack: |-
*
*
*
*
...
# Subtest: callback abort signal
not ok 4 - callback abort signal
---
duration_ms: *
type: 'test'
location: '/test/fixtures/test-runner/output/abort.js:(LINE):1'
failureType: 'testAborted'
error: 'This operation was aborted'
code: 20
name: 'AbortError'
stack: |-
*
*
*
*
*
*
*
*
*
*
...
1..4
# tests 22
# suites 0
# pass 8
# fail 0
# cancelled 14
# skipped 0
# todo 0
# duration_ms *

View File

@ -0,0 +1,62 @@
'use strict';
const { before, beforeEach, describe, it, after, afterEach } = require('node:test');
describe('1 before describe', () => {
const ac = new AbortController();
before(() => {
console.log('before');
ac.abort();
}, { signal: ac.signal });
it('test 1', () => {
console.log('1.1');
});
it('test 2', () => {
console.log('1.2');
});
});
describe('2 after describe', () => {
const ac = new AbortController();
after(() => {
console.log('after');
ac.abort();
}, { signal: ac.signal });
it('test 1', () => {
console.log('2.1');
});
it('test 2', () => {
console.log('2.2');
});
});
describe('3 beforeEach describe', () => {
const ac = new AbortController();
beforeEach(() => {
console.log('beforeEach');
ac.abort();
}, { signal: ac.signal });
it('test 1', () => {
console.log('3.1');
});
it('test 2', () => {
console.log('3.2');
});
});
describe('4 afterEach describe', () => {
const ac = new AbortController();
afterEach(() => {
console.log('afterEach');
ac.abort();
}, { signal: ac.signal });
it('test 1', () => {
console.log('4.1');
});
it('test 2', () => {
console.log('4.2');
});
});

View File

@ -0,0 +1,206 @@
before
2.1
2.2
after
beforeEach
4.1
afterEach
4.2
TAP version 13
# Subtest: 1 before describe
# Subtest: test 1
not ok 1 - test 1
---
duration_ms: *
type: 'test'
location: '/test/fixtures/test-runner/output/abort_hooks.js:(LINE):3'
failureType: 'cancelledByParent'
error: 'test did not finish before its parent and was cancelled'
code: 'ERR_TEST_FAILURE'
...
# Subtest: test 2
not ok 2 - test 2
---
duration_ms: *
type: 'test'
location: '/test/fixtures/test-runner/output/abort_hooks.js:(LINE):3'
failureType: 'cancelledByParent'
error: 'test did not finish before its parent and was cancelled'
code: 'ERR_TEST_FAILURE'
...
1..2
not ok 1 - 1 before describe
---
duration_ms: *
type: 'suite'
location: '/test/fixtures/test-runner/output/abort_hooks.js:(LINE):1'
failureType: 'hookFailed'
error: 'This operation was aborted'
code: 20
name: 'AbortError'
stack: |-
*
*
*
*
*
*
*
*
*
*
...
# Subtest: 2 after describe
# Subtest: test 1
ok 1 - test 1
---
duration_ms: *
type: 'test'
...
# Subtest: test 2
ok 2 - test 2
---
duration_ms: *
type: 'test'
...
1..2
not ok 2 - 2 after describe
---
duration_ms: *
type: 'suite'
location: '/test/fixtures/test-runner/output/abort_hooks.js:(LINE):1'
failureType: 'hookFailed'
error: 'This operation was aborted'
code: 20
name: 'AbortError'
stack: |-
*
*
*
*
*
*
*
*
*
*
...
# Subtest: 3 beforeEach describe
# Subtest: test 1
not ok 1 - test 1
---
duration_ms: *
type: 'test'
location: '/test/fixtures/test-runner/output/abort_hooks.js:(LINE):3'
failureType: 'hookFailed'
error: 'This operation was aborted'
code: 20
name: 'AbortError'
stack: |-
*
*
*
*
*
*
*
*
*
*
...
# Subtest: test 2
not ok 2 - test 2
---
duration_ms: *
type: 'test'
location: '/test/fixtures/test-runner/output/abort_hooks.js:(LINE):3'
failureType: 'hookFailed'
error: 'This operation was aborted'
code: 20
name: 'AbortError'
stack: |-
*
*
*
*
*
*
*
*
*
*
...
1..2
not ok 3 - 3 beforeEach describe
---
duration_ms: *
type: 'suite'
location: '/test/fixtures/test-runner/output/abort_hooks.js:(LINE):1'
failureType: 'subtestsFailed'
error: '2 subtests failed'
code: 'ERR_TEST_FAILURE'
...
# Subtest: 4 afterEach describe
# Subtest: test 1
not ok 1 - test 1
---
duration_ms: *
type: 'test'
location: '/test/fixtures/test-runner/output/abort_hooks.js:(LINE):3'
failureType: 'hookFailed'
error: 'This operation was aborted'
code: 20
name: 'AbortError'
stack: |-
*
*
*
*
*
*
*
*
*
*
...
# Subtest: test 2
not ok 2 - test 2
---
duration_ms: *
type: 'test'
location: '/test/fixtures/test-runner/output/abort_hooks.js:(LINE):3'
failureType: 'hookFailed'
error: 'This operation was aborted'
code: 20
name: 'AbortError'
stack: |-
*
*
*
*
*
*
*
*
*
*
...
1..2
not ok 4 - 4 afterEach describe
---
duration_ms: *
type: 'suite'
location: '/test/fixtures/test-runner/output/abort_hooks.js:(LINE):1'
failureType: 'subtestsFailed'
error: '2 subtests failed'
code: 'ERR_TEST_FAILURE'
...
1..4
# tests 8
# suites 4
# pass 2
# fail 4
# cancelled 2
# skipped 0
# todo 0
# duration_ms *

View File

@ -0,0 +1,26 @@
'use strict';
require('../../../common');
const { describe, it } = require('node:test');
describe('describe timeout signal', { signal: AbortSignal.timeout(1) }, (t) => {
it('ok 1', async () => {});
it('ok 2', () => {});
it('ok 3', { signal: t.signal }, async () => {});
it('ok 4', { signal: t.signal }, () => {});
it('not ok 1', () => new Promise(() => {}));
it('not ok 2', (done) => {});
it('not ok 3', { signal: t.signal }, () => new Promise(() => {}));
it('not ok 4', { signal: t.signal }, (done) => {});
it('not ok 5', { signal: t.signal }, function(done) {
this.signal.addEventListener('abort', done);
});
});
describe('describe abort signal', { signal: AbortSignal.abort() }, () => {
it('should not appear', () => {});
});
// AbortSignal.timeout(1) doesn't prevent process from closing
// thus we have to keep the process open to prevent cancelation
// of the entire test tree
setTimeout(() => {}, 1000);

View File

@ -0,0 +1,159 @@
TAP version 13
# Subtest: describe timeout signal
# Subtest: ok 1
ok 1 - ok 1
---
duration_ms: *
type: 'test'
...
# Subtest: ok 2
ok 2 - ok 2
---
duration_ms: *
type: 'test'
...
# Subtest: ok 3
ok 3 - ok 3
---
duration_ms: *
type: 'test'
...
# Subtest: ok 4
ok 4 - ok 4
---
duration_ms: *
type: 'test'
...
# Subtest: not ok 1
not ok 5 - not ok 1
---
duration_ms: *
type: 'test'
location: '/test/fixtures/test-runner/output/abort_suite.js:(LINE):3'
failureType: 'cancelledByParent'
error: 'test did not finish before its parent and was cancelled'
code: 'ERR_TEST_FAILURE'
...
# Subtest: not ok 2
not ok 6 - not ok 2
---
duration_ms: *
type: 'test'
location: '/test/fixtures/test-runner/output/abort_suite.js:(LINE):3'
failureType: 'cancelledByParent'
error: 'test did not finish before its parent and was cancelled'
code: 'ERR_TEST_FAILURE'
...
# Subtest: not ok 3
not ok 7 - not ok 3
---
duration_ms: *
type: 'test'
location: '/test/fixtures/test-runner/output/abort_suite.js:(LINE):3'
failureType: 'testAborted'
error: 'This operation was aborted'
code: 20
name: 'AbortError'
stack: |-
*
*
*
*
*
*
*
*
*
*
...
# Subtest: not ok 4
not ok 8 - not ok 4
---
duration_ms: *
type: 'test'
location: '/test/fixtures/test-runner/output/abort_suite.js:(LINE):3'
failureType: 'testAborted'
error: 'This operation was aborted'
code: 20
name: 'AbortError'
stack: |-
*
*
*
*
*
*
*
*
*
*
...
# Subtest: not ok 5
not ok 9 - not ok 5
---
duration_ms: *
type: 'test'
location: '/test/fixtures/test-runner/output/abort_suite.js:(LINE):3'
failureType: 'testAborted'
error: 'This operation was aborted'
code: 20
name: 'AbortError'
stack: |-
*
*
*
*
*
*
*
*
*
*
...
1..9
not ok 1 - describe timeout signal
---
duration_ms: *
type: 'suite'
location: '/test/fixtures/test-runner/output/abort_suite.js:(LINE):1'
failureType: 'testAborted'
error: 'The operation was aborted due to timeout'
code: 23
name: 'TimeoutError'
stack: |-
*
*
*
*
...
# Subtest: describe abort signal
not ok 2 - describe abort signal
---
duration_ms: *
type: 'suite'
location: '/test/fixtures/test-runner/output/abort_suite.js:(LINE):1'
failureType: 'testAborted'
error: 'This operation was aborted'
code: 20
name: 'AbortError'
stack: |-
*
*
*
*
*
*
*
*
*
*
...
1..2
# tests 9
# suites 2
# pass 4
# fail 0
# cancelled 5
# skipped 0
# todo 0
# duration_ms *

View File

@ -0,0 +1,7 @@
'use strict';
const test = require('node:test');
console.log({ foo: 'bar' });
test('passing test', () => {
console.log(1);
});

View File

@ -0,0 +1,15 @@
'use strict';
const common = require('../../../common');
const { once } = require('node:events');
const { spawn } = require('node:child_process');
const fixtures = require('../../../common/fixtures');
(async function run() {
const test = fixtures.path('test-runner/output/arbitrary-output-colored-1.js');
const reset = fixtures.path('test-runner/output/reset-color-depth.js');
await once(spawn(process.execPath, ['-r', reset, '--test', test], { stdio: 'inherit' }), 'exit');
await once(
spawn(process.execPath, ['-r', reset, '--test', '--test-reporter', 'tap', test], { stdio: 'inherit' }),
'exit',
);
})().then(common.mustCall());

View File

@ -0,0 +1,29 @@
{ foo: [32m'bar'[39m }
[33m1[39m
[32m✔ passing test [90m(*ms)[39m[39m
[34mℹ tests 1[39m
[34mℹ suites 0[39m
[34mℹ pass 1[39m
[34mℹ fail 0[39m
[34mℹ cancelled 0[39m
[34mℹ skipped 0[39m
[34mℹ todo 0[39m
[34mℹ duration_ms *[39m
TAP version 13
# { foo: [32m'bar'[39m }
# [33m1[39m
# Subtest: passing test
ok 1 - passing test
---
duration_ms: *
type: 'test'
...
1..1
# tests 1
# suites 0
# pass 1
# fail 0
# cancelled 0
# skipped 0
# todo 0
# duration_ms *

View File

@ -0,0 +1,23 @@
// Flags: --test --expose-internals
'use strict';
const v8_reporter = require('internal/test_runner/reporter/v8-serializer');
const { Buffer } = require('buffer');
// eslint-disable-next-line node-core/async-iife-no-unused-result
(async function() {
const reported = v8_reporter([
{
type: 'test:pass',
data: { name: 'test', nesting: 0, file: __filename, testNumber: 1, details: { duration_ms: 0 } },
},
]);
for await (const chunk of reported) {
process.stdout.write(chunk);
process.stdout.write(Buffer.concat([Buffer.from('arbitrary - pre'), chunk]));
process.stdout.write(Buffer.from('arbitrary - mid'));
process.stdout.write(Buffer.concat([chunk, Buffer.from('arbitrary - post')]));
}
})();

View File

@ -0,0 +1,25 @@
TAP version 13
ok 1 - test
---
duration_ms: *
...
# arbitrary - pre
ok 2 - test
---
duration_ms: *
...
# arbitrary - mid
ok 3 - test
---
duration_ms: *
...
# arbitrary - post
1..3
# tests 3
# suites 0
# pass 3
# fail 0
# cancelled 0
# skipped 0
# todo 0
# duration_ms *

View File

@ -0,0 +1,6 @@
import assert from 'node:assert/strict';
import { test } from 'node:test';
test('failing assertion', () => {
assert.strictEqual('!Hello World', 'Hello World!');
});

View File

@ -0,0 +1,25 @@
[31m✖ failing assertion [90m(*ms)[39m[39m
[34mℹ tests 1[39m
[34mℹ suites 0[39m
[34mℹ pass 0[39m
[34mℹ fail 1[39m
[34mℹ cancelled 0[39m
[34mℹ skipped 0[39m
[34mℹ todo 0[39m
[34mℹ duration_ms *[39m
[31m✖ failing tests:[39m
*
[31m✖ failing assertion [90m(*ms)[39m[39m
[AssertionError [ERR_ASSERTION]: Expected values to be strictly equal:
[32mactual[39m [31mexpected[39m
[39m'[39m[32m![39m[39mH[39m[39me[39m[39ml[39m[39ml[39m[39mo[39m[39m [39m[39mW[39m[39mo[39m[39mr[39m[39ml[39m[39md[39m[31m![39m[39m'[39m
] {
generatedMessage: [33mtrue[39m,
code: [32m'ERR_ASSERTION'[39m,
actual: [32m'!Hello World'[39m,
expected: [32m'Hello World!'[39m,
operator: [32m'strictEqual'[39m
}

View File

@ -0,0 +1,13 @@
import * as common from '../../../common/index.mjs';
import { describe, test } from 'node:test';
import { setTimeout } from 'node:timers/promises';
test('test', common.mustCall());
describe('suite', common.mustCall(async () => {
test('test', common.mustCall());
await setTimeout(10);
test('scheduled async', common.mustCall());
}));
await setTimeout(10);
test('scheduled async', common.mustCall());

Some files were not shown because too many files have changed in this diff Show More