diff options
author | Ryan Dahl <ry@tinyclouds.org> | 2019-01-06 16:32:21 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-01-06 16:32:21 -0500 |
commit | 1b7938e3aa0ba1fb7ad7d6699f01cbf3c8a4196c (patch) | |
tree | 25b63f93af0d5e9e571a1fd3c8c4b02191706dcf /libdeno/libdeno_test.cc | |
parent | f37d67e80933bc437fbd29092108eaf2deeee383 (diff) |
Add libdeno.builtinModules (#1463)
This is needed to support builtin modules like
import { open } from "deno"
Diffstat (limited to 'libdeno/libdeno_test.cc')
-rw-r--r-- | libdeno/libdeno_test.cc | 25 |
1 files changed, 25 insertions, 0 deletions
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<Deno*>(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); +} |