-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Labels
enhancement: pending triagep2-to-be-discussedEnhancement under consideration (priority)Enhancement under consideration (priority)
Description
Clear and concise description of the problem
When tests that depend on other processes, like during loadtesting or long-running tests, tests that have a teardown process (using afterAll or afterEach) - it would be great to have an AbortSignal in the test itself that would abort when the run is cancelled (by pressing Q or CTRL+C) that would be used to abort the dependant processes.
Suggested solution
Roughly
import { it, expect } from 'vitest';
import { startServer, loadtest } from './my-tools';
it('should pass this long running test', async (ctx) => {
const server = await startServer();
const highestMemoryUsage = await loadtest({
server,
// the loadtest runs for a longer period of time, it'll use this signal to stop loadtesting earlier on run cancel
signal: ctx.signal,
});
expect(highestMemoryUsage).toBeLessThan(100);
});Alternative
import { it, expect } from 'vitest';
import { onCancel } from 'vitest/runners';
import { startServer, loadtest } from './my-tools';
const ctrl = new AbortController();
onCancel(() => ctrl.abort());
it('should pass this long running test', async (ctx) => {
const server = await startServer();
const highestMemoryUsage = await loadtest({
server,
// the loadtest runs for a longer period of time, it'll use this signal to stop loadtesting earlier on run cancel
signal: ctx.signal,
});
expect(highestMemoryUsage).toBeLessThan(100);
});Additional context
If terminating abruptly (double CTRL+C), the teardown wont happen leaving processes or services (like Docker containers) running after the tests end.
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that request the same feature to avoid creating a duplicate.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancement: pending triagep2-to-be-discussedEnhancement under consideration (priority)Enhancement under consideration (priority)
Type
Projects
Status
P2 - 2