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

Add debug hint for new users #194

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config.js
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ async function readConfigFile(configDir, env) {
}

/**
* @typedef {{no_external_locking?: boolean, no_locking?: boolean, locking_verbose?: boolean, external_locking_client?: string, external_locking_url?: string, expect_nothing?: boolean}} Config
* @typedef {{no_external_locking?: boolean, no_locking?: boolean, locking_verbose?: boolean, external_locking_client?: string, external_locking_url?: string, expect_nothing?: boolean, filter?: RegExp, forward_console?: boolean, keep_open?: boolean}} Config
*/

/**
Expand Down
1 change: 1 addition & 0 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ async function real_main(options={}) {
if (!test_info) return;

results = render.craftResults(config, test_info);
console.log(test_info);
}

await render.doRender(config, results);
Expand Down
33 changes: 29 additions & 4 deletions output.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,11 @@ function resultSummary(config, tasks, onTests=false) {
return res;
}


/**
* @param {import('./config').Config} config
* @param {import('./runner').RunnerState} state
* @private
*/
function finish(config, state) {
last_state = null;
const {tasks} = state;
Expand All @@ -213,10 +217,31 @@ function finish(config, state) {
print(resultSummary(config, tasks) + '\n');

const expectedToFail = tasks.filter(t => t.expectedToFail && t.status === 'error');

let hasHint = false;
if (!config.expect_nothing && (expectedToFail.length > 0)) {
let msg = color(config, 'gray', ' Pass in -E/--expect-nothing to ignore expectedToFail declarations.');
msg += '\n\n';
print(msg);
const msg = color(config, 'gray', ' Pass in -E/--expect-nothing to ignore expectedToFail declarations.');
print(msg + '\n');
hasHint = true;
}
const hasDebug = config.debug || config.forward_console || config.keep_open || config.devtools || config.devtools_preserve;
if ((!config.filter || !hasDebug) && utils.count(tasks, t => t.status === 'error' && (!t.expectedToFail || config.expect_nothing)) > 0) {
let msg = '';
if (!config.filter && !hasDebug) {
msg = ' Pass in -f/--filter REGEX and -d/--debug to inspect specific tests.';
} else if (!config.filter) {
msg = ' Pass in -f/--filter REGEX to inspect specific tests.';
} else if (!hasDebug) {
msg = ' Pass in -d/--debug to inspect tests.';
}

if (msg) {
print(color(config, 'gray', msg) + '\n');
hasHint = true;
}
}
if (hasHint) {
print('\n');
}

// Internal self-check
Expand Down
1 change: 1 addition & 0 deletions tests/debug_tests/config/local.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
8 changes: 8 additions & 0 deletions tests/debug_tests/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env node

const pentf = require('../../index.js');

pentf.main({
rootDir: __dirname,
testsDir: __dirname,
});
8 changes: 8 additions & 0 deletions tests/debug_tests/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
async function run() {
throw new Error('fail');
}

module.exports = {
run,
description: 'fail'
};
39 changes: 39 additions & 0 deletions tests/selftest_debug_hint.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const assert = require('assert').strict;
const path = require('path');
const child_process = require('child_process');

async function run() {
// Run in subprocess so that handle exhaustion does not affect this process
const sub_run = path.join(__dirname, 'debug_tests', 'run');

async function runPentf(...args) {
return await new Promise((resolve, reject) => {
child_process.execFile(
sub_run,
['--exit-zero', '--no-screenshots', ...args],
(err, stdout, stderr) => {
if (err) reject(err);
else resolve({stdout, stderr});
}
);
});
}

let stderr = (await runPentf()).stderr;
assert(/Pass in -f\/--filter REGEX and -d\/--debug to inspect specific tests/.test(stderr));

// stderr = (await runPentf('-d')).stderr;
// assert(/Pass in -f\/--filter REGEX to inspect specific tests/.test(stderr));

// stderr = (await runPentf('-f test')).stderr;
// assert(/Pass in -d\/--debug to inspect tests/.test(stderr));

// stderr = (await runPentf('-f test -d')).stderr;
// assert(!/Pass in/.test(stderr));
}

module.exports = {
description: 'Display debug hints',
resources: [],
run,
};
5 changes: 5 additions & 0 deletions utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ function arange(count) {
return Array.from(range(count));
}

/**
* @template T
* @param {T[]} ar
* @param {(item: T) => boolean} filter
*/
function count(ar, filter) {
let res = 0;
for (var el of ar) {
Expand Down