aboutsummaryrefslogtreecommitdiff
path: root/test/transpiler/runtime-transpiler.test.ts
diff options
context:
space:
mode:
Diffstat (limited to 'test/transpiler/runtime-transpiler.test.ts')
-rw-r--r--test/transpiler/runtime-transpiler.test.ts130
1 files changed, 130 insertions, 0 deletions
diff --git a/test/transpiler/runtime-transpiler.test.ts b/test/transpiler/runtime-transpiler.test.ts
index c1881ee67..23e972be4 100644
--- a/test/transpiler/runtime-transpiler.test.ts
+++ b/test/transpiler/runtime-transpiler.test.ts
@@ -30,3 +30,133 @@ describe("// @bun", () => {
expect(exitCode).toBe(0);
});
});
+
+describe("json imports", () => {
+ test("require(*.json)", async () => {
+ const {
+ name,
+ description,
+ players,
+ version,
+ creator,
+ default: defaultExport,
+ ...other
+ } = require("./runtime-transpiler-json-fixture.json");
+ const obj = {
+ "name": "Spiral 4v4 NS",
+ "description": "4v4 unshared map. 4 spawns in a spiral. Preferred to play with 4v4 NS.",
+ "version": "1.0",
+ "creator": "Grand Homie",
+ "players": [8, 8],
+ default: { a: 1 },
+ };
+ expect({
+ name,
+ description,
+ players,
+ version,
+ creator,
+ default: { a: 1 },
+ }).toEqual(obj);
+ expect(other).toEqual({});
+
+ // This tests that importing and requiring when already in the cache keeps the state the same
+ {
+ const {
+ name,
+ description,
+ players,
+ version,
+ creator,
+ default: defaultExport,
+ // @ts-ignore
+ } = await import("./runtime-transpiler-json-fixture.json");
+ const obj = {
+ "name": "Spiral 4v4 NS",
+ "description": "4v4 unshared map. 4 spawns in a spiral. Preferred to play with 4v4 NS.",
+ "version": "1.0",
+ "creator": "Grand Homie",
+ "players": [8, 8],
+ default: { a: 1 },
+ };
+ expect({
+ name,
+ description,
+ players,
+ version,
+ creator,
+ default: { a: 1 },
+ }).toEqual(obj);
+ // They should be strictly equal
+ expect(defaultExport.players).toBe(players);
+ expect(defaultExport).toEqual(obj);
+ }
+
+ delete require.cache[require.resolve("./runtime-transpiler-json-fixture.json")];
+ });
+
+ test("import(*.json)", async () => {
+ const {
+ name,
+ description,
+ players,
+ version,
+ creator,
+ default: defaultExport,
+ // @ts-ignore
+ } = await import("./runtime-transpiler-json-fixture.json");
+ delete require.cache[require.resolve("./runtime-transpiler-json-fixture.json")];
+ const obj = {
+ "name": "Spiral 4v4 NS",
+ "description": "4v4 unshared map. 4 spawns in a spiral. Preferred to play with 4v4 NS.",
+ "version": "1.0",
+ "creator": "Grand Homie",
+ "players": [8, 8],
+ default: { a: 1 },
+ };
+ expect({
+ name,
+ description,
+ players,
+ version,
+ creator,
+ default: { a: 1 },
+ }).toEqual(obj);
+ // They should be strictly equal
+ expect(defaultExport.players).toBe(players);
+ expect(defaultExport).toEqual(obj);
+ });
+
+ test("should support comments in tsconfig.json", async () => {
+ // @ts-ignore
+ const { buildOptions, default: defaultExport } = await import("./tsconfig.with-commas.json");
+ delete require.cache[require.resolve("./tsconfig.with-commas.json")];
+ const obj = {
+ "buildOptions": {
+ "outDir": "dist",
+ "baseUrl": ".",
+ "paths": {
+ "src/*": ["src/*"],
+ },
+ },
+ };
+ expect({
+ buildOptions,
+ }).toEqual(obj);
+ // They should be strictly equal
+ expect(defaultExport.buildOptions).toBe(buildOptions);
+ expect(defaultExport).toEqual(obj);
+ });
+
+ test("should handle non-boecjts in tsconfig.json", async () => {
+ // @ts-ignore
+ const { default: num } = await import("./tsconfig.is-just-a-number.json");
+ delete require.cache[require.resolve("./tsconfig.is-just-a-number.json")];
+ expect(num).toBe(1);
+ });
+
+ test("should handle duplicate keys", async () => {
+ // @ts-ignore
+ expect((await import("./runtime-transpiler-fixture-duplicate-keys.json")).a).toBe("4");
+ });
+});