summaryrefslogtreecommitdiff
path: root/libdeno/libdeno_test.cc
diff options
context:
space:
mode:
authorKevin (Kun) "Kassimo" Qian <kevinkassimo@gmail.com>2019-01-15 09:19:58 -0800
committerRyan Dahl <ry@tinyclouds.org>2019-01-15 12:19:58 -0500
commitc870cf40823a4900278f8ddf03489338c169878b (patch)
tree80c171f7bb36c988f459a4d0ee248a40d3feb34b /libdeno/libdeno_test.cc
parentac6ac5037ff53f4e7b9693aeed24f1e3ef1339ad (diff)
Add --prefetch flag for deps prefetch without running (#1475)
Diffstat (limited to 'libdeno/libdeno_test.cc')
-rw-r--r--libdeno/libdeno_test.cc32
1 files changed, 27 insertions, 5 deletions
diff --git a/libdeno/libdeno_test.cc b/libdeno/libdeno_test.cc
index 9873987ea..78091be59 100644
--- a/libdeno/libdeno_test.cc
+++ b/libdeno/libdeno_test.cc
@@ -284,7 +284,7 @@ TEST(LibDenoTest, ModuleResolution) {
deno_resolve_ok(d, "b.js", mod_b);
};
Deno* d = deno_new(deno_config{0, empty, empty, nullptr, resolve_cb});
- EXPECT_TRUE(deno_execute_mod(d, d, "a.js", mod_a));
+ EXPECT_TRUE(deno_execute_mod(d, d, "a.js", mod_a, false));
EXPECT_EQ(count, 1);
deno_delete(d);
}
@@ -299,7 +299,7 @@ TEST(LibDenoTest, ModuleResolutionFail) {
// Do not call deno_resolve_ok();
};
Deno* d = deno_new(deno_config{0, empty, empty, nullptr, resolve_cb});
- EXPECT_FALSE(deno_execute_mod(d, d, "a.js", mod_a));
+ EXPECT_FALSE(deno_execute_mod(d, d, "a.js", mod_a, false));
EXPECT_EQ(count, 1);
deno_delete(d);
}
@@ -309,7 +309,8 @@ TEST(LibDenoTest, ModuleSnapshot) {
EXPECT_TRUE(deno_execute_mod(d1, nullptr, "x.js",
"const globalEval = eval\n"
"const global = globalEval('this')\n"
- "global.a = 1 + 2"));
+ "global.a = 1 + 2",
+ 0));
deno_buf test_snapshot = deno_get_snapshot(d1);
deno_delete(d1);
@@ -321,12 +322,32 @@ TEST(LibDenoTest, ModuleSnapshot) {
deno_delete(d2);
Deno* d3 = deno_new(config);
- EXPECT_TRUE(deno_execute_mod(d3, nullptr, "y.js", y_src));
+ EXPECT_TRUE(deno_execute_mod(d3, nullptr, "y.js", y_src, false));
deno_delete(d3);
delete[] test_snapshot.data_ptr;
}
+TEST(LibDenoTest, ModuleResolveOnly) {
+ static int count = 0;
+ auto resolve_cb = [](void* user_data, const char* specifier,
+ const char* referrer) {
+ EXPECT_STREQ(specifier, "b.js");
+ EXPECT_STREQ(referrer, "a.js");
+ count++;
+ auto d = reinterpret_cast<Deno*>(user_data);
+ deno_resolve_ok(d, "b.js", mod_b);
+ };
+ Deno* d = deno_new(deno_config{0, empty, empty, nullptr, resolve_cb});
+ // Code should not execute. If executed, the error would be thrown
+ EXPECT_TRUE(deno_execute_mod(d, d, "a.js",
+ "import { retb } from 'b.js'\n"
+ "throw Error('unreachable');",
+ true));
+ EXPECT_EQ(count, 1);
+ deno_delete(d);
+}
+
TEST(LibDenoTest, BuiltinModules) {
static int count = 0;
auto resolve_cb = [](void* user_data, const char* specifier,
@@ -347,7 +368,8 @@ TEST(LibDenoTest, BuiltinModules) {
"import * as deno from 'deno'\n"
"if (retb() != 'b') throw Error('retb');\n"
// " libdeno.print('deno ' + JSON.stringify(deno));\n"
- "if (deno.foo != 'bar') throw Error('foo');\n"));
+ "if (deno.foo != 'bar') throw Error('foo');\n",
+ false));
EXPECT_EQ(count, 1);
deno_delete(d);
}