-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocessor.integration.test.ts
More file actions
65 lines (59 loc) · 2.04 KB
/
Copy pathprocessor.integration.test.ts
File metadata and controls
65 lines (59 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import assert from "node:assert/strict";
import { describe, test } from "node:test";
import { setupGame } from "@modkit/test";
const MOD_ID = "example.structure-processor";
const STRUCTURE_ID = `${MOD_ID}:scanner`;
const SPRITE_ID = `${MOD_ID}:scanner-sprite`;
/** Fixed Void-save cell on the Empty.save platform (snap-grid aligned). */
const SCANNER_CELL = { x: 2080, y: 1612 };
const game = await setupGame();
describe("structure-processor", { concurrency: false }, () => {
test("structure-processor scanner and sprite are registered", async (t) => {
const ids = await game.orderedModIds();
if (!ids.includes(MOD_ID)) {
t.skip(`${MOD_ID} is not loaded`);
return;
}
const live = await game.waitFor(
(structureId: string, spriteId: string) => {
let structure = false;
try {
structure = sandkit.api.structures.getTypeById(structureId) != null;
} catch {
structure = false;
}
return {
structure,
sprite: sandkit.api.sprites.getById(spriteId) !== undefined,
};
},
(value) => value.structure && value.sprite,
{ args: [STRUCTURE_ID, SPRITE_ID], message: "scanner did not register", timeoutMs: 4000 },
);
assert.equal(live.structure, true);
assert.equal(live.sprite, true);
});
test("scanner builds at a platform cell", async (t) => {
const ids = await game.orderedModIds();
if (!ids.includes(MOD_ID)) {
t.skip(`${MOD_ID} is not loaded`);
return;
}
await game.evaluate(
(x: number, y: number) => {
if (sandkit.api.structures.getAtCell(x, y)) {
sandkit.api.structures.removeAtCell(x, y);
}
},
SCANNER_CELL.x,
SCANNER_CELL.y,
);
await game.buildStructures([{ type: STRUCTURE_ID, x: SCANNER_CELL.x, y: SCANNER_CELL.y }]);
const type = await game.evaluate(
(x: number, y: number) => sandkit.api.structures.getAtCell(x, y)?.type ?? null,
SCANNER_CELL.x,
SCANNER_CELL.y,
);
assert.equal(type, STRUCTURE_ID);
});
});