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: test runner #516

Merged
merged 20 commits into from
Aug 15, 2019
Merged
Show file tree
Hide file tree
Changes from 9 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 .ci/template.common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ parameters:

steps:
- bash: deno${{ parameters.exe_suffix }} run --allow-run --allow-write --allow-read --allow-env ./format.ts --check
- bash: deno${{ parameters.exe_suffix }} run --allow-run --allow-net --allow-write --allow-read --allow-env --config=tsconfig.test.json ./test.ts
- bash: deno${{ parameters.exe_suffix }} run --allow-run --allow-net --allow-write --allow-read --allow-env --config=tsconfig.test.json ./testing/runner.ts --exclude node_modules/\* -- **/*_test.ts **/test.ts
4 changes: 0 additions & 4 deletions encoding/test.ts

This file was deleted.

14 changes: 0 additions & 14 deletions flags/test.ts

This file was deleted.

19 changes: 0 additions & 19 deletions fs/test.ts

This file was deleted.

5 changes: 0 additions & 5 deletions http/test.ts

This file was deleted.

6 changes: 0 additions & 6 deletions io/test.ts

This file was deleted.

3 changes: 0 additions & 3 deletions log/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ import { assertEquals } from "../testing/asserts.ts";
import * as log from "./mod.ts";
import { LogLevel } from "./levels.ts";

import "./handlers_test.ts";
import "./logger_test.ts";

class TestHandler extends log.handlers.BaseHandler {
public messages: string[] = [];

Expand Down
2 changes: 0 additions & 2 deletions mime/test.ts

This file was deleted.

2 changes: 0 additions & 2 deletions multipart/test.ts

This file was deleted.

1 change: 0 additions & 1 deletion prettier/test.ts

This file was deleted.

2 changes: 0 additions & 2 deletions strings/test.ts

This file was deleted.

65 changes: 0 additions & 65 deletions test.ts

This file was deleted.

100 changes: 100 additions & 0 deletions testing/runner.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
#!/usr/bin/env deno -A
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
import { parse } from "../flags/mod.ts";
import { glob, walk } from "../fs/mod.ts";
import { runTests } from "./mod.ts";
const { args, cwd } = Deno;

const DEFAULT_GLOBS = [
"**/*_test.ts",
"**/*_test.js",
"**/test.ts",
"**/test.js"
];

/* eslint-disable max-len */
function showHelp(): void {
console.log(`Deno test runner

USAGE:
deno -A https://deno.land/std/testing/runner.ts [OPTIONS] [FILES...]

OPTIONS:
-q, --quiet Don't show output from test cases
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--silent

Prevent tests from printing messages through the console.

-f, --failfast Stop test suite on first error
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--bail

Alias: -b. Exit the test suite immediately upon n number of failing test suite. Defaults to 1.

-e, --exclude <FILES...> List of file names to exclude from run. If this options is
used files to match must be specified after "--".
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--testPathIgnorePatterns=[array]

An array of regexp pattern strings that is tested against all tests paths before executing the test. Contrary to --testPathPattern, it will only run those test with a path that does not match with the provided regexp expressions.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I’m wondering if -x would be a better short name for this option if you keep the exclude name.


ARGS:
[FILES...] List of file names to run. Defaults to: ${DEFAULT_GLOBS.join(
","
)}
`);
}
/* eslint-enable max-len */

async function main(): Promise<void> {
const parsedArgs = parse(args.slice(1), {
boolean: ["quiet", "failfast", "help"],
string: ["exclude"],
alias: {
help: ["h"],
quiet: ["q"],
failfast: ["f"],
exclude: ["e"]
}
});

if (parsedArgs.help) {
return showHelp();
}

let includeFiles;
let excludeFiles;

if (parsedArgs._.length) {
includeFiles = (parsedArgs._ as string[])
.map(
(fileGlob: string): string[] => {
return fileGlob.split(",");
}
)
.flat();
} else {
includeFiles = DEFAULT_GLOBS;
}

if (parsedArgs.exclude) {
excludeFiles = (parsedArgs.exclude as string).split(",");
} else {
excludeFiles = [];
}

const filesIterator = walk(cwd(), {
bartlomieju marked this conversation as resolved.
Show resolved Hide resolved
match: includeFiles.map(glob),
skip: excludeFiles.map(glob)
});

const foundTestFiles: string[] = [];
for await (const { filename } of filesIterator) {
foundTestFiles.push(filename);
}

if (foundTestFiles.length === 0) {
console.error("No matching test files found.");
Deno.exit(0);
bartlomieju marked this conversation as resolved.
Show resolved Hide resolved
}

console.log(`Found ${foundTestFiles.length} matching test files.`);

for (const filename of foundTestFiles) {
await import(filename);
}

await runTests({
exitOnFail: !!parsedArgs.failfast,
disableLog: !!parsedArgs.quiet
});
bartlomieju marked this conversation as resolved.
Show resolved Hide resolved
}

main();
ry marked this conversation as resolved.
Show resolved Hide resolved
5 changes: 0 additions & 5 deletions testing/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@ import {
assertThrows,
assertThrowsAsync
} from "./asserts.ts";
import "./format_test.ts";
import "./diff_test.ts";
import "./pretty_test.ts";
import "./asserts_test.ts";
import "./bench_test.ts";

test(function testingAssertEqualActualUncoercable(): void {
let didThrow = false;
Expand Down
1 change: 0 additions & 1 deletion textproto/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import { append } from "./mod.ts";
import { assertEquals } from "../testing/asserts.ts";
import { test } from "../testing/mod.ts";
import "./reader_test.ts";

test(async function textprotoAppend(): Promise<void> {
const enc = new TextEncoder();
Expand Down
2 changes: 0 additions & 2 deletions util/test.ts

This file was deleted.

1 change: 0 additions & 1 deletion ws/test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
import "./sha1_test.ts";
import { BufReader } from "../io/bufio.ts";
import { assert, assertEquals } from "../testing/asserts.ts";
import { runIfMain, test } from "../testing/mod.ts";
Expand Down