Skip to content

Commit

Permalink
Added a timeout option
Browse files Browse the repository at this point in the history
  • Loading branch information
pirog committed Jul 22, 2024
1 parent 95c7a4d commit f2900c1
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pr-leia-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
10 changes: 5 additions & 5 deletions cli/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
}
Expand Down
8 changes: 4 additions & 4 deletions lib/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,29 +34,29 @@ 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
_(test.tests)
.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;
})
.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));
});

Expand Down
8 changes: 4 additions & 4 deletions lib/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
})
Expand All @@ -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;
Expand All @@ -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
Expand Down
7 changes: 5 additions & 2 deletions lib/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

Expand Down

0 comments on commit f2900c1

Please sign in to comment.