diff --git a/.github/workflows/pr-leia-tests.yml b/.github/workflows/pr-leia-tests.yml index 1693ae1..0dbd962 100644 --- a/.github/workflows/pr-leia-tests.yml +++ b/.github/workflows/pr-leia-tests.yml @@ -46,4 +46,4 @@ jobs: # Try a comma separated list of headers npx leia examples/custom-headers.md -s Blue,No,Yellow,Hello -t Sup -c Goodbye # Assess envvars - npx leia examples/environment.md examples/basic-example.md --retry 4 + npx leia examples/environment.md examples/basic-example.md --retry 4 --timeout 1 diff --git a/CHANGELOG.md b/CHANGELOG.md index 60c2ee9..18e2a4c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ ## {{ UNRELEASED_VERSION }} - [{{ UNRELEASED_DATE }}]({{ UNRELEASED_LINK }}) +* Added a `--timeout` option * Changed default `timeout` to 30 minutes * Improved usage in `--help` * Removed misleading `shell` debugging diff --git a/cli/default.js b/cli/default.js index 941a260..4b83c31 100644 --- a/cli/default.js +++ b/cli/default.js @@ -139,20 +139,20 @@ class LeiaCommand extends Command { // Combine all patterns and search for the things const files = leia.find(options.tests, options.ignore); - debug('detected possible test source files: %s', files.join(', ')); + debug('detected possible test source files: %o', files.join(', ')); // Combine our args and options const sources = leia.parse(files, options); - debug('detected valid test sources %s', _.map(sources, 'file').join(', ')); + debug('detected valid test sources %o', _.map(sources, 'file').join(', ')); // Generate test files from parsed data and return list of generated files const tests = leia.generate(sources); - debug('generated leia tests to %s', tests.join(', ')); + debug('generated leia tests to %o', tests.join(', ')); // Get the test runner and execute - const runner = leia.run(tests); + const runner = leia.run(tests, options); runner.run((failures) => { - debug('tests completed with %s failures', failures); + debug('tests completed with %o failures', failures); process.exitCode = failures ? 1 : 0; }); } diff --git a/lib/generate.js b/lib/generate.js index 8fc2a47..94f50a1 100644 --- a/lib/generate.js +++ b/lib/generate.js @@ -34,13 +34,13 @@ module.exports = (tests, opts = {strip: false}) => { const templateFile = path.join(templateDir, 'leia.test.jst'); // Get render function - debug('getting render function using template: %s and opts: %o', templateDir, opts); + debug('getting render function using template: %o and opts: %o', templateDir, opts); const render = getRenderFunction(templateFile, opts); // Loop through our tests and dump stuff _.forEach(tests, (test) => { // @TODO: do we want a stronger check that this dir is set up how we need it? - debug('insuring directory exists and is ready to go %s ', path.dirname(test.destination)); + debug('insuring directory exists and is ready to go %o ', path.dirname(test.destination)); fs.mkdirpSync(path.dirname(test.destination)); // Build and generate all our test scripts and make them executable @@ -48,7 +48,7 @@ module.exports = (tests, opts = {strip: false}) => { .filter((value, key) => key !== 'invalid') .flatten() .map((data) => { - debug('generating script to %s and making it executable', data.script); + debug('generating script to %o and making it executable', data.script); fs.writeFileSync(data.script, data.command); fs.chmodSync(data.script, '755'); return data.script; @@ -56,7 +56,7 @@ module.exports = (tests, opts = {strip: false}) => { .value(); // Write the mocha test out - debug('generating test %s from %s to %s', test.id, test.file, test.destination); + debug('generating test %o from %o to %o', test.id, test.file, test.destination); fs.writeFileSync(test.destination, render(test)); }); diff --git a/lib/parse.js b/lib/parse.js index e3f01d7..a6e3e9d 100644 --- a/lib/parse.js +++ b/lib/parse.js @@ -170,14 +170,14 @@ module.exports = (files, { .map((datum) => { if (datum.type === 'heading' && datum.depth === 1) { const title = parseTitle(datum, {retry, stdin}); - debug('found test file candidate %s with title "%s"', title.text, title.file); + debug('found test file candidate %o with title "%o"', title.text, title.file); return title; } else return datum; }) .map((datum) => { if (datum.type === 'heading' && datum.depth === 2) { const section = parseSection(datum, {testHeader, setupHeader, cleanupHeader}); - debug('found %s testing section candidate "%s" in %s', section.test, section.text, section.file); + debug('found %o testing section candidate "%o" in %o', section.test, section.text, section.file); return section; } else return datum; }) @@ -186,7 +186,7 @@ module.exports = (files, { const codeblock = parseCode(_.assign(datum, {shell: getShell(shell)})); _.forEach(codeblock.code, (code) => { if (!_.isEmpty(code.describe)) { - debug('found test candidate "%s" in %s', _.first(code.describe), codeblock.file); + debug('found test candidate "%o" in %o', _.first(code.describe), codeblock.file); } }); return codeblock; @@ -206,7 +206,7 @@ module.exports = (files, { .map((pair) => ([pair[0], _.size(pair[1])])) .fromPairs() .value(); - debug('parsed %s and found these tests: %o', file.file, stats); + debug('parsed %o and found these tests: %o', file.file, stats); return file; }) // Return diff --git a/lib/run.js b/lib/run.js index c3f95eb..b828fd3 100644 --- a/lib/run.js +++ b/lib/run.js @@ -6,15 +6,18 @@ const debug = require('debug')('leia:run'); const Mocha = require('mocha'); module.exports = (tests, options) => { + // calculate the timeout + const timeout = parseInt(options?.timeout ?? 30) * 60 * 1000; + // Instantiate a Mocha instance. - const mocha = new Mocha(_.merge({}, {timeout: 1800000}, options)); + const mocha = new Mocha(_.merge({}, {timeout})); // Throw an error if there are no tests if (_.isEmpty(tests)) throw Error('You must pass in some tests!'); // Add all our tests _.forEach(tests, (test) => { - debug('adding %s to the test runner', test); + debug('adding %o to the test runner with timeout %o', test, timeout); mocha.addFile(test); });