-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests based on official spritepacks
- Loading branch information
1 parent
8d03897
commit 81e6988
Showing
8 changed files
with
2,433 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
name: Run official spritepack tests | ||
|
||
on: | ||
pull_request: | ||
push: | ||
|
||
jobs: | ||
test: | ||
name: Test schema files on official spritepacks | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
- name: Setup NodeJS | ||
uses: actions/setup-node@v4 | ||
with: { node-version: 21 } | ||
- name: Install packages | ||
run: cd test && yarn install | ||
- name: Run tests | ||
run: cd test && yarn test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules | ||
mas_git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { stat } from "fs/promises"; | ||
import { exec } from "child_process"; | ||
import { glob } from "glob"; | ||
|
||
const masGitUrl = "https://github.com/Monika-After-Story/MonikaModDev.git"; | ||
const masGitDir = "mas_git"; | ||
|
||
async function isMasGitPresent() { | ||
try { | ||
await stat(masGitDir); | ||
return true; | ||
} catch (e) { | ||
if (e.code === "ENOENT") return false; | ||
throw e; | ||
} | ||
} | ||
|
||
async function cloneMasGit() { | ||
return await new Promise((resolve, reject) => { | ||
exec(`git clone --depth=1 ${masGitUrl} ${masGitDir}`, (err) => { | ||
if (!err) resolve(); | ||
else reject(err); | ||
}); | ||
}); | ||
} | ||
|
||
async function updateMasGit() { | ||
return await new Promise((resolve, reject) => { | ||
exec(`git pull origin master`, { cwd: masGitDir }, (err) => { | ||
if (!err) resolve(); | ||
else reject(err); | ||
}) | ||
}); | ||
} | ||
|
||
export async function syncMasGit() { | ||
const exists = await isMasGitPresent(); | ||
if (!exists) await cloneMasGit(); | ||
else await updateMasGit(); | ||
} | ||
|
||
export async function getJsonList(type = "released") { | ||
return await glob(`${masGitDir}/spritepacks/${type}/**/*.json`); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"setupFilesAfterEnv": ["jest-expect-message"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"type": "module", | ||
"scripts": { | ||
"test": "node --experimental-vm-modules $(yarn bin jest)" | ||
}, | ||
"dependencies": { | ||
"ajv": "^8.12.0", | ||
"glob": "^10.3.12" | ||
}, | ||
"devDependencies": { | ||
"jest": "^29.7.0", | ||
"jest-expect-message": "^1.1.3" | ||
}, | ||
"resolutions": { | ||
"string-width": "4.2.3" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { readFile } from "fs/promises"; | ||
import Ajv from "ajv"; | ||
|
||
const ajv = new Ajv({ | ||
allowUnionTypes: true, | ||
allErrors: true, | ||
allowMatchingProperties: true | ||
}); | ||
|
||
async function compileSchemaJson(name) { | ||
const json = await readFile(`../${name}.schema.json`, { encoding: "utf-8" }); | ||
return ajv.compile(JSON.parse(json)); | ||
} | ||
|
||
const schema = {}; | ||
schema["0"] = await compileSchemaJson("acs"); | ||
schema["0-split"] = await compileSchemaJson("acs-split"); | ||
schema["1"] = await compileSchemaJson("hair"); | ||
schema["2"] = await compileSchemaJson("clothes"); | ||
|
||
export function inferSchema(json) { | ||
const { type, arm_split } = json; | ||
if (type === 0) return schema[!!arm_split ? "0-split" : "0"]; | ||
return schema[type]; | ||
} | ||
|
||
export async function readJson(path) { | ||
const json = await readFile(path, { encoding: "utf-8" }); | ||
return JSON.parse(json); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { getJsonList, syncMasGit } from "./git.js"; | ||
import { inferSchema, readJson } from "./schema.js"; | ||
|
||
function testJson(path, json) { | ||
test(path, () => { | ||
const validate = inferSchema(json); | ||
const pass = validate(json); | ||
const errors = validate.errors ?? []; | ||
const message = JSON.stringify(errors, null, 2); | ||
expect(pass, message, { showPrefix: false }).toBeTruthy(); | ||
}); | ||
} | ||
|
||
await syncMasGit(); | ||
await Promise.all((await getJsonList()) | ||
.map(async (it) => { | ||
const json = await readJson(it); | ||
testJson(it, json); | ||
})); |
Oops, something went wrong.