Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set test.meta.debugMode = true when timeout has been disabled for debugging #3152

Open
bitjson opened this issue Jan 13, 2023 · 3 comments
Open
Labels

Comments

@bitjson
Copy link
Contributor

bitjson commented Jan 13, 2023

I'm using AVA to test a program that interacts with a Postgres database and has timing-related tests (code here).

I'm analyzing the stdout from a child process to verify it's producing the expected results. Results can sometimes come in unexpected orders, so I need close control over how long to wait for each, and timers run in parallel, so t.timeout() isn't really a good fit.

It's easy enough to manage the timers myself, but one inconvenience is that I need to manually disable them when debugging the tests. (AVA logs ⚠ The timeout option has been disabled to help with debugging. which is perfect, but my timers still interfere with debugging.)

Also, my tests can't inspect whether or not the inspector is active for some reason (probably something about them being in separate processes?) so I can't use the same code as AVA here:

ava/lib/cli.js

Lines 122 to 133 in 639b905

// Enter debug mode if the main process is being inspected. This assumes the
// worker processes are automatically inspected, too. It is not necessary to
// run AVA with the debug command, though it's allowed.
let activeInspector = false;
try {
const {default: inspector} = await import('node:inspector');
activeInspector = inspector.url() !== undefined;
} catch {}
let debug = activeInspector
? {

It would be very helpful if AVA somehow exposed this boolean to my tests so I can have them deliberately behave differently in debug mode. Maybe by adding it to test.meta? E.g.:

if(test.meta.debugMode) {
  // code to run if AVA is in debugging mode
}
@novemberborn novemberborn added enhancement new functionality help wanted and removed question labels Jan 15, 2023
@novemberborn
Copy link
Member

I like it!

@bitjson are you game to implement this? Let me know if you need some pointers.

@bitjson
Copy link
Contributor Author

bitjson commented Jan 19, 2023

@novemberborn I'd be happy to try! Though I'll need help with testing the feature.

I tried hacking something together initially, but I probably need a better understanding of the codebase. Could you point me to the location where test.meta is actually set?

@novemberborn
Copy link
Member

Hi @bitjson, I think the meta object is defined here:

ava/lib/runner.js

Lines 71 to 77 in c749348

const meta = Object.freeze({
file: makeFileURL(options.file),
get snapshotDirectory() {
const {file, snapshotDir: fixedLocation, projectDir} = options;
return makeFileURL(determineSnapshotDir({file, fixedLocation, projectDir}));
},
});

It's then made available through the CJS and ESM entrypoints and some indirection.

Runner is instantiated here:

runner = new Runner({

The options there should have the debug flag, see further down:

if (options.debug && options.debug.port !== undefined && options.debug.host !== undefined) {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants