@deno/shim-deno-test
Advanced tools
Comparing version 0.4.0 to 0.5.0
@@ -1,3 +0,3 @@ | ||
import { TestDefinition } from "./deno.types.gen.js"; | ||
import type { TestDefinition } from "./deno.types.gen.js"; | ||
/** Reference to the array that `Deno.test` calls insert their definition into. */ | ||
export declare const testDefinitions: TestDefinition[]; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -39,4 +39,249 @@ /// <reference types="node" /> | ||
*/ | ||
export declare function test(t: TestDefinition): void; | ||
export declare const test: DenoTest; | ||
/** @category Testing */ | ||
export interface DenoTest { | ||
/** | ||
* Register a test which will be run when `deno test` is used on the command | ||
* line and the containing module looks like a test module. | ||
* | ||
* `fn` can be async if required. | ||
* | ||
* ```ts | ||
* import { assertEquals } from "https://deno.land/std/testing/asserts.ts"; | ||
* | ||
* Deno.test({ | ||
* name: "example test", | ||
* fn() { | ||
* assertEquals("world", "world"); | ||
* }, | ||
* }); | ||
* | ||
* Deno.test({ | ||
* name: "example ignored test", | ||
* ignore: Deno.build.os === "windows", | ||
* fn() { | ||
* // This test is ignored only on Windows machines | ||
* }, | ||
* }); | ||
* | ||
* Deno.test({ | ||
* name: "example async test", | ||
* async fn() { | ||
* const decoder = new TextDecoder("utf-8"); | ||
* const data = await Deno.readFile("hello_world.txt"); | ||
* assertEquals(decoder.decode(data), "Hello world"); | ||
* } | ||
* }); | ||
* ``` | ||
* | ||
* @category Testing | ||
*/ | ||
(t: TestDefinition): void; | ||
/** | ||
* Register a test which will be run when `deno test` is used on the command | ||
* line and the containing module looks like a test module. | ||
* | ||
* `fn` can be async if required. | ||
* | ||
* ```ts | ||
* import { assertEquals } from "https://deno.land/std/testing/asserts.ts"; | ||
* | ||
* Deno.test("My test description", () => { | ||
* assertEquals("hello", "hello"); | ||
* }); | ||
* | ||
* Deno.test("My async test description", async () => { | ||
* const decoder = new TextDecoder("utf-8"); | ||
* const data = await Deno.readFile("hello_world.txt"); | ||
* assertEquals(decoder.decode(data), "Hello world"); | ||
* }); | ||
* ``` | ||
* | ||
* @category Testing | ||
*/ | ||
(name: string, fn: (t: TestContext) => void | Promise<void>): void; | ||
/** | ||
* Register a test which will be run when `deno test` is used on the command | ||
* line and the containing module looks like a test module. | ||
* | ||
* `fn` can be async if required. Declared function must have a name. | ||
* | ||
* ```ts | ||
* import { assertEquals } from "https://deno.land/std/testing/asserts.ts"; | ||
* | ||
* Deno.test(function myTestName() { | ||
* assertEquals("hello", "hello"); | ||
* }); | ||
* | ||
* Deno.test(async function myOtherTestName() { | ||
* const decoder = new TextDecoder("utf-8"); | ||
* const data = await Deno.readFile("hello_world.txt"); | ||
* assertEquals(decoder.decode(data), "Hello world"); | ||
* }); | ||
* ``` | ||
* | ||
* @category Testing | ||
*/ | ||
(fn: (t: TestContext) => void | Promise<void>): void; | ||
/** | ||
* Register a test which will be run when `deno test` is used on the command | ||
* line and the containing module looks like a test module. | ||
* | ||
* `fn` can be async if required. | ||
* | ||
* ```ts | ||
* import {assert, fail, assertEquals} from "https://deno.land/std/testing/asserts.ts"; | ||
* | ||
* Deno.test("My test description", { permissions: { read: true } }, (): void => { | ||
* assertEquals("hello", "hello"); | ||
* }); | ||
* | ||
* Deno.test("My async test description", { permissions: { read: false } }, async (): Promise<void> => { | ||
* const decoder = new TextDecoder("utf-8"); | ||
* const data = await Deno.readFile("hello_world.txt"); | ||
* assertEquals(decoder.decode(data), "Hello world"); | ||
* }); | ||
* ``` | ||
* | ||
* @category Testing | ||
*/ | ||
(name: string, options: Omit<TestDefinition, "fn" | "name">, fn: (t: TestContext) => void | Promise<void>): void; | ||
/** | ||
* Register a test which will be run when `deno test` is used on the command | ||
* line and the containing module looks like a test module. | ||
* | ||
* `fn` can be async if required. | ||
* | ||
* ```ts | ||
* import { assertEquals } from "https://deno.land/std/testing/asserts.ts"; | ||
* | ||
* Deno.test( | ||
* { | ||
* name: "My test description", | ||
* permissions: { read: true }, | ||
* }, | ||
* () => { | ||
* assertEquals("hello", "hello"); | ||
* }, | ||
* ); | ||
* | ||
* Deno.test( | ||
* { | ||
* name: "My async test description", | ||
* permissions: { read: false }, | ||
* }, | ||
* async () => { | ||
* const decoder = new TextDecoder("utf-8"); | ||
* const data = await Deno.readFile("hello_world.txt"); | ||
* assertEquals(decoder.decode(data), "Hello world"); | ||
* }, | ||
* ); | ||
* ``` | ||
* | ||
* @category Testing | ||
*/ | ||
(options: Omit<TestDefinition, "fn" | "name">, fn: (t: TestContext) => void | Promise<void>): void; | ||
/** | ||
* Register a test which will be run when `deno test` is used on the command | ||
* line and the containing module looks like a test module. | ||
* | ||
* `fn` can be async if required. Declared function must have a name. | ||
* | ||
* ```ts | ||
* import { assertEquals } from "https://deno.land/std/testing/asserts.ts"; | ||
* | ||
* Deno.test( | ||
* { permissions: { read: true } }, | ||
* function myTestName() { | ||
* assertEquals("hello", "hello"); | ||
* }, | ||
* ); | ||
* | ||
* Deno.test( | ||
* { permissions: { read: false } }, | ||
* async function myOtherTestName() { | ||
* const decoder = new TextDecoder("utf-8"); | ||
* const data = await Deno.readFile("hello_world.txt"); | ||
* assertEquals(decoder.decode(data), "Hello world"); | ||
* }, | ||
* ); | ||
* ``` | ||
* | ||
* @category Testing | ||
*/ | ||
(options: Omit<TestDefinition, "fn">, fn: (t: TestContext) => void | Promise<void>): void; | ||
/** | ||
* Shorthand property for ignoring a particular test case. | ||
* | ||
* @category Testing | ||
*/ | ||
ignore(t: Omit<TestDefinition, "ignore">): void; | ||
/** | ||
* Shorthand property for ignoring a particular test case. | ||
* | ||
* @category Testing | ||
*/ | ||
ignore(name: string, fn: (t: TestContext) => void | Promise<void>): void; | ||
/** | ||
* Shorthand property for ignoring a particular test case. | ||
* | ||
* @category Testing | ||
*/ | ||
ignore(fn: (t: TestContext) => void | Promise<void>): void; | ||
/** | ||
* Shorthand property for ignoring a particular test case. | ||
* | ||
* @category Testing | ||
*/ | ||
ignore(name: string, options: Omit<TestDefinition, "fn" | "name" | "ignore">, fn: (t: TestContext) => void | Promise<void>): void; | ||
/** | ||
* Shorthand property for ignoring a particular test case. | ||
* | ||
* @category Testing | ||
*/ | ||
ignore(options: Omit<TestDefinition, "fn" | "name" | "ignore">, fn: (t: TestContext) => void | Promise<void>): void; | ||
/** | ||
* Shorthand property for ignoring a particular test case. | ||
* | ||
* @category Testing | ||
*/ | ||
ignore(options: Omit<TestDefinition, "fn" | "ignore">, fn: (t: TestContext) => void | Promise<void>): void; | ||
/** | ||
* Shorthand property for focusing a particular test case. | ||
* | ||
* @category Testing | ||
*/ | ||
only(t: Omit<TestDefinition, "only">): void; | ||
/** | ||
* Shorthand property for focusing a particular test case. | ||
* | ||
* @category Testing | ||
*/ | ||
only(name: string, fn: (t: TestContext) => void | Promise<void>): void; | ||
/** | ||
* Shorthand property for focusing a particular test case. | ||
* | ||
* @category Testing | ||
*/ | ||
only(fn: (t: TestContext) => void | Promise<void>): void; | ||
/** | ||
* Shorthand property for focusing a particular test case. | ||
* | ||
* @category Testing | ||
*/ | ||
only(name: string, options: Omit<TestDefinition, "fn" | "name" | "only">, fn: (t: TestContext) => void | Promise<void>): void; | ||
/** | ||
* Shorthand property for focusing a particular test case. | ||
* | ||
* @category Testing | ||
*/ | ||
only(options: Omit<TestDefinition, "fn" | "name" | "only">, fn: (t: TestContext) => void | Promise<void>): void; | ||
/** | ||
* Shorthand property for focusing a particular test case. | ||
* | ||
* @category Testing | ||
*/ | ||
only(options: Omit<TestDefinition, "fn" | "only">, fn: (t: TestContext) => void | Promise<void>): void; | ||
} | ||
/** @category Testing */ | ||
export interface TestDefinition { | ||
@@ -65,3 +310,3 @@ fn: (t: TestContext) => void | Promise<void>; | ||
* | ||
* Defaults to `true`. | ||
* @default {true} | ||
*/ | ||
@@ -74,3 +319,3 @@ sanitizeOps?: boolean; | ||
* | ||
* Defaults to `true`. | ||
* @default {true} | ||
*/ | ||
@@ -82,3 +327,3 @@ sanitizeResources?: boolean; | ||
* | ||
* Defaults to `true`. | ||
* @default {true} | ||
*/ | ||
@@ -93,3 +338,3 @@ sanitizeExit?: boolean; | ||
* | ||
* Defaults to `"inherit"`. | ||
* @default {"inherit"} | ||
*/ | ||
@@ -165,2 +410,21 @@ permissions?: PermissionOptions; | ||
step(name: string, fn: (t: TestContext) => void | Promise<void>): Promise<boolean>; | ||
/** | ||
* Run a sub step of the parent test or step. Returns a promise | ||
* that resolves to a boolean signifying if the step completed successfully. | ||
* | ||
* The returned promise never rejects unless the arguments are invalid. | ||
* | ||
* If the test was ignored the promise returns `false`. | ||
* | ||
* ```ts | ||
* Deno.test(async function aParentTest(t) { | ||
* console.log("before the step"); | ||
* await t.step(function step1(t) { | ||
* console.log("current step:", t.name); | ||
* }); | ||
* console.log("after the step"); | ||
* }); | ||
* ``` | ||
*/ | ||
step(fn: (t: TestContext) => void | Promise<void>): Promise<boolean>; | ||
} | ||
@@ -223,3 +487,3 @@ /** @category Testing */ | ||
* | ||
* Defaults to `false`. | ||
* @default {false} | ||
*/ | ||
@@ -233,3 +497,3 @@ env?: "inherit" | boolean | string[]; | ||
* | ||
* Defaults to `false`. | ||
* @default {false} | ||
*/ | ||
@@ -243,3 +507,3 @@ sys?: "inherit" | boolean | string[]; | ||
* | ||
* Defaults to `false`. | ||
* @default {false} | ||
*/ | ||
@@ -255,3 +519,3 @@ hrtime?: "inherit" | boolean; | ||
* | ||
* Defaults to `false`. | ||
* @default {false} | ||
* | ||
@@ -327,3 +591,3 @@ * Examples: | ||
* | ||
* Defaults to `false`. | ||
* @default {false} | ||
*/ | ||
@@ -339,3 +603,3 @@ ffi?: "inherit" | boolean | Array<string | URL>; | ||
* | ||
* Defaults to `false`. | ||
* @default {false} | ||
*/ | ||
@@ -349,3 +613,3 @@ read?: "inherit" | boolean | Array<string | URL>; | ||
* | ||
* Defaults to `false`. | ||
* @default {false} | ||
*/ | ||
@@ -361,3 +625,3 @@ run?: "inherit" | boolean | Array<string | URL>; | ||
* | ||
* Defaults to `false`. | ||
* @default {false} | ||
*/ | ||
@@ -376,135 +640,2 @@ write?: "inherit" | boolean | Array<string | URL>; | ||
*/ | ||
export declare type PermissionOptions = "inherit" | "none" | PermissionOptionsObject; | ||
/** | ||
* Register a test which will be run when `deno test` is used on the command | ||
* line and the containing module looks like a test module. | ||
* | ||
* `fn` can be async if required. | ||
* | ||
* ```ts | ||
* import { assertEquals } from "https://deno.land/std/testing/asserts.ts"; | ||
* | ||
* Deno.test("My test description", () => { | ||
* assertEquals("hello", "hello"); | ||
* }); | ||
* | ||
* Deno.test("My async test description", async () => { | ||
* const decoder = new TextDecoder("utf-8"); | ||
* const data = await Deno.readFile("hello_world.txt"); | ||
* assertEquals(decoder.decode(data), "Hello world"); | ||
* }); | ||
* ``` | ||
* | ||
* @category Testing | ||
*/ | ||
export declare function test(name: string, fn: (t: TestContext) => void | Promise<void>): void; | ||
/** | ||
* Register a test which will be run when `deno test` is used on the command | ||
* line and the containing module looks like a test module. | ||
* | ||
* `fn` can be async if required. Declared function must have a name. | ||
* | ||
* ```ts | ||
* import { assertEquals } from "https://deno.land/std/testing/asserts.ts"; | ||
* | ||
* Deno.test(function myTestName() { | ||
* assertEquals("hello", "hello"); | ||
* }); | ||
* | ||
* Deno.test(async function myOtherTestName() { | ||
* const decoder = new TextDecoder("utf-8"); | ||
* const data = await Deno.readFile("hello_world.txt"); | ||
* assertEquals(decoder.decode(data), "Hello world"); | ||
* }); | ||
* ``` | ||
* | ||
* @category Testing | ||
*/ | ||
export declare function test(fn: (t: TestContext) => void | Promise<void>): void; | ||
/** | ||
* Register a test which will be run when `deno test` is used on the command | ||
* line and the containing module looks like a test module. | ||
* | ||
* `fn` can be async if required. | ||
* | ||
* ```ts | ||
* import {assert, fail, assertEquals} from "https://deno.land/std/testing/asserts.ts"; | ||
* | ||
* Deno.test("My test description", { permissions: { read: true } }, (): void => { | ||
* assertEquals("hello", "hello"); | ||
* }); | ||
* | ||
* Deno.test("My async test description", { permissions: { read: false } }, async (): Promise<void> => { | ||
* const decoder = new TextDecoder("utf-8"); | ||
* const data = await Deno.readFile("hello_world.txt"); | ||
* assertEquals(decoder.decode(data), "Hello world"); | ||
* }); | ||
* ``` | ||
* | ||
* @category Testing | ||
*/ | ||
export declare function test(name: string, options: Omit<TestDefinition, "fn" | "name">, fn: (t: TestContext) => void | Promise<void>): void; | ||
/** | ||
* Register a test which will be run when `deno test` is used on the command | ||
* line and the containing module looks like a test module. | ||
* | ||
* `fn` can be async if required. | ||
* | ||
* ```ts | ||
* import { assertEquals } from "https://deno.land/std/testing/asserts.ts"; | ||
* | ||
* Deno.test( | ||
* { | ||
* name: "My test description", | ||
* permissions: { read: true }, | ||
* }, | ||
* () => { | ||
* assertEquals("hello", "hello"); | ||
* }, | ||
* ); | ||
* | ||
* Deno.test( | ||
* { | ||
* name: "My async test description", | ||
* permissions: { read: false }, | ||
* }, | ||
* async () => { | ||
* const decoder = new TextDecoder("utf-8"); | ||
* const data = await Deno.readFile("hello_world.txt"); | ||
* assertEquals(decoder.decode(data), "Hello world"); | ||
* }, | ||
* ); | ||
* ``` | ||
* | ||
* @category Testing | ||
*/ | ||
export declare function test(options: Omit<TestDefinition, "fn">, fn: (t: TestContext) => void | Promise<void>): void; | ||
/** | ||
* Register a test which will be run when `deno test` is used on the command | ||
* line and the containing module looks like a test module. | ||
* | ||
* `fn` can be async if required. Declared function must have a name. | ||
* | ||
* ```ts | ||
* import { assertEquals } from "https://deno.land/std/testing/asserts.ts"; | ||
* | ||
* Deno.test( | ||
* { permissions: { read: true } }, | ||
* function myTestName() { | ||
* assertEquals("hello", "hello"); | ||
* }, | ||
* ); | ||
* | ||
* Deno.test( | ||
* { permissions: { read: false } }, | ||
* async function myOtherTestName() { | ||
* const decoder = new TextDecoder("utf-8"); | ||
* const data = await Deno.readFile("hello_world.txt"); | ||
* assertEquals(decoder.decode(data), "Hello world"); | ||
* }, | ||
* ); | ||
* ``` | ||
* | ||
* @category Testing | ||
*/ | ||
export declare function test(options: Omit<TestDefinition, "fn" | "name">, fn: (t: TestContext) => void | Promise<void>): void; | ||
export type PermissionOptions = "inherit" | "none" | PermissionOptionsObject; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); |
export * as Deno from "./test.js"; | ||
export * from "./test.js"; | ||
export { testDefinitions } from "./definitions.js"; |
@@ -0,0 +0,0 @@ "use strict"; |
import * as Deno from "./deno.types.gen.js"; | ||
export type { TestContext, TestDefinition, TestStepDefinition, } from "./deno.types.gen.js"; | ||
export declare const test: typeof Deno.test; |
@@ -5,8 +5,18 @@ "use strict"; | ||
const definitions_js_1 = require("./definitions.js"); | ||
const test = function test() { | ||
exports.test = Object.assign(function test() { | ||
handleDefinition(arguments); | ||
}, { | ||
ignore() { | ||
handleDefinition(arguments, { ignore: true }); | ||
}, | ||
only() { | ||
handleDefinition(arguments, { only: true }); | ||
}, | ||
}); | ||
function handleDefinition(args, additional) { | ||
var _a, _b; | ||
let testDef; | ||
const firstArg = arguments[0]; | ||
const secondArg = arguments[1]; | ||
const thirdArg = arguments[2]; | ||
const firstArg = args[0]; | ||
const secondArg = args[1]; | ||
const thirdArg = args[2]; | ||
if (typeof firstArg === "string") { | ||
@@ -71,4 +81,9 @@ if (typeof secondArg === "object") { | ||
} | ||
if (additional === null || additional === void 0 ? void 0 : additional.ignore) { | ||
testDef.ignore = true; | ||
} | ||
if (additional === null || additional === void 0 ? void 0 : additional.only) { | ||
testDef.only = true; | ||
} | ||
definitions_js_1.testDefinitions.push(testDef); | ||
}; | ||
exports.test = test; | ||
} |
{ | ||
"name": "@deno/shim-deno-test", | ||
"version": "0.4.0", | ||
"version": "0.5.0", | ||
"description": "Deno.test only shim.", | ||
@@ -32,4 +32,4 @@ "main": "dist/index.js", | ||
"devDependencies": { | ||
"typescript": "^4.7.2" | ||
"typescript": "^5.2.2" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
28644
750