2024-01-01 21:11:32 +00:00
|
|
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
2024-04-29 02:57:30 +00:00
|
|
|
import { assertEquals } from "@std/assert";
|
|
|
|
import * as path from "@std/path";
|
2022-02-23 08:49:15 +00:00
|
|
|
|
|
|
|
const moduleDir = path.dirname(path.fromFileUrl(import.meta.url));
|
|
|
|
const testdataDir = path.resolve(moduleDir, "testdata");
|
|
|
|
|
|
|
|
Deno.test({
|
2023-12-20 10:01:13 +00:00
|
|
|
name: "load()",
|
2022-02-23 08:49:15 +00:00
|
|
|
async fn() {
|
2022-11-15 06:00:59 +00:00
|
|
|
const command = new Deno.Command(Deno.execPath(), {
|
2022-05-25 09:08:27 +00:00
|
|
|
args: [
|
2022-02-23 08:49:15 +00:00
|
|
|
"run",
|
|
|
|
"--allow-read",
|
|
|
|
"--allow-env",
|
2024-01-12 04:38:41 +00:00
|
|
|
"--no-lock",
|
2022-02-23 08:49:15 +00:00
|
|
|
path.join(testdataDir, "./app_load.ts"),
|
|
|
|
],
|
2023-09-22 12:18:08 +00:00
|
|
|
clearEnv: true,
|
2022-02-23 08:49:15 +00:00
|
|
|
cwd: testdataDir,
|
|
|
|
});
|
2022-11-15 06:00:59 +00:00
|
|
|
const { stdout } = await command.output();
|
2022-02-23 08:49:15 +00:00
|
|
|
|
|
|
|
const decoder = new TextDecoder();
|
|
|
|
assertEquals(
|
2022-05-25 09:08:27 +00:00
|
|
|
decoder.decode(stdout).trim(),
|
2022-02-23 08:49:15 +00:00
|
|
|
"hello world",
|
|
|
|
);
|
|
|
|
},
|
|
|
|
});
|
2022-02-26 01:28:52 +00:00
|
|
|
|
|
|
|
Deno.test({
|
2023-12-20 10:01:13 +00:00
|
|
|
name: "load() works as expected when the multiple files are imported",
|
2022-02-26 01:28:52 +00:00
|
|
|
async fn() {
|
2022-11-15 06:00:59 +00:00
|
|
|
const command = new Deno.Command(Deno.execPath(), {
|
2022-05-25 09:08:27 +00:00
|
|
|
args: [
|
2022-02-26 01:28:52 +00:00
|
|
|
"run",
|
2024-01-12 04:38:41 +00:00
|
|
|
"--no-lock",
|
2022-02-26 01:28:52 +00:00
|
|
|
"--allow-read",
|
|
|
|
"--allow-env",
|
|
|
|
path.join(testdataDir, "./app_load_parent.ts"),
|
|
|
|
],
|
2023-09-22 12:18:08 +00:00
|
|
|
clearEnv: true,
|
2022-02-26 01:28:52 +00:00
|
|
|
cwd: testdataDir,
|
|
|
|
});
|
2022-11-15 06:00:59 +00:00
|
|
|
const { stdout } = await command.output();
|
2022-02-26 01:28:52 +00:00
|
|
|
|
|
|
|
const decoder = new TextDecoder();
|
|
|
|
assertEquals(
|
2022-05-25 09:08:27 +00:00
|
|
|
decoder.decode(stdout).trim(),
|
2022-02-26 01:28:52 +00:00
|
|
|
"hello world",
|
|
|
|
);
|
|
|
|
},
|
|
|
|
});
|