|
1 | 1 | import assert from "node:assert/strict"; |
2 | | -import { readFileSync } from "node:fs"; |
3 | | -import { |
4 | | - createDefaultCameraPathPayload, |
5 | | - validateCameraPathPayload |
6 | | -} from "../../tools/schemas/tools/cameraPathPayload.schema.js"; |
7 | | -import { |
8 | | - createDefaultMapPayload, |
9 | | - validateMapPayload |
10 | | -} from "../../tools/schemas/tools/mapPayload.schema.js"; |
11 | | -import { |
12 | | - createDefaultAssetPayload, |
13 | | - validateAssetPayload |
14 | | -} from "../../tools/schemas/tools/assetPayload.schema.js"; |
15 | | -import { |
16 | | - validateWorkspaceManifestSchema, |
17 | | - WORKSPACE_MANIFEST_SCHEMA, |
18 | | - WORKSPACE_MANIFEST_VERSION, |
19 | | - WORKSPACE_DOCUMENT_KIND |
20 | | -} from "../../tools/schemas/workspaceManifest.schema.js"; |
| 2 | +import { existsSync, readFileSync } from "node:fs"; |
21 | 3 |
|
22 | | -export async function run() { |
23 | | - const cameraValidation = validateCameraPathPayload(createDefaultCameraPathPayload(), { |
24 | | - requireSchema: true, |
25 | | - requireWaypoints: true |
26 | | - }); |
27 | | - assert.equal(cameraValidation.valid, true, cameraValidation.issues.join(" ")); |
| 4 | +function readJson(relativePath) { |
| 5 | + return JSON.parse(readFileSync(new URL(`../../${relativePath}`, import.meta.url), "utf8")); |
| 6 | +} |
28 | 7 |
|
29 | | - const mapValidation = validateMapPayload(createDefaultMapPayload(), { |
30 | | - requireSchema: true, |
31 | | - requirePoints: true |
| 8 | +export async function run() { |
| 9 | + const schemaFiles = [ |
| 10 | + "tools/schemas/workspace.manifest.schema.json", |
| 11 | + "tools/schemas/tool.manifest.schema.json", |
| 12 | + "tools/schemas/palette.schema.json", |
| 13 | + "tools/schemas/sample.tool-payload.schema.json", |
| 14 | + "tools/schemas/tools/vector-map-editor.schema.json", |
| 15 | + "tools/schemas/tools/vector-asset-studio.schema.json", |
| 16 | + "tools/schemas/tools/sprite-editor.schema.json" |
| 17 | + ]; |
| 18 | + schemaFiles.forEach((relativePath) => { |
| 19 | + const schema = readJson(relativePath); |
| 20 | + assert.equal(schema.$schema, "https://json-schema.org/draft/2020-12/schema"); |
| 21 | + assert.equal(typeof schema.$id, "string"); |
| 22 | + assert.equal(schema.$id.length > 0, true); |
32 | 23 | }); |
33 | | - assert.equal(mapValidation.valid, true, mapValidation.issues.join(" ")); |
34 | 24 |
|
35 | | - const assetValidation = validateAssetPayload(createDefaultAssetPayload(), { |
36 | | - requireSchema: true, |
37 | | - requireVertices: true |
| 25 | + const toolSchemaFiles = [ |
| 26 | + "tools/vector-map-editor/tool.schema.json", |
| 27 | + "tools/vector-asset-studio/tool.schema.json", |
| 28 | + "tools/palette-editor/tool.schema.json" |
| 29 | + ]; |
| 30 | + toolSchemaFiles.forEach((relativePath) => { |
| 31 | + const document = readJson(relativePath); |
| 32 | + assert.equal(document.$schema, "https://json-schema.org/draft/2020-12/schema"); |
38 | 33 | }); |
39 | | - assert.equal(assetValidation.valid, true, assetValidation.issues.join(" ")); |
40 | | - |
41 | | - const workspaceManifest = { |
42 | | - documentKind: WORKSPACE_DOCUMENT_KIND, |
43 | | - schema: WORKSPACE_MANIFEST_SCHEMA, |
44 | | - version: WORKSPACE_MANIFEST_VERSION, |
45 | | - id: "workspace-test", |
46 | | - name: "Workspace Test", |
47 | | - tools: { |
48 | | - "3d-asset-viewer": { |
49 | | - schema: "tools.3d-asset-viewer.asset/1", |
50 | | - assetId: "asset-test", |
51 | | - vertices: [{ x: 0, y: 0, z: 0 }] |
52 | | - } |
53 | | - }, |
54 | | - sharedLibrary: { |
55 | | - assets: [ |
56 | | - { |
57 | | - id: "asset-test", |
58 | | - type: "vector", |
59 | | - displayName: "Asset Test", |
60 | | - sourcePath: "/games/Test/assets/vectors/asset-test.vector.json", |
61 | | - sourceToolId: "3d-asset-viewer" |
62 | | - } |
63 | | - ], |
64 | | - palettes: [] |
65 | | - }, |
66 | | - exportArtifacts: [ |
67 | | - { |
68 | | - kind: "png", |
69 | | - path: "/games/Test/exports/asset-preview.png", |
70 | | - sourceToolId: "3d-asset-viewer" |
71 | | - } |
72 | | - ] |
73 | | - }; |
74 | | - const workspaceValidation = validateWorkspaceManifestSchema(workspaceManifest); |
75 | | - assert.equal(workspaceValidation.valid, true, workspaceValidation.issues.join(" ")); |
76 | 34 |
|
77 | | - const invalidWorkspaceValidation = validateWorkspaceManifestSchema({ |
78 | | - ...workspaceManifest, |
79 | | - externalAssets: ["/games/Test/assets/outside-manifest.asset.json"], |
80 | | - exportArtifacts: [{ kind: "jpg", path: "/games/Test/exports/asset-preview.jpg" }] |
| 35 | + const removedValidationUtilities = [ |
| 36 | + "tools/schemas/workspaceManifest.schema.js", |
| 37 | + "tools/schemas/tools/cameraPathPayload.schema.js", |
| 38 | + "tools/schemas/tools/mapPayload.schema.js", |
| 39 | + "tools/schemas/tools/assetPayload.schema.js" |
| 40 | + ]; |
| 41 | + removedValidationUtilities.forEach((relativePath) => { |
| 42 | + const absolutePath = new URL(`../../${relativePath}`, import.meta.url); |
| 43 | + assert.equal(existsSync(absolutePath), false); |
81 | 44 | }); |
82 | | - assert.equal(invalidWorkspaceValidation.valid, false); |
83 | | - assert.equal( |
84 | | - invalidWorkspaceValidation.issues.some((issue) => issue.includes("workspace.manifest")), |
85 | | - true |
86 | | - ); |
87 | | - assert.equal( |
88 | | - invalidWorkspaceValidation.issues.some((issue) => issue.includes(".png")), |
89 | | - true |
90 | | - ); |
91 | 45 |
|
92 | 46 | const paletteBrowserSource = readFileSync(new URL("../../tools/Palette Browser/main.js", import.meta.url), "utf8"); |
93 | 47 | assert.match(paletteBrowserSource, /function duplicateSelectedPalette\(/); |
|
0 commit comments