Commit 29b0d8f2 authored by nanahira's avatar nanahira

add jest

parent d264bde8
Pipeline #42884 passed with stages
in 4 minutes and 49 seconds
webpack.config.js
dist/*
build/*
*.js
module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: {
project: 'tsconfig.json',
tsconfigRootDir : __dirname,
sourceType: 'module',
},
plugins: ['@typescript-eslint/eslint-plugin'],
extends: [
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended',
],
root: true,
env: {
node: true,
jest: true,
},
ignorePatterns: ['.eslintrc.js'],
rules: {
'@typescript-eslint/interface-name-prefix': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-explicit-any': 'off',
},
};
# compiled output
/dist
/node_modules
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
# OS
.DS_Store
# Tests
/coverage
/.nyc_output
# IDEs and editors
/.idea
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace
# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
/data
/output
/config.yaml
/test-release.cdb /test-release.cdb
/bin /bin
/ygopro
...@@ -36,6 +36,30 @@ merge_databases: ...@@ -36,6 +36,30 @@ merge_databases:
- test-release.cdb - test-release.cdb
- test-update.cdb - test-update.cdb
prepare_jest_env:
stage: prepare
dependencies: []
tags:
- linux
script:
- mkdir ygopro
- git clone --depth=1 https://code.moenext.com/mycard/ygopro-scripts-888 ygopro/script
- wget https://code.moenext.com/mycard/ygopro-database/-/raw/master/locales/zh-CN/cards.cdb -O ygopro/test.cdb
artifacts:
paths:
- ygopro
npm_ci:
stage: prepare
dependencies: []
tags:
- linux
script:
- npm ci
artifacts:
paths:
- node_modules
add_script_diff: add_script_diff:
stage: prepare stage: prepare
dependencies: [] dependencies: []
...@@ -115,25 +139,35 @@ json2: ...@@ -115,25 +139,35 @@ json2:
paths: paths:
- test-release-v2.json - test-release-v2.json
redtext: # redtext:
# stage: prepare2
# dependencies:
# - add_script_diff
# tags:
# - linux
# image: git-registry.moenext.com/nanahira/srvpro:lite
# script:
# - apt update && apt -y install sqlite3
# - mv /ygopro-server/ygopro .
# - mkdir dist
# - cd ygopro
# - rm -rf expansions
# - ln -s ../ ./expansions
# - ls -1 ../*.cdb | xargs -I '{}' sqlite3 '{}' "select id from datas where type != 0x11 and (type & 0x4000) = 0;" | xargs -I {} -P $(nproc) bash -c './ygopro {} 2>&1 | tee ../redtext-{}.txt'
# - cd ..
# - cat redtext-*.txt > redtext.txt
# # if there are any lines in redtext.txt fail the job
# - exit $(wc -l < redtext.txt)
jest:
stage: prepare2 stage: prepare2
dependencies: dependencies:
- add_script_diff - prepare_jest_env
- npm_ci
tags: tags:
- linux - linux
image: git-registry.moenext.com/nanahira/srvpro:lite
script: script:
- apt update && apt -y install sqlite3 - npm run test
- mv /ygopro-server/ygopro .
- mkdir dist
- cd ygopro
- rm -rf expansions
- ln -s ../ ./expansions
- ls -1 ../*.cdb | xargs -I '{}' sqlite3 '{}' "select id from datas where type != 0x11 and (type & 0x4000) = 0;" | xargs -I {} -P $(nproc) bash -c './ygopro {} 2>&1 | tee ../redtext-{}.txt'
- cd ..
- cat redtext-*.txt > redtext.txt
# if there are any lines in redtext.txt fail the job
- exit $(wc -l < redtext.txt)
neos: neos:
stage: pack stage: pack
......
This source diff could not be displayed because it is too large. You can view the blob instead.
{
"name": "pre-release-database-cdb",
"description": "YGOPro super pre cards",
"version": "1.0.0",
"scripts": {
"lint": "eslint --fix .",
"test": "jest --passWithNoTests"
},
"repository": {
"type": "git",
"url": "https://code.moenext.com/mycard/pre-release-database-cdb.git"
},
"author": "Nanahira <nanahira@momobako.com>",
"license": "MIT",
"keywords": [],
"bugs": {
"url": "https://code.moenext.com/mycard/pre-release-database-cdb/issues"
},
"homepage": "https://code.moenext.com/mycard/pre-release-database-cdb",
"jest": {
"moduleFileExtensions": [
"js",
"json",
"ts"
],
"rootDir": "tests",
"testRegex": ".*\\.spec\\.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
},
"collectCoverageFrom": [
"**/*.(t|j)s"
],
"coverageDirectory": "../coverage",
"testEnvironment": "node",
"testTimeout": 60000
},
"devDependencies": {
"@types/jest": "^30.0.0",
"@types/node": "^25.2.1",
"@types/sql.js": "^1.4.9",
"@typescript-eslint/eslint-plugin": "^8.54.0",
"@typescript-eslint/parser": "^8.54.0",
"eslint": "^8.57.1",
"eslint-config-prettier": "^10.1.8",
"eslint-plugin-prettier": "^5.5.5",
"jest": "^30.2.0",
"prettier": "^3.8.1",
"ts-jest": "^29.4.6",
"typescript": "^5.9.3"
},
"dependencies": {
"sql.js": "^1.13.0",
"ygopro-jstest": "^1.0.5",
"ygopro-msg-encode": "^1.1.5"
}
}
import initSqlJs from "sql.js";
import fs from "node:fs";
import path from "node:path";
import { createTest } from "./utility/create-test";
import { OcgcoreScriptConstants } from "ygopro-msg-encode";
import { NoEffectAdvancor } from "ygopro-jstest";
describe("No Red Text", () => {
it("should not get redtext Lua errors", async () => {
const SQL = await initSqlJs();
// load everything and make sure no redtext errors occur
const files = await fs.promises.readdir(process.cwd());
for (const file of files) {
if (!file.endsWith(".cdb")) continue;
const buf = await fs.promises.readFile(path.resolve(process.cwd(), file));
const db = new SQL.Database(buf);
const res = db.exec(
`SELECT id FROM datas where type != ${OcgcoreScriptConstants.TYPE_MONSTER | OcgcoreScriptConstants.TYPE_NORMAL} and type & ${OcgcoreScriptConstants.TYPE_TOKEN} = 0 and not (alias > 0 and alias - id < 20)`,
);
for (const data of res) {
for (const row of data.values) {
const id = row[0] as number;
expect(id).toBeGreaterThan(0); // dummy assertion to use id variable
console.log(
`Testing redtext of card ID: ${id} from database: ${file}`,
);
await createTest({}, (ygo) =>
ygo
.addCard({
code: id,
location: OcgcoreScriptConstants.LOCATION_DECK,
})
.advance(NoEffectAdvancor()),
);
}
}
db.close();
}
});
});
jest.setTimeout(300000);
import path from "node:path";
import { useYGOProTest, YGOProTestOptions } from "ygopro-jstest";
export const createTest = (
options: Partial<YGOProTestOptions> = {},
cb: Parameters<typeof useYGOProTest>[1],
) =>
useYGOProTest(
{
...options,
ygoproPath: [
...(options.ygoproPath || []),
process.cwd(),
path.resolve(process.cwd(), process.env.YGOPRO_PATH || "ygopro"),
],
},
cb,
);
{
"compilerOptions": {
"outDir": "dist",
"module": "commonjs",
"target": "es2021",
"esModuleInterop": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"declaration": true,
"sourceMap": true,
"types": [
"jest",
"node"
]
},
"compileOnSave": true,
"allowJs": true,
"include": [
"*.ts",
"src/**/*.ts",
"tests/**/*.ts"
]
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment