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

feat: support Deno.test.only #367

Merged
merged 2 commits into from
Feb 3, 2024
Merged
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
25 changes: 25 additions & 0 deletions lib/test_runner/test_runner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,31 @@ GokG
);
});

Deno.test("only test definitions", async () => {
const context = getContext();
await assertRejects(
async () => {
await runTestDefinitions([{
name: "won't run",
fn: () => {
throw new Error("FAIL");
},
}, {
only: true,
name: "my test",
fn: () => {}, // pass
}], context);
},
Error,
"Exit code 1 thrown.",
);
wildcardAssertEquals(
context.output,
`test my test[WILDCARD]
error: Test failed because the "only" option was used.\n`,
);
});

function getContext() {
let output = "";
return {
Expand Down
10 changes: 10 additions & 0 deletions lib/test_runner/test_runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export interface RunTestDefinitionsOptions {
export interface TestDefinition {
name: string;
fn: (context: TestContext) => Promise<void> | void;
only?: boolean;
ignore?: boolean;
}

Expand All @@ -46,6 +47,10 @@ export async function runTestDefinitions(
options: RunTestDefinitionsOptions,
) {
const testFailures = [];
const hasOnly = testDefinitions.some((d) => d.only);
if (hasOnly) {
testDefinitions = testDefinitions.filter((d) => d.only);
}
for (const definition of testDefinitions) {
options.process.stdout.write("test " + definition.name + " ...");
if (definition.ignore) {
Expand Down Expand Up @@ -87,6 +92,11 @@ export async function runTestDefinitions(
);
}
options.process.exit(1);
} else if (hasOnly) {
options.process.stdout.write(
'error: Test failed because the "only" option was used.\n',
);
options.process.exit(1);
}

function getTestContext(
Expand Down
Loading