diff --git a/scripts/test.build.js b/scripts/test.build.js index a3a4f229..7ffe1e8a 100644 --- a/scripts/test.build.js +++ b/scripts/test.build.js @@ -30,6 +30,11 @@ const contextPatch = [ command: "Nocalhost.applyKubernetesObject", when: "viewItem =~ /^application-(.*)-installed/i", }, + { + command: "Nocalhost.reset", + when: + "viewItem =~ /^workload-(deployment|statefulSet|job|daemonSet|cronjob|pod|crd-resources)-dev-(?!vpn_)/i", + }, ]; packageJson.contributes.menus["view/item/context"].forEach((context) => { if ( diff --git a/test/extension/index.js b/test/extension/index.js index 82662b66..ad4a72dc 100644 --- a/test/extension/index.js +++ b/test/extension/index.js @@ -133,12 +133,6 @@ const getUserDataDir = async () => { } await fse.copy(path.join(__dirname, "./config/vscode"), userDataDir); - - // copy test config file - await fse.copy( - path.join(__dirname, "./config/yaml"), - path.join(os.tmpdir(), "./config/yaml") - ); return userDataDir; }; diff --git a/test/extension/integration/applyManifest.js b/test/extension/integration/applyManifest.js index a1ae7608..4985bcf6 100644 --- a/test/extension/integration/applyManifest.js +++ b/test/extension/integration/applyManifest.js @@ -11,7 +11,7 @@ const applyDeployment = async () => { ".action-label[title='Apply New Manifest']" ); await applyNode.click(); - await file.selectPath(path.join(os.tmpdir(), "./config/yaml")); + await file.selectPath(path.join(__dirname, "../config/yaml")); return waitForMessage("Resource(Deployment) php created", 60 * 1000); }; diff --git a/test/extension/integration/index.spec.js b/test/extension/integration/index.spec.js index ee626fdf..44c1ec4a 100644 --- a/test/extension/integration/index.spec.js +++ b/test/extension/integration/index.spec.js @@ -10,6 +10,8 @@ const { viewLogTests } = require("./viewLog.test"); const { editConfigTests } = require("./editConfig.test"); const { remoteRunTests } = require("./remoteRun.test"); const { applyManifestTests } = require("./applyManifest.test"); +const { resetPodTests } = require("./resetPod.test"); +let fpsArr = []; const screenshotPath = path.join(__dirname, "../../../.screenshot"); @@ -33,6 +35,43 @@ afterEach(async () => { }); }); +beforeAll(async () => { + await page.tracing.start({ + path: `${screenshotPath}/.trace.json`, + screenshots: true, + screenshotPath: screenshotPath, + }); + + // calc fps + await page.evaluate(async () => { + let lastTime = (window.performance || window.Date).now(); + let fpsCount = 0; + let fps = 0; + let arr = []; + const fpsInterval = 30; + + const getFps = () => { + fpsCount++; + const timeNow = (window.performance || window.Date).now(); + if (fpsCount >= fpsInterval) { + fps = Math.round((1000 * fpsCount) / (timeNow - lastTime)); + lastTime = timeNow; + fpsCount = 0; + // const memory = window.performance.memory; + arr.push({ fps }); + } + }; + + const start = () => { + getFps(); + window.__data = JSON.stringify(arr); + window.requestAnimationFrame(start); + }; + + start(); + }); +}); + describe("nhctl", nhctlTests); describe("connect", connectTests); describe("install", installTests); @@ -43,6 +82,22 @@ describe("editConfig", editConfigTests); // remote run after edit config hotreload describe("remoteRun", remoteRunTests); describe("applyManifest", applyManifestTests); +describe("resetPod", resetPodTests); + +afterAll(async () => { + const fps = await page.evaluate(() => { + return window.__data; + }); + logger.info(`fps: ${fps}`); + await (() => { + return new Promise((resolve) => { + setTimeout(() => { + resolve(); + }, 2000); + }); + })(); + await page.tracing.stop(); +}); module.exports = { screenshotPath, diff --git a/test/extension/integration/portForward.js b/test/extension/integration/portForward.js index 9748e0b9..f519259b 100644 --- a/test/extension/integration/portForward.js +++ b/test/extension/integration/portForward.js @@ -39,7 +39,6 @@ async function checkReady() { async function add() { const treeItem = await tree.getItem(...treeItemPath); - const portForward = await treeItem.$(".action-label[title='Port Forward']"); await portForward.click(); diff --git a/test/extension/integration/resetPod.js b/test/extension/integration/resetPod.js new file mode 100644 index 00000000..fe36e55b --- /dev/null +++ b/test/extension/integration/resetPod.js @@ -0,0 +1,43 @@ +const { performance, PerformanceObserver } = require("perf_hooks"); +const { tree } = require("../lib/components"); +const { waitForMessage } = require("./index"); +const logger = require("../lib/log"); + +const treeItemPath = [ + "", + "default", + "bookinfo", + "Workloads", + "Deployments", + "ratings", +]; + +const resetPod = async () => { + // add performance mark + /* * / + const obs = new PerformanceObserver((items) => { + const entry = items.getEntries()[0]; + logger.info(entry.duration); + performance.clearMarks(); + obs.disconnect(); + }); + obs.observe({ entryTypes: ["measure"] }); + // performance.measure("Start to Now"); + performance.mark("tree-start-time"); + + performance.mark("tree-end-time"); + performance.measure("tree-time", { + start: "tree-start-time", + end: "tree-end-time", + }); + /** */ + const ratings = await tree.getItem(...treeItemPath); + const resetNode = await ratings.$(".action-label[title='Reset Pod']"); + + await resetNode.click(); + return waitForMessage("reset service ratings", 60 * 1000); +}; + +module.exports = { + resetPod, +}; diff --git a/test/extension/integration/resetPod.test.js b/test/extension/integration/resetPod.test.js new file mode 100644 index 00000000..6b511d5e --- /dev/null +++ b/test/extension/integration/resetPod.test.js @@ -0,0 +1,14 @@ +const { checkReady } = require("./portForward"); +const { resetPod } = require("./resetPod"); + +const resetPodTests = () => { + beforeAll(async (done) => { + checkReady().then(done).catch(done.fail); + }); + + it("reset pod", resetPod); +}; + +module.exports = { + resetPodTests, +}; diff --git a/test/extension/lib/components/file.js b/test/extension/lib/components/file.js index 95406f24..275532e9 100644 --- a/test/extension/lib/components/file.js +++ b/test/extension/lib/components/file.js @@ -13,7 +13,7 @@ async function selectPath(path) { await input.type(" "); await page.keyboard.press("Backspace"); - await page.waitForTimeout(1_00); + await page.waitForTimeout(1_000); const action = await page.waitForSelector( ".quick-input-widget .quick-input-action a"