From 94ac119d0c4eb99d63da9337d1ae6dc044825d9e Mon Sep 17 00:00:00 2001 From: Danny Gleckler Date: Mon, 24 Jul 2023 12:48:22 -0400 Subject: [PATCH 1/4] Add fixture pausing with UI controls --- src/browser/fixture.js | 13 +++ src/server/headed-mode-plugin.js | 4 +- src/server/pause.js | 131 +++++++++++++++++++++++++++++++ 3 files changed, 147 insertions(+), 1 deletion(-) create mode 100644 src/server/pause.js diff --git a/src/browser/fixture.js b/src/browser/fixture.js index 4818e34f..b57f55c5 100644 --- a/src/browser/fixture.js +++ b/src/browser/fixture.js @@ -51,5 +51,18 @@ export async function fixture(element, opts = {}) { await Promise.all([reset(opts), document.fonts.ready]); const elem = await wcFixture(element); await waitForElem(elem, opts.awaitLoadingComplete); + + await pause(); return elem; } + +async function pause() { + const test = window.d2lTest || {}; + + test.update?.(); + + if (test.pause) { + await test.pause; + if (test.pause) test.pause = new Promise(r => test.run = r); + } +} diff --git a/src/server/headed-mode-plugin.js b/src/server/headed-mode-plugin.js index 35916cba..2a371d1d 100644 --- a/src/server/headed-mode-plugin.js +++ b/src/server/headed-mode-plugin.js @@ -1,3 +1,4 @@ +import { dirname, join } from 'node:path'; import { globSync } from 'glob'; export function headedMode({ open, watch, pattern }) { @@ -8,7 +9,8 @@ export function headedMode({ open, watch, pattern }) { name: 'brightspace-headed-mode', async transform(context) { if ((watch || open) && files.includes(context.path.slice(1))) { - return `debugger;\n${context.body}`; + const pausePath = join(dirname(import.meta.url), 'pause.js').replace('file:', ''); + return `debugger;\nimport '${pausePath}'\n${context.body}`; } } }; diff --git a/src/server/pause.js b/src/server/pause.js new file mode 100644 index 00000000..4d95e7f6 --- /dev/null +++ b/src/server/pause.js @@ -0,0 +1,131 @@ +const test = window.d2lTest = {}; +test.pause = new Promise(r => test.start = r); + +const controls = ` + +
+
+ .${window.__WTR_CONFIG__.testFile.split('?')[0]} + +
+ +
+`; + +document.body.insertAdjacentHTML('afterBegin', controls); + +const startBtn = document.querySelector('#start-button'); +startBtn.addEventListener('click', start); + +const runAllBtn = document.querySelector('#run-all-button'); +runAllBtn.addEventListener('click', runAll); + +const runBtn = document.querySelector('#run-button'); +runBtn.addEventListener('click', run); + +const testName = document.querySelector('#test-name'); + +beforeEach(async function() { // eslint-disable-line no-undef + const fixture = new Promise(r => test.update = r); + const currentTest = this.currentTest; // eslint-disable-line no-invalid-this + setTimeout(async() => { + await fixture; + testName.innerText = currentTest.fullTitle(); + if (test.pause) { + runBtn.disabled = false; + runBtn.focus(); + } + }); +}); + +function start() { + document.querySelector('#start').hidden = true; + document.querySelector('#run').hidden = false; + test.start(); +} + +function run() { + runBtn.disabled = true; + test.run(); +} + +function runAll() { + runAllBtn.disabled = true; + test.pause = null; + run(); +} + +await test.pause; +test.pause = new Promise(r => test.run = r); From 7bd0fbb0d1936e5ea277f25fd4e493a8b3efbb5e Mon Sep 17 00:00:00 2001 From: Danny Gleckler Date: Mon, 24 Jul 2023 13:04:28 -0400 Subject: [PATCH 2/4] Fix indentation --- src/server/pause.js | 160 ++++++++++++++++++++++---------------------- 1 file changed, 80 insertions(+), 80 deletions(-) diff --git a/src/server/pause.js b/src/server/pause.js index 4d95e7f6..36137821 100644 --- a/src/server/pause.js +++ b/src/server/pause.js @@ -2,86 +2,86 @@ const test = window.d2lTest = {}; test.pause = new Promise(r => test.start = r); const controls = ` - -
-
- .${window.__WTR_CONFIG__.testFile.split('?')[0]} - -
- -
+ +
+
+ .${window.__WTR_CONFIG__.testFile.split('?')[0]} + +
+ +
`; document.body.insertAdjacentHTML('afterBegin', controls); From fac5fe8a2224647f7178712e58ea20dcb685e8bd Mon Sep 17 00:00:00 2001 From: Danny Gleckler Date: Mon, 24 Jul 2023 15:27:25 -0400 Subject: [PATCH 3/4] Update src/server/pause.js Co-authored-by: Dave Lockhart --- src/server/pause.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/server/pause.js b/src/server/pause.js index 36137821..415be9b2 100644 --- a/src/server/pause.js +++ b/src/server/pause.js @@ -68,6 +68,7 @@ const controls = ` } #d2l-test-controls button[disabled] { + cursor: default; opacity: 0.5; } From 0ca2b02ab4e8fe440d616eb4c0f561f439d637d0 Mon Sep 17 00:00:00 2001 From: Danny Gleckler Date: Mon, 24 Jul 2023 15:41:31 -0400 Subject: [PATCH 4/4] Fix button styles --- src/server/pause.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/server/pause.js b/src/server/pause.js index 415be9b2..8a9f20fa 100644 --- a/src/server/pause.js +++ b/src/server/pause.js @@ -51,8 +51,9 @@ const controls = ` cursor: pointer; } - #d2l-test-controls button:focus { - background-color: #cdd5dc; + #d2l-test-controls button.primary { + color: #fff; + background-color: #006fbf; } #d2l-test-controls button:focus {