Skip to content
Open
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 lib/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export default class Api extends Emittery {

const {providers = []} = this.options;

let testFiles;
let testFiles = [];
try {
testFiles = await globs.findTests({cwd: this.options.projectDir, ...apiOptions.globs});
if (typeof testFileSelector === 'function') {
Expand Down
4 changes: 2 additions & 2 deletions lib/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class ExecutionContext extends Assertions {

if (discarded) {
test.saveFirstError(new Error('Can’t commit a result that was previously discarded'));
throw this.testFailure;
throw test.testFailure;
}

committed = true;
Expand All @@ -154,7 +154,7 @@ class ExecutionContext extends Assertions {
discard({retainLogs = false} = {}) {
if (committed) {
test.saveFirstError(new Error('Can’t discard a result that was previously committed'));
throw this.testFailure;
throw test.testFailure;
}

if (discarded) {
Expand Down
21 changes: 21 additions & 0 deletions test-tap/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,27 @@ const options = [
];

for (const opt of options) {
test(`propagates glob errors - workerThreads: ${opt.workerThreads}`, async t => {
const invalidProjectDir = path.join(__dirname, 'fixture', 'fail-fast', 'single-file', 'test.cjs');
const api = await apiCreator({
...opt,
projectDir: invalidProjectDir,
});

const errors = [];
api.on('run', plan => {
plan.status.on('stateChange', event => {
if (event.type === 'internal-error') {
errors.push(event.err);
}
});
});

const runStatus = await api.run();
t.equal(runStatus.stats.internalErrors, 1);
t.equal(errors.length, 1);
t.match(errors[0].message, /cwd.*directory/);
});
test(`fail-fast mode - workerThreads: ${opt.workerThreads} - single file & serial`, async t => {
const api = await apiCreator({
...opt,
Expand Down
19 changes: 19 additions & 0 deletions test/multiple-implementations/fixtures/try-guards.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import test from 'ava';

test('commit after discard throws', async t => {
const attempt = await t.try(tt => {
tt.pass();
});

attempt.discard();
attempt.commit();
});

test('discard after commit throws', async t => {
const attempt = await t.try(tt => {
tt.pass();
});

attempt.commit();
attempt.discard();
});
6 changes: 6 additions & 0 deletions test/multiple-implementations/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,9 @@ test('t.try()', async t => {
const result = await t.throwsAsync(fixture(['try.js']));
t.regex(result.stdout, /Expected an implementation/);
});

test('t.try() guardrails report errors', async t => {
const result = await t.throwsAsync(fixture(['try-guards.js']));
t.regex(result.stdout, /Can’t commit a result that was previously discarded/);
t.regex(result.stdout, /Can’t discard a result that was previously committed/);
});