summaryrefslogtreecommitdiff
path: root/js/compiler_test.ts
diff options
context:
space:
mode:
authorKitson Kelly <me@kitsonkelly.com>2018-08-23 13:29:31 -0700
committerRyan Dahl <ry@tinyclouds.org>2018-08-23 17:55:22 -0400
commit59231d74b5e275b6cb1c7a551c3382202c3f0d9e (patch)
tree9bcff21188977926496514e7f37681ed13d47751 /js/compiler_test.ts
parent1355803849aebab738b5f704386a034463192aab (diff)
Improve DenoCompiler.makeDefine and localRequire
Diffstat (limited to 'js/compiler_test.ts')
-rw-r--r--js/compiler_test.ts33
1 files changed, 33 insertions, 0 deletions
diff --git a/js/compiler_test.ts b/js/compiler_test.ts
index d8861e2a9..cc3cda406 100644
--- a/js/compiler_test.ts
+++ b/js/compiler_test.ts
@@ -108,6 +108,12 @@ const moduleMap: {
"/root/project/foo/bar.ts",
fooBarTsSource,
fooBarTsOutput
+ ),
+ "./qat.ts": mockModuleInfo(
+ "foo/qat",
+ "/root/project/foo/qat.ts",
+ "export const foo = 'bar'",
+ null
)
}
};
@@ -275,6 +281,33 @@ test(function compilerMakeDefine() {
// external modules, this is implicitly tested though in
// `compilerRunMultiModule`
+test(function compilerLocalRequire() {
+ const moduleMetaData = new ModuleMetaData(
+ "/root/project/foo/baz.ts",
+ fooBazTsSource,
+ fooBazTsOutput
+ );
+ const localDefine = compilerInstance.makeDefine(moduleMetaData);
+ let requireCallbackCalled = false;
+ localDefine(
+ ["require", "exports"],
+ (_require, _exports, _compiler): void => {
+ assertEqual(typeof _require, "function");
+ _require(
+ ["./qat.ts"],
+ _qat => {
+ requireCallbackCalled = true;
+ assert(_qat);
+ },
+ () => {
+ throw new Error("Should not error");
+ }
+ );
+ }
+ );
+ assert(requireCallbackCalled, "Factory expected to be called");
+});
+
test(function compilerRun() {
// equal to `deno foo/bar.ts`
reset();