From ecca6581e9e6c55ad8359e09b7c1bf72d16de0ae Mon Sep 17 00:00:00 2001 From: Don McCurdy Date: Wed, 22 Dec 2021 14:38:00 -0800 Subject: [PATCH] [core] Add test scaffold for Deno. --- test/deno-import-map.json | 10 ++++++++++ test/deno-tape.ts | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 test/deno-import-map.json create mode 100644 test/deno-tape.ts diff --git a/test/deno-import-map.json b/test/deno-import-map.json new file mode 100644 index 000000000..414f2f2e0 --- /dev/null +++ b/test/deno-import-map.json @@ -0,0 +1,10 @@ +{ + "imports": { + "tape": "../test/deno-tape.ts", + "canvas": "https://deno.land/x/canvas/mod.ts", + "@gltf-transform/core": "../packages/core/dist/core.modern.js", + "gl-matrix/mat4": "../node_modules/gl-matrix/esm/mat4.js", + "gl-matrix/vec3": "../node_modules/gl-matrix/esm/vec3.js", + "property-graph": "../node_modules/property-graph/dist/property-graph.modern.js" + } +} diff --git a/test/deno-tape.ts b/test/deno-tape.ts new file mode 100644 index 000000000..6df86fc57 --- /dev/null +++ b/test/deno-tape.ts @@ -0,0 +1,39 @@ + +import { assert, assertEquals, assertNotEquals, assertStrictEquals, assertNotStrictEquals, assertMatch, assertThrows } from "https://deno.land/std@0.85.0/testing/asserts.ts"; + +class TestInstance { + ok = assert; + equal = assertStrictEquals; + equals = assertStrictEquals; + notEqual = assertNotStrictEquals; + notEquals = assertNotStrictEquals; + deepEqual = assertEquals; + deepEquals = assertEquals; + notDeepEqual = assertNotEquals; + notDeepEquals = assertNotEquals; + match = assertMatch; + throws = assertThrows; + fail(msg: string) { + throw new Error(msg); + } + end() {}; +} + +interface TestOptions { + skip?: boolean; +} + +type TestCallback = (t: any) => any; + +function test(name: string, fn: TestCallback): void; +function test(name: string, opts: TestOptions, fn: TestCallback): void; +function test(name: string, fnOrOpts: TestOptions | TestCallback, fn?: TestCallback): void { + const t = new TestInstance(); + if (typeof fnOrOpts === 'function') { + Deno.test(name, fnOrOpts.bind(t, t)); + } else if (!fnOrOpts.skip) { + Deno.test(name, (fn as TestCallback).bind(t, t)); + } +} + +export default test;