setup jest-puppeteer

This commit is contained in:
LouisLam 2021-10-03 18:16:55 +08:00
parent 446fc1af0b
commit a2a4c70cf5
7 changed files with 6225 additions and 5 deletions

View File

@ -91,6 +91,23 @@ module.exports = {
"rules": { "rules": {
"comma-dangle": ["error", "always-multiline"], "comma-dangle": ["error", "always-multiline"],
} }
},
// Override for jest puppeteer
{
"files": [
"**/*.spec.js",
"**/*.spec.jsx"
],
env: {
jest: true,
},
globals: {
page: true,
browser: true,
context: true,
jestPuppeteer: true,
},
} }
] ]
}; };

1
.gitignore vendored
View File

@ -11,3 +11,4 @@ dist-ssr
/private /private
/out /out
/tmp

5
jest-puppeteer.config.js Normal file
View File

@ -0,0 +1,5 @@
module.exports = {
"launch": {
"headless": false
}
};

6171
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -20,6 +20,8 @@
"start-server": "node server/server.js", "start-server": "node server/server.js",
"start-server-dev": "cross-env NODE_ENV=development node server/server.js", "start-server-dev": "cross-env NODE_ENV=development node server/server.js",
"build": "vite build", "build": "vite build",
"prepare-test": "npm run build && node server/server.js --port=3002 --data-dir=./data/test",
"test": "jest",
"tsc": "tsc", "tsc": "tsc",
"vite-preview-dist": "vite preview --host", "vite-preview-dist": "vite preview --host",
"build-docker": "npm run build-docker-debian && npm run build-docker-alpine", "build-docker": "npm run build-docker-debian && npm run build-docker-alpine",
@ -104,10 +106,22 @@
"dns2": "~2.0.1", "dns2": "~2.0.1",
"eslint": "~7.32.0", "eslint": "~7.32.0",
"eslint-plugin-vue": "~7.18.0", "eslint-plugin-vue": "~7.18.0",
"jest": "~27.2.4",
"jest-puppeteer": "~6.0.0",
"puppeteer": "~10.4.0",
"sass": "~1.42.1", "sass": "~1.42.1",
"stylelint": "~13.13.1", "stylelint": "~13.13.1",
"stylelint-config-standard": "~22.0.0", "stylelint-config-standard": "~22.0.0",
"typescript": "~4.4.3", "typescript": "~4.4.3",
"vite": "~2.5.10" "vite": "~2.5.10"
},
"jest": {
"verbose": true,
"preset": "jest-puppeteer",
"globals": {
"__DEV__": true
},
"testRegex": "./test/*.spec.js",
"rootDir": "."
} }
} }

View File

@ -22,7 +22,6 @@ exports.startInterval = () => {
} }
exports.latestVersion = res.data.version; exports.latestVersion = res.data.version;
console.log("Latest Version: " + exports.latestVersion);
} catch (_) { } } catch (_) { }
}; };

21
test/test.spec.js Normal file
View File

@ -0,0 +1,21 @@
beforeAll(() => {
});
afterAll(() => {
return console.log("Cleanup");
});
describe("Very Simple Test", () => {
const title = "Uptime Kuma";
beforeAll(async () => {
await page.goto("http://127.0.0.1:3002");
});
it(`should be titled "${title}"`, async () => {
await expect(page.title()).resolves.toMatch(title);
});
});