Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
RiskyMH committed Jan 10, 2025
1 parent 7793a7d commit 335faa8
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
27 changes: 27 additions & 0 deletions test/js/bun/resolve/bun-lock.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { expect, test } from "bun:test";
import { tempDirWithFiles } from "harness";
import { join } from "path";

const lockfile = `{
"lockfileVersion": 0,
"workspaces": {
"": {
"name": "something",
"dependencies": { },
},
},
"packages": { },
}`;

test("import bun.lock file as json", async () => {
const dir = tempDirWithFiles("bun-lock", {
"bun.lock": lockfile,
"index.ts": `
import lockfile from './bun.lock';
const _lockfile = ${lockfile}
if (!Bun.deepEquals(lockfile, _lockfile)) throw new Error('bun.lock wasnt imported as jsonc');
`,
});

expect([join(dir, "index.ts")]).toRun();
});
16 changes: 16 additions & 0 deletions test/js/bun/resolve/jsonc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,19 @@ test("empty jsonc - tsconfig.json", async () => {
});
expect([join(dir, "index.ts")]).toRun();
});

test("import anything.jsonc as json", async () => {
const jsoncFile = `{
// comment
"trailingComma": 0,
}`;
const dir = tempDirWithFiles("jsonc", {
"anything.jsonc": jsoncFile,
"index.ts": `
import file from './anything.jsonc';
const _file = ${jsoncFile}
if (!Bun.deepEquals(file, _file)) throw new Error('anything.jsonc wasnt imported as jsonc');
`,
});
expect([join(dir, "index.ts")]).toRun();
});

0 comments on commit 335faa8

Please sign in to comment.