What is the problem this feature will solve?
I'm sorry if there's already such a feature and I haven't found a way how to solve this. Basically what I'm looking for is to run some function that would run beofre all the tests and setup the environment. So far the only way how to setup some environment is doing it with the run function but that is only limited for each test suite from what I've tried. I would love to have the have some setup file in the way how does it work for example in jest or mocha or other testing framework.
What is the feature you are proposing to solve the problem?
Have a setup.js/setup.ts file that will run before all the tests, you would somehow specify in command that starts the tests this setup file.
What alternatives have you considered?
node version: v20.6.1
npm version: 9.8.1
I've tried this setup file
setup.ts
import { performance } from 'perf_hooks'
import { run } from 'node:test'
run({
files: ['src/node-test-runner/suite.test.ts'],
setup: () => {
let memStats: Record<string | number, number> = {};
const perf = performance;
const start = perf.now();
const cpuUsage = process.cpuUsage()
process.nextTick(() => {
const current = process.memoryUsage();
for (const key in current) {
memStats[key] = Math.max(memStats[key] ?? 0, current[key as keyof ReturnType<typeof process.memoryUsage>]);
}
});
process.on("exit", () => {
logger.info({
memStats,
timeMilliseconds: perf.now() - start,
cpuUsage: process.cpuUsage(cpuUsage),
pid: process.pid,
});
});
},
})
suite.test.ts
import { describe, it } from 'node:test'
import {equal} from 'node:assert'
import { testBody } from '../index'
import { logger } from '../logger'
const TEST_ITERATIONS = Number(process.env.TEST_ITERATIONS);
describe(__filename, () => {
it(`${__filename}`, async () => {
equal(true, true)
})
})
and I'm running this command to execute tests: node --require ts-node/register --test
but neither the setup.ts file is executed nor the suite.test.ts file is executed
What is the problem this feature will solve?
I'm sorry if there's already such a feature and I haven't found a way how to solve this. Basically what I'm looking for is to run some function that would run beofre all the tests and setup the environment. So far the only way how to setup some environment is doing it with the run function but that is only limited for each test suite from what I've tried. I would love to have the have some setup file in the way how does it work for example in jest or mocha or other testing framework.
What is the feature you are proposing to solve the problem?
Have a
setup.js/setup.tsfile that will run before all the tests, you would somehow specify in command that starts the tests this setup file.What alternatives have you considered?
node version:
v20.6.1npm version:
9.8.1I've tried this setup file
setup.tssuite.test.tsand I'm running this command to execute tests:
node --require ts-node/register --testbut neither the setup.ts file is executed nor the suite.test.ts file is executed