diff --git a/std/archive/tar_test.ts b/std/archive/tar_test.ts index d317a89dd7..1bac623b09 100644 --- a/std/archive/tar_test.ts +++ b/std/archive/tar_test.ts @@ -8,7 +8,6 @@ * **to run this test** * deno run --allow-read archive/tar_test.ts */ -import { test, runIfMain } from "../testing/mod.ts"; import { assertEquals } from "../testing/asserts.ts"; import { resolve } from "../path/mod.ts"; @@ -16,7 +15,7 @@ import { Tar, Untar } from "./tar.ts"; const filePath = resolve("archive", "testdata", "example.txt"); -test(async function createTarArchive(): Promise { +Deno.test(async function createTarArchive(): Promise { // initialize const tar = new Tar(); @@ -41,7 +40,7 @@ test(async function createTarArchive(): Promise { assertEquals(wrote, 3072); }); -test(async function deflateTarArchive(): Promise { +Deno.test(async function deflateTarArchive(): Promise { const fileName = "output.txt"; const text = "hello tar world!"; @@ -64,7 +63,7 @@ test(async function deflateTarArchive(): Promise { assertEquals(untarText, text); }); -test(async function appendFileWithLongNameToTarArchive(): Promise { +Deno.test(async function appendFileWithLongNameToTarArchive(): Promise { // 9 * 15 + 13 = 148 bytes const fileName = new Array(10).join("long-file-name/") + "file-name.txt"; const text = "hello tar world!"; @@ -87,5 +86,3 @@ test(async function appendFileWithLongNameToTarArchive(): Promise { assertEquals(result.fileName, fileName); assertEquals(untarText, text); }); - -runIfMain(import.meta); diff --git a/std/bytes/test.ts b/std/bytes/test.ts index fc7089c2f8..c1609ebdc3 100644 --- a/std/bytes/test.ts +++ b/std/bytes/test.ts @@ -1,10 +1,9 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. import { findIndex, findLastIndex, equal, hasPrefix, repeat } from "./mod.ts"; -import { test } from "../testing/mod.ts"; import { assertEquals, assertThrows } from "../testing/asserts.ts"; -test(function bytesfindIndex1(): void { +Deno.test(function bytesfindIndex1(): void { const i = findIndex( new Uint8Array([1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 3]), new Uint8Array([0, 1, 2]) @@ -12,12 +11,12 @@ test(function bytesfindIndex1(): void { assertEquals(i, 2); }); -test(function bytesfindIndex2(): void { +Deno.test(function bytesfindIndex2(): void { const i = findIndex(new Uint8Array([0, 0, 1]), new Uint8Array([0, 1])); assertEquals(i, 1); }); -test(function bytesfindLastIndex1(): void { +Deno.test(function bytesfindLastIndex1(): void { const i = findLastIndex( new Uint8Array([0, 1, 2, 0, 1, 2, 0, 1, 3]), new Uint8Array([0, 1, 2]) @@ -25,22 +24,22 @@ test(function bytesfindLastIndex1(): void { assertEquals(i, 3); }); -test(function bytesfindLastIndex2(): void { +Deno.test(function bytesfindLastIndex2(): void { const i = findLastIndex(new Uint8Array([0, 1, 1]), new Uint8Array([0, 1])); assertEquals(i, 0); }); -test(function bytesBytesequal(): void { +Deno.test(function bytesBytesequal(): void { const v = equal(new Uint8Array([0, 1, 2, 3]), new Uint8Array([0, 1, 2, 3])); assertEquals(v, true); }); -test(function byteshasPrefix(): void { +Deno.test(function byteshasPrefix(): void { const v = hasPrefix(new Uint8Array([0, 1, 2]), new Uint8Array([0, 1])); assertEquals(v, true); }); -test(function bytesrepeat(): void { +Deno.test(function bytesrepeat(): void { // input / output / count / error message const repeatTestCase = [ ["", "", 0], diff --git a/std/datetime/test.ts b/std/datetime/test.ts index 1958c6fabb..979fd34bec 100644 --- a/std/datetime/test.ts +++ b/std/datetime/test.ts @@ -1,9 +1,8 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. -import { test } from "../testing/mod.ts"; import { assertEquals, assertThrows } from "../testing/asserts.ts"; import * as datetime from "./mod.ts"; -test(function parseDateTime(): void { +Deno.test(function parseDateTime(): void { assertEquals( datetime.parseDateTime("01-03-2019 16:30", "mm-dd-yyyy hh:mm"), new Date(2019, 0, 3, 16, 30) @@ -30,7 +29,7 @@ test(function parseDateTime(): void { ); }); -test(function invalidParseDateTimeFormatThrows(): void { +Deno.test(function invalidParseDateTimeFormatThrows(): void { assertThrows( (): void => { // eslint-disable-next-line @typescript-eslint/no-explicit-any @@ -41,7 +40,7 @@ test(function invalidParseDateTimeFormatThrows(): void { ); }); -test(function parseDate(): void { +Deno.test(function parseDate(): void { assertEquals( datetime.parseDate("01-03-2019", "mm-dd-yyyy"), new Date(2019, 0, 3) @@ -56,7 +55,7 @@ test(function parseDate(): void { ); }); -test(function invalidParseDateFormatThrows(): void { +Deno.test(function invalidParseDateFormatThrows(): void { assertThrows( (): void => { // eslint-disable-next-line @typescript-eslint/no-explicit-any @@ -67,17 +66,17 @@ test(function invalidParseDateFormatThrows(): void { ); }); -test(function DayOfYear(): void { +Deno.test(function DayOfYear(): void { assertEquals(1, datetime.dayOfYear(new Date("2019-01-01T03:24:00"))); assertEquals(70, datetime.dayOfYear(new Date("2019-03-11T03:24:00"))); assertEquals(365, datetime.dayOfYear(new Date("2019-12-31T03:24:00"))); }); -test(function currentDayOfYear(): void { +Deno.test(function currentDayOfYear(): void { assertEquals(datetime.currentDayOfYear(), datetime.dayOfYear(new Date())); }); -test({ +Deno.test({ name: "[DateTime] to IMF", fn(): void { const actual = datetime.toIMF(new Date(Date.UTC(1994, 3, 5, 15, 32))); @@ -86,7 +85,7 @@ test({ } }); -test({ +Deno.test({ name: "[DateTime] to IMF 0", fn(): void { const actual = datetime.toIMF(new Date(0)); diff --git a/std/encoding/base32_test.ts b/std/encoding/base32_test.ts index 6a8734fd01..eb51e44ab0 100644 --- a/std/encoding/base32_test.ts +++ b/std/encoding/base32_test.ts @@ -1,7 +1,6 @@ // Test cases copied from https://github.com/LinusU/base32-encode/blob/master/test.js // Copyright (c) 2016-2017 Linus Unnebäck. MIT license. // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. -import { test, runIfMain } from "../testing/mod.ts"; import { assertEquals, assert } from "../testing/asserts.ts"; import { encode, decode } from "./base32.ts"; @@ -87,7 +86,7 @@ const testCases = [ ] ]; -test({ +Deno.test({ name: "[encoding.base32] encode", fn(): void { for (const [bin, b32] of testCases) { @@ -96,7 +95,7 @@ test({ } }); -test({ +Deno.test({ name: "[encoding.base32] decode", fn(): void { for (const [bin, b32] of testCases) { @@ -105,7 +104,7 @@ test({ } }); -test({ +Deno.test({ name: "[encoding.base32] decode bad length", fn(): void { let errorCaught = false; @@ -121,7 +120,7 @@ test({ } }); -test({ +Deno.test({ name: "[encoding.base32] decode bad padding", fn(): void { let errorCaught = false; @@ -134,5 +133,3 @@ test({ assert(errorCaught); } }); - -runIfMain(import.meta); diff --git a/std/encoding/csv_test.ts b/std/encoding/csv_test.ts index 6c726835e9..74ba8face2 100644 --- a/std/encoding/csv_test.ts +++ b/std/encoding/csv_test.ts @@ -1,6 +1,5 @@ // Test ported from Golang // https://github.com/golang/go/blob/2cc15b1/src/encoding/csv/reader_test.go -import { test, runIfMain } from "../testing/mod.ts"; import { assertEquals, assert } from "../testing/asserts.ts"; import { readMatrix, parse } from "./csv.ts"; import { StringReader } from "../io/readers.ts"; @@ -450,7 +449,7 @@ x,,, } ]; for (const t of testCases) { - test({ + Deno.test({ name: `[CSV] ${t.Name}`, async fn(): Promise { let comma = ","; @@ -605,7 +604,7 @@ const parseTestCases = [ ]; for (const testCase of parseTestCases) { - test({ + Deno.test({ name: `[CSV] Parse ${testCase.name}`, async fn(): Promise { const r = await parse(testCase.in, { @@ -616,5 +615,3 @@ for (const testCase of parseTestCases) { } }); } - -runIfMain(import.meta); diff --git a/std/encoding/hex_test.ts b/std/encoding/hex_test.ts index 126aa8ac47..f98fe5422d 100644 --- a/std/encoding/hex_test.ts +++ b/std/encoding/hex_test.ts @@ -4,7 +4,6 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. -import { test, runIfMain } from "../testing/mod.ts"; import { assertEquals, assertThrows } from "../testing/asserts.ts"; import { @@ -46,7 +45,7 @@ const errCases = [ ["ffeed", "\xff\xee", errLength()] ]; -test({ +Deno.test({ name: "[encoding.hex] encodedLen", fn(): void { assertEquals(encodedLen(0), 0); @@ -57,7 +56,7 @@ test({ } }); -test({ +Deno.test({ name: "[encoding.hex] encode", fn(): void { { @@ -92,7 +91,7 @@ test({ } }); -test({ +Deno.test({ name: "[encoding.hex] encodeToString", fn(): void { for (const [enc, dec] of testCases) { @@ -101,7 +100,7 @@ test({ } }); -test({ +Deno.test({ name: "[encoding.hex] decodedLen", fn(): void { assertEquals(decodedLen(0), 0); @@ -112,7 +111,7 @@ test({ } }); -test({ +Deno.test({ name: "[encoding.hex] decode", fn(): void { // Case for decoding uppercase hex characters, since @@ -133,7 +132,7 @@ test({ } }); -test({ +Deno.test({ name: "[encoding.hex] decodeString", fn(): void { for (const [enc, dec] of testCases) { @@ -144,7 +143,7 @@ test({ } }); -test({ +Deno.test({ name: "[encoding.hex] decode error", fn(): void { for (const [input, output, expectedErr] of errCases) { @@ -159,7 +158,7 @@ test({ } }); -test({ +Deno.test({ name: "[encoding.hex] decodeString error", fn(): void { for (const [input, output, expectedErr] of errCases) { @@ -178,5 +177,3 @@ test({ } } }); - -runIfMain(import.meta); diff --git a/std/encoding/toml_test.ts b/std/encoding/toml_test.ts index 8dab996a60..f1f89b4289 100644 --- a/std/encoding/toml_test.ts +++ b/std/encoding/toml_test.ts @@ -1,5 +1,4 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. -import { runIfMain, test } from "../testing/mod.ts"; import { assertEquals } from "../testing/asserts.ts"; import { existsSync } from "../fs/exists.ts"; import { readFileStrSync } from "../fs/read_file_str.ts"; @@ -16,7 +15,7 @@ function parseFile(filePath: string): object { return parse(strFile); } -test({ +Deno.test({ name: "[TOML] Strings", fn(): void { const expected = { @@ -38,7 +37,7 @@ test({ } }); -test({ +Deno.test({ name: "[TOML] CRLF", fn(): void { const expected = { boolean: { bool1: true, bool2: false } }; @@ -47,7 +46,7 @@ test({ } }); -test({ +Deno.test({ name: "[TOML] Boolean", fn(): void { const expected = { boolean: { bool1: true, bool2: false } }; @@ -56,7 +55,7 @@ test({ } }); -test({ +Deno.test({ name: "[TOML] Integer", fn(): void { const expected = { @@ -81,7 +80,7 @@ test({ } }); -test({ +Deno.test({ name: "[TOML] Float", fn(): void { const expected = { @@ -107,7 +106,7 @@ test({ } }); -test({ +Deno.test({ name: "[TOML] Arrays", fn(): void { const expected = { @@ -124,7 +123,7 @@ test({ } }); -test({ +Deno.test({ name: "[TOML] Table", fn(): void { const expected = { @@ -157,7 +156,7 @@ test({ } }); -test({ +Deno.test({ name: "[TOML] Simple", fn(): void { const expected = { @@ -172,7 +171,7 @@ test({ } }); -test({ +Deno.test({ name: "[TOML] Datetime", fn(): void { const expected = { @@ -191,7 +190,7 @@ test({ } }); -test({ +Deno.test({ name: "[TOML] Inline Table", fn(): void { const expected = { @@ -236,7 +235,7 @@ test({ } }); -test({ +Deno.test({ name: "[TOML] Array of Tables", fn(): void { const expected = { @@ -251,7 +250,7 @@ test({ } }); -test({ +Deno.test({ name: "[TOML] Cargo", fn(): void { /* eslint-disable @typescript-eslint/camelcase */ @@ -298,7 +297,7 @@ test({ } }); -test({ +Deno.test({ name: "[TOML] Stringify", fn(): void { const src = { @@ -412,5 +411,3 @@ the = "array" assertEquals(actual, expected); } }); - -runIfMain(import.meta); diff --git a/std/encoding/yaml/parse_test.ts b/std/encoding/yaml/parse_test.ts index b7b742d61b..bdcd8db629 100644 --- a/std/encoding/yaml/parse_test.ts +++ b/std/encoding/yaml/parse_test.ts @@ -4,10 +4,9 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. import { parse, parseAll } from "./parse.ts"; -import { test } from "../../testing/mod.ts"; import { assertEquals } from "../../testing/asserts.ts"; -test({ +Deno.test({ name: "`parse` parses single document yaml string", fn(): void { const yaml = ` @@ -24,7 +23,7 @@ test({ } }); -test({ +Deno.test({ name: "`parseAll` parses the yaml string with multiple documents", fn(): void { const yaml = ` diff --git a/std/encoding/yaml/stringify_test.ts b/std/encoding/yaml/stringify_test.ts index ceedb7a3cb..941beb789f 100644 --- a/std/encoding/yaml/stringify_test.ts +++ b/std/encoding/yaml/stringify_test.ts @@ -3,11 +3,10 @@ // Copyright 2011-2015 by Vitaly Puzrin. All rights reserved. MIT license. // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. -import { test } from "../../testing/mod.ts"; import { assertEquals } from "../../testing/asserts.ts"; import { stringify } from "./stringify.ts"; -test({ +Deno.test({ name: "stringified correctly", fn(): void { const FIXTURE = { diff --git a/std/examples/test.ts b/std/examples/test.ts index 26dd989e47..641a2ef74b 100644 --- a/std/examples/test.ts +++ b/std/examples/test.ts @@ -1,19 +1,18 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. const { run } = Deno; -import { test } from "../testing/mod.ts"; import { assertEquals } from "../testing/asserts.ts"; /** Example of how to do basic tests */ -test(function t1(): void { +Deno.test(function t1(): void { assertEquals("hello", "hello"); }); -test(function t2(): void { +Deno.test(function t2(): void { assertEquals("world", "world"); }); /** A more complicated test that runs a subprocess. */ -test(async function catSmoke(): Promise { +Deno.test(async function catSmoke(): Promise { const p = run({ args: [ Deno.execPath(), diff --git a/std/examples/tests/xeval_test.ts b/std/examples/tests/xeval_test.ts index 1c4be1f957..bfd66c097c 100644 --- a/std/examples/tests/xeval_test.ts +++ b/std/examples/tests/xeval_test.ts @@ -6,16 +6,15 @@ import { assertStrContains, assert } from "../../testing/asserts.ts"; -import { test } from "../../testing/mod.ts"; const { execPath, run } = Deno; -test(async function xevalSuccess(): Promise { +Deno.test(async function xevalSuccess(): Promise { const chunks: string[] = []; await xeval(stringsReader("a\nb\nc"), ($): number => chunks.push($)); assertEquals(chunks, ["a", "b", "c"]); }); -test(async function xevalDelimiter(): Promise { +Deno.test(async function xevalDelimiter(): Promise { const chunks: string[] = []; await xeval(stringsReader("!MADMADAMADAM!"), ($): number => chunks.push($), { delimiter: "MADAM" @@ -26,7 +25,7 @@ test(async function xevalDelimiter(): Promise { // https://github.com/denoland/deno/issues/2861 const xevalPath = "examples/xeval.ts"; -test(async function xevalCliReplvar(): Promise { +Deno.test(async function xevalCliReplvar(): Promise { const p = run({ args: [execPath(), xevalPath, "--", "--replvar=abc", "console.log(abc)"], stdin: "piped", @@ -40,7 +39,7 @@ test(async function xevalCliReplvar(): Promise { assertEquals(decode(await p.output()).trimEnd(), "hello"); }); -test(async function xevalCliSyntaxError(): Promise { +Deno.test(async function xevalCliSyntaxError(): Promise { const p = run({ args: [execPath(), xevalPath, "--", "("], stdin: "null", diff --git a/std/flags/all_bool_test.ts b/std/flags/all_bool_test.ts index d738d1afc7..6516f48ed5 100755 --- a/std/flags/all_bool_test.ts +++ b/std/flags/all_bool_test.ts @@ -1,10 +1,9 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. -import { test } from "../testing/mod.ts"; import { assertEquals } from "../testing/asserts.ts"; import { parse } from "./mod.ts"; // flag boolean true (default all --args to boolean) -test(function flagBooleanTrue(): void { +Deno.test(function flagBooleanTrue(): void { const argv = parse(["moo", "--honk", "cow"], { boolean: true }); @@ -18,7 +17,7 @@ test(function flagBooleanTrue(): void { }); // flag boolean true only affects double hyphen arguments without equals signs -test(function flagBooleanTrueOnlyAffectsDoubleDash(): void { +Deno.test(function flagBooleanTrueOnlyAffectsDoubleDash(): void { const argv = parse(["moo", "--honk", "cow", "-p", "55", "--tacos=good"], { boolean: true }); diff --git a/std/flags/bool_test.ts b/std/flags/bool_test.ts index fd3b6487f2..2d6a8b9380 100755 --- a/std/flags/bool_test.ts +++ b/std/flags/bool_test.ts @@ -1,9 +1,8 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. -import { test } from "../testing/mod.ts"; import { assertEquals } from "../testing/asserts.ts"; import { parse } from "./mod.ts"; -test(function flagBooleanDefaultFalse(): void { +Deno.test(function flagBooleanDefaultFalse(): void { const argv = parse(["moo"], { boolean: ["t", "verbose"], default: { verbose: false, t: false } @@ -19,7 +18,7 @@ test(function flagBooleanDefaultFalse(): void { assertEquals(typeof argv.t, "boolean"); }); -test(function booleanGroups(): void { +Deno.test(function booleanGroups(): void { const argv = parse(["-x", "-z", "one", "two", "three"], { boolean: ["x", "y", "z"] }); @@ -36,7 +35,7 @@ test(function booleanGroups(): void { assertEquals(typeof argv.z, "boolean"); }); -test(function booleanAndAliasWithChainableApi(): void { +Deno.test(function booleanAndAliasWithChainableApi(): void { const aliased = ["-h", "derp"]; const regular = ["--herp", "derp"]; const aliasedArgv = parse(aliased, { @@ -57,7 +56,7 @@ test(function booleanAndAliasWithChainableApi(): void { assertEquals(propertyArgv, expected); }); -test(function booleanAndAliasWithOptionsHash(): void { +Deno.test(function booleanAndAliasWithOptionsHash(): void { const aliased = ["-h", "derp"]; const regular = ["--herp", "derp"]; const opts = { @@ -75,7 +74,7 @@ test(function booleanAndAliasWithOptionsHash(): void { assertEquals(propertyArgv, expected); }); -test(function booleanAndAliasArrayWithOptionsHash(): void { +Deno.test(function booleanAndAliasArrayWithOptionsHash(): void { const aliased = ["-h", "derp"]; const regular = ["--herp", "derp"]; const alt = ["--harp", "derp"]; @@ -97,7 +96,7 @@ test(function booleanAndAliasArrayWithOptionsHash(): void { assertEquals(altPropertyArgv, expected); }); -test(function booleanAndAliasUsingExplicitTrue(): void { +Deno.test(function booleanAndAliasUsingExplicitTrue(): void { const aliased = ["-h", "true"]; const regular = ["--herp", "true"]; const opts = { @@ -118,7 +117,7 @@ test(function booleanAndAliasUsingExplicitTrue(): void { // regression, see https://github.com/substack/node-optimist/issues/71 // boolean and --x=true -test(function booleanAndNonBoolean(): void { +Deno.test(function booleanAndNonBoolean(): void { const parsed = parse(["--boool", "--other=true"], { boolean: "boool" }); @@ -134,7 +133,7 @@ test(function booleanAndNonBoolean(): void { assertEquals(parsed2.other, "false"); }); -test(function booleanParsingTrue(): void { +Deno.test(function booleanParsingTrue(): void { const parsed = parse(["--boool=true"], { default: { boool: false @@ -145,7 +144,7 @@ test(function booleanParsingTrue(): void { assertEquals(parsed.boool, true); }); -test(function booleanParsingFalse(): void { +Deno.test(function booleanParsingFalse(): void { const parsed = parse(["--boool=false"], { default: { boool: true @@ -156,7 +155,7 @@ test(function booleanParsingFalse(): void { assertEquals(parsed.boool, false); }); -test(function booleanParsingTrueLike(): void { +Deno.test(function booleanParsingTrueLike(): void { const parsed = parse(["-t", "true123"], { boolean: ["t"] }); assertEquals(parsed.t, true); @@ -167,7 +166,7 @@ test(function booleanParsingTrueLike(): void { assertEquals(parsed3.t, true); }); -test(function booleanNegationAfterBoolean(): void { +Deno.test(function booleanNegationAfterBoolean(): void { const parsed = parse(["--foo", "--no-foo"], { boolean: ["foo"] }); assertEquals(parsed.foo, false); @@ -175,7 +174,7 @@ test(function booleanNegationAfterBoolean(): void { assertEquals(parsed2.foo, false); }); -test(function booleanAfterBooleanNegation(): void { +Deno.test(function booleanAfterBooleanNegation(): void { const parsed = parse(["--no--foo", "--foo"], { boolean: ["foo"] }); assertEquals(parsed.foo, true); @@ -183,7 +182,7 @@ test(function booleanAfterBooleanNegation(): void { assertEquals(parsed2.foo, true); }); -test(function latestFlagIsBooleanNegation(): void { +Deno.test(function latestFlagIsBooleanNegation(): void { const parsed = parse(["--no-foo", "--foo", "--no-foo"], { boolean: ["foo"] }); assertEquals(parsed.foo, false); @@ -193,7 +192,7 @@ test(function latestFlagIsBooleanNegation(): void { assertEquals(parsed2.foo, false); }); -test(function latestFlagIsBoolean(): void { +Deno.test(function latestFlagIsBoolean(): void { const parsed = parse(["--foo", "--no-foo", "--foo"], { boolean: ["foo"] }); assertEquals(parsed.foo, true); diff --git a/std/flags/dash_test.ts b/std/flags/dash_test.ts index 053351fbda..bdf8f502df 100755 --- a/std/flags/dash_test.ts +++ b/std/flags/dash_test.ts @@ -1,9 +1,8 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. -import { test } from "../testing/mod.ts"; import { assertEquals } from "../testing/asserts.ts"; import { parse } from "./mod.ts"; -test(function hyphen(): void { +Deno.test(function hyphen(): void { assertEquals(parse(["-n", "-"]), { n: "-", _: [] }); assertEquals(parse(["-"]), { _: ["-"] }); assertEquals(parse(["-f-"]), { f: "-", _: [] }); @@ -11,13 +10,13 @@ test(function hyphen(): void { assertEquals(parse(["-s", "-"], { string: "s" }), { s: "-", _: [] }); }); -test(function doubleDash(): void { +Deno.test(function doubleDash(): void { assertEquals(parse(["-a", "--", "b"]), { a: true, _: ["b"] }); assertEquals(parse(["--a", "--", "b"]), { a: true, _: ["b"] }); assertEquals(parse(["--a", "--", "b"]), { a: true, _: ["b"] }); }); -test(function moveArgsAfterDoubleDashIntoOwnArray(): void { +Deno.test(function moveArgsAfterDoubleDashIntoOwnArray(): void { assertEquals( parse(["--name", "John", "before", "--", "after"], { "--": true }), { diff --git a/std/flags/default_bool_test.ts b/std/flags/default_bool_test.ts index bf44f5b472..813b6870b9 100755 --- a/std/flags/default_bool_test.ts +++ b/std/flags/default_bool_test.ts @@ -1,9 +1,8 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. -import { test } from "../testing/mod.ts"; import { assertEquals } from "../testing/asserts.ts"; import { parse } from "./mod.ts"; -test(function booleanDefaultTrue(): void { +Deno.test(function booleanDefaultTrue(): void { const argv = parse([], { boolean: "sometrue", default: { sometrue: true } @@ -11,7 +10,7 @@ test(function booleanDefaultTrue(): void { assertEquals(argv.sometrue, true); }); -test(function booleanDefaultFalse(): void { +Deno.test(function booleanDefaultFalse(): void { const argv = parse([], { boolean: "somefalse", default: { somefalse: false } @@ -19,7 +18,7 @@ test(function booleanDefaultFalse(): void { assertEquals(argv.somefalse, false); }); -test(function booleanDefaultNull(): void { +Deno.test(function booleanDefaultNull(): void { const argv = parse([], { boolean: "maybe", default: { maybe: null } diff --git a/std/flags/dotted_test.ts b/std/flags/dotted_test.ts index 6b98d11d0d..93dd3031f6 100755 --- a/std/flags/dotted_test.ts +++ b/std/flags/dotted_test.ts @@ -1,9 +1,8 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. -import { test } from "../testing/mod.ts"; import { assertEquals } from "../testing/asserts.ts"; import { parse } from "./mod.ts"; -test(function dottedAlias(): void { +Deno.test(function dottedAlias(): void { const argv = parse(["--a.b", "22"], { default: { "a.b": 11 }, alias: { "a.b": "aa.bb" } @@ -12,13 +11,13 @@ test(function dottedAlias(): void { assertEquals(argv.aa.bb, 22); }); -test(function dottedDefault(): void { +Deno.test(function dottedDefault(): void { const argv = parse([], { default: { "a.b": 11 }, alias: { "a.b": "aa.bb" } }); assertEquals(argv.a.b, 11); assertEquals(argv.aa.bb, 11); }); -test(function dottedDefaultWithNoAlias(): void { +Deno.test(function dottedDefaultWithNoAlias(): void { const argv = parse([], { default: { "a.b": 11 } }); assertEquals(argv.a.b, 11); }); diff --git a/std/flags/kv_short_test.ts b/std/flags/kv_short_test.ts index e5aec0fd2c..050e550e32 100755 --- a/std/flags/kv_short_test.ts +++ b/std/flags/kv_short_test.ts @@ -1,14 +1,13 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. -import { test } from "../testing/mod.ts"; import { assertEquals } from "../testing/asserts.ts"; import { parse } from "./mod.ts"; -test(function short(): void { +Deno.test(function short(): void { const argv = parse(["-b=123"]); assertEquals(argv, { b: 123, _: [] }); }); -test(function multiShort(): void { +Deno.test(function multiShort(): void { const argv = parse(["-a=whatever", "-b=robots"]); assertEquals(argv, { a: "whatever", b: "robots", _: [] }); }); diff --git a/std/flags/long_test.ts b/std/flags/long_test.ts index 7c19efaca7..e5b68f8c00 100755 --- a/std/flags/long_test.ts +++ b/std/flags/long_test.ts @@ -1,9 +1,8 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. -import { test } from "../testing/mod.ts"; import { assertEquals } from "../testing/asserts.ts"; import { parse } from "./mod.ts"; -test(function longOpts(): void { +Deno.test(function longOpts(): void { assertEquals(parse(["--bool"]), { bool: true, _: [] }); assertEquals(parse(["--pow", "xixxle"]), { pow: "xixxle", _: [] }); assertEquals(parse(["--pow=xixxle"]), { pow: "xixxle", _: [] }); diff --git a/std/flags/num_test.ts b/std/flags/num_test.ts index 265a4a3d47..979d36cbf9 100755 --- a/std/flags/num_test.ts +++ b/std/flags/num_test.ts @@ -1,9 +1,8 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. -import { test } from "../testing/mod.ts"; import { assertEquals } from "../testing/asserts.ts"; import { parse } from "./mod.ts"; -test(function nums(): void { +Deno.test(function nums(): void { const argv = parse([ "-x", "1234", @@ -33,7 +32,7 @@ test(function nums(): void { assertEquals(typeof argv._[0], "number"); }); -test(function alreadyNumber(): void { +Deno.test(function alreadyNumber(): void { const argv = parse(["-x", 1234, 789]); assertEquals(argv, { x: 1234, _: [789] }); assertEquals(typeof argv.x, "number"); diff --git a/std/flags/parse_test.ts b/std/flags/parse_test.ts index 6ed158a9a1..cd93c1f810 100755 --- a/std/flags/parse_test.ts +++ b/std/flags/parse_test.ts @@ -1,9 +1,8 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. -import { test } from "../testing/mod.ts"; import { assertEquals } from "../testing/asserts.ts"; import { parse } from "./mod.ts"; -test(function _arseArgs(): void { +Deno.test(function parseArgs(): void { assertEquals(parse(["--no-moo"]), { moo: false, _: [] }); assertEquals(parse(["-v", "a", "-v", "b", "-v", "c"]), { v: ["a", "b", "c"], @@ -11,7 +10,7 @@ test(function _arseArgs(): void { }); }); -test(function comprehensive(): void { +Deno.test(function comprehensive(): void { assertEquals( parse([ "--name=meowmers", @@ -48,13 +47,13 @@ test(function comprehensive(): void { ); }); -test(function flagBoolean(): void { +Deno.test(function flagBoolean(): void { const argv = parse(["-t", "moo"], { boolean: "t" }); assertEquals(argv, { t: true, _: ["moo"] }); assertEquals(typeof argv.t, "boolean"); }); -test(function flagBooleanValue(): void { +Deno.test(function flagBooleanValue(): void { const argv = parse(["--verbose", "false", "moo", "-t", "true"], { boolean: ["t", "verbose"], default: { verbose: true } @@ -70,7 +69,7 @@ test(function flagBooleanValue(): void { assertEquals(typeof argv.t, "boolean"); }); -test(function newlinesInParams(): void { +Deno.test(function newlinesInParams(): void { const args = parse(["-s", "X\nX"]); assertEquals(args, { _: [], s: "X\nX" }); @@ -82,7 +81,7 @@ test(function newlinesInParams(): void { assertEquals(args2, { _: [], s: "X\nX" }); }); -test(function strings(): void { +Deno.test(function strings(): void { const s = parse(["-s", "0001234"], { string: "s" }).s; assertEquals(s, "0001234"); assertEquals(typeof s, "string"); @@ -92,7 +91,7 @@ test(function strings(): void { assertEquals(typeof x, "string"); }); -test(function stringArgs(): void { +Deno.test(function stringArgs(): void { const s = parse([" ", " "], { string: "_" })._; assertEquals(s.length, 2); assertEquals(typeof s[0], "string"); @@ -101,7 +100,7 @@ test(function stringArgs(): void { assertEquals(s[1], " "); }); -test(function emptyStrings(): void { +Deno.test(function emptyStrings(): void { const s = parse(["-s"], { string: "s" }).s; assertEquals(s, ""); assertEquals(typeof s, "string"); @@ -119,7 +118,7 @@ test(function emptyStrings(): void { assertEquals(letters.t, ""); }); -test(function stringAndAlias(): void { +Deno.test(function stringAndAlias(): void { const x = parse(["--str", "000123"], { string: "s", alias: { s: "str" } @@ -141,7 +140,7 @@ test(function stringAndAlias(): void { assertEquals(typeof y.s, "string"); }); -test(function slashBreak(): void { +Deno.test(function slashBreak(): void { assertEquals(parse(["-I/foo/bar/baz"]), { I: "/foo/bar/baz", _: [] }); assertEquals(parse(["-xyz/foo/bar/baz"]), { x: true, @@ -151,7 +150,7 @@ test(function slashBreak(): void { }); }); -test(function alias(): void { +Deno.test(function alias(): void { const argv = parse(["-f", "11", "--zoom", "55"], { alias: { z: "zoom" } }); @@ -160,7 +159,7 @@ test(function alias(): void { assertEquals(argv.f, 11); }); -test(function multiAlias(): void { +Deno.test(function multiAlias(): void { const argv = parse(["-f", "11", "--zoom", "55"], { alias: { z: ["zm", "zoom"] } }); @@ -170,7 +169,7 @@ test(function multiAlias(): void { assertEquals(argv.f, 11); }); -test(function nestedDottedObjects(): void { +Deno.test(function nestedDottedObjects(): void { const argv = parse([ "--foo.bar", "3", @@ -193,7 +192,7 @@ test(function nestedDottedObjects(): void { assertEquals(argv.beep, { boop: true }); }); -test(function flagBuiltinProperty(): void { +Deno.test(function flagBuiltinProperty(): void { const argv = parse(["--toString", "--valueOf", "foo"]); assertEquals(argv, { toString: true, valueOf: "foo", _: [] }); assertEquals(typeof argv.toString, "boolean"); diff --git a/std/flags/short_test.ts b/std/flags/short_test.ts index ff0190437e..d7171b920d 100755 --- a/std/flags/short_test.ts +++ b/std/flags/short_test.ts @@ -1,14 +1,13 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. -import { test } from "../testing/mod.ts"; import { assertEquals } from "../testing/asserts.ts"; import { parse } from "./mod.ts"; -test(function numbericShortArgs(): void { +Deno.test(function numbericShortArgs(): void { assertEquals(parse(["-n123"]), { n: 123, _: [] }); assertEquals(parse(["-123", "456"]), { 1: true, 2: true, 3: 456, _: [] }); }); -test(function short(): void { +Deno.test(function short(): void { assertEquals(parse(["-b"]), { b: true, _: [] }); assertEquals(parse(["foo", "bar", "baz"]), { _: ["foo", "bar", "baz"] }); assertEquals(parse(["-cats"]), { c: true, a: true, t: true, s: true, _: [] }); @@ -27,7 +26,7 @@ test(function short(): void { }); }); -test(function mixedShortBoolAndCapture(): void { +Deno.test(function mixedShortBoolAndCapture(): void { assertEquals(parse(["-h", "localhost", "-fp", "555", "script.js"]), { f: true, p: 555, @@ -36,7 +35,7 @@ test(function mixedShortBoolAndCapture(): void { }); }); -test(function shortAndLong(): void { +Deno.test(function shortAndLong(): void { assertEquals(parse(["-h", "localhost", "-fp", "555", "script.js"]), { f: true, p: 555, diff --git a/std/flags/stop_early_test.ts b/std/flags/stop_early_test.ts index f054d780bc..d1996e7aa0 100755 --- a/std/flags/stop_early_test.ts +++ b/std/flags/stop_early_test.ts @@ -1,10 +1,9 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. -import { test } from "../testing/mod.ts"; import { assertEquals } from "../testing/asserts.ts"; import { parse } from "./mod.ts"; // stops parsing on the first non-option when stopEarly is set -test(function stopParsing(): void { +Deno.test(function stopParsing(): void { const argv = parse(["--aaa", "bbb", "ccc", "--ddd"], { stopEarly: true }); diff --git a/std/flags/unknown_test.ts b/std/flags/unknown_test.ts index b7817564c4..acbb131ee6 100755 --- a/std/flags/unknown_test.ts +++ b/std/flags/unknown_test.ts @@ -1,9 +1,8 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. -import { test } from "../testing/mod.ts"; import { assertEquals } from "../testing/asserts.ts"; import { parse } from "./mod.ts"; -test(function booleanAndAliasIsNotUnknown(): void { +Deno.test(function booleanAndAliasIsNotUnknown(): void { const unknown: unknown[] = []; function unknownFn(arg: unknown): boolean { unknown.push(arg); @@ -22,7 +21,7 @@ test(function booleanAndAliasIsNotUnknown(): void { assertEquals(unknown, ["--derp", "-d"]); }); -test(function flagBooleanTrueAnyDoubleHyphenArgumentIsNotUnknown(): void { +Deno.test(function flagBooleanTrueAnyDoubleHyphenArgumentIsNotUnknown(): void { const unknown: unknown[] = []; function unknownFn(arg: unknown): boolean { unknown.push(arg); @@ -39,7 +38,7 @@ test(function flagBooleanTrueAnyDoubleHyphenArgumentIsNotUnknown(): void { }); }); -test(function stringAndAliasIsNotUnkown(): void { +Deno.test(function stringAndAliasIsNotUnkown(): void { const unknown: unknown[] = []; function unknownFn(arg: unknown): boolean { unknown.push(arg); @@ -58,7 +57,7 @@ test(function stringAndAliasIsNotUnkown(): void { assertEquals(unknown, ["--derp", "-d"]); }); -test(function defaultAndAliasIsNotUnknown(): void { +Deno.test(function defaultAndAliasIsNotUnknown(): void { const unknown: unknown[] = []; function unknownFn(arg: unknown): boolean { unknown.push(arg); @@ -77,7 +76,7 @@ test(function defaultAndAliasIsNotUnknown(): void { assertEquals(unknown, []); }); -test(function valueFollowingDoubleHyphenIsNotUnknown(): void { +Deno.test(function valueFollowingDoubleHyphenIsNotUnknown(): void { const unknown: unknown[] = []; function unknownFn(arg: unknown): boolean { unknown.push(arg); diff --git a/std/flags/whitespace_test.ts b/std/flags/whitespace_test.ts index 9f66dfdfc0..878ed28df7 100755 --- a/std/flags/whitespace_test.ts +++ b/std/flags/whitespace_test.ts @@ -1,8 +1,7 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. -import { test } from "../testing/mod.ts"; import { assertEquals } from "../testing/asserts.ts"; import { parse } from "./mod.ts"; -test(function whitespaceShouldBeWhitespace(): void { +Deno.test(function whitespaceShouldBeWhitespace(): void { assertEquals(parse(["-x", "\t"]).x, "\t"); }); diff --git a/std/fmt/colors_test.ts b/std/fmt/colors_test.ts index 6113bd22f7..9d221dc8b6 100644 --- a/std/fmt/colors_test.ts +++ b/std/fmt/colors_test.ts @@ -1,22 +1,21 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. -import { test } from "../testing/mod.ts"; import { assertEquals } from "../testing/asserts.ts"; import * as c from "./colors.ts"; import "../examples/colors.ts"; -test(function singleColor(): void { +Deno.test(function singleColor(): void { assertEquals(c.red("foo bar"), "foo bar"); }); -test(function doubleColor(): void { +Deno.test(function doubleColor(): void { assertEquals(c.bgBlue(c.red("foo bar")), "foo bar"); }); -test(function replacesCloseCharacters(): void { +Deno.test(function replacesCloseCharacters(): void { assertEquals(c.red("Hello"), "Hello"); }); -test(function enablingColors(): void { +Deno.test(function enablingColors(): void { assertEquals(c.getColorEnabled(), true); c.setColorEnabled(false); assertEquals(c.bgBlue(c.red("foo bar")), "foo bar"); @@ -24,98 +23,98 @@ test(function enablingColors(): void { assertEquals(c.red("foo bar"), "foo bar"); }); -test(function testBold(): void { +Deno.test(function testBold(): void { assertEquals(c.bold("foo bar"), "foo bar"); }); -test(function testDim(): void { +Deno.test(function testDim(): void { assertEquals(c.dim("foo bar"), "foo bar"); }); -test(function testItalic(): void { +Deno.test(function testItalic(): void { assertEquals(c.italic("foo bar"), "foo bar"); }); -test(function testUnderline(): void { +Deno.test(function testUnderline(): void { assertEquals(c.underline("foo bar"), "foo bar"); }); -test(function testInverse(): void { +Deno.test(function testInverse(): void { assertEquals(c.inverse("foo bar"), "foo bar"); }); -test(function testHidden(): void { +Deno.test(function testHidden(): void { assertEquals(c.hidden("foo bar"), "foo bar"); }); -test(function testStrikethrough(): void { +Deno.test(function testStrikethrough(): void { assertEquals(c.strikethrough("foo bar"), "foo bar"); }); -test(function testBlack(): void { +Deno.test(function testBlack(): void { assertEquals(c.black("foo bar"), "foo bar"); }); -test(function testRed(): void { +Deno.test(function testRed(): void { assertEquals(c.red("foo bar"), "foo bar"); }); -test(function testGreen(): void { +Deno.test(function testGreen(): void { assertEquals(c.green("foo bar"), "foo bar"); }); -test(function testYellow(): void { +Deno.test(function testYellow(): void { assertEquals(c.yellow("foo bar"), "foo bar"); }); -test(function testBlue(): void { +Deno.test(function testBlue(): void { assertEquals(c.blue("foo bar"), "foo bar"); }); -test(function testMagenta(): void { +Deno.test(function testMagenta(): void { assertEquals(c.magenta("foo bar"), "foo bar"); }); -test(function testCyan(): void { +Deno.test(function testCyan(): void { assertEquals(c.cyan("foo bar"), "foo bar"); }); -test(function testWhite(): void { +Deno.test(function testWhite(): void { assertEquals(c.white("foo bar"), "foo bar"); }); -test(function testGray(): void { +Deno.test(function testGray(): void { assertEquals(c.gray("foo bar"), "foo bar"); }); -test(function testBgBlack(): void { +Deno.test(function testBgBlack(): void { assertEquals(c.bgBlack("foo bar"), "foo bar"); }); -test(function testBgRed(): void { +Deno.test(function testBgRed(): void { assertEquals(c.bgRed("foo bar"), "foo bar"); }); -test(function testBgGreen(): void { +Deno.test(function testBgGreen(): void { assertEquals(c.bgGreen("foo bar"), "foo bar"); }); -test(function testBgYellow(): void { +Deno.test(function testBgYellow(): void { assertEquals(c.bgYellow("foo bar"), "foo bar"); }); -test(function testBgBlue(): void { +Deno.test(function testBgBlue(): void { assertEquals(c.bgBlue("foo bar"), "foo bar"); }); -test(function testBgMagenta(): void { +Deno.test(function testBgMagenta(): void { assertEquals(c.bgMagenta("foo bar"), "foo bar"); }); -test(function testBgCyan(): void { +Deno.test(function testBgCyan(): void { assertEquals(c.bgCyan("foo bar"), "foo bar"); }); -test(function testBgWhite(): void { +Deno.test(function testBgWhite(): void { assertEquals(c.bgWhite("foo bar"), "foo bar"); }); diff --git a/std/fmt/sprintf_test.ts b/std/fmt/sprintf_test.ts index 26757c3cc6..917878bc16 100644 --- a/std/fmt/sprintf_test.ts +++ b/std/fmt/sprintf_test.ts @@ -1,21 +1,20 @@ import { sprintf } from "./sprintf.ts"; import { assertEquals } from "../testing/asserts.ts"; -import { test, runIfMain } from "../testing/mod.ts"; const S = sprintf; -test(function noVerb(): void { +Deno.test(function noVerb(): void { assertEquals(sprintf("bla"), "bla"); }); -test(function percent(): void { +Deno.test(function percent(): void { assertEquals(sprintf("%%"), "%"); assertEquals(sprintf("!%%!"), "!%!"); assertEquals(sprintf("!%%"), "!%"); assertEquals(sprintf("%%!"), "%!"); }); -test(function testBoolean(): void { +Deno.test(function testBoolean(): void { assertEquals(sprintf("%t", true), "true"); assertEquals(sprintf("%10t", true), " true"); assertEquals(sprintf("%-10t", false), "false "); @@ -24,7 +23,7 @@ test(function testBoolean(): void { assertEquals(sprintf("%tbla", false), "falsebla"); }); -test(function testIntegerB(): void { +Deno.test(function testIntegerB(): void { assertEquals(S("%b", 4), "100"); assertEquals(S("%b", -4), "-100"); assertEquals( @@ -48,7 +47,7 @@ test(function testIntegerB(): void { assertEquals(S("%4b", 4), " 100"); }); -test(function testIntegerC(): void { +Deno.test(function testIntegerC(): void { assertEquals(S("%c", 0x31), "1"); assertEquals(S("%c%b", 0x31, 1), "11"); assertEquals(S("%c", 0x1f4a9), "💩"); @@ -56,14 +55,14 @@ test(function testIntegerC(): void { assertEquals(S("%4c", 0x31), " 1"); }); -test(function testIntegerD(): void { +Deno.test(function testIntegerD(): void { assertEquals(S("%d", 4), "4"); assertEquals(S("%d", -4), "-4"); assertEquals(S("%d", Number.MAX_SAFE_INTEGER), "9007199254740991"); assertEquals(S("%d", Number.MIN_SAFE_INTEGER), "-9007199254740991"); }); -test(function testIntegerO(): void { +Deno.test(function testIntegerO(): void { assertEquals(S("%o", 4), "4"); assertEquals(S("%o", -4), "-4"); assertEquals(S("%o", 9), "11"); @@ -73,7 +72,7 @@ test(function testIntegerO(): void { // width assertEquals(S("%4o", 4), " 4"); }); -test(function testIntegerx(): void { +Deno.test(function testIntegerx(): void { assertEquals(S("%x", 4), "4"); assertEquals(S("%x", -4), "-4"); assertEquals(S("%x", 9), "9"); @@ -87,7 +86,7 @@ test(function testIntegerx(): void { assertEquals(S("%+4x", 4), " +4"); assertEquals(S("%-+4x", 4), "+4 "); }); -test(function testIntegerX(): void { +Deno.test(function testIntegerX(): void { assertEquals(S("%X", 4), "4"); assertEquals(S("%X", -4), "-4"); assertEquals(S("%X", 9), "9"); @@ -96,7 +95,7 @@ test(function testIntegerX(): void { assertEquals(S("%X", Number.MIN_SAFE_INTEGER), "-1FFFFFFFFFFFFF"); }); -test(function testFloate(): void { +Deno.test(function testFloate(): void { assertEquals(S("%e", 4), "4.000000e+00"); assertEquals(S("%e", -4), "-4.000000e+00"); assertEquals(S("%e", 4.1), "4.100000e+00"); @@ -104,7 +103,7 @@ test(function testFloate(): void { assertEquals(S("%e", Number.MAX_SAFE_INTEGER), "9.007199e+15"); assertEquals(S("%e", Number.MIN_SAFE_INTEGER), "-9.007199e+15"); }); -test(function testFloatE(): void { +Deno.test(function testFloatE(): void { assertEquals(S("%E", 4), "4.000000E+00"); assertEquals(S("%E", -4), "-4.000000E+00"); assertEquals(S("%E", 4.1), "4.100000E+00"); @@ -114,7 +113,7 @@ test(function testFloatE(): void { assertEquals(S("%E", Number.MIN_VALUE), "5.000000E-324"); assertEquals(S("%E", Number.MAX_VALUE), "1.797693E+308"); }); -test(function testFloatfF(): void { +Deno.test(function testFloatfF(): void { assertEquals(S("%f", 4), "4.000000"); assertEquals(S("%F", 4), "4.000000"); assertEquals(S("%f", -4), "-4.000000"); @@ -146,32 +145,32 @@ test(function testFloatfF(): void { ); }); -test(function testString(): void { +Deno.test(function testString(): void { assertEquals(S("%s World%s", "Hello", "!"), "Hello World!"); }); -test(function testHex(): void { +Deno.test(function testHex(): void { assertEquals(S("%x", "123"), "313233"); assertEquals(S("%x", "n"), "6e"); }); -test(function testHeX(): void { +Deno.test(function testHeX(): void { assertEquals(S("%X", "123"), "313233"); assertEquals(S("%X", "n"), "6E"); }); -test(function testType(): void { +Deno.test(function testType(): void { assertEquals(S("%T", new Date()), "object"); assertEquals(S("%T", 123), "number"); assertEquals(S("%T", "123"), "string"); assertEquals(S("%.3T", "123"), "str"); }); -test(function testPositional(): void { +Deno.test(function testPositional(): void { assertEquals(S("%[1]d%[2]d", 1, 2), "12"); assertEquals(S("%[2]d%[1]d", 1, 2), "21"); }); -test(function testSharp(): void { +Deno.test(function testSharp(): void { assertEquals(S("%#x", "123"), "0x313233"); assertEquals(S("%#X", "123"), "0X313233"); assertEquals(S("%#x", 123), "0x7b"); @@ -180,7 +179,7 @@ test(function testSharp(): void { assertEquals(S("%#b", 4), "0b100"); }); -test(function testWidthAndPrecision(): void { +Deno.test(function testWidthAndPrecision(): void { assertEquals( S("%9.99d", 9), // eslint-disable-next-line max-len @@ -206,21 +205,21 @@ test(function testWidthAndPrecision(): void { assertEquals(S("%#*x", 4, 1), " 0x1"); }); -test(function testDash(): void { +Deno.test(function testDash(): void { assertEquals(S("%-2s", "a"), "a "); assertEquals(S("%-2d", 1), "1 "); }); -test(function testPlus(): void { +Deno.test(function testPlus(): void { assertEquals(S("%-+3d", 1), "+1 "); assertEquals(S("%+3d", 1), " +1"); assertEquals(S("%+3d", -1), " -1"); }); -test(function testSpace(): void { +Deno.test(function testSpace(): void { assertEquals(S("% -3d", 3), " 3 "); }); -test(function testZero(): void { +Deno.test(function testZero(): void { assertEquals(S("%04s", "a"), "000a"); }); @@ -586,7 +585,7 @@ const tests: Array<[string, any, string]> = [ ["% +07.2f", -1.0, "-001.00"] ]; -test(function testThorough(): void { +Deno.test(function testThorough(): void { tests.forEach((t, i): void => { // p(t) const is = S(t[0], t[1]); @@ -599,7 +598,7 @@ test(function testThorough(): void { }); }); -test(function testWeirdos(): void { +Deno.test(function testWeirdos(): void { assertEquals(S("%.d", 9), "9"); assertEquals( S("dec[%d]=%d hex[%[1]d]=%#x oct[%[1]d]=%#o %s", 1, 255, "Third"), @@ -607,7 +606,7 @@ test(function testWeirdos(): void { ); }); -test(function formatV(): void { +Deno.test(function formatV(): void { const a = { a: { a: { a: { a: { a: { a: { a: {} } } } } } } }; assertEquals(S("%v", a), "[object Object]"); assertEquals(S("%#v", a), "{ a: { a: { a: { a: [Object] } } } }"); @@ -618,12 +617,12 @@ test(function formatV(): void { assertEquals(S("%#.1v", a), "{ a: [Object] }"); }); -test(function formatJ(): void { +Deno.test(function formatJ(): void { const a = { a: { a: { a: { a: { a: { a: { a: {} } } } } } } }; assertEquals(S("%j", a), `{"a":{"a":{"a":{"a":{"a":{"a":{"a":{}}}}}}}}`); }); -test(function flagLessThan(): void { +Deno.test(function flagLessThan(): void { const a = { a: { a: { a: { a: { a: { a: { a: {} } } } } } } }; const aArray = [a, a, a]; assertEquals( @@ -634,7 +633,7 @@ test(function flagLessThan(): void { assertEquals(S("%<.2f", fArray), "[ 1.23, 0.99, 123456789.57 ]"); }); -test(function testErrors(): void { +Deno.test(function testErrors(): void { // wrong type : TODO strict mode ... //assertEquals(S("%f", "not a number"), "%!(BADTYPE flag=f type=string)") assertEquals(S("A %h", ""), "A %!(BAD VERB 'h')"); @@ -664,5 +663,3 @@ test(function testErrors(): void { assertEquals(S("%.[5]f"), "%!(BAD INDEX)"); assertEquals(S("%.[5]*f"), "%!(BAD INDEX)"); }); - -runIfMain(import.meta); diff --git a/std/fs/copy_test.ts b/std/fs/copy_test.ts index 8134eb1d82..fb8827f0c7 100644 --- a/std/fs/copy_test.ts +++ b/std/fs/copy_test.ts @@ -1,5 +1,4 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. -import { test } from "../testing/mod.ts"; import { assertEquals, assertThrows, @@ -22,7 +21,7 @@ async function testCopy( name: string, cb: (tempDir: string) => Promise ): Promise { - test({ + Deno.test({ name, async fn(): Promise { const tempDir = await Deno.makeTempDir({ @@ -35,7 +34,7 @@ async function testCopy( } function testCopySync(name: string, cb: (tempDir: string) => void): void { - test({ + Deno.test({ name, fn: (): void => { const tempDir = Deno.makeTempDirSync({ diff --git a/std/fs/empty_dir_test.ts b/std/fs/empty_dir_test.ts index b9145767e1..b27ebd033d 100644 --- a/std/fs/empty_dir_test.ts +++ b/std/fs/empty_dir_test.ts @@ -1,5 +1,4 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. -import { test } from "../testing/mod.ts"; import { assertEquals, assertStrContains, @@ -11,7 +10,7 @@ import { emptyDir, emptyDirSync } from "./empty_dir.ts"; const testdataDir = path.resolve("fs", "testdata"); -test(async function emptyDirIfItNotExist(): Promise { +Deno.test(async function emptyDirIfItNotExist(): Promise { const testDir = path.join(testdataDir, "empty_dir_test_1"); const testNestDir = path.join(testDir, "nest"); // empty a dir which not exist. then it will create new one @@ -27,7 +26,7 @@ test(async function emptyDirIfItNotExist(): Promise { } }); -test(function emptyDirSyncIfItNotExist(): void { +Deno.test(function emptyDirSyncIfItNotExist(): void { const testDir = path.join(testdataDir, "empty_dir_test_2"); const testNestDir = path.join(testDir, "nest"); // empty a dir which not exist. then it will create new one @@ -43,7 +42,7 @@ test(function emptyDirSyncIfItNotExist(): void { } }); -test(async function emptyDirIfItExist(): Promise { +Deno.test(async function emptyDirIfItExist(): Promise { const testDir = path.join(testdataDir, "empty_dir_test_3"); const testNestDir = path.join(testDir, "nest"); // create test dir @@ -86,7 +85,7 @@ test(async function emptyDirIfItExist(): Promise { } }); -test(function emptyDirSyncIfItExist(): void { +Deno.test(function emptyDirSyncIfItExist(): void { const testDir = path.join(testdataDir, "empty_dir_test_4"); const testNestDir = path.join(testDir, "nest"); // create test dir @@ -125,7 +124,7 @@ test(function emptyDirSyncIfItExist(): void { } }); -test(async function emptyDirPermission(): Promise { +Deno.test(async function emptyDirPermission(): Promise { interface Scenes { read: boolean; // --allow-read write: boolean; // --allow-write diff --git a/std/fs/ensure_dir_test.ts b/std/fs/ensure_dir_test.ts index 231196ae9d..10c19c9c91 100644 --- a/std/fs/ensure_dir_test.ts +++ b/std/fs/ensure_dir_test.ts @@ -1,5 +1,4 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. -import { test } from "../testing/mod.ts"; import { assertThrows, assertThrowsAsync } from "../testing/asserts.ts"; import * as path from "../path/mod.ts"; import { ensureDir, ensureDirSync } from "./ensure_dir.ts"; @@ -7,7 +6,7 @@ import { ensureFile, ensureFileSync } from "./ensure_file.ts"; const testdataDir = path.resolve("fs", "testdata"); -test(async function ensureDirIfItNotExist(): Promise { +Deno.test(async function ensureDirIfItNotExist(): Promise { const baseDir = path.join(testdataDir, "ensure_dir_not_exist"); const testDir = path.join(baseDir, "test"); @@ -24,7 +23,7 @@ test(async function ensureDirIfItNotExist(): Promise { await Deno.remove(baseDir, { recursive: true }); }); -test(function ensureDirSyncIfItNotExist(): void { +Deno.test(function ensureDirSyncIfItNotExist(): void { const baseDir = path.join(testdataDir, "ensure_dir_sync_not_exist"); const testDir = path.join(baseDir, "test"); @@ -35,7 +34,7 @@ test(function ensureDirSyncIfItNotExist(): void { Deno.removeSync(baseDir, { recursive: true }); }); -test(async function ensureDirIfItExist(): Promise { +Deno.test(async function ensureDirIfItExist(): Promise { const baseDir = path.join(testdataDir, "ensure_dir_exist"); const testDir = path.join(baseDir, "test"); @@ -55,7 +54,7 @@ test(async function ensureDirIfItExist(): Promise { await Deno.remove(baseDir, { recursive: true }); }); -test(function ensureDirSyncIfItExist(): void { +Deno.test(function ensureDirSyncIfItExist(): void { const baseDir = path.join(testdataDir, "ensure_dir_sync_exist"); const testDir = path.join(baseDir, "test"); @@ -72,7 +71,7 @@ test(function ensureDirSyncIfItExist(): void { Deno.removeSync(baseDir, { recursive: true }); }); -test(async function ensureDirIfItAsFile(): Promise { +Deno.test(async function ensureDirIfItAsFile(): Promise { const baseDir = path.join(testdataDir, "ensure_dir_exist_file"); const testFile = path.join(baseDir, "test"); @@ -89,7 +88,7 @@ test(async function ensureDirIfItAsFile(): Promise { await Deno.remove(baseDir, { recursive: true }); }); -test(function ensureDirSyncIfItAsFile(): void { +Deno.test(function ensureDirSyncIfItAsFile(): void { const baseDir = path.join(testdataDir, "ensure_dir_exist_file_async"); const testFile = path.join(baseDir, "test"); diff --git a/std/fs/ensure_file_test.ts b/std/fs/ensure_file_test.ts index a5d237e5f4..92d5ac0622 100644 --- a/std/fs/ensure_file_test.ts +++ b/std/fs/ensure_file_test.ts @@ -1,12 +1,11 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. -import { test } from "../testing/mod.ts"; import { assertThrows, assertThrowsAsync } from "../testing/asserts.ts"; import * as path from "../path/mod.ts"; import { ensureFile, ensureFileSync } from "./ensure_file.ts"; const testdataDir = path.resolve("fs", "testdata"); -test(async function ensureFileIfItNotExist(): Promise { +Deno.test(async function ensureFileIfItNotExist(): Promise { const testDir = path.join(testdataDir, "ensure_file_1"); const testFile = path.join(testDir, "test.txt"); @@ -23,7 +22,7 @@ test(async function ensureFileIfItNotExist(): Promise { await Deno.remove(testDir, { recursive: true }); }); -test(function ensureFileSyncIfItNotExist(): void { +Deno.test(function ensureFileSyncIfItNotExist(): void { const testDir = path.join(testdataDir, "ensure_file_2"); const testFile = path.join(testDir, "test.txt"); @@ -37,7 +36,7 @@ test(function ensureFileSyncIfItNotExist(): void { Deno.removeSync(testDir, { recursive: true }); }); -test(async function ensureFileIfItExist(): Promise { +Deno.test(async function ensureFileIfItExist(): Promise { const testDir = path.join(testdataDir, "ensure_file_3"); const testFile = path.join(testDir, "test.txt"); @@ -57,7 +56,7 @@ test(async function ensureFileIfItExist(): Promise { await Deno.remove(testDir, { recursive: true }); }); -test(function ensureFileSyncIfItExist(): void { +Deno.test(function ensureFileSyncIfItExist(): void { const testDir = path.join(testdataDir, "ensure_file_4"); const testFile = path.join(testDir, "test.txt"); @@ -74,7 +73,7 @@ test(function ensureFileSyncIfItExist(): void { Deno.removeSync(testDir, { recursive: true }); }); -test(async function ensureFileIfItExistAsDir(): Promise { +Deno.test(async function ensureFileIfItExistAsDir(): Promise { const testDir = path.join(testdataDir, "ensure_file_5"); await Deno.mkdir(testDir, { recursive: true }); @@ -90,7 +89,7 @@ test(async function ensureFileIfItExistAsDir(): Promise { await Deno.remove(testDir, { recursive: true }); }); -test(function ensureFileSyncIfItExistAsDir(): void { +Deno.test(function ensureFileSyncIfItExistAsDir(): void { const testDir = path.join(testdataDir, "ensure_file_6"); Deno.mkdirSync(testDir, { recursive: true }); diff --git a/std/fs/ensure_link_test.ts b/std/fs/ensure_link_test.ts index daf216c492..6e9804152a 100644 --- a/std/fs/ensure_link_test.ts +++ b/std/fs/ensure_link_test.ts @@ -1,6 +1,5 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. // TODO(axetroy): Add test for Windows once symlink is implemented for Windows. -import { test } from "../testing/mod.ts"; import { assertEquals, assertThrows, @@ -11,7 +10,7 @@ import { ensureLink, ensureLinkSync } from "./ensure_link.ts"; const testdataDir = path.resolve("fs", "testdata"); -test(async function ensureLinkIfItNotExist(): Promise { +Deno.test(async function ensureLinkIfItNotExist(): Promise { const srcDir = path.join(testdataDir, "ensure_link_1"); const destDir = path.join(testdataDir, "ensure_link_1_2"); const testFile = path.join(srcDir, "test.txt"); @@ -26,7 +25,7 @@ test(async function ensureLinkIfItNotExist(): Promise { await Deno.remove(destDir, { recursive: true }); }); -test(function ensureLinkSyncIfItNotExist(): void { +Deno.test(function ensureLinkSyncIfItNotExist(): void { const testDir = path.join(testdataDir, "ensure_link_2"); const testFile = path.join(testDir, "test.txt"); const linkFile = path.join(testDir, "link.txt"); @@ -38,7 +37,7 @@ test(function ensureLinkSyncIfItNotExist(): void { Deno.removeSync(testDir, { recursive: true }); }); -test(async function ensureLinkIfItExist(): Promise { +Deno.test(async function ensureLinkIfItExist(): Promise { const testDir = path.join(testdataDir, "ensure_link_3"); const testFile = path.join(testDir, "test.txt"); const linkFile = path.join(testDir, "link.txt"); @@ -85,7 +84,7 @@ test(async function ensureLinkIfItExist(): Promise { await Deno.remove(testDir, { recursive: true }); }); -test(function ensureLinkSyncIfItExist(): void { +Deno.test(function ensureLinkSyncIfItExist(): void { const testDir = path.join(testdataDir, "ensure_link_4"); const testFile = path.join(testDir, "test.txt"); const linkFile = path.join(testDir, "link.txt"); @@ -133,7 +132,7 @@ test(function ensureLinkSyncIfItExist(): void { Deno.removeSync(testDir, { recursive: true }); }); -test(async function ensureLinkDirectoryIfItExist(): Promise { +Deno.test(async function ensureLinkDirectoryIfItExist(): Promise { const testDir = path.join(testdataDir, "ensure_link_origin_3"); const linkDir = path.join(testdataDir, "ensure_link_link_3"); const testFile = path.join(testDir, "test.txt"); @@ -153,7 +152,7 @@ test(async function ensureLinkDirectoryIfItExist(): Promise { Deno.removeSync(testDir, { recursive: true }); }); -test(function ensureLinkSyncDirectoryIfItExist(): void { +Deno.test(function ensureLinkSyncDirectoryIfItExist(): void { const testDir = path.join(testdataDir, "ensure_link_origin_3"); const linkDir = path.join(testdataDir, "ensure_link_link_3"); const testFile = path.join(testDir, "test.txt"); diff --git a/std/fs/ensure_symlink_test.ts b/std/fs/ensure_symlink_test.ts index 0470af57e9..8017bcebf6 100644 --- a/std/fs/ensure_symlink_test.ts +++ b/std/fs/ensure_symlink_test.ts @@ -1,6 +1,5 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. // TODO(axetroy): Add test for Windows once symlink is implemented for Windows. -import { test } from "../testing/mod.ts"; import { assertEquals, assertThrows, @@ -12,7 +11,7 @@ import { ensureSymlink, ensureSymlinkSync } from "./ensure_symlink.ts"; const testdataDir = path.resolve("fs", "testdata"); const isWindows = Deno.build.os === "win"; -test(async function ensureSymlinkIfItNotExist(): Promise { +Deno.test(async function ensureSymlinkIfItNotExist(): Promise { const testDir = path.join(testdataDir, "link_file_1"); const testFile = path.join(testDir, "test.txt"); @@ -31,7 +30,7 @@ test(async function ensureSymlinkIfItNotExist(): Promise { ); }); -test(function ensureSymlinkSyncIfItNotExist(): void { +Deno.test(function ensureSymlinkSyncIfItNotExist(): void { const testDir = path.join(testdataDir, "link_file_2"); const testFile = path.join(testDir, "test.txt"); @@ -45,7 +44,7 @@ test(function ensureSymlinkSyncIfItNotExist(): void { }); }); -test(async function ensureSymlinkIfItExist(): Promise { +Deno.test(async function ensureSymlinkIfItExist(): Promise { const testDir = path.join(testdataDir, "link_file_3"); const testFile = path.join(testDir, "test.txt"); const linkFile = path.join(testDir, "link.txt"); @@ -74,7 +73,7 @@ test(async function ensureSymlinkIfItExist(): Promise { await Deno.remove(testDir, { recursive: true }); }); -test(function ensureSymlinkSyncIfItExist(): void { +Deno.test(function ensureSymlinkSyncIfItExist(): void { const testDir = path.join(testdataDir, "link_file_4"); const testFile = path.join(testDir, "test.txt"); const linkFile = path.join(testDir, "link.txt"); @@ -104,7 +103,7 @@ test(function ensureSymlinkSyncIfItExist(): void { Deno.removeSync(testDir, { recursive: true }); }); -test(async function ensureSymlinkDirectoryIfItExist(): Promise { +Deno.test(async function ensureSymlinkDirectoryIfItExist(): Promise { const testDir = path.join(testdataDir, "link_file_origin_3"); const linkDir = path.join(testdataDir, "link_file_link_3"); const testFile = path.join(testDir, "test.txt"); @@ -136,7 +135,7 @@ test(async function ensureSymlinkDirectoryIfItExist(): Promise { await Deno.remove(testDir, { recursive: true }); }); -test(function ensureSymlinkSyncDirectoryIfItExist(): void { +Deno.test(function ensureSymlinkSyncDirectoryIfItExist(): void { const testDir = path.join(testdataDir, "link_file_origin_3"); const linkDir = path.join(testdataDir, "link_file_link_3"); const testFile = path.join(testDir, "test.txt"); diff --git a/std/fs/eol_test.ts b/std/fs/eol_test.ts index 92306ce6ba..aa2dcf3953 100644 --- a/std/fs/eol_test.ts +++ b/std/fs/eol_test.ts @@ -1,5 +1,4 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. -import { test } from "../testing/mod.ts"; import { assertEquals } from "../testing/asserts.ts"; import { format, detect, EOL } from "./eol.ts"; @@ -9,28 +8,28 @@ const Mixedinput2 = "deno\r\nis not\nnode"; const LFinput = "deno\nis not\nnode"; const NoNLinput = "deno is not node"; -test({ +Deno.test({ name: "[EOL] Detect CR LF", fn(): void { assertEquals(detect(CRLFinput), EOL.CRLF); } }); -test({ +Deno.test({ name: "[EOL] Detect LF", fn(): void { assertEquals(detect(LFinput), EOL.LF); } }); -test({ +Deno.test({ name: "[EOL] Detect No New Line", fn(): void { assertEquals(detect(NoNLinput), null); } }); -test({ +Deno.test({ name: "[EOL] Detect Mixed", fn(): void { assertEquals(detect(Mixedinput), EOL.CRLF); @@ -38,7 +37,7 @@ test({ } }); -test({ +Deno.test({ name: "[EOL] Format", fn(): void { assertEquals(format(CRLFinput, EOL.LF), LFinput); diff --git a/std/fs/exists_test.ts b/std/fs/exists_test.ts index c7c7dc54e9..06b908b9db 100644 --- a/std/fs/exists_test.ts +++ b/std/fs/exists_test.ts @@ -1,12 +1,11 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. -import { test } from "../testing/mod.ts"; import { assertEquals, assertStrContains } from "../testing/asserts.ts"; import * as path from "../path/mod.ts"; import { exists, existsSync } from "./exists.ts"; const testdataDir = path.resolve("fs", "testdata"); -test(async function existsFile(): Promise { +Deno.test(async function existsFile(): Promise { assertEquals( await exists(path.join(testdataDir, "not_exist_file.ts")), false @@ -14,12 +13,12 @@ test(async function existsFile(): Promise { assertEquals(await existsSync(path.join(testdataDir, "0.ts")), true); }); -test(function existsFileSync(): void { +Deno.test(function existsFileSync(): void { assertEquals(existsSync(path.join(testdataDir, "not_exist_file.ts")), false); assertEquals(existsSync(path.join(testdataDir, "0.ts")), true); }); -test(async function existsDirectory(): Promise { +Deno.test(async function existsDirectory(): Promise { assertEquals( await exists(path.join(testdataDir, "not_exist_directory")), false @@ -27,7 +26,7 @@ test(async function existsDirectory(): Promise { assertEquals(existsSync(testdataDir), true); }); -test(function existsDirectorySync(): void { +Deno.test(function existsDirectorySync(): void { assertEquals( existsSync(path.join(testdataDir, "not_exist_directory")), false @@ -35,19 +34,19 @@ test(function existsDirectorySync(): void { assertEquals(existsSync(testdataDir), true); }); -test(function existsLinkSync(): void { +Deno.test(function existsLinkSync(): void { // TODO(axetroy): generate link file use Deno api instead of set a link file // in repository assertEquals(existsSync(path.join(testdataDir, "0-link.ts")), true); }); -test(async function existsLink(): Promise { +Deno.test(async function existsLink(): Promise { // TODO(axetroy): generate link file use Deno api instead of set a link file // in repository assertEquals(await exists(path.join(testdataDir, "0-link.ts")), true); }); -test(async function existsPermission(): Promise { +Deno.test(async function existsPermission(): Promise { interface Scenes { read: boolean; // --allow-read async: boolean; diff --git a/std/fs/expand_glob_test.ts b/std/fs/expand_glob_test.ts index 718c8183f7..58da2c1bfc 100644 --- a/std/fs/expand_glob_test.ts +++ b/std/fs/expand_glob_test.ts @@ -1,6 +1,5 @@ const { cwd, execPath, run } = Deno; import { decode } from "../strings/mod.ts"; -import { test, runIfMain } from "../testing/mod.ts"; import { assert, assertEquals, assertStrContains } from "../testing/asserts.ts"; import { isWindows, @@ -52,7 +51,7 @@ const EG_OPTIONS: ExpandGlobOptions = { globstar: false }; -test(async function expandGlobWildcard(): Promise { +Deno.test(async function expandGlobWildcard(): Promise { const options = EG_OPTIONS; assertEquals(await expandGlobArray("*", options), [ "abc", @@ -62,12 +61,12 @@ test(async function expandGlobWildcard(): Promise { ]); }); -test(async function expandGlobTrailingSeparator(): Promise { +Deno.test(async function expandGlobTrailingSeparator(): Promise { const options = EG_OPTIONS; assertEquals(await expandGlobArray("*/", options), ["subdir"]); }); -test(async function expandGlobParent(): Promise { +Deno.test(async function expandGlobParent(): Promise { const options = EG_OPTIONS; assertEquals(await expandGlobArray("subdir/../*", options), [ "abc", @@ -77,7 +76,7 @@ test(async function expandGlobParent(): Promise { ]); }); -test(async function expandGlobExt(): Promise { +Deno.test(async function expandGlobExt(): Promise { const options = { ...EG_OPTIONS, extended: true }; assertEquals(await expandGlobArray("abc?(def|ghi)", options), [ "abc", @@ -97,7 +96,7 @@ test(async function expandGlobExt(): Promise { assertEquals(await expandGlobArray("abc!(def|ghi)", options), ["abc"]); }); -test(async function expandGlobGlobstar(): Promise { +Deno.test(async function expandGlobGlobstar(): Promise { const options = { ...EG_OPTIONS, globstar: true }; assertEquals( await expandGlobArray(joinGlobs(["**", "abc"], options), options), @@ -105,7 +104,7 @@ test(async function expandGlobGlobstar(): Promise { ); }); -test(async function expandGlobGlobstarParent(): Promise { +Deno.test(async function expandGlobGlobstarParent(): Promise { const options = { ...EG_OPTIONS, globstar: true }; assertEquals( await expandGlobArray(joinGlobs(["subdir", "**", ".."], options), options), @@ -113,12 +112,12 @@ test(async function expandGlobGlobstarParent(): Promise { ); }); -test(async function expandGlobIncludeDirs(): Promise { +Deno.test(async function expandGlobIncludeDirs(): Promise { const options = { ...EG_OPTIONS, includeDirs: false }; assertEquals(await expandGlobArray("subdir", options), []); }); -test(async function expandGlobPermError(): Promise { +Deno.test(async function expandGlobPermError(): Promise { const exampleUrl = new URL("testdata/expand_wildcard.js", import.meta.url); const p = run({ args: [execPath(), exampleUrl.toString()], @@ -133,5 +132,3 @@ test(async function expandGlobPermError(): Promise { "Uncaught PermissionDenied" ); }); - -runIfMain(import.meta); diff --git a/std/fs/move_test.ts b/std/fs/move_test.ts index 7958935091..b835e6dfa7 100644 --- a/std/fs/move_test.ts +++ b/std/fs/move_test.ts @@ -1,5 +1,4 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. -import { test } from "../testing/mod.ts"; import { assertEquals, assertThrows, @@ -13,7 +12,7 @@ import { exists, existsSync } from "./exists.ts"; const testdataDir = path.resolve("fs", "testdata"); -test(async function moveDirectoryIfSrcNotExists(): Promise { +Deno.test(async function moveDirectoryIfSrcNotExists(): Promise { const srcDir = path.join(testdataDir, "move_test_src_1"); const destDir = path.join(testdataDir, "move_test_dest_1"); // if src directory not exist @@ -24,7 +23,7 @@ test(async function moveDirectoryIfSrcNotExists(): Promise { ); }); -test(async function moveDirectoryIfDestNotExists(): Promise { +Deno.test(async function moveDirectoryIfDestNotExists(): Promise { const srcDir = path.join(testdataDir, "move_test_src_2"); const destDir = path.join(testdataDir, "move_test_dest_2"); @@ -43,7 +42,7 @@ test(async function moveDirectoryIfDestNotExists(): Promise { await Deno.remove(destDir); }); -test(async function moveFileIfSrcNotExists(): Promise { +Deno.test(async function moveFileIfSrcNotExists(): Promise { const srcFile = path.join(testdataDir, "move_test_src_3", "test.txt"); const destFile = path.join(testdataDir, "move_test_dest_3", "test.txt"); @@ -55,7 +54,7 @@ test(async function moveFileIfSrcNotExists(): Promise { ); }); -test(async function moveFileIfDestExists(): Promise { +Deno.test(async function moveFileIfDestExists(): Promise { const srcDir = path.join(testdataDir, "move_test_src_4"); const destDir = path.join(testdataDir, "move_test_dest_4"); const srcFile = path.join(srcDir, "test.txt"); @@ -105,7 +104,7 @@ test(async function moveFileIfDestExists(): Promise { ]); }); -test(async function moveDirectory(): Promise { +Deno.test(async function moveDirectory(): Promise { const srcDir = path.join(testdataDir, "move_test_src_5"); const destDir = path.join(testdataDir, "move_test_dest_5"); const srcFile = path.join(srcDir, "test.txt"); @@ -130,7 +129,7 @@ test(async function moveDirectory(): Promise { await Deno.remove(destDir, { recursive: true }); }); -test(async function moveIfSrcAndDestDirectoryExistsAndOverwrite(): Promise< +Deno.test(async function moveIfSrcAndDestDirectoryExistsAndOverwrite(): Promise< void > { const srcDir = path.join(testdataDir, "move_test_src_6"); @@ -165,7 +164,7 @@ test(async function moveIfSrcAndDestDirectoryExistsAndOverwrite(): Promise< await Deno.remove(destDir, { recursive: true }); }); -test(async function moveIntoSubDir(): Promise { +Deno.test(async function moveIntoSubDir(): Promise { const srcDir = path.join(testdataDir, "move_test_src_7"); const destDir = path.join(srcDir, "nest"); @@ -181,7 +180,7 @@ test(async function moveIntoSubDir(): Promise { await Deno.remove(srcDir, { recursive: true }); }); -test(function moveSyncDirectoryIfSrcNotExists(): void { +Deno.test(function moveSyncDirectoryIfSrcNotExists(): void { const srcDir = path.join(testdataDir, "move_sync_test_src_1"); const destDir = path.join(testdataDir, "move_sync_test_dest_1"); // if src directory not exist @@ -190,7 +189,7 @@ test(function moveSyncDirectoryIfSrcNotExists(): void { }); }); -test(function moveSyncDirectoryIfDestNotExists(): void { +Deno.test(function moveSyncDirectoryIfDestNotExists(): void { const srcDir = path.join(testdataDir, "move_sync_test_src_2"); const destDir = path.join(testdataDir, "move_sync_test_dest_2"); @@ -209,7 +208,7 @@ test(function moveSyncDirectoryIfDestNotExists(): void { Deno.removeSync(destDir); }); -test(function moveSyncFileIfSrcNotExists(): void { +Deno.test(function moveSyncFileIfSrcNotExists(): void { const srcFile = path.join(testdataDir, "move_sync_test_src_3", "test.txt"); const destFile = path.join(testdataDir, "move_sync_test_dest_3", "test.txt"); @@ -219,7 +218,7 @@ test(function moveSyncFileIfSrcNotExists(): void { }); }); -test(function moveSyncFileIfDestExists(): void { +Deno.test(function moveSyncFileIfDestExists(): void { const srcDir = path.join(testdataDir, "move_sync_test_src_4"); const destDir = path.join(testdataDir, "move_sync_test_dest_4"); const srcFile = path.join(srcDir, "test.txt"); @@ -266,7 +265,7 @@ test(function moveSyncFileIfDestExists(): void { Deno.removeSync(destDir, { recursive: true }); }); -test(function moveSyncDirectory(): void { +Deno.test(function moveSyncDirectory(): void { const srcDir = path.join(testdataDir, "move_sync_test_src_5"); const destDir = path.join(testdataDir, "move_sync_test_dest_5"); const srcFile = path.join(srcDir, "test.txt"); @@ -289,7 +288,7 @@ test(function moveSyncDirectory(): void { Deno.removeSync(destDir, { recursive: true }); }); -test(function moveSyncIfSrcAndDestDirectoryExistsAndOverwrite(): void { +Deno.test(function moveSyncIfSrcAndDestDirectoryExistsAndOverwrite(): void { const srcDir = path.join(testdataDir, "move_sync_test_src_6"); const destDir = path.join(testdataDir, "move_sync_test_dest_6"); const srcFile = path.join(srcDir, "test.txt"); @@ -316,7 +315,7 @@ test(function moveSyncIfSrcAndDestDirectoryExistsAndOverwrite(): void { Deno.removeSync(destDir, { recursive: true }); }); -test(function moveSyncIntoSubDir(): void { +Deno.test(function moveSyncIntoSubDir(): void { const srcDir = path.join(testdataDir, "move_sync_test_src_7"); const destDir = path.join(srcDir, "nest"); diff --git a/std/fs/read_file_str_test.ts b/std/fs/read_file_str_test.ts index 58c649322e..c652fe0961 100644 --- a/std/fs/read_file_str_test.ts +++ b/std/fs/read_file_str_test.ts @@ -1,18 +1,17 @@ -import { test } from "../testing/mod.ts"; import { assert } from "../testing/asserts.ts"; import * as path from "../path/mod.ts"; import { readFileStrSync, readFileStr } from "./read_file_str.ts"; const testdataDir = path.resolve("fs", "testdata"); -test(function testReadFileSync(): void { +Deno.test(function testReadFileSync(): void { const jsonFile = path.join(testdataDir, "json_valid_obj.json"); const strFile = readFileStrSync(jsonFile); assert(typeof strFile === "string"); assert(strFile.length > 0); }); -test(async function testReadFile(): Promise { +Deno.test(async function testReadFile(): Promise { const jsonFile = path.join(testdataDir, "json_valid_obj.json"); const strFile = await readFileStr(jsonFile); assert(typeof strFile === "string"); diff --git a/std/fs/read_json_test.ts b/std/fs/read_json_test.ts index c89006ec15..c394963b0f 100644 --- a/std/fs/read_json_test.ts +++ b/std/fs/read_json_test.ts @@ -1,5 +1,4 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. -import { test } from "../testing/mod.ts"; import { assertEquals, assertThrowsAsync, @@ -10,7 +9,7 @@ import { readJson, readJsonSync } from "./read_json.ts"; const testdataDir = path.resolve("fs", "testdata"); -test(async function readJsonFileNotExists(): Promise { +Deno.test(async function readJsonFileNotExists(): Promise { const emptyJsonFile = path.join(testdataDir, "json_not_exists.json"); await assertThrowsAsync( @@ -20,7 +19,7 @@ test(async function readJsonFileNotExists(): Promise { ); }); -test(async function readEmptyJsonFile(): Promise { +Deno.test(async function readEmptyJsonFile(): Promise { const emptyJsonFile = path.join(testdataDir, "json_empty.json"); await assertThrowsAsync( @@ -30,7 +29,7 @@ test(async function readEmptyJsonFile(): Promise { ); }); -test(async function readInvalidJsonFile(): Promise { +Deno.test(async function readInvalidJsonFile(): Promise { const invalidJsonFile = path.join(testdataDir, "json_invalid.json"); await assertThrowsAsync( @@ -40,7 +39,7 @@ test(async function readInvalidJsonFile(): Promise { ); }); -test(async function readValidArrayJsonFile(): Promise { +Deno.test(async function readValidArrayJsonFile(): Promise { const invalidJsonFile = path.join(testdataDir, "json_valid_array.json"); const json = await readJson(invalidJsonFile); @@ -48,7 +47,7 @@ test(async function readValidArrayJsonFile(): Promise { assertEquals(json, ["1", "2", "3"]); }); -test(async function readValidObjJsonFile(): Promise { +Deno.test(async function readValidObjJsonFile(): Promise { const invalidJsonFile = path.join(testdataDir, "json_valid_obj.json"); const json = await readJson(invalidJsonFile); @@ -56,13 +55,13 @@ test(async function readValidObjJsonFile(): Promise { assertEquals(json, { key1: "value1", key2: "value2" }); }); -test(async function readValidObjJsonFileWithRelativePath(): Promise { +Deno.test(async function readValidObjJsonFileWithRelativePath(): Promise { const json = await readJson("./fs/testdata/json_valid_obj.json"); assertEquals(json, { key1: "value1", key2: "value2" }); }); -test(function readJsonFileNotExistsSync(): void { +Deno.test(function readJsonFileNotExistsSync(): void { const emptyJsonFile = path.join(testdataDir, "json_not_exists.json"); assertThrows((): void => { @@ -70,7 +69,7 @@ test(function readJsonFileNotExistsSync(): void { }); }); -test(function readEmptyJsonFileSync(): void { +Deno.test(function readEmptyJsonFileSync(): void { const emptyJsonFile = path.join(testdataDir, "json_empty.json"); assertThrows((): void => { @@ -78,7 +77,7 @@ test(function readEmptyJsonFileSync(): void { }); }); -test(function readInvalidJsonFile(): void { +Deno.test(function readInvalidJsonFile(): void { const invalidJsonFile = path.join(testdataDir, "json_invalid.json"); assertThrows((): void => { @@ -86,7 +85,7 @@ test(function readInvalidJsonFile(): void { }); }); -test(function readValidArrayJsonFileSync(): void { +Deno.test(function readValidArrayJsonFileSync(): void { const invalidJsonFile = path.join(testdataDir, "json_valid_array.json"); const json = readJsonSync(invalidJsonFile); @@ -94,7 +93,7 @@ test(function readValidArrayJsonFileSync(): void { assertEquals(json, ["1", "2", "3"]); }); -test(function readValidObjJsonFileSync(): void { +Deno.test(function readValidObjJsonFileSync(): void { const invalidJsonFile = path.join(testdataDir, "json_valid_obj.json"); const json = readJsonSync(invalidJsonFile); @@ -102,7 +101,7 @@ test(function readValidObjJsonFileSync(): void { assertEquals(json, { key1: "value1", key2: "value2" }); }); -test(function readValidObjJsonFileSyncWithRelativePath(): void { +Deno.test(function readValidObjJsonFileSyncWithRelativePath(): void { const json = readJsonSync("./fs/testdata/json_valid_obj.json"); assertEquals(json, { key1: "value1", key2: "value2" }); diff --git a/std/fs/utils_test.ts b/std/fs/utils_test.ts index 7511801775..93f4664e7d 100644 --- a/std/fs/utils_test.ts +++ b/std/fs/utils_test.ts @@ -1,6 +1,5 @@ // Copyright the Browserify authors. MIT License. -import { test } from "../testing/mod.ts"; import { assertEquals } from "../testing/asserts.ts"; import * as path from "../path/mod.ts"; import { isSubdir, getFileInfoType, PathType } from "./utils.ts"; @@ -9,7 +8,7 @@ import { ensureDirSync } from "./ensure_dir.ts"; const testdataDir = path.resolve("fs", "testdata"); -test(function _isSubdir(): void { +Deno.test(function _isSubdir(): void { const pairs = [ ["", "", false, path.posix.sep], ["/first/second", "/first", false, path.posix.sep], @@ -34,7 +33,7 @@ test(function _isSubdir(): void { }); }); -test(function _getFileInfoType(): void { +Deno.test(function _getFileInfoType(): void { const pairs = [ [path.join(testdataDir, "file_type_1"), "file"], [path.join(testdataDir, "file_type_dir_1"), "dir"] diff --git a/std/fs/walk_test.ts b/std/fs/walk_test.ts index 8f218eca6c..4984546f21 100644 --- a/std/fs/walk_test.ts +++ b/std/fs/walk_test.ts @@ -3,12 +3,11 @@ const { remove } = Deno; type ErrorKind = Deno.ErrorKind; type DenoError = Deno.DenoError; import { walk, walkSync, WalkOptions, WalkInfo } from "./walk.ts"; -import { test, TestFunction, runIfMain } from "../testing/mod.ts"; import { assertEquals, assertThrowsAsync } from "../testing/asserts.ts"; export async function testWalk( setup: (arg0: string) => void | Promise, - t: TestFunction + t: Deno.TestFunction ): Promise { const name = t.name; async function fn(): Promise { @@ -23,7 +22,7 @@ export async function testWalk( remove(d, { recursive: true }); } } - test({ name, fn }); + Deno.test({ name, fn }); } function normalize({ filename }: WalkInfo): string { @@ -275,5 +274,3 @@ testWalk( } ); */ - -runIfMain(import.meta); diff --git a/std/fs/write_file_str_test.ts b/std/fs/write_file_str_test.ts index f9cf760fe0..279afe3d1a 100644 --- a/std/fs/write_file_str_test.ts +++ b/std/fs/write_file_str_test.ts @@ -1,11 +1,10 @@ -import { test } from "../testing/mod.ts"; import { assertEquals } from "../testing/asserts.ts"; import * as path from "../path/mod.ts"; import { writeFileStr, writeFileStrSync } from "./write_file_str.ts"; const testdataDir = path.resolve("fs", "testdata"); -test(function testReadFileSync(): void { +Deno.test(function testReadFileSync(): void { const jsonFile = path.join(testdataDir, "write_file_1.json"); const content = "write_file_str_test"; writeFileStrSync(jsonFile, content); @@ -21,7 +20,7 @@ test(function testReadFileSync(): void { assertEquals(content, result); }); -test(async function testReadFile(): Promise { +Deno.test(async function testReadFile(): Promise { const jsonFile = path.join(testdataDir, "write_file_2.json"); const content = "write_file_str_test"; await writeFileStr(jsonFile, content); diff --git a/std/fs/write_json_test.ts b/std/fs/write_json_test.ts index 5b1d88c5a1..09fa05d604 100644 --- a/std/fs/write_json_test.ts +++ b/std/fs/write_json_test.ts @@ -1,5 +1,4 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. -import { test } from "../testing/mod.ts"; import { assertEquals, assertThrowsAsync, @@ -10,7 +9,7 @@ import { writeJson, writeJsonSync } from "./write_json.ts"; const testdataDir = path.resolve("fs", "testdata"); -test(async function writeJsonIfNotExists(): Promise { +Deno.test(async function writeJsonIfNotExists(): Promise { const notExistsJsonFile = path.join(testdataDir, "file_not_exists.json"); await assertThrowsAsync( @@ -29,7 +28,7 @@ test(async function writeJsonIfNotExists(): Promise { assertEquals(new TextDecoder().decode(content), `{"a":"1"}`); }); -test(async function writeJsonIfExists(): Promise { +Deno.test(async function writeJsonIfExists(): Promise { const existsJsonFile = path.join(testdataDir, "file_write_exists.json"); await Deno.writeFile(existsJsonFile, new Uint8Array()); @@ -50,7 +49,7 @@ test(async function writeJsonIfExists(): Promise { assertEquals(new TextDecoder().decode(content), `{"a":"1"}`); }); -test(async function writeJsonIfExistsAnInvalidJson(): Promise { +Deno.test(async function writeJsonIfExistsAnInvalidJson(): Promise { const existsInvalidJsonFile = path.join( testdataDir, "file_write_invalid.json" @@ -75,7 +74,7 @@ test(async function writeJsonIfExistsAnInvalidJson(): Promise { assertEquals(new TextDecoder().decode(content), `{"a":"1"}`); }); -test(async function writeJsonWithSpaces(): Promise { +Deno.test(async function writeJsonWithSpaces(): Promise { const existsJsonFile = path.join(testdataDir, "file_write_spaces.json"); const invalidJsonContent = new TextEncoder().encode(); @@ -97,7 +96,7 @@ test(async function writeJsonWithSpaces(): Promise { assertEquals(new TextDecoder().decode(content), `{\n "a": "1"\n}`); }); -test(async function writeJsonWithReplacer(): Promise { +Deno.test(async function writeJsonWithReplacer(): Promise { const existsJsonFile = path.join(testdataDir, "file_write_replacer.json"); const invalidJsonContent = new TextEncoder().encode(); @@ -125,7 +124,7 @@ test(async function writeJsonWithReplacer(): Promise { assertEquals(new TextDecoder().decode(content), `{"a":"1"}`); }); -test(function writeJsonSyncIfNotExists(): void { +Deno.test(function writeJsonSyncIfNotExists(): void { const notExistsJsonFile = path.join(testdataDir, "file_not_exists_sync.json"); assertThrows( @@ -144,7 +143,7 @@ test(function writeJsonSyncIfNotExists(): void { assertEquals(new TextDecoder().decode(content), `{"a":"1"}`); }); -test(function writeJsonSyncIfExists(): void { +Deno.test(function writeJsonSyncIfExists(): void { const existsJsonFile = path.join(testdataDir, "file_write_exists_sync.json"); Deno.writeFileSync(existsJsonFile, new Uint8Array()); @@ -165,7 +164,7 @@ test(function writeJsonSyncIfExists(): void { assertEquals(new TextDecoder().decode(content), `{"a":"1"}`); }); -test(function writeJsonSyncIfExistsAnInvalidJson(): void { +Deno.test(function writeJsonSyncIfExistsAnInvalidJson(): void { const existsInvalidJsonFile = path.join( testdataDir, "file_write_invalid_sync.json" @@ -190,7 +189,7 @@ test(function writeJsonSyncIfExistsAnInvalidJson(): void { assertEquals(new TextDecoder().decode(content), `{"a":"1"}`); }); -test(function writeJsonWithSpaces(): void { +Deno.test(function writeJsonWithSpaces(): void { const existsJsonFile = path.join(testdataDir, "file_write_spaces_sync.json"); const invalidJsonContent = new TextEncoder().encode(); @@ -212,7 +211,7 @@ test(function writeJsonWithSpaces(): void { assertEquals(new TextDecoder().decode(content), `{\n "a": "1"\n}`); }); -test(function writeJsonWithReplacer(): void { +Deno.test(function writeJsonWithReplacer(): void { const existsJsonFile = path.join( testdataDir, "file_write_replacer_sync.json" diff --git a/std/http/cookie_test.ts b/std/http/cookie_test.ts index 5f51a6d326..5e29fede73 100644 --- a/std/http/cookie_test.ts +++ b/std/http/cookie_test.ts @@ -2,9 +2,8 @@ import { ServerRequest, Response } from "./server.ts"; import { getCookies, delCookie, setCookie } from "./cookie.ts"; import { assert, assertEquals } from "../testing/asserts.ts"; -import { test } from "../testing/mod.ts"; -test({ +Deno.test({ name: "[HTTP] Cookie parser", fn(): void { const req = new ServerRequest(); @@ -32,7 +31,7 @@ test({ } }); -test({ +Deno.test({ name: "[HTTP] Cookie Delete", fn(): void { const res: Response = {}; @@ -44,7 +43,7 @@ test({ } }); -test({ +Deno.test({ name: "[HTTP] Cookie Set", fn(): void { const res: Response = {}; diff --git a/std/http/file_server_test.ts b/std/http/file_server_test.ts index 099723b878..ba625b7c81 100644 --- a/std/http/file_server_test.ts +++ b/std/http/file_server_test.ts @@ -1,8 +1,8 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. -import { test, runIfMain } from "../testing/mod.ts"; import { assert, assertEquals, assertStrContains } from "../testing/asserts.ts"; import { BufReader } from "../io/bufio.ts"; import { TextProtoReader } from "../textproto/mod.ts"; +const { test } = Deno; let fileServer: Deno.Process; @@ -135,5 +135,3 @@ test(async function printHelp(): Promise { helpProcess.close(); helpProcess.stdout.close(); }); - -runIfMain(import.meta); diff --git a/std/http/racing_server_test.ts b/std/http/racing_server_test.ts index 27be0d79c0..6399353390 100644 --- a/std/http/racing_server_test.ts +++ b/std/http/racing_server_test.ts @@ -1,6 +1,5 @@ const { connect, run } = Deno; -import { test, runIfMain } from "../testing/mod.ts"; import { assert, assertEquals } from "../testing/asserts.ts"; import { BufReader } from "../io/bufio.ts"; import { TextProtoReader } from "../textproto/mod.ts"; @@ -48,7 +47,7 @@ content-length: 8 World 4 `; -test(async function serverPipelineRace(): Promise { +Deno.test(async function serverPipelineRace(): Promise { await startServer(); const conn = await connect({ port: 4501 }); @@ -62,5 +61,3 @@ test(async function serverPipelineRace(): Promise { } killServer(); }); - -runIfMain(import.meta); diff --git a/std/http/server_test.ts b/std/http/server_test.ts index 10b0fec20f..a18cd273c8 100644 --- a/std/http/server_test.ts +++ b/std/http/server_test.ts @@ -5,9 +5,8 @@ // Ported from // https://github.com/golang/go/blob/master/src/net/http/responsewrite_test.go -const { Buffer } = Deno; +const { Buffer, test } = Deno; import { TextProtoReader } from "../textproto/mod.ts"; -import { test, runIfMain } from "../testing/mod.ts"; import { assert, assertEquals, @@ -820,5 +819,3 @@ test("writeTrailer should throw", async () => { "Not trailer" ); }); - -runIfMain(import.meta); diff --git a/std/io/bufio_test.ts b/std/io/bufio_test.ts index 780dfd3db5..665c25361b 100644 --- a/std/io/bufio_test.ts +++ b/std/io/bufio_test.ts @@ -5,7 +5,6 @@ const { Buffer } = Deno; type Reader = Deno.Reader; -import { test, runIfMain } from "../testing/mod.ts"; import { assert, assertEquals, @@ -43,7 +42,7 @@ async function readBytes(buf: BufReader): Promise { return decoder.decode(b.subarray(0, nb)); } -test(async function bufioReaderSimple(): Promise { +Deno.test(async function bufioReaderSimple(): Promise { const data = "hello world"; const b = new BufReader(stringsReader(data)); const s = await readBytes(b); @@ -111,7 +110,7 @@ const bufsizes: number[] = [ 4096 ]; -test(async function bufioBufReader(): Promise { +Deno.test(async function bufioBufReader(): Promise { const texts = new Array(31); let str = ""; let all = ""; @@ -139,7 +138,7 @@ test(async function bufioBufReader(): Promise { } }); -test(async function bufioBufferFull(): Promise { +Deno.test(async function bufioBufferFull(): Promise { const longString = "And now, hello, world! It is the time for all good men to come to the" + " aid of their party"; @@ -160,7 +159,7 @@ test(async function bufioBufferFull(): Promise { assertEquals(actual, "world!"); }); -test(async function bufioReadString(): Promise { +Deno.test(async function bufioReadString(): Promise { const string = "And now, hello world!"; const buf = new BufReader(stringsReader(string), MIN_READ_BUFFER_SIZE); @@ -242,12 +241,12 @@ async function testReadLine(input: Uint8Array): Promise { } } -test(async function bufioReadLine(): Promise { +Deno.test(async function bufioReadLine(): Promise { await testReadLine(testInput); await testReadLine(testInputrn); }); -test(async function bufioPeek(): Promise { +Deno.test(async function bufioPeek(): Promise { const decoder = new TextDecoder(); const p = new Uint8Array(10); // string is 16 (minReadBufferSize) long. @@ -323,7 +322,7 @@ test(async function bufioPeek(): Promise { */ }); -test(async function bufioWriter(): Promise { +Deno.test(async function bufioWriter(): Promise { const data = new Uint8Array(8192); for (let i = 0; i < data.byteLength; i++) { @@ -357,7 +356,7 @@ test(async function bufioWriter(): Promise { } }); -test(async function bufReaderReadFull(): Promise { +Deno.test(async function bufReaderReadFull(): Promise { const enc = new TextEncoder(); const dec = new TextDecoder(); const text = "Hello World"; @@ -382,5 +381,3 @@ test(async function bufReaderReadFull(): Promise { } } }); - -runIfMain(import.meta); diff --git a/std/io/ioutil_test.ts b/std/io/ioutil_test.ts index 26f307a6b3..261f4def0d 100644 --- a/std/io/ioutil_test.ts +++ b/std/io/ioutil_test.ts @@ -1,7 +1,6 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. const { Buffer } = Deno; type Reader = Deno.Reader; -import { test } from "../testing/mod.ts"; import { assertEquals } from "../testing/asserts.ts"; import { copyN, @@ -25,19 +24,19 @@ class BinaryReader implements Reader { } } -test(async function testReadShort(): Promise { +Deno.test(async function testReadShort(): Promise { const r = new BinaryReader(new Uint8Array([0x12, 0x34])); const short = await readShort(new BufReader(r)); assertEquals(short, 0x1234); }); -test(async function testReadInt(): Promise { +Deno.test(async function testReadInt(): Promise { const r = new BinaryReader(new Uint8Array([0x12, 0x34, 0x56, 0x78])); const int = await readInt(new BufReader(r)); assertEquals(int, 0x12345678); }); -test(async function testReadLong(): Promise { +Deno.test(async function testReadLong(): Promise { const r = new BinaryReader( new Uint8Array([0x00, 0x00, 0x00, 0x78, 0x12, 0x34, 0x56, 0x78]) ); @@ -45,7 +44,7 @@ test(async function testReadLong(): Promise { assertEquals(long, 0x7812345678); }); -test(async function testReadLong2(): Promise { +Deno.test(async function testReadLong2(): Promise { const r = new BinaryReader( new Uint8Array([0, 0, 0, 0, 0x12, 0x34, 0x56, 0x78]) ); @@ -53,7 +52,7 @@ test(async function testReadLong2(): Promise { assertEquals(long, 0x12345678); }); -test(async function testSliceLongToBytes(): Promise { +Deno.test(async function testSliceLongToBytes(): Promise { const arr = sliceLongToBytes(0x1234567890abcdef); const actual = readLong(new BufReader(new BinaryReader(new Uint8Array(arr)))); const expected = readLong( @@ -66,12 +65,12 @@ test(async function testSliceLongToBytes(): Promise { assertEquals(actual, expected); }); -test(async function testSliceLongToBytes2(): Promise { +Deno.test(async function testSliceLongToBytes2(): Promise { const arr = sliceLongToBytes(0x12345678); assertEquals(arr, [0, 0, 0, 0, 0x12, 0x34, 0x56, 0x78]); }); -test(async function testCopyN1(): Promise { +Deno.test(async function testCopyN1(): Promise { const w = new Buffer(); const r = stringsReader("abcdefghij"); const n = await copyN(w, r, 3); @@ -79,7 +78,7 @@ test(async function testCopyN1(): Promise { assertEquals(w.toString(), "abc"); }); -test(async function testCopyN2(): Promise { +Deno.test(async function testCopyN2(): Promise { const w = new Buffer(); const r = stringsReader("abcdefghij"); const n = await copyN(w, r, 11); diff --git a/std/io/readers_test.ts b/std/io/readers_test.ts index 474407427a..e3aaad0a59 100644 --- a/std/io/readers_test.ts +++ b/std/io/readers_test.ts @@ -1,5 +1,4 @@ -const { copy } = Deno; -import { test } from "../testing/mod.ts"; +const { copy, test } = Deno; import { assertEquals } from "../testing/asserts.ts"; import { MultiReader, StringReader } from "./readers.ts"; import { StringWriter } from "./writers.ts"; diff --git a/std/io/util_test.ts b/std/io/util_test.ts index 472b0dfb9d..f7179cd1eb 100644 --- a/std/io/util_test.ts +++ b/std/io/util_test.ts @@ -1,6 +1,5 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. -const { remove } = Deno; -import { test } from "../testing/mod.ts"; +const { remove, test } = Deno; import { assert, assertEquals } from "../testing/asserts.ts"; import * as path from "../path/mod.ts"; import { copyBytes, tempFile } from "./util.ts"; diff --git a/std/io/writers_test.ts b/std/io/writers_test.ts index decf611f1b..916ad043e9 100644 --- a/std/io/writers_test.ts +++ b/std/io/writers_test.ts @@ -1,5 +1,4 @@ -const { copy } = Deno; -import { test } from "../testing/mod.ts"; +const { copy, test } = Deno; import { assertEquals } from "../testing/asserts.ts"; import { StringWriter } from "./writers.ts"; import { StringReader } from "./readers.ts"; diff --git a/std/log/handlers_test.ts b/std/log/handlers_test.ts index bfba4f840c..693d2a4855 100644 --- a/std/log/handlers_test.ts +++ b/std/log/handlers_test.ts @@ -1,5 +1,5 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. -import { test } from "../testing/mod.ts"; +const { test } = Deno; import { assertEquals } from "../testing/asserts.ts"; import { LogLevel, getLevelName, getLevelByName } from "./levels.ts"; import { BaseHandler } from "./handlers.ts"; diff --git a/std/log/logger_test.ts b/std/log/logger_test.ts index 2385ac378e..76ff4cf955 100644 --- a/std/log/logger_test.ts +++ b/std/log/logger_test.ts @@ -1,5 +1,5 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. -import { test } from "../testing/mod.ts"; +const { test } = Deno; import { assertEquals } from "../testing/asserts.ts"; import { LogRecord, Logger } from "./logger.ts"; import { LogLevel } from "./levels.ts"; diff --git a/std/log/test.ts b/std/log/test.ts index a970d10bad..d4385968c6 100644 --- a/std/log/test.ts +++ b/std/log/test.ts @@ -1,5 +1,5 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. -import { test } from "../testing/mod.ts"; +const { test } = Deno; import { assertEquals } from "../testing/asserts.ts"; import * as log from "./mod.ts"; import { LogLevel } from "./levels.ts"; diff --git a/std/media_types/test.ts b/std/media_types/test.ts index 155dd6e3d0..3a9a7d9fef 100644 --- a/std/media_types/test.ts +++ b/std/media_types/test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. -import { test } from "../testing/mod.ts"; +const { test } = Deno; import { assertEquals } from "../testing/asserts.ts"; import { lookup, diff --git a/std/mime/multipart_test.ts b/std/mime/multipart_test.ts index d3e49aa4d5..95425368ce 100644 --- a/std/mime/multipart_test.ts +++ b/std/mime/multipart_test.ts @@ -7,7 +7,7 @@ import { assertThrows, assertThrowsAsync } from "../testing/asserts.ts"; -import { test, runIfMain } from "../testing/mod.ts"; +const { test } = Deno; import * as path from "../path/mod.ts"; import { FormFile, @@ -213,5 +213,3 @@ test(async function multipartMultipartReader2(): Promise { } } }); - -runIfMain(import.meta); diff --git a/std/node/events_test.ts b/std/node/events_test.ts index 0d8dd52e18..a2ed901127 100644 --- a/std/node/events_test.ts +++ b/std/node/events_test.ts @@ -1,4 +1,4 @@ -import { test } from "../testing/mod.ts"; +const { test } = Deno; import { assert, assertEquals, diff --git a/std/node/fs_test.ts b/std/node/fs_test.ts index c63891c443..9753d95207 100755 --- a/std/node/fs_test.ts +++ b/std/node/fs_test.ts @@ -1,5 +1,5 @@ +const { test } = Deno; import { readFile, readFileSync, readlink, readlinkSync } from "./fs.ts"; -import { test } from "../testing/mod.ts"; import * as path from "../path/mod.ts"; import { assertEquals, assert } from "../testing/asserts.ts"; diff --git a/std/node/module_test.ts b/std/node/module_test.ts index a869179ddf..7415f1845b 100644 --- a/std/node/module_test.ts +++ b/std/node/module_test.ts @@ -1,4 +1,4 @@ -import { test } from "../testing/mod.ts"; +const { test } = Deno; import { assertEquals, assert } from "../testing/asserts.ts"; import { createRequire } from "./module.ts"; diff --git a/std/node/os_test.ts b/std/node/os_test.ts index 65a9ef374b..14d4e42ab3 100644 --- a/std/node/os_test.ts +++ b/std/node/os_test.ts @@ -1,4 +1,4 @@ -import { test } from "../testing/mod.ts"; +const { test } = Deno; import { assert, assertThrows, diff --git a/std/node/process_test.ts b/std/node/process_test.ts index 0ddf71fbc2..51dbcd630b 100644 --- a/std/node/process_test.ts +++ b/std/node/process_test.ts @@ -1,4 +1,4 @@ -import { test } from "../testing/mod.ts"; +const { test } = Deno; import { assert, assertThrows, assertEquals } from "../testing/asserts.ts"; import { process } from "./process.ts"; diff --git a/std/node/util_test.ts b/std/node/util_test.ts index 45867f660a..751dba57e7 100644 --- a/std/node/util_test.ts +++ b/std/node/util_test.ts @@ -1,4 +1,4 @@ -import { test } from "../testing/mod.ts"; +const { test } = Deno; import { assert } from "../testing/asserts.ts"; import * as util from "./util.ts"; diff --git a/std/path/basename_test.ts b/std/path/basename_test.ts index c4e294501a..0c933307a1 100644 --- a/std/path/basename_test.ts +++ b/std/path/basename_test.ts @@ -1,7 +1,7 @@ // Copyright the Browserify authors. MIT License. // Ported from https://github.com/browserify/path-browserify/ -import { test } from "../testing/mod.ts"; +const { test } = Deno; import { assertEquals } from "../testing/asserts.ts"; import * as path from "./mod.ts"; diff --git a/std/path/dirname_test.ts b/std/path/dirname_test.ts index ffcfa99931..4ce80eef3e 100644 --- a/std/path/dirname_test.ts +++ b/std/path/dirname_test.ts @@ -1,7 +1,7 @@ // Copyright the Browserify authors. MIT License. // Ported from https://github.com/browserify/path-browserify/ -import { test } from "../testing/mod.ts"; +const { test } = Deno; import { assertEquals } from "../testing/asserts.ts"; import * as path from "./mod.ts"; diff --git a/std/path/extname_test.ts b/std/path/extname_test.ts index e272226556..d9e14bb48f 100644 --- a/std/path/extname_test.ts +++ b/std/path/extname_test.ts @@ -1,7 +1,7 @@ // Copyright the Browserify authors. MIT License. // Ported from https://github.com/browserify/path-browserify/ -import { test } from "../testing/mod.ts"; +const { test } = Deno; import { assertEquals } from "../testing/asserts.ts"; import * as path from "./mod.ts"; diff --git a/std/path/glob_test.ts b/std/path/glob_test.ts index 7f67ca219f..d8da1a47b6 100644 --- a/std/path/glob_test.ts +++ b/std/path/glob_test.ts @@ -1,5 +1,4 @@ -const { mkdir } = Deno; -import { test, runIfMain } from "../testing/mod.ts"; +const { mkdir, test } = Deno; import { assert, assertEquals } from "../testing/asserts.ts"; import { testWalk, touch, walkArray } from "../fs/walk_test.ts"; import { globToRegExp, isGlob, joinGlobs, normalizeGlob } from "./glob.ts"; @@ -247,5 +246,3 @@ test(function normalizeGlobGlobstar(): void { test(function joinGlobsGlobstar(): void { assertEquals(joinGlobs(["**", ".."], { globstar: true }), `**${SEP}..`); }); - -runIfMain(import.meta); diff --git a/std/path/globrex_test.ts b/std/path/globrex_test.ts index f091ebe9b8..29f039837d 100644 --- a/std/path/globrex_test.ts +++ b/std/path/globrex_test.ts @@ -2,7 +2,7 @@ // MIT License // Copyright (c) 2018 Terkel Gjervig Nielsen -import { test } from "../testing/mod.ts"; +const { test } = Deno; import { assertEquals } from "../testing/asserts.ts"; import { GlobrexOptions, globrex } from "./globrex.ts"; diff --git a/std/path/isabsolute_test.ts b/std/path/isabsolute_test.ts index 9a472e18cc..7db87c9cb9 100644 --- a/std/path/isabsolute_test.ts +++ b/std/path/isabsolute_test.ts @@ -1,7 +1,7 @@ // Copyright the Browserify authors. MIT License. // Ported from https://github.com/browserify/path-browserify/ -import { test } from "../testing/mod.ts"; +const { test } = Deno; import { assertEquals } from "../testing/asserts.ts"; import * as path from "./mod.ts"; diff --git a/std/path/join_test.ts b/std/path/join_test.ts index 878e896551..a73cf36794 100644 --- a/std/path/join_test.ts +++ b/std/path/join_test.ts @@ -1,4 +1,4 @@ -import { test } from "../testing/mod.ts"; +const { test } = Deno; import { assertEquals } from "../testing/asserts.ts"; import * as path from "./mod.ts"; diff --git a/std/path/parse_format_test.ts b/std/path/parse_format_test.ts index 6ecce73043..0a7e83bbad 100644 --- a/std/path/parse_format_test.ts +++ b/std/path/parse_format_test.ts @@ -3,7 +3,7 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ // TODO(kt3k): fix any types in this file -import { test } from "../testing/mod.ts"; +const { test } = Deno; import { assertEquals } from "../testing/asserts.ts"; import * as path from "./mod.ts"; diff --git a/std/path/relative_test.ts b/std/path/relative_test.ts index 8a130fbff8..3fe5aab4b7 100644 --- a/std/path/relative_test.ts +++ b/std/path/relative_test.ts @@ -1,7 +1,7 @@ // Copyright the Browserify authors. MIT License. // Ported from https://github.com/browserify/path-browserify/ -import { test } from "../testing/mod.ts"; +const { test } = Deno; import { assertEquals } from "../testing/asserts.ts"; import * as path from "./mod.ts"; diff --git a/std/path/resolve_test.ts b/std/path/resolve_test.ts index 65a8a2d050..2fc49e398d 100644 --- a/std/path/resolve_test.ts +++ b/std/path/resolve_test.ts @@ -1,8 +1,7 @@ // Copyright the Browserify authors. MIT License. // Ported from https://github.com/browserify/path-browserify/ -const { cwd } = Deno; -import { test } from "../testing/mod.ts"; +const { cwd, test } = Deno; import { assertEquals } from "../testing/asserts.ts"; import * as path from "./mod.ts"; diff --git a/std/path/zero_length_strings_test.ts b/std/path/zero_length_strings_test.ts index 5649f6999b..128ba242db 100644 --- a/std/path/zero_length_strings_test.ts +++ b/std/path/zero_length_strings_test.ts @@ -1,8 +1,7 @@ // Copyright the Browserify authors. MIT License. // Ported from https://github.com/browserify/path-browserify/ -const { cwd } = Deno; -import { test } from "../testing/mod.ts"; +const { cwd, test } = Deno; import { assertEquals } from "../testing/asserts.ts"; import * as path from "./mod.ts"; diff --git a/std/signal/test.ts b/std/signal/test.ts index cff9672e5e..dfe5bf4cfc 100644 --- a/std/signal/test.ts +++ b/std/signal/test.ts @@ -1,4 +1,5 @@ -import { test, assertEquals, assertThrows } from "../testing/mod.ts"; +const { test } = Deno; +import { assertEquals, assertThrows } from "../testing/asserts.ts"; import { delay } from "../util/async.ts"; import { signal } from "./mod.ts"; diff --git a/std/strings/pad_test.ts b/std/strings/pad_test.ts index e0364cf38a..9a125b9d2c 100644 --- a/std/strings/pad_test.ts +++ b/std/strings/pad_test.ts @@ -1,4 +1,4 @@ -import { test } from "../testing/mod.ts"; +const { test } = Deno; import { assertEquals } from "../testing/asserts.ts"; import { pad } from "./pad.ts"; diff --git a/std/testing/asserts_test.ts b/std/testing/asserts_test.ts index ede5abbde5..3a846417ab 100644 --- a/std/testing/asserts_test.ts +++ b/std/testing/asserts_test.ts @@ -14,8 +14,8 @@ import { unimplemented, unreachable } from "./asserts.ts"; -import { test } from "./mod.ts"; import { red, green, white, gray, bold } from "../fmt/colors.ts"; +const { test } = Deno; test(function testingEqual(): void { assert(equal("world", "world")); diff --git a/std/testing/bench_test.ts b/std/testing/bench_test.ts index 8af2f0d6db..b384b21f73 100644 --- a/std/testing/bench_test.ts +++ b/std/testing/bench_test.ts @@ -1,4 +1,4 @@ -import { test, runIfMain } from "./mod.ts"; +const { test } = Deno; import { bench, runBenchmarks } from "./bench.ts"; import "./bench_example.ts"; @@ -56,5 +56,3 @@ test(async function benching(): Promise { await runBenchmarks({ skip: /throw/ }); }); - -runIfMain(import.meta); diff --git a/std/testing/diff_test.ts b/std/testing/diff_test.ts index d9fbdb9564..0e84162740 100644 --- a/std/testing/diff_test.ts +++ b/std/testing/diff_test.ts @@ -1,6 +1,6 @@ import diff from "./diff.ts"; import { assertEquals } from "../testing/asserts.ts"; -import { test } from "./mod.ts"; +const { test } = Deno; test({ name: "empty", diff --git a/std/testing/format_test.ts b/std/testing/format_test.ts index e2bb8df239..14f84f3c2b 100644 --- a/std/testing/format_test.ts +++ b/std/testing/format_test.ts @@ -6,7 +6,7 @@ * LICENSE file in the root directory of this source tree. * */ -import { test } from "./mod.ts"; +const { test } = Deno; import { assertEquals } from "../testing/asserts.ts"; import { format } from "./format.ts"; diff --git a/std/testing/mod.ts b/std/testing/mod.ts deleted file mode 100644 index a60e9c93fc..0000000000 --- a/std/testing/mod.ts +++ /dev/null @@ -1,450 +0,0 @@ -// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. - -export * from "./asserts.ts"; -export * from "./bench.ts"; -import diff from "./diff.ts"; -export { diff }; -export * from "./format.ts"; -export * from "./runner.ts"; - -import { - bgRed, - white, - bold, - green, - red, - gray, - yellow, - italic -} from "../fmt/colors.ts"; -import { assert } from "./asserts.ts"; -export type TestFunction = () => void | Promise; - -export interface TestDefinition { - fn: TestFunction; - name: string; -} - -// Replacement of the global `console` function to be in silent mode -const noop = function(): void {}; - -// Clear the current line of the console. -// see: http://ascii-table.com/ansi-escape-sequences-vt-100.php -const CLEAR_LINE = "\x1b[2K\r"; - -// Save Object of the global `console` in case of silent mode -type Console = typeof window.console; -// ref https://console.spec.whatwg.org/#console-namespace -// For historical web-compatibility reasons, the namespace object for -// console must have as its [[Prototype]] an empty object, created as if -// by ObjectCreate(%ObjectPrototype%), instead of %ObjectPrototype%. -const disabledConsole = Object.create({}) as Console; -Object.assign(disabledConsole, { - log: noop, - debug: noop, - info: noop, - dir: noop, - warn: noop, - error: noop, - assert: noop, - count: noop, - countReset: noop, - table: noop, - time: noop, - timeLog: noop, - timeEnd: noop, - group: noop, - groupCollapsed: noop, - groupEnd: noop, - clear: noop -}); - -const originalConsole = window.console; - -function enableConsole(): void { - window.console = originalConsole; -} - -function disableConsole(): void { - window.console = disabledConsole; -} - -const encoder = new TextEncoder(); -function print(txt: string, newline = true): void { - if (newline) { - txt += "\n"; - } - Deno.stdout.writeSync(encoder.encode(`${txt}`)); -} - -declare global { - interface Window { - /** - * A global property to collect all registered test cases. - * - * It is required because user's code can import multiple versions - * of `testing` module. - * - * If test cases aren't registered in a globally shared - * object, then imports from different versions would register test cases - * to registry from it's respective version of `testing` module. - */ - __DENO_TEST_REGISTRY: TestDefinition[]; - } -} - -let candidates: TestDefinition[] = []; -if (window["__DENO_TEST_REGISTRY"]) { - candidates = window.__DENO_TEST_REGISTRY as TestDefinition[]; -} else { - window["__DENO_TEST_REGISTRY"] = candidates; -} -let filterRegExp: RegExp | null; -let filtered = 0; - -// Must be called before any test() that needs to be filtered. -export function setFilter(s: string): void { - filterRegExp = new RegExp(s, "i"); -} - -function filter(name: string): boolean { - if (filterRegExp) { - return filterRegExp.test(name); - } else { - return true; - } -} - -export function test(t: TestDefinition): void; -export function test(fn: TestFunction): void; -export function test(name: string, fn: TestFunction): void; -export function test( - t: string | TestDefinition | TestFunction, - fn?: TestFunction -): void { - let name: string; - - if (typeof t === "string") { - if (!fn) { - throw new Error("Missing test function"); - } - name = t; - if (!name) { - throw new Error("The name of test case can't be empty"); - } - } else if (typeof t === "function") { - fn = t; - name = t.name; - if (!name) { - throw new Error("Test function can't be anonymous"); - } - } else { - fn = t.fn; - if (!fn) { - throw new Error("Missing test function"); - } - name = t.name; - if (!name) { - throw new Error("The name of test case can't be empty"); - } - } - assert(!!name, "The name of test case shouldn't be empty"); - assert(!!fn, "Test function shouldn't be empty"); - - if (filter(name)) { - candidates.push({ fn, name }); - } else { - filtered++; - } -} - -const RED_FAILED = red("FAILED"); -const GREEN_OK = green("OK"); -const RED_BG_FAIL = bgRed(" FAIL "); - -interface TestStats { - filtered: number; - ignored: number; - measured: number; - passed: number; - failed: number; -} - -interface TestResult { - timeElapsed?: number; - name: string; - error?: Error; - ok: boolean; - printed: boolean; -} - -interface TestResults { - keys: Map; - cases: Map; -} - -function createTestResults(tests: TestDefinition[]): TestResults { - return tests.reduce( - (acc: TestResults, { name }: TestDefinition, i: number): TestResults => { - acc.keys.set(name, i); - acc.cases.set(i, { name, printed: false, ok: false, error: undefined }); - return acc; - }, - { cases: new Map(), keys: new Map() } - ); -} - -function formatTestTime(time = 0): string { - return `${time.toFixed(2)}ms`; -} - -function promptTestTime(time = 0, displayWarning = false): string { - // if time > 5s we display a warning - // only for test time, not the full runtime - if (displayWarning && time >= 5000) { - return bgRed(white(bold(`(${formatTestTime(time)})`))); - } else { - return gray(italic(`(${formatTestTime(time)})`)); - } -} - -function report(result: TestResult): void { - if (result.ok) { - print( - `${GREEN_OK} ${result.name} ${promptTestTime( - result.timeElapsed, - true - )}` - ); - } else if (result.error) { - print(`${RED_FAILED} ${result.name}\n${result.error.stack}`); - } else { - print(`test ${result.name} ... unresolved`); - } - result.printed = true; -} - -function printFailedSummary(results: TestResults): void { - results.cases.forEach((v): void => { - if (!v.ok) { - console.error(`${RED_BG_FAIL} ${red(v.name)}`); - console.error(v.error); - } - }); -} - -function printResults( - stats: TestStats, - results: TestResults, - flush: boolean, - exitOnFail: boolean, - timeElapsed: number -): void { - if (flush) { - for (const result of results.cases.values()) { - if (!result.printed) { - report(result); - if (result.error && exitOnFail) { - break; - } - } - } - } - // Attempting to match the output of Rust's test runner. - print( - `\ntest result: ${stats.failed ? RED_BG_FAIL : GREEN_OK} ` + - `${stats.passed} passed; ${stats.failed} failed; ` + - `${stats.ignored} ignored; ${stats.measured} measured; ` + - `${stats.filtered} filtered out ` + - `${promptTestTime(timeElapsed)}\n` - ); -} - -function previousPrinted(name: string, results: TestResults): boolean { - const curIndex = results.keys.get(name); - assert(curIndex != null); - if (curIndex === 0) { - return true; - } - const prev = results.cases.get(curIndex - 1); - assert(prev != null); - return prev.printed; -} - -async function createTestCase( - stats: TestStats, - results: TestResults, - exitOnFail: boolean, - { fn, name }: TestDefinition -): Promise { - const i = results.keys.get(name); - assert(i != null); - const result = results.cases.get(i); - assert(result != null); - try { - const start = performance.now(); - await fn(); - const end = performance.now(); - stats.passed++; - result.ok = true; - result.timeElapsed = end - start; - } catch (err) { - stats.failed++; - result.error = err; - if (exitOnFail) { - throw err; - } - } - if (previousPrinted(name, results)) { - report(result); - } -} - -function initTestCases( - stats: TestStats, - results: TestResults, - tests: TestDefinition[], - exitOnFail: boolean -): Array> { - return tests.map(createTestCase.bind(null, stats, results, exitOnFail)); -} - -async function runTestsParallel( - stats: TestStats, - results: TestResults, - tests: TestDefinition[], - exitOnFail: boolean -): Promise { - try { - await Promise.all(initTestCases(stats, results, tests, exitOnFail)); - } catch (_) { - // The error was thrown to stop awaiting all promises if exitOnFail === true - // stats.failed has been incremented and the error stored in results - } -} - -async function runTestsSerial( - stats: TestStats, - results: TestResults, - tests: TestDefinition[], - exitOnFail: boolean, - disableLog: boolean -): Promise { - for (const { fn, name } of tests) { - // Displaying the currently running test if silent mode - if (disableLog) { - print(`${yellow("RUNNING")} ${name}`, false); - } - try { - const start = performance.now(); - await fn(); - const end = performance.now(); - if (disableLog) { - // Rewriting the current prompt line to erase `running ....` - print(CLEAR_LINE, false); - } - stats.passed++; - print( - GREEN_OK + " " + name + " " + promptTestTime(end - start, true) - ); - results.cases.forEach((v): void => { - if (v.name === name) { - v.ok = true; - v.printed = true; - } - }); - } catch (err) { - if (disableLog) { - print(CLEAR_LINE, false); - } - print(`${RED_FAILED} ${name}`); - print(err.stack); - stats.failed++; - results.cases.forEach((v): void => { - if (v.name === name) { - v.error = err; - v.ok = false; - v.printed = true; - } - }); - if (exitOnFail) { - break; - } - } - } -} - -/** Defines options for controlling execution details of a test suite. */ -export interface RunTestsOptions { - parallel?: boolean; - exitOnFail?: boolean; - only?: RegExp; - skip?: RegExp; - disableLog?: boolean; -} - -/** - * Runs specified test cases. - * Parallel execution can be enabled via the boolean option; default: serial. - */ -// TODO: change return type to `Promise` - ie. don't -// exit but return value -export async function runTests({ - parallel = false, - exitOnFail = false, - only = /[^\s]/, - skip = /^\s*$/, - disableLog = false -}: RunTestsOptions = {}): Promise { - const tests: TestDefinition[] = candidates.filter( - ({ name }): boolean => only.test(name) && !skip.test(name) - ); - const stats: TestStats = { - measured: 0, - ignored: candidates.length - tests.length, - filtered: filtered, - passed: 0, - failed: 0 - }; - const results: TestResults = createTestResults(tests); - print(`running ${tests.length} tests`); - const start = performance.now(); - if (Deno.args.includes("--quiet")) { - disableLog = true; - } - if (disableLog) { - disableConsole(); - } - if (parallel) { - await runTestsParallel(stats, results, tests, exitOnFail); - } else { - await runTestsSerial(stats, results, tests, exitOnFail, disableLog); - } - const end = performance.now(); - if (disableLog) { - enableConsole(); - } - printResults(stats, results, parallel, exitOnFail, end - start); - if (stats.failed) { - // Use setTimeout to avoid the error being ignored due to unhandled - // promise rejections being swallowed. - setTimeout((): void => { - console.error(`There were ${stats.failed} test failures.`); - printFailedSummary(results); - Deno.exit(1); - }, 0); - } -} - -/** - * Runs specified test cases if the enclosing script is main. - * Execution mode is toggleable via opts.parallel, defaults to false. - */ -export async function runIfMain( - meta: ImportMeta, - opts?: RunTestsOptions -): Promise { - if (meta.main) { - return runTests(opts); - } -} diff --git a/std/testing/runner.ts b/std/testing/runner.ts index 17d5942f89..8d6501e029 100755 --- a/std/testing/runner.ts +++ b/std/testing/runner.ts @@ -3,7 +3,6 @@ import { parse } from "../flags/mod.ts"; import { ExpandGlobOptions, expandGlob } from "../fs/mod.ts"; import { isWindows, join } from "../path/mod.ts"; -import { RunTestsOptions, runTests } from "./mod.ts"; const { DenoError, ErrorKind, args, cwd, exit } = Deno; const DIR_GLOBS = [join("**", "?(*_)test.{js,ts}")]; @@ -110,7 +109,7 @@ export async function* findTestModules( yield* includeUrls.filter(shouldIncludeUrl); } -export interface RunTestModulesOptions extends RunTestsOptions { +export interface RunTestModulesOptions extends Deno.RunTestsOptions { include?: string[]; exclude?: string[]; allowNone?: boolean; @@ -168,7 +167,6 @@ export async function runTestModules({ include = ["."], exclude = [], allowNone = false, - parallel = false, exitOnFail = false, only = /[^\s]/, skip = /^\s*$/, @@ -233,8 +231,7 @@ export async function runTestModules({ console.log(`Found ${moduleCount} matching test modules.`); } - await runTests({ - parallel, + await Deno.runTests({ exitOnFail, only, skip, diff --git a/std/testing/runner_test.ts b/std/testing/runner_test.ts index 95f2b49cc0..f39e5d3268 100644 --- a/std/testing/runner_test.ts +++ b/std/testing/runner_test.ts @@ -1,9 +1,8 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. import { assertEquals } from "../testing/asserts.ts"; import { isWindows } from "../path/mod.ts"; -import { test } from "./mod.ts"; import { findTestModules } from "./runner.ts"; -const { cwd } = Deno; +const { cwd, test } = Deno; function urlToFilePath(url: URL): string { // Since `new URL('file:///C:/a').pathname` is `/C:/a`, remove leading slash. diff --git a/std/testing/test.ts b/std/testing/test.ts deleted file mode 100644 index 5379a5199e..0000000000 --- a/std/testing/test.ts +++ /dev/null @@ -1,293 +0,0 @@ -// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. -import { test, runIfMain } from "./mod.ts"; -import { - assert, - assertEquals, - assertStrictEq, - assertThrows, - assertThrowsAsync -} from "./asserts.ts"; - -test(function testingAssertEqualActualUncoercable(): void { - let didThrow = false; - const a = Object.create(null); - try { - assertEquals(a, "bar"); - } catch (e) { - didThrow = true; - } - assert(didThrow); -}); - -test(function testingAssertEqualExpectedUncoercable(): void { - let didThrow = false; - const a = Object.create(null); - try { - assertStrictEq("bar", a); - } catch (e) { - didThrow = true; - } - assert(didThrow); -}); - -test(function testingAssertStrictEqual(): void { - const a = {}; - const b = a; - assertStrictEq(a, b); -}); - -test(function testingAssertNotStrictEqual(): void { - let didThrow = false; - const a = {}; - const b = {}; - try { - assertStrictEq(a, b); - } catch (e) { - assert(e.message === "actual: [object Object] expected: [object Object]"); - didThrow = true; - } - assert(didThrow); -}); - -test(function testingDoesThrow(): void { - let count = 0; - assertThrows((): void => { - count++; - throw new Error(); - }); - assert(count === 1); -}); - -test(function testingDoesNotThrow(): void { - let count = 0; - let didThrow = false; - try { - assertThrows((): void => { - count++; - console.log("Hello world"); - }); - } catch (e) { - assert(e.message === "Expected function to throw."); - didThrow = true; - } - assert(count === 1); - assert(didThrow); -}); - -test(function testingThrowsErrorType(): void { - let count = 0; - assertThrows((): void => { - count++; - throw new TypeError(); - }, TypeError); - assert(count === 1); -}); - -test(function testingThrowsNotErrorType(): void { - let count = 0; - let didThrow = false; - try { - assertThrows((): void => { - count++; - throw new TypeError(); - }, RangeError); - } catch (e) { - assert(e.message === `Expected error to be instance of "RangeError".`); - didThrow = true; - } - assert(count === 1); - assert(didThrow); -}); - -test(function testingThrowsMsgIncludes(): void { - let count = 0; - assertThrows( - (): void => { - count++; - throw new TypeError("Hello world!"); - }, - TypeError, - "world" - ); - assert(count === 1); -}); - -test(function testingThrowsMsgNotIncludes(): void { - let count = 0; - let didThrow = false; - try { - assertThrows( - (): void => { - count++; - throw new TypeError("Hello world!"); - }, - TypeError, - "foobar" - ); - } catch (e) { - assert( - e.message === - `Expected error message to include "foobar", but got "Hello world!".` - ); - didThrow = true; - } - assert(count === 1); - assert(didThrow); -}); - -test(async function testingDoesThrowAsync(): Promise { - let count = 0; - await assertThrowsAsync( - async (): Promise => { - count++; - throw new Error(); - } - ); - assert(count === 1); -}); - -test(async function testingDoesReject(): Promise { - let count = 0; - await assertThrowsAsync( - (): Promise => { - count++; - return Promise.reject(new Error()); - } - ); - assert(count === 1); -}); - -test(async function testingDoesNotThrowAsync(): Promise { - let count = 0; - let didThrow = false; - try { - await assertThrowsAsync( - async (): Promise => { - count++; - console.log("Hello world"); - } - ); - } catch (e) { - assert(e.message === "Expected function to throw."); - didThrow = true; - } - assert(count === 1); - assert(didThrow); -}); - -test(async function testingDoesNotRejectAsync(): Promise { - let count = 0; - let didThrow = false; - try { - await assertThrowsAsync( - (): Promise => { - count++; - console.log("Hello world"); - return Promise.resolve(); - } - ); - } catch (e) { - assert(e.message === "Expected function to throw."); - didThrow = true; - } - assert(count === 1); - assert(didThrow); -}); - -test(async function testingThrowsAsyncErrorType(): Promise { - let count = 0; - await assertThrowsAsync((): Promise => { - count++; - throw new TypeError(); - }, TypeError); - assert(count === 1); -}); - -test(async function testingThrowsAsyncNotErrorType(): Promise { - let count = 0; - let didThrow = false; - try { - await assertThrowsAsync(async (): Promise => { - count++; - throw new TypeError(); - }, RangeError); - } catch (e) { - assert(e.message === `Expected error to be instance of "RangeError".`); - didThrow = true; - } - assert(count === 1); - assert(didThrow); -}); - -test(async function testingThrowsAsyncMsgIncludes(): Promise { - let count = 0; - await assertThrowsAsync( - async (): Promise => { - count++; - throw new TypeError("Hello world!"); - }, - TypeError, - "world" - ); - assert(count === 1); -}); - -test(async function testingThrowsAsyncMsgNotIncludes(): Promise { - let count = 0; - let didThrow = false; - try { - await assertThrowsAsync( - async (): Promise => { - count++; - throw new TypeError("Hello world!"); - }, - TypeError, - "foobar" - ); - } catch (e) { - assert( - e.message === - `Expected error message to include "foobar", but got "Hello world!".` - ); - didThrow = true; - } - assert(count === 1); - assert(didThrow); -}); - -test("test fn overloading", (): void => { - // just verifying that you can use this test definition syntax - assert(true); -}); - -test("The name of test case can't be empty", () => { - assertThrows( - () => { - test("", () => {}); - }, - Error, - "The name of test case can't be empty" - ); - assertThrows( - () => { - test({ - name: "", - fn: () => {} - }); - }, - Error, - "The name of test case can't be empty" - ); -}); - -test("test function can't be anonymous", () => { - assertThrows( - () => { - test(function() {}); - }, - Error, - "Test function can't be anonymous" - ); -}); - -runIfMain(import.meta); diff --git a/std/testing/testing_bench.ts b/std/testing/testing_bench.ts deleted file mode 100644 index 9033e3a72f..0000000000 --- a/std/testing/testing_bench.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { bench, runIfMain } from "./bench.ts"; -import { runTests } from "./mod.ts"; - -import "./asserts_test.ts"; - -bench(async function testingSerial(b): Promise { - b.start(); - await runTests(); - b.stop(); -}); - -bench(async function testingParallel(b): Promise { - b.start(); - await runTests({ parallel: true }); - b.stop(); -}); - -runIfMain(import.meta); diff --git a/std/textproto/reader_test.ts b/std/textproto/reader_test.ts index fe842e0e2c..8f4b072423 100644 --- a/std/textproto/reader_test.ts +++ b/std/textproto/reader_test.ts @@ -12,7 +12,7 @@ import { assertNotEquals, assertThrows } from "../testing/asserts.ts"; -import { test, runIfMain } from "../testing/mod.ts"; +const { test } = Deno; function assertNotEOF(val: T | Deno.EOF): T { assertNotEquals(val, Deno.EOF); @@ -180,5 +180,3 @@ test({ assertEquals(m.get("Content-Disposition"), 'form-data; name="test"'); } }); - -runIfMain(import.meta); diff --git a/std/textproto/test.ts b/std/textproto/test.ts index bdb9293699..5b67bbf956 100644 --- a/std/textproto/test.ts +++ b/std/textproto/test.ts @@ -5,7 +5,7 @@ import { append } from "./mod.ts"; import { assertEquals } from "../testing/asserts.ts"; -import { test } from "../testing/mod.ts"; +const { test } = Deno; test(async function textprotoAppend(): Promise { const enc = new TextEncoder(); diff --git a/std/util/async_test.ts b/std/util/async_test.ts index f51d001387..4607cf6cd2 100644 --- a/std/util/async_test.ts +++ b/std/util/async_test.ts @@ -1,5 +1,5 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. -import { test, runIfMain } from "../testing/mod.ts"; +const { test } = Deno; import { assert, assertEquals, assertStrictEq } from "../testing/asserts.ts"; import { collectUint8Arrays, deferred, MuxAsyncIterator } from "./async.ts"; @@ -69,5 +69,3 @@ test(async function collectUint8Arrays4(): Promise { assertStrictEq(result[i], i + 1); } }); - -runIfMain(import.meta); diff --git a/std/util/deep_assign_test.ts b/std/util/deep_assign_test.ts index bc66d2179f..a69d30b737 100644 --- a/std/util/deep_assign_test.ts +++ b/std/util/deep_assign_test.ts @@ -1,5 +1,5 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. -import { test } from "../testing/mod.ts"; +const { test } = Deno; import { assertEquals, assert } from "../testing/asserts.ts"; import { deepAssign } from "./deep_assign.ts"; diff --git a/std/uuid/test.ts b/std/uuid/test.ts index 1e6e981543..aeb6ed1123 100755 --- a/std/uuid/test.ts +++ b/std/uuid/test.ts @@ -1,6 +1,5 @@ #!/usr/bin/env -S deno run // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. -import { runIfMain } from "../testing/mod.ts"; // Generic Tests import "./tests/isNil.ts"; @@ -8,5 +7,3 @@ import "./tests/isNil.ts"; // V4 Tests import "./tests/v4/validate.ts"; import "./tests/v4/generate.ts"; - -runIfMain(import.meta); diff --git a/std/uuid/tests/isNil.ts b/std/uuid/tests/isNil.ts index dcb10b84d5..80ec2e0fd0 100644 --- a/std/uuid/tests/isNil.ts +++ b/std/uuid/tests/isNil.ts @@ -1,6 +1,6 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. import { assert } from "../../testing/asserts.ts"; -import { test } from "../../testing/mod.ts"; +const { test } = Deno; // @ts-ignore import { NIL_UUID, isNil } from "../mod.ts"; diff --git a/std/uuid/tests/v4/generate.ts b/std/uuid/tests/v4/generate.ts index dfbd90c03b..c9946d46c0 100644 --- a/std/uuid/tests/v4/generate.ts +++ b/std/uuid/tests/v4/generate.ts @@ -1,6 +1,6 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. import { assert, assertEquals } from "../../../testing/asserts.ts"; -import { test } from "../../../testing/mod.ts"; +const { test } = Deno; import { generate, validate } from "../../v4.ts"; test({ diff --git a/std/uuid/tests/v4/validate.ts b/std/uuid/tests/v4/validate.ts index 6a8b665559..feeecf6b7c 100644 --- a/std/uuid/tests/v4/validate.ts +++ b/std/uuid/tests/v4/validate.ts @@ -1,9 +1,8 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. import { assert } from "../../../testing/asserts.ts"; -import { test } from "../../../testing/mod.ts"; import { generate, validate } from "../../v4.ts"; -test({ +Deno.test({ name: "[UUID] is_valid_uuid_v4", fn(): void { const u = generate(); diff --git a/std/ws/sha1_test.ts b/std/ws/sha1_test.ts index 43b4bc3c18..9d0d90ea43 100644 --- a/std/ws/sha1_test.ts +++ b/std/ws/sha1_test.ts @@ -1,5 +1,5 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. -import { test } from "../testing/mod.ts"; +const { test } = Deno; import { assertEquals } from "../testing/asserts.ts"; import { Sha1 } from "./sha1.ts"; diff --git a/std/ws/test.ts b/std/ws/test.ts index d3148f7adb..a8dbc903ca 100644 --- a/std/ws/test.ts +++ b/std/ws/test.ts @@ -1,7 +1,7 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. import { BufReader, BufWriter } from "../io/bufio.ts"; import { assert, assertEquals, assertThrowsAsync } from "../testing/asserts.ts"; -import { runIfMain, test } from "../testing/mod.ts"; +const { test } = Deno; import { TextProtoReader } from "../textproto/mod.ts"; import * as bytes from "../bytes/mod.ts"; import { @@ -326,5 +326,3 @@ test("WebSocket.send(), WebSocket.ping() should be exclusive", async (): Promise assertEquals(third.opcode, OpCode.BinaryFrame); assertEquals(bytes.equal(third.payload, new Uint8Array([3])), true); }); - -runIfMain(import.meta);