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

refactor: rewrite tests in std/ to use Deno.test #3930

Merged
merged 28 commits into from
Feb 11, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Next Next commit
fix runIfMain
  • Loading branch information
bartlomieju committed Feb 1, 2020
commit 339868df6b5511c585a389786bf82ece48af8e88
31 changes: 22 additions & 9 deletions std/testing/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,19 +109,19 @@ interface TestCase {

export interface RunTestsOptions {
exitOnFail?: boolean;
// only?: RegExp;
// skip?: RegExp;
// disableLog?: boolean;
only?: RegExp;
skip?: RegExp;
disableLog?: boolean;
}

export async function runTests({
exitOnFail = false
exitOnFail = false,
only = /[^\s]/,
skip = /^\s*$/,
}: RunTestsOptions = {}): Promise<void> {
// TODO: add filtering
const testsToRun = TEST_REGISTRY;
// const testsToRun = TEST_REGISTRY.filter(
// ({ name }): boolean => include.test(name) && !exclude.test(name)
// );
const testsToRun = TEST_REGISTRY.filter(
({ name }): boolean => only.test(name) && !skip.test(name)
);

const stats: TestStats = {
measured: 0,
Expand Down Expand Up @@ -194,3 +194,16 @@ export async function runTests({
}, 0);
}
}


/**
* Runs specified test cases if the enclosing script is main.
*/
export async function runIfMain(
meta: ImportMeta,
opts?: RunTestsOptions
): Promise<void> {
if (meta.main) {
return runTests(opts);
}
}
15 changes: 6 additions & 9 deletions std/testing/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ export interface RunTestModulesOptions extends RunTestsOptions {
include?: string[];
exclude?: string[];
allowNone?: boolean;
disableLog?: boolean;
}

/**
Expand Down Expand Up @@ -169,10 +168,9 @@ export async function runTestModules({
include = ["."],
exclude = [],
allowNone = false,
// parallel = false,
exitOnFail = false,
// only = /[^\s]/,
// skip = /^\s*$/,
only = /[^\s]/,
skip = /^\s*$/,
disableLog = false
}: RunTestModulesOptions = {}): Promise<void> {
let moduleCount = 0;
Expand Down Expand Up @@ -235,11 +233,10 @@ export async function runTestModules({
}

await runTests({
// parallel,
exitOnFail
// only,
// skip,
// disableLog
exitOnFail,
only,
skip,
disableLog
});
}

Expand Down