setup unit test for setup

This commit is contained in:
LouisLam 2021-10-05 17:39:44 +08:00
parent e6ff957d9d
commit 79e0c9e1f1
6 changed files with 3078 additions and 77 deletions

View file

@ -1,5 +1,6 @@
module.exports = { module.exports = {
"launch": { "launch": {
"headless": false "headless": false,
"userDataDir": "./data/test-chrome-profile",
} }
}; };

3091
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -20,8 +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/", "prepare-test-server": "node test/prepare-test-server.js && node server/server.js --port=3002 --data-dir=./data/test/",
"test": "jest", "test": "node test/prepare-jest.js && 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",
@ -101,8 +101,6 @@
"@vitejs/plugin-legacy": "~1.5.3", "@vitejs/plugin-legacy": "~1.5.3",
"@vitejs/plugin-vue": "~1.9.1", "@vitejs/plugin-vue": "~1.9.1",
"@vue/compiler-sfc": "~3.2.16", "@vue/compiler-sfc": "~3.2.16",
"@vue/test-utils": "next",
"@vue/vue3-jest": "^27.0.0-alpha.1",
"core-js": "~3.18.0", "core-js": "~3.18.0",
"cross-env": "~7.0.3", "cross-env": "~7.0.3",
"dns2": "~2.0.1", "dns2": "~2.0.1",
@ -124,6 +122,7 @@
"__DEV__": true "__DEV__": true
}, },
"testRegex": "./test/*.spec.js", "testRegex": "./test/*.spec.js",
"rootDir": "." "rootDir": ".",
"testTimeout": 15000
} }
} }

5
test/prepare-jest.js Normal file
View file

@ -0,0 +1,5 @@
const fs = require("fs");
fs.rmdirSync("./data/test-chrome-profile", {
recursive: true,
});

View file

@ -0,0 +1,5 @@
const fs = require("fs");
fs.rmdirSync("./data/test", {
recursive: true,
});

View file

@ -1,16 +1,21 @@
const fs = require("fs"); // eslint-disable-next-line no-unused-vars
const { Page } = require("puppeteer");
/**
* Set back the correct data type for page object
* @type {Page}
*/
page;
beforeAll(() => { beforeAll(() => {
fs.rmdirSync("./data/test", {
recursive: true,
});
}); });
afterAll(() => { afterAll(() => {
}); });
describe("Very Simple Test", () => { describe("Init", () => {
const title = "Uptime Kuma"; const title = "Uptime Kuma";
beforeAll(async () => { beforeAll(async () => {
@ -21,8 +26,31 @@ describe("Very Simple Test", () => {
await expect(page.title()).resolves.toMatch(title); await expect(page.title()).resolves.toMatch(title);
}); });
it("Create an admin account", async () => { it("Setup", async () => {
await page.evaluate(() => document.); // Create an Admin
await page.waitForSelector("#floatingInput");
await page.waitForSelector("#repeat");
await page.click("#floatingInput");
await page.type("#floatingInput", "admin");
await page.type("#floatingPassword", "admin123");
await page.type("#repeat", "admin123");
await page.click(".btn-primary[type=submit]");
await page.waitFor(3000);
// Go to /setup again
await page.goto("http://127.0.0.1:3002/setup");
await page.waitFor(3000);
const pathname = await page.evaluate(() => location.pathname);
expect(pathname).toEqual("/dashboard");
// Go to /
await page.goto("http://127.0.0.1:3002");
expect(pathname).toEqual("/dashboard");
expect(pathname).toEqual("/dashboard");
});
describe("Init", () => {
}); });
}); });