mirror of
https://github.com/DaanVandenBosch/phantasmal-world.git
synced 2025-04-04 22:58:29 +08:00
Jest tests are working again.
This commit is contained in:
parent
e859477727
commit
4eeda19837
6
jest.config.js
Normal file
6
jest.config.js
Normal file
@ -0,0 +1,6 @@
|
||||
module.exports = {
|
||||
preset: 'ts-jest',
|
||||
testEnvironment: 'node',
|
||||
moduleDirectories: ["node_modules"],
|
||||
globalSetup: "./test/src/global_setup.js",
|
||||
};
|
@ -4,7 +4,6 @@
|
||||
"private": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@types/jest": "24.0.15",
|
||||
"@types/lodash": "^4.14.132",
|
||||
"@types/react": "16.8.20",
|
||||
"@types/react-dom": "16.8.4",
|
||||
@ -31,7 +30,7 @@
|
||||
"scripts": {
|
||||
"start": "webpack-dev-server --port 1623 --config webpack.dev.js",
|
||||
"buildweb": "webpack --config webpack.prod.js",
|
||||
"test": "scripts/test.js",
|
||||
"test": "jest",
|
||||
"update_generic_data": "ts-node --project=tsconfig-scripts.json assets_generation/update_generic_data.ts",
|
||||
"update_ephinea_data": "ts-node --project=tsconfig-scripts.json assets_generation/update_ephinea_data.ts",
|
||||
"lint": "prettier --check \"{src,assets_generation,test}/**/*.{ts,tsx}\" && echo Linting... && eslint \"{src,assets_generation,test}/**/*.{ts,tsx}\" && echo All code passes the prettier and eslint checks."
|
||||
@ -41,6 +40,7 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/cheerio": "^0.22.11",
|
||||
"@types/jest": "^24.0.15",
|
||||
"@typescript-eslint/eslint-plugin": "^1.13.0",
|
||||
"@typescript-eslint/parser": "^1.13.0",
|
||||
"cheerio": "^1.0.0-rc.3",
|
||||
@ -56,6 +56,7 @@
|
||||
"file-loader": "^4.1.0",
|
||||
"fork-ts-checker-webpack-plugin": "^1.4.3",
|
||||
"html-webpack-plugin": "^3.2.0",
|
||||
"jest": "^24.8.0",
|
||||
"less": "^3.9.0",
|
||||
"less-loader": "^5.0.0",
|
||||
"mini-css-extract-plugin": "^0.8.0",
|
||||
@ -63,6 +64,7 @@
|
||||
"optimize-css-assets-webpack-plugin": "^5.0.3",
|
||||
"prettier": "1.18.2",
|
||||
"terser-webpack-plugin": "^1.3.0",
|
||||
"ts-jest": "^24.0.2",
|
||||
"ts-loader": "^6.0.4",
|
||||
"ts-node": "^8.3.0",
|
||||
"typescript": "^3.5.3",
|
||||
|
@ -206,10 +206,6 @@ export class ArrayBufferCursor implements Cursor {
|
||||
null_terminated: boolean,
|
||||
drop_remaining: boolean
|
||||
): string {
|
||||
if (null_terminated) {
|
||||
max_byte_length = Math.min(max_byte_length, this.size - this.position);
|
||||
}
|
||||
|
||||
const string_length = null_terminated
|
||||
? this.index_of_u8(0, max_byte_length) - this.position
|
||||
: max_byte_length;
|
||||
@ -229,10 +225,6 @@ export class ArrayBufferCursor implements Cursor {
|
||||
null_terminated: boolean,
|
||||
drop_remaining: boolean
|
||||
): string {
|
||||
if (null_terminated) {
|
||||
max_byte_length = Math.min(max_byte_length, this.size - this.position);
|
||||
}
|
||||
|
||||
const string_length = null_terminated
|
||||
? this.index_of_u16(0, max_byte_length) - this.position
|
||||
: Math.floor(max_byte_length / 2) * 2;
|
||||
|
@ -236,10 +236,6 @@ export class ResizableBufferCursor implements Cursor {
|
||||
null_terminated: boolean,
|
||||
drop_remaining: boolean
|
||||
): string {
|
||||
if (null_terminated) {
|
||||
max_byte_length = Math.min(max_byte_length, this.size - this.position);
|
||||
}
|
||||
|
||||
this.check_size("max_byte_length", max_byte_length, max_byte_length);
|
||||
|
||||
const string_length = null_terminated
|
||||
@ -261,10 +257,6 @@ export class ResizableBufferCursor implements Cursor {
|
||||
null_terminated: boolean,
|
||||
drop_remaining: boolean
|
||||
): string {
|
||||
if (null_terminated) {
|
||||
max_byte_length = Math.min(max_byte_length, this.size - this.position);
|
||||
}
|
||||
|
||||
this.check_size("max_byte_length", max_byte_length, max_byte_length);
|
||||
|
||||
const string_length = null_terminated
|
||||
|
@ -24,7 +24,7 @@ export function parse_unitxt(buf: Cursor, compressed: boolean = true): Unitxt {
|
||||
|
||||
for (const entry_offset of category_entry_offset) {
|
||||
buf.seek_start(entry_offset);
|
||||
const str = buf.string_utf16(1024, true, true);
|
||||
const str = buf.string_utf16(Math.min(1024, buf.bytes_left), true, true);
|
||||
entries.push(str);
|
||||
}
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ import "golden-layout/src/css/goldenlayout-dark-theme.css";
|
||||
import "antd/dist/antd.less";
|
||||
|
||||
Logger.useDefaults({
|
||||
defaultLevel: (Logger as any)[process.env["REACT_APP_LOG_LEVEL"] || "OFF"],
|
||||
defaultLevel: (Logger as any)[process.env["LOG_LEVEL"] || "OFF"],
|
||||
});
|
||||
|
||||
const root_element = document.createElement("div");
|
||||
|
@ -1,5 +0,0 @@
|
||||
import Logger from "js-logger";
|
||||
|
||||
Logger.useDefaults({
|
||||
defaultLevel: Logger[process.env["REACT_APP_LOG_LEVEL"] || "OFF"],
|
||||
});
|
12
test/src/global_setup.js
Normal file
12
test/src/global_setup.js
Normal file
@ -0,0 +1,12 @@
|
||||
const Logger = require("js-logger");
|
||||
require('dotenv').config({ path: ".env.test" })
|
||||
|
||||
module.exports = async () => {
|
||||
const log_level = process.env["LOG_LEVEL"] || "OFF";
|
||||
|
||||
console.log(`Log level: ${log_level}`);
|
||||
|
||||
Logger.useDefaults({
|
||||
defaultLevel: Logger[log_level],
|
||||
});
|
||||
};
|
@ -8,6 +8,7 @@
|
||||
"allowJs": true,
|
||||
"skipLibCheck": true,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"esModuleInterop": true,
|
||||
"strict": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"moduleResolution": "node",
|
||||
|
Loading…
Reference in New Issue
Block a user