From 1b7938e3aa0ba1fb7ad7d6699f01cbf3c8a4196c Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Sun, 6 Jan 2019 16:32:21 -0500 Subject: Add libdeno.builtinModules (#1463) This is needed to support builtin modules like import { open } from "deno" --- libdeno/libdeno_test.cc | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'libdeno/libdeno_test.cc') diff --git a/libdeno/libdeno_test.cc b/libdeno/libdeno_test.cc index 8b95c1831..6ee8979ee 100644 --- a/libdeno/libdeno_test.cc +++ b/libdeno/libdeno_test.cc @@ -306,3 +306,28 @@ TEST(LibDenoTest, ModuleSnapshot) { delete[] test_snapshot.data_ptr; } + +TEST(LibDenoTest, BuiltinModules) { + static int count = 0; + auto resolve_cb = [](void* user_data, const char* specifier, + const char* referrer) { + EXPECT_STREQ(specifier, "b.js"); + EXPECT_STREQ(referrer, "c.js"); + count++; + auto d = reinterpret_cast(user_data); + deno_resolve_ok(d, "b.js", mod_b); + }; + Deno* d = deno_new(deno_config{0, empty, empty, nullptr, resolve_cb}); + EXPECT_TRUE(deno_execute( + d, d, "setup.js", "libdeno.builtinModules['deno'] = { foo: 'bar' }; \n")); + EXPECT_EQ(count, 0); + EXPECT_TRUE( + deno_execute_mod(d, d, "c.js", + "import { retb } from 'b.js'\n" + "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")); + EXPECT_EQ(count, 1); + deno_delete(d); +} -- cgit v1.2.3