diff --git a/.github/workflows/auto-test.yml b/.github/workflows/auto-test.yml index d26b76e6..b49a253c 100644 --- a/.github/workflows/auto-test.yml +++ b/.github/workflows/auto-test.yml @@ -50,3 +50,19 @@ jobs: cache: 'npm' - run: npm install - run: npm run lint + + e2e-tests: + needs: [ check-linters ] + runs-on: ubuntu-latest + steps: + - run: git config --global core.autocrlf false # Mainly for Windows + - uses: actions/checkout@v3 + + - name: Use Node.js 14 + uses: actions/setup-node@v3 + with: + node-version: 14 + cache: 'npm' + - run: npm install + - run: npm run build + - run: npm run cy:test diff --git a/cypress.config.ts b/cypress.config.ts index ceeebca3..d97e0875 100644 --- a/cypress.config.ts +++ b/cypress.config.ts @@ -2,13 +2,14 @@ import { defineConfig } from "cypress"; export default defineConfig({ e2e: { - baseUrl: "http://localhost:3000", + baseUrl: "http://localhost:3002", defaultCommandTimeout: 10000, pageLoadTimeout: 60000, viewportWidth: 1920, viewportHeight: 1080, + specPattern: ["cypress/e2e/setup.cy.ts", "cypress/e2e/**/*.ts"], }, env: { - baseUrl: "http://localhost:3000", + baseUrl: "http://localhost:3002", }, }); diff --git a/cypress/fixtures/example.json b/cypress/fixtures/example.json deleted file mode 100644 index 02e42543..00000000 --- a/cypress/fixtures/example.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "Using fixtures to represent data", - "email": "hello@cypress.io", - "body": "Fixtures are a great way to mock data for responses to routes" -} diff --git a/package.json b/package.json index 508722f4..ae0622ec 100644 --- a/package.json +++ b/package.json @@ -59,6 +59,7 @@ "release-beta": "node extra/beta/update-version.js && npm run build && node ./extra/env2arg.js docker buildx build -f docker/dockerfile --platform linux/amd64,linux/arm64,linux/arm/v7 -t louislam/uptime-kuma:$VERSION -t louislam/uptime-kuma:beta . --target release --push && node ./extra/press-any-key.js && npm run upload-artifacts", "git-remove-tag": "git tag -d", "build-dist-and-restart": "npm run build && npm run start-server-dev", + "cy:test": "node test/prepare-test-server.js && node server/server.js --port=3002 --data-dir=./data/test/ --e2e", "cy:run": "npx cypress run --browser chrome --headless" }, "dependencies": { diff --git a/server/server.js b/server/server.js index 2d3f37ee..c5777f0a 100644 --- a/server/server.js +++ b/server/server.js @@ -61,7 +61,7 @@ log.info("server", "Importing this project modules"); log.debug("server", "Importing Monitor"); const Monitor = require("./model/monitor"); log.debug("server", "Importing Settings"); -const { getSettings, setSettings, setting, initJWTSecret, checkLogin, startUnitTest, FBSD, doubleCheckPassword } = require("./util-server"); +const { getSettings, setSettings, setting, initJWTSecret, checkLogin, startUnitTest, FBSD, doubleCheckPassword, startE2eTests } = require("./util-server"); log.debug("server", "Importing Notification"); const { Notification } = require("./notification"); @@ -112,6 +112,7 @@ const twoFAVerifyOptions = { * @type {boolean} */ const testMode = !!args["test"] || false; +const e2eTestMode = !!args["e2e"] || false; if (config.demoMode) { log.info("server", "==== Demo Mode ===="); @@ -1459,6 +1460,10 @@ let needSetup = false; if (testMode) { startUnitTest(); } + + if (e2eTestMode) { + startE2eTests(); + } }); initBackgroundJobs(args); diff --git a/server/util-server.js b/server/util-server.js index ec68c2f3..fd95a744 100644 --- a/server/util-server.js +++ b/server/util-server.js @@ -508,6 +508,25 @@ exports.startUnitTest = async () => { }); }; +exports.startE2eTests = async () => { + console.log("Starting unit test..."); + const npm = /^win/.test(process.platform) ? "npm.cmd" : "npm"; + const child = childProcess.spawn(npm, [ "run", "cy:run" ]); + + child.stdout.on("data", (data) => { + console.log(data.toString()); + }); + + child.stderr.on("data", (data) => { + console.log(data.toString()); + }); + + child.on("close", function (code) { + console.log("Jest exit code: " + code); + process.exit(code); + }); +}; + /** * Convert unknown string to UTF8 * @param {Uint8Array} body Buffer