* Setup jest framework for unit tests

* Move tests to a separate package

* Remove test script
This commit is contained in:
Cohee 2024-07-10 00:45:39 +03:00 committed by GitHub
parent d5c2bf3781
commit 2cd85f1a51
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 6073 additions and 20 deletions

43
package-lock.json generated
View File

@ -165,19 +165,6 @@
"dev": true, "dev": true,
"license": "MIT" "license": "MIT"
}, },
"node_modules/@eslint/eslintrc/node_modules/strip-json-comments": {
"version": "3.1.1",
"resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.1.1.tgz",
"integrity": "sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig==",
"dev": true,
"license": "MIT",
"engines": {
"node": ">=8"
},
"funding": {
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/@eslint/js": { "node_modules/@eslint/js": {
"version": "8.55.0", "version": "8.55.0",
"resolved": "https://registry.npmjs.org/@eslint/js/-/js-8.55.0.tgz", "resolved": "https://registry.npmjs.org/@eslint/js/-/js-8.55.0.tgz",
@ -2445,9 +2432,9 @@
} }
}, },
"node_modules/escalade": { "node_modules/escalade": {
"version": "3.1.1", "version": "3.1.2",
"resolved": "https://registry.npmjs.org/escalade/-/escalade-3.1.1.tgz", "resolved": "https://registry.npmjs.org/escalade/-/escalade-3.1.2.tgz",
"integrity": "sha512-k0er2gUkLf8O0zKJiAhmkTnJlTvINGv7ygDNPbeIsX/TJjGJZHuh9B2UxbsaEkmlEo9MfhrSzmhIlhRlI2GXnw==", "integrity": "sha512-ErCHMCae19vR8vQGe50xIsVomy19rg6gFu3+r3jkEO46suLMWBksvVyoGgQV+jOfl84ZSOSlmv6Gxa89PmTGmA==",
"license": "MIT", "license": "MIT",
"engines": { "engines": {
"node": ">=6" "node": ">=6"
@ -3009,10 +2996,13 @@
"license": "ISC" "license": "ISC"
}, },
"node_modules/function-bind": { "node_modules/function-bind": {
"version": "1.1.1", "version": "1.1.2",
"resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz", "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz",
"integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==", "integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==",
"license": "MIT" "license": "MIT",
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
}, },
"node_modules/get-caller-file": { "node_modules/get-caller-file": {
"version": "2.0.5", "version": "2.0.5",
@ -5085,6 +5075,19 @@
"node": ">=8" "node": ">=8"
} }
}, },
"node_modules/strip-json-comments": {
"version": "3.1.1",
"resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.1.1.tgz",
"integrity": "sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig==",
"dev": true,
"license": "MIT",
"engines": {
"node": ">=8"
},
"funding": {
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/strtok3": { "node_modules/strtok3": {
"version": "6.3.0", "version": "6.3.0",
"resolved": "https://registry.npmjs.org/strtok3/-/strtok3-6.3.0.tgz", "resolved": "https://registry.npmjs.org/strtok3/-/strtok3-6.3.0.tgz",

37
tests/.eslintrc.js Normal file
View File

@ -0,0 +1,37 @@
module.exports = {
root: true,
plugins: [
'jest',
],
extends: [
'eslint:recommended',
],
env: {
es6: true,
node: true,
"jest/globals": true,
},
parserOptions: {
ecmaVersion: 'latest',
},
overrides: [
],
ignorePatterns: [
],
rules: {
'no-unused-vars': ['error', { args: 'none' }],
'no-control-regex': 'off',
'no-constant-condition': ['error', { checkLoops: false }],
'require-yield': 'off',
'quotes': ['error', 'single'],
'semi': ['error', 'always'],
'indent': ['error', 4, { SwitchCase: 1, FunctionDeclaration: { parameters: 'first' } }],
'comma-dangle': ['error', 'always-multiline'],
'eol-last': ['error', 'always'],
'no-trailing-spaces': 'error',
'object-curly-spacing': ['error', 'always'],
'space-infix-ops': 'error',
'no-unused-expressions': ['error', { allowShortCircuit: true, allowTernary: true }],
'no-cond-assign': 'error',
},
};

9
tests/jest.config.json Normal file
View File

@ -0,0 +1,9 @@
{
"verbose": true,
"transform": {},
"extensionsToTreatAsEsm": [],
"preset": "jest-puppeteer",
"setupFilesAfterEnv": [
"<rootDir>/jest.setup.js"
]
}

2
tests/jest.setup.js Normal file
View File

@ -0,0 +1,2 @@
// Initialize global variables for Jest tests here
global.ST_URL = 'http://localhost:8000';

5977
tests/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

15
tests/package.json Normal file
View File

@ -0,0 +1,15 @@
{
"name": "sillytavern-tests",
"type": "module",
"license": "AGPL-3.0",
"scripts": {
"test": "jest"
},
"dependencies": {
"@types/jest": "^29.5.12",
"eslint": "^8.57.0",
"eslint-plugin-jest": "^28.6.0",
"jest": "^29.7.0",
"jest-puppeteer": "^10.0.1"
}
}

10
tests/sample.test.js Normal file
View File

@ -0,0 +1,10 @@
describe('sample', () => {
beforeAll(async () => {
await page.goto(global.ST_URL);
await page.waitForFunction('document.getElementById("preloader") === null', { timeout: 0 });
});
it('should be titled "SillyTavern"', async () => {
await expect(page.title()).resolves.toMatch('SillyTavern');
});
});