diff options
author | Ryan Dahl <ry@tinyclouds.org> | 2019-10-09 17:10:09 -0400 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2019-10-09 17:10:09 -0400 |
commit | 151ce0266eb4de2c8fc600c81c192a5f791b6169 (patch) | |
tree | 7cb04016a1c7ee88adde83814548d7a9409dcde3 /std/bundle/test.ts | |
parent | a355f7c807686918734416d91b79c26c21effba9 (diff) |
Move everything into std subdir
Diffstat (limited to 'std/bundle/test.ts')
-rw-r--r-- | std/bundle/test.ts | 116 |
1 files changed, 116 insertions, 0 deletions
diff --git a/std/bundle/test.ts b/std/bundle/test.ts new file mode 100644 index 000000000..504e449a6 --- /dev/null +++ b/std/bundle/test.ts @@ -0,0 +1,116 @@ +// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. + +import { test } from "../testing/mod.ts"; +import { + assert, + AssertionError, + assertEquals, + assertThrowsAsync +} from "../testing/asserts.ts"; +import { instantiate, load, ModuleMetaData } from "./utils.ts"; + +/* eslint-disable @typescript-eslint/no-namespace */ +declare global { + namespace globalThis { + // eslint-disable-next-line no-var + var __results: [string, string] | undefined; + } +} +/* eslint-disable max-len */ +/* eslint-enable @typescript-eslint/no-namespace */ +/* +const fixture = ` +define("data", [], { "baz": "qat" }); +define("modB", ["require", "exports", "data"], function(require, exports, data) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + exports.foo = "bar"; + exports.baz = data.baz; +}); +define("modA", ["require", "exports", "modB"], function(require, exports, modB) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + globalThis.__results = [modB.foo, modB.baz]; +}); +`; +*/ +/* eslint-enable max-len */ + +const fixtureQueue = ["data", "modB", "modA"]; +const fixtureModules = new Map<string, ModuleMetaData>(); +fixtureModules.set("data", { + dependencies: [], + factory: { + baz: "qat" + }, + exports: {} +}); +fixtureModules.set("modB", { + dependencies: ["require", "exports", "data"], + factory(_require, exports, data): void { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + exports.foo = "bar"; + exports.baz = data.baz; + }, + exports: {} +}); +fixtureModules.set("modA", { + dependencies: ["require", "exports", "modB"], + factory(_require, exports, modB): void { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + globalThis.__results = [modB.foo, modB.baz]; + }, + exports: {} +}); + +test(async function loadBundle(): Promise<void> { + const result = await load(["", "./bundle/testdata/bundle.js", "--foo"]); + assert(result != null); + assert( + result.includes( + `define("subdir/print_hello", ["require", "exports"], function(` + ) + ); +}); + +test(async function loadBadArgs(): Promise<void> { + await assertThrowsAsync( + async (): Promise<void> => { + await load(["bundle/test.ts"]); + }, + AssertionError, + "Expected at least two arguments." + ); +}); + +test(async function loadMissingBundle(): Promise<void> { + await assertThrowsAsync( + async (): Promise<void> => { + await load([".", "bad_bundle.js"]); + }, + AssertionError, + `Expected "bad_bundle.js" to exist.` + ); +}); + +/* TODO re-enable test +test(async function evaluateBundle(): Promise<void> { + assert(globalThis.define == null, "Expected 'define' to be undefined"); + const [queue, modules] = evaluate(fixture); + assert(globalThis.define == null, "Expected 'define' to be undefined"); + assertEquals(queue, ["data", "modB", "modA"]); + assert(modules.has("modA")); + assert(modules.has("modB")); + assert(modules.has("data")); + assertStrictEq(modules.size, 3); +}); +*/ + +test(async function instantiateBundle(): Promise<void> { + assert(globalThis.__results == null); + instantiate(fixtureQueue, fixtureModules); + assertEquals(globalThis.__results, ["bar", "qat"]); + delete globalThis.__results; +}); |