From 7f4d5a0f7682276a690add6b375f8d5ec4e2c0c8 Mon Sep 17 00:00:00 2001 From: Nelson Chan Date: Tue, 16 Nov 2021 11:35:04 +0800 Subject: [PATCH] Test: fix tests Test: Attempt to fix tests Test: Attempt to fix tests Test: Attempt to fix tests Test: Attempt to fix tests Test: Attempt to fix tests Test: Attempt to fix tests Test: Attempt to fix tests Test: Attempt to fix tests Test: Attempt to fix tests Test: Attempt to fix tests Test: Attempt to fix tests Test: Attempt to fix tests Test: Attempt to fix tests Test: Attempt to fix tests Test: Investigate error message Test: Attempt to fix tests Chore: Cleanup code Test: Attempt to fix tests Test: Attempt to fix tests --- config/jest-debug-env.js | 33 +++++++++++++++++++++++++++++++++ config/jest-puppeteer.config.js | 12 ++++++++++-- config/jest.config.js | 1 + server/server.js | 2 +- test/e2e.spec.js | 6 ++++++ 5 files changed, 51 insertions(+), 3 deletions(-) create mode 100644 config/jest-debug-env.js diff --git a/config/jest-debug-env.js b/config/jest-debug-env.js new file mode 100644 index 00000000..74f6d783 --- /dev/null +++ b/config/jest-debug-env.js @@ -0,0 +1,33 @@ +const PuppeteerEnvironment = require("jest-environment-puppeteer"); +const util = require("util"); + +class DebugEnv extends PuppeteerEnvironment { + async handleTestEvent(event, state) { + const ignoredEvents = [ + "setup", + "add_hook", + "start_describe_definition", + "add_test", + "finish_describe_definition", + "run_start", + "run_describe_start", + "test_start", + "hook_start", + "hook_success", + "test_fn_start", + "test_fn_success", + "test_done", + "run_describe_finish", + "run_finish", + "teardown", + "test_fn_failure", + ]; + if (!ignoredEvents.includes(event.name)) { + console.log( + new Date().toString() + ` Unhandled event [${event.name}] ` + util.inspect(event) + ); + } + } +} + +module.exports = DebugEnv; diff --git a/config/jest-puppeteer.config.js b/config/jest-puppeteer.config.js index a34937c1..dc4f7b34 100644 --- a/config/jest-puppeteer.config.js +++ b/config/jest-puppeteer.config.js @@ -1,12 +1,20 @@ module.exports = { "launch": { + "dumpio": true, + "slowMo": 500, "headless": process.env.HEADLESS_TEST || false, "userDataDir": "./data/test-chrome-profile", args: [ - "--no-sandbox", "--disable-setuid-sandbox", "--disable-gpu", - "--disable-dev-shm-usage" + "--disable-dev-shm-usage", + "--no-default-browser-check", + "--no-experiments", + "--no-first-run", + "--no-pings", + "--no-sandbox", + "--no-zygote", + "--single-process", ], } }; diff --git a/config/jest.config.js b/config/jest.config.js index 4baaa0fb..2d3f585e 100644 --- a/config/jest.config.js +++ b/config/jest.config.js @@ -5,6 +5,7 @@ module.exports = { "__DEV__": true }, "testRegex": "./test/e2e.spec.js", + "testEnvironment": "./config/jest-debug-env.js", "rootDir": "..", "testTimeout": 30000, }; diff --git a/server/server.js b/server/server.js index 709a54c9..eea61dc7 100644 --- a/server/server.js +++ b/server/server.js @@ -541,8 +541,8 @@ exports.entryPage = "dashboard"; await updateMonitorNotification(bean.id, notificationIDList); - await startMonitor(socket.userID, bean.id); await sendMonitorList(socket); + await startMonitor(socket.userID, bean.id); callback({ ok: true, diff --git a/test/e2e.spec.js b/test/e2e.spec.js index 488179e1..d96e88c5 100644 --- a/test/e2e.spec.js +++ b/test/e2e.spec.js @@ -74,6 +74,12 @@ describe("Init", () => { await page.click("#url", { clickCount: 3 }); await page.keyboard.type(baseURL); await page.keyboard.press("Enter"); + + await page.waitForFunction(() => { + const badge = document.querySelector("span.badge"); + return badge && badge.innerText == "100%"; + }, { timeout: 5000 }); + }); // Settings Page