Skip to content

Commit ae67feb

Browse files
committed
ci: add smoke test for worker idle timeout
1 parent 423e8ed commit ae67feb

6 files changed

Lines changed: 122 additions & 10 deletions

File tree

e2e/assertions/index.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { MatcherContext } from 'expect'
2-
import type { TreeItem } from 'wdio-vscode-service'
2+
import type { TreeItem, Workbench } from 'wdio-vscode-service'
33
import type { STATUS } from '../helpers/index.ts'
44

55
export interface ExpectedTreeItem {
@@ -92,6 +92,18 @@ try {
9292
async toMatchTreeStructure(tree: TreeItem[], expectedStructure: ExpectedTreeItem[]) {
9393
return await expectTreeToMatchStructure.call(this as unknown as MatcherContext, tree, expectedStructure)
9494
},
95+
async hasExpectedLog(workbench: Workbench, expectedLog: RegExp | string) {
96+
const bottomBar = workbench.getBottomBar()
97+
const outputView = await bottomBar.openOutputView()
98+
await outputView.selectChannel('WebdriverIO')
99+
const logs = await outputView.getText()
100+
101+
const regexp = typeof expectedLog === 'string' ? new RegExp(expectedLog) : expectedLog
102+
103+
const pass = logs.some((log) => regexp.test(log))
104+
const message = pass ? 'The log outputs include expected text.' : 'The expected text is not included'
105+
return { pass, message }
106+
},
95107
})
96108
}
97109
} catch (error) {

e2e/assertions/wdio.shim.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ declare global {
44
namespace ExpectWebdriverIO {
55
interface Matchers<R, T> {
66
toMatchTreeStructure(expectedStructure: ExpectedTreeItem[]): R
7+
hasExpectedLog(expectedLog: RegExp | string): R
78
}
89
}
910
}

e2e/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
"test:e2e:basic:cucumber": "cross-env VSCODE_WDIO_E2E_SCENARIO=cucumber xvfb-maybe pnpm run wdio",
1818
"test:e2e:workspace": "cross-env VSCODE_WDIO_E2E_SCENARIO=workspace xvfb-maybe pnpm run wdio",
1919
"test:smoke": "run-s test:smoke:*",
20-
"test:smoke:update-config": "xvfb-maybe wdio run ./wdioSmoke.conf.ts",
20+
"test:smoke:update-config": "cross-env VSCODE_WDIO_E2E_SCENARIO=config xvfb-maybe wdio run ./wdioSmoke.conf.ts",
21+
"test:smoke:timeout": "cross-env VSCODE_WDIO_E2E_SCENARIO=timeout xvfb-maybe wdio run ./wdioSmoke.conf.ts",
2122
"wdio": "wdio run ./wdio.conf.ts"
2223
},
2324
"devDependencies": {
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import { browser, expect } from '@wdio/globals'
2+
3+
import { createCucumberExpected } from '../helpers/cucumber.ts'
4+
import {
5+
STATUS,
6+
clearAllTestResults,
7+
clickTitleActionButton,
8+
collapseAllTests,
9+
getTestingSection,
10+
openTestingView,
11+
waitForResolved,
12+
waitForTestStatus,
13+
} from '../helpers/index.ts'
14+
15+
import type { SideBarView, ViewControl, Workbench } from 'wdio-vscode-service'
16+
17+
const targetFramework = process.env.VSCODE_WDIO_E2E_SCENARIO || 'mocha'
18+
19+
const expected = createCucumberExpected()
20+
21+
describe(`VS Code Extension Testing with ${targetFramework}`, function () {
22+
this.retries(3)
23+
let workbench: Workbench
24+
let testingViewControl: ViewControl
25+
let sideBarView: SideBarView<any>
26+
27+
beforeEach(async function () {
28+
workbench = await browser.getWorkbench()
29+
testingViewControl = await openTestingView(workbench)
30+
sideBarView = workbench.getSideBar()
31+
32+
const testingSection = await getTestingSection(sideBarView.getContent())
33+
await collapseAllTests(testingSection)
34+
35+
await browser.waitUntil(async () => (await testingSection.getVisibleItems()).length === 1)
36+
})
37+
38+
afterEach(async function () {
39+
await clearAllTestResults(workbench)
40+
})
41+
42+
it('should be displayed the testing screen at the sideBar', async function () {
43+
expect(await testingViewControl.getTitle()).toBe('Testing')
44+
expect(await sideBarView.getTitlePart().getTitle()).toBe('TESTING')
45+
})
46+
47+
it('should resolve defined tests correctly', async function () {
48+
const testingSection = await getTestingSection(sideBarView.getContent())
49+
const items = await testingSection.getVisibleItems()
50+
51+
await waitForResolved(browser, items[0])
52+
53+
await expect(items).toMatchTreeStructure(expected.notRun)
54+
})
55+
56+
it('should shutdown the work process after idle timeout was reached', async function () {
57+
await new Promise((resolve) => setTimeout(resolve, 2000))
58+
59+
await expect(workbench).hasExpectedLog(/Worker#0 process shutdown gracefully/)
60+
61+
const bottomBar = workbench.getBottomBar()
62+
const outputView = await bottomBar.openOutputView()
63+
await outputView.selectChannel('WebdriverIO')
64+
await outputView.clearText()
65+
})
66+
67+
it('should start work process and run test successfully', async function () {
68+
const testingSection = await getTestingSection(sideBarView.getContent())
69+
const items = await testingSection.getVisibleItems()
70+
71+
await waitForResolved(browser, items[0])
72+
73+
await clickTitleActionButton(sideBarView.getTitlePart(), 'Run Tests')
74+
75+
await waitForTestStatus(browser, items[0], STATUS.PASSED)
76+
77+
// assert that start work process
78+
await expect(workbench).hasExpectedLog(/\[#1\] Worker process started successfully/)
79+
80+
// assert that run test successfully
81+
await expect(items).toMatchTreeStructure(expected.runAll)
82+
})
83+
})

e2e/wdioSmoke.conf.ts

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,29 @@
11
import { createBaseConfig } from './wdio.conf.ts'
22

3-
const specs = [
4-
'./tests/updateConfig.spec.ts',
5-
'./tests/updateSpec.spec.ts',
6-
'./tests/updateErrorSpec.spec.ts',
7-
'./tests/updateErrorConfig.spec.ts',
8-
]
3+
type TestTargets = 'config' | 'timeout'
4+
5+
const target = (process.env.VSCODE_WDIO_E2E_SCENARIO || 'config') as TestTargets
6+
7+
const workspace = target === 'config' ? '../samples/smoke/update-config' : '../samples/e2e/cucumber'
8+
9+
function defineSpecs(target: TestTargets) {
10+
switch (target) {
11+
case 'config':
12+
return [
13+
'./tests/updateConfig.spec.ts',
14+
'./tests/updateSpec.spec.ts',
15+
'./tests/updateErrorSpec.spec.ts',
16+
'./tests/updateErrorConfig.spec.ts',
17+
]
18+
default:
19+
return ['./tests/workerIdleTimeout.spec.ts']
20+
}
21+
}
22+
23+
const specs = defineSpecs(target)
924

1025
export const config: WebdriverIO.Config = {
11-
...createBaseConfig('../samples/smoke/update-config'),
26+
...createBaseConfig(workspace, { 'webdriverio.logLevel': 'debug', 'webdriverio.workerIdleTimeout': 2 }),
1227
specs,
1328
maxInstances: 1,
1429
}

packages/vscode-wdio-server/src/worker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ export class WdioExtensionWorker extends TypedEventEmitter<WdioExtensionWorkerEv
206206
// Start idle monitoring after successful connection
207207
this.idleMonitor.start()
208208
this.startHealthCheck()
209-
log.debug('Worker process started successfully')
209+
log.debug(`[${this.cid}] Worker process started successfully`)
210210
})
211211
}
212212

0 commit comments

Comments
 (0)