Skip to content

Commit 0888bc2

Browse files
authored
fix: Improve node ID check robustness & WebdriverIO test CI stability (#745)
RaspberryPiFoundation/blockly#9384 revealed that one of the Block comment tests was a bit fragile in directly validating a specific node ID. Since node IDs can change if new elements on the page require a generated ID, the test could easily fail with changes to core Blockly. This PR fixes the issue by using a regex check instead of a direct ID match. The 'comment_textarea' part is _probably_ sufficiently unique for the test to be considered correct (though it is possible for the wrong comment to be focused here, but it seems really unlikely with how simple the test is being set up and, if that actually happened, it's sort of incidentally still correct as there would be _some_ comment that has focus). This PR also includes a number of attempts to improve test stability (particularly in CI): - It introduces a CI-specific command that adds a 30 second Mocha test timeout to provide a lot more time for tests to fail (since CI tends to run on less performant machines than used for development). - It introduces a synchronization between the Mocha timeout and the timeout used for WebdriverIO's `waitFor*` functions. Note that this actually will usually be 60 seconds regardless of the configured Mocha timeout due to the way the hook is set up. However, this is still far better than the 5 second default as at least 1 test seemed to fairly regularly fail against that limit. - It adds a few missing 'wait' calls for helpers that are performing side effects which ensures better synchronization when using `PAUSE_TIME` (and possibly better stability when running in CI, too, though it's unclear of `pause()` actually does anything when the provided timeout is 0). - See #745 (comment) attempts to further stabilize OS X tests only to yield that there are actual test failures. This will be merged into the screen reader experimental branch to unblock the core Blockly PR as well. #746 has been filed to track the discovered test failures.
1 parent 30c5286 commit 0888bc2

20 files changed

+81
-36
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ jobs:
6363
- name: Run tests
6464
run: |
6565
cd main
66-
npm run test
66+
npm run test:ci
6767
6868
webdriverio_tests:
6969
name: WebdriverIO tests (against pinned v12)
@@ -90,4 +90,4 @@ jobs:
9090
run: npm install
9191

9292
- name: Run tests
93-
run: npm run test
93+
run: npm run test:ci

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,16 @@
1515
"prepublishOnly": "npm login --registry https://wombat-dressing-room.appspot.com",
1616
"start": "blockly-scripts start",
1717
"test": "npm run test:mocha && npm run test:wdio",
18+
"test:ci": "npm run test:mocha && npm run test:wdio:ci",
1819
"test:mocha": "blockly-scripts test",
1920
"test:wdio": "npm run wdio:clean && npm run wdio:run",
21+
"test:wdio:ci": "npm run wdio:clean && npm run wdio:run:ci",
2022
"wdio:build": "npm run wdio:build:app && npm run wdio:build:tests",
2123
"wdio:build:app": "cd test/webdriverio && webpack",
2224
"wdio:build:tests": "tsc -p ./test/webdriverio/test/tsconfig.json",
2325
"wdio:clean": "cd test/webdriverio/test && rm -rf dist",
24-
"wdio:run": "npm run wdio:build && cd test/webdriverio/test && npx mocha dist"
26+
"wdio:run": "npm run wdio:build && cd test/webdriverio/test && npx mocha dist",
27+
"wdio:run:ci": "npm run wdio:build && cd test/webdriverio/test && npx mocha --timeout 30000 dist"
2528
},
2629
"main": "./dist/index.js",
2730
"module": "./src/index.js",

test/webdriverio/test/actions_test.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,10 @@ suite('Menus test', function () {
9292

9393
// Clear the workspace and load start blocks.
9494
setup(async function () {
95-
// This is the first test suite, which must wait for Chrome +
96-
// chromedriver to start up, which can be slow—perhaps a few
97-
// seconds. Allow 30s just in case.
98-
this.timeout(30000);
99-
100-
this.browser = await testSetup(testFileLocations.MORE_BLOCKS);
95+
this.browser = await testSetup(
96+
testFileLocations.MORE_BLOCKS,
97+
this.timeout(),
98+
);
10199
await this.browser.pause(PAUSE_TIME);
102100
});
103101

test/webdriverio/test/basic_test.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ suite('Keyboard navigation on Blocks', function () {
3131

3232
// Clear the workspace and load start blocks.
3333
suiteSetup(async function () {
34-
this.browser = await testSetup(testFileLocations.NAVIGATION_TEST_BLOCKS);
34+
this.browser = await testSetup(
35+
testFileLocations.NAVIGATION_TEST_BLOCKS,
36+
this.timeout(),
37+
);
3538
});
3639

3740
test('Default workspace', async function () {
@@ -226,7 +229,10 @@ suite('Keyboard navigation on Fields', function () {
226229

227230
// Clear the workspace and load start blocks.
228231
suiteSetup(async function () {
229-
this.browser = await testSetup(testFileLocations.NAVIGATION_TEST_BLOCKS);
232+
this.browser = await testSetup(
233+
testFileLocations.NAVIGATION_TEST_BLOCKS,
234+
this.timeout(),
235+
);
230236
});
231237

232238
test('Up from first field selects block', async function () {

test/webdriverio/test/block_comment_test.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ suite('Block comment navigation', function () {
2323

2424
// Clear the workspace and load start blocks.
2525
setup(async function () {
26-
this.browser = await testSetup(testFileLocations.NAVIGATION_TEST_BLOCKS);
26+
this.browser = await testSetup(
27+
testFileLocations.NAVIGATION_TEST_BLOCKS,
28+
this.timeout(),
29+
);
2730
await this.browser.execute(() => {
2831
Blockly.getMainWorkspace()
2932
.getBlockById('p5_canvas_1')
@@ -36,7 +39,8 @@ suite('Block comment navigation', function () {
3639
await keyRight(this.browser);
3740
await sendKeyAndWait(this.browser, Key.Enter);
3841
const focusedNodeId = await getCurrentFocusNodeId(this.browser);
39-
chai.assert.equal(focusedNodeId, 'blockly-2s_comment_textarea_');
42+
chai.assert.isDefined(focusedNodeId);
43+
chai.assert.match(focusedNodeId, /blockly-\w+_comment_textarea_/);
4044
});
4145

4246
test('Escape from a focused comment focuses its bubble', async function () {

test/webdriverio/test/clipboard_test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ suite('Clipboard test', function () {
2727

2828
// Clear the workspace and load start blocks.
2929
setup(async function () {
30-
this.browser = await testSetup(testFileLocations.BASE);
30+
this.browser = await testSetup(testFileLocations.BASE, this.timeout());
3131
await this.browser.pause(PAUSE_TIME);
3232
});
3333

test/webdriverio/test/delete_test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ suite('Deleting Blocks', function () {
2727

2828
// Clear the workspace and load start blocks.
2929
setup(async function () {
30-
this.browser = await testSetup(testFileLocations.NAVIGATION_TEST_BLOCKS);
30+
this.browser = await testSetup(
31+
testFileLocations.NAVIGATION_TEST_BLOCKS,
32+
this.timeout(),
33+
);
3134
await this.browser.pause(PAUSE_TIME);
3235
});
3336

test/webdriverio/test/duplicate_test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ suite('Duplicate test', function () {
2323

2424
// Clear the workspace and load start blocks.
2525
setup(async function () {
26-
this.browser = await testSetup(testFileLocations.BASE);
26+
this.browser = await testSetup(testFileLocations.BASE, this.timeout());
2727
await this.browser.pause(PAUSE_TIME);
2828
});
2929

test/webdriverio/test/flyout_test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ suite('Toolbox and flyout test', function () {
2828

2929
// Clear the workspace and load start blocks.
3030
setup(async function () {
31-
this.browser = await testSetup(testFileLocations.BASE);
31+
this.browser = await testSetup(testFileLocations.BASE, this.timeout());
3232
await this.browser.pause(PAUSE_TIME);
3333
});
3434

test/webdriverio/test/hooks.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export const mochaHooks: RootHookObject = {
1616
async beforeAll(this: Mocha.Context) {
1717
// Set a long timeout for startup.
1818
this.timeout(60000);
19-
return await driverSetup();
19+
return await driverSetup(this.timeout());
2020
},
2121
async afterAll() {
2222
return await driverTeardown();

0 commit comments

Comments
 (0)