aboutsummaryrefslogtreecommitdiff
path: root/test/js
diff options
context:
space:
mode:
Diffstat (limited to 'test/js')
-rw-r--r--test/js/bun/resolve/resolve.test.ts (renamed from test/js/bun/resolve/resolve.test.js)50
-rw-r--r--test/js/node/fs/fs.test.ts7
2 files changed, 56 insertions, 1 deletions
diff --git a/test/js/bun/resolve/resolve.test.js b/test/js/bun/resolve/resolve.test.ts
index 33bf510eb..1b66f711f 100644
--- a/test/js/bun/resolve/resolve.test.js
+++ b/test/js/bun/resolve/resolve.test.ts
@@ -1,7 +1,7 @@
import { it, expect } from "bun:test";
import { mkdirSync, writeFileSync, existsSync, rmSync, copyFileSync } from "fs";
import { join } from "path";
-import { bunExe, bunEnv } from "harness";
+import { bunExe, bunEnv, tempDirWithFiles } from "harness";
it("spawn test file", () => {
writePackageJSONImportsFixture();
@@ -85,3 +85,51 @@ function writePackageJSONImportsFixture() {
),
);
}
+
+it("file url in import resolves", async () => {
+ const dir = tempDirWithFiles("fileurl", {
+ "index.js": "export const foo = 1;",
+ });
+ writeFileSync(`${dir}/test.js`, `import {foo} from 'file://${dir}/index.js';\nconsole.log(foo);`);
+
+ console.log("dir", dir);
+ const { exitCode, stdout } = Bun.spawnSync({
+ cmd: [bunExe(), `${dir}/test.js`],
+ env: bunEnv,
+ cwd: import.meta.dir,
+ });
+ expect(exitCode).toBe(0);
+ expect(stdout.toString("utf8")).toBe("1\n");
+});
+
+it("file url in await import resolves", async () => {
+ const dir = tempDirWithFiles("fileurl", {
+ "index.js": "export const foo = 1;",
+ });
+ writeFileSync(`${dir}/test.js`, `const {foo} = await import('file://${dir}/index.js');\nconsole.log(foo);`);
+
+ console.log("dir", dir);
+ const { exitCode, stdout } = Bun.spawnSync({
+ cmd: [bunExe(), `${dir}/test.js`],
+ env: bunEnv,
+ cwd: import.meta.dir,
+ });
+ expect(exitCode).toBe(0);
+ expect(stdout.toString("utf8")).toBe("1\n");
+});
+
+it("file url in require resolves", async () => {
+ const dir = tempDirWithFiles("fileurl", {
+ "index.js": "export const foo = 1;",
+ });
+ writeFileSync(`${dir}/test.js`, `const {foo} = require('file://${dir}/index.js');\nconsole.log(foo);`);
+
+ console.log("dir", dir);
+ const { exitCode, stdout } = Bun.spawnSync({
+ cmd: [bunExe(), `${dir}/test.js`],
+ env: bunEnv,
+ cwd: import.meta.dir,
+ });
+ expect(exitCode).toBe(0);
+ expect(stdout.toString("utf8")).toBe("1\n");
+});
diff --git a/test/js/node/fs/fs.test.ts b/test/js/node/fs/fs.test.ts
index 9eb4399b3..e9cafe957 100644
--- a/test/js/node/fs/fs.test.ts
+++ b/test/js/node/fs/fs.test.ts
@@ -1159,3 +1159,10 @@ it("repro 1516: can use undefined/null to specify default flag", () => {
expect(readFileSync(path, { encoding: "utf8", flag: null })).toBe("b");
rmSync(path);
});
+
+it("existsSync with invalid path doesn't throw", () => {
+ expect(existsSync(null as any)).toBe(false);
+ expect(existsSync(123 as any)).toBe(false);
+ expect(existsSync(undefined as any)).toBe(false);
+ expect(existsSync({ invalid: 1 } as any)).toBe(false);
+});