aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/transpiler/runtime-transpiler-fixture-duplicate-keys.json5
-rw-r--r--test/transpiler/runtime-transpiler-json-fixture.json8
-rw-r--r--test/transpiler/runtime-transpiler.test.ts130
-rw-r--r--test/transpiler/tsconfig.is-just-a-number.json1
-rw-r--r--test/transpiler/tsconfig.with-commas.json11
5 files changed, 155 insertions, 0 deletions
diff --git a/test/transpiler/runtime-transpiler-fixture-duplicate-keys.json b/test/transpiler/runtime-transpiler-fixture-duplicate-keys.json
new file mode 100644
index 000000000..3093e5c80
--- /dev/null
+++ b/test/transpiler/runtime-transpiler-fixture-duplicate-keys.json
@@ -0,0 +1,5 @@
+{
+ "a": 1,
+ "b": 2,
+ "a": "4"
+}
diff --git a/test/transpiler/runtime-transpiler-json-fixture.json b/test/transpiler/runtime-transpiler-json-fixture.json
new file mode 100644
index 000000000..81517c7fe
--- /dev/null
+++ b/test/transpiler/runtime-transpiler-json-fixture.json
@@ -0,0 +1,8 @@
+{
+ "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 }
+}
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");
+ });
+});
diff --git a/test/transpiler/tsconfig.is-just-a-number.json b/test/transpiler/tsconfig.is-just-a-number.json
new file mode 100644
index 000000000..d00491fd7
--- /dev/null
+++ b/test/transpiler/tsconfig.is-just-a-number.json
@@ -0,0 +1 @@
+1
diff --git a/test/transpiler/tsconfig.with-commas.json b/test/transpiler/tsconfig.with-commas.json
new file mode 100644
index 000000000..d30671e77
--- /dev/null
+++ b/test/transpiler/tsconfig.with-commas.json
@@ -0,0 +1,11 @@
+{
+ "buildOptions": {
+ "outDir": "dist",
+ "baseUrl": ".",
+ "paths": {
+ "src/*": ["src/*"]
+ }
+ }
+ // such comment
+ // very much
+}