diff options
author | 2023-06-01 19:48:37 -0400 | |
---|---|---|
committer | 2023-06-01 16:48:37 -0700 | |
commit | 42d8b7183ca55e546d207124e01ba01603a5f07b (patch) | |
tree | b325d2bc70b1c06f49be951dc22453b2445ec5e3 /test/js | |
parent | f9809f0044e59de10c9d64a89715c6008608358c (diff) | |
download | bun-42d8b7183ca55e546d207124e01ba01603a5f07b.tar.gz bun-42d8b7183ca55e546d207124e01ba01603a5f07b.tar.zst bun-42d8b7183ca55e546d207124e01ba01603a5f07b.zip |
random fixes that help vite/sveltekit (#3140)
* existsSync with invalid paths should return false
* partially support file urls (does not do percent encoding)
* add utf16 support for Path.isAbsoluteString
* Update src/resolver/resolver.zig
Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
* fixups
* revert
* prettier format
---------
Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
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.ts | 7 |
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); +}); |