Skip to content

Commit 7a50671

Browse files
authored
test: add smoke test for updating spec files (#42)
## Proposed changes Add the smoke test for updating spec files. ## Types of changes [//]: # 'What types of changes does your code introduce to WebdriverIO?' [//]: # '_Put an `x` in the boxes that apply_' - [ ] Polish (an improvement for an existing feature) - [ ] Bugfix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] Documentation update (improvements to the project's docs) - [X] Internal updates (everything related to internal scripts, governance documentation and CI files) ## Checklist [//]: # "_Put an `x` in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code._" - [X] I have read the [CONTRIBUTING](https://github.com/webdriverio/vscode-webdriverio/blob/main/CONTRIBUTION.md) doc - [X] I have added tests that prove my fix is effective or that my feature works - [ ] I have added the necessary documentation (if appropriate) - [ ] I have added proper type definitions for new commands (if appropriate) ## Further comments [//]: # 'If this is a relatively large or complex change, kick off the discussion by explaining why you chose the solution you did and what alternatives you considered, etc...' ### Reviewers: @webdriverio/project-committers
1 parent 87ba6ac commit 7a50671

15 files changed

Lines changed: 250 additions & 57 deletions

File tree

.github/workflows/update.yaml

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -8,41 +8,41 @@ on: pull_request_target
88

99
# Dependabot PRs' tokens have read permissions by default and thus we must enable write permissions.
1010
permissions:
11-
checks: read
12-
contents: write
13-
pull-requests: write
11+
checks: read
12+
contents: write
13+
pull-requests: write
1414

1515
jobs:
16-
dependencies:
17-
runs-on: ubuntu-latest
18-
if: github.event.pull_request.user.login == 'dependabot[bot]'
16+
dependencies:
17+
runs-on: ubuntu-latest
18+
if: github.event.pull_request.user.login == 'dependabot[bot]'
1919

20-
steps:
21-
- name: Fetch PR metadata
22-
id: metadata
23-
uses: dependabot/[email protected]
24-
with:
25-
github-token: ${{ secrets.GITHUB_TOKEN }}
20+
steps:
21+
- name: Fetch PR metadata
22+
id: metadata
23+
uses: dependabot/[email protected]
24+
with:
25+
github-token: ${{ secrets.GITHUB_TOKEN }}
2626

27-
- name: Wait for PR CI
28-
# Don't merge updates to GitHub Actions versions automatically.
29-
# (Some repos may wish to limit by version range (major/minor/patch), or scope (dep vs dev-dep), too.)
30-
if: contains(steps.metadata.outputs.package-ecosystem, 'npm')
31-
uses: lewagon/[email protected]
32-
with:
33-
ref: ${{ github.event.pull_request.head.sha }}
34-
repo-token: ${{ secrets.GITHUB_TOKEN }}
35-
wait-interval: 30 # seconds
36-
running-workflow-name: dependencies # wait for all checks except this one
37-
allowed-conclusions: success,skipped,cancelled # all other checks must pass, being skipped or cancelled is not sufficient
27+
- name: Wait for PR CI
28+
# Don't merge updates to GitHub Actions versions automatically.
29+
# (Some repos may wish to limit by version range (major/minor/patch), or scope (dep vs dev-dep), too.)
30+
if: contains(steps.metadata.outputs.package-ecosystem, 'npm')
31+
uses: lewagon/[email protected]
32+
with:
33+
ref: ${{ github.event.pull_request.head.sha }}
34+
repo-token: ${{ secrets.GITHUB_TOKEN }}
35+
wait-interval: 30 # seconds
36+
running-workflow-name: dependencies # wait for all checks except this one
37+
allowed-conclusions: success,skipped,cancelled # all other checks must pass, being skipped or cancelled is not sufficient
3838

39-
- name: Auto-merge dependabot PRs
40-
# Don't merge updates to GitHub Actions versions automatically.
41-
# (Some repos may wish to limit by version range (major/minor/patch), or scope (dep vs dev-dep), too.)
42-
if: contains(steps.metadata.outputs.package-ecosystem, 'npm')
43-
env:
44-
PR_URL: ${{ github.event.pull_request.html_url }}
45-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
46-
# The "auto" flag will only merge once all of the target branch's required checks
47-
# are met. Configure those in the "branch protection" settings for each repo.
48-
run: gh pr merge --auto --squash "$PR_URL"
39+
- name: Auto-merge dependabot PRs
40+
# Don't merge updates to GitHub Actions versions automatically.
41+
# (Some repos may wish to limit by version range (major/minor/patch), or scope (dep vs dev-dep), too.)
42+
if: contains(steps.metadata.outputs.package-ecosystem, 'npm')
43+
env:
44+
PR_URL: ${{ github.event.pull_request.html_url }}
45+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
46+
# The "auto" flag will only merge once all of the target branch's required checks
47+
# are met. Configure those in the "branch protection" settings for each repo.
48+
run: gh pr merge --auto --squash "$PR_URL"

e2e/tests/basic.spec.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ describe(`VS Code Extension Testing with ${targetFramework}`, function () {
2020
let testingViewControl: ViewControl
2121
let sideBarView: SideBarView<any>
2222

23-
beforeEach(async () => {
23+
beforeEach(async function () {
2424
workbench = await browser.getWorkbench()
2525
testingViewControl = await openTestingView(workbench)
2626
sideBarView = workbench.getSideBar()
@@ -35,16 +35,16 @@ describe(`VS Code Extension Testing with ${targetFramework}`, function () {
3535
await browser.waitUntil(async () => (await testingSection.getVisibleItems()).length === 1)
3636
})
3737

38-
afterEach(async () => {
38+
afterEach(async function () {
3939
await clearAllTestResults(workbench)
4040
})
4141

42-
it('should be displayed the testing screen at the sideBar', async () => {
42+
it('should be displayed the testing screen at the sideBar', async function () {
4343
expect(await testingViewControl.getTitle()).toBe('Testing')
4444
expect(await sideBarView.getTitlePart().getTitle()).toBe('TESTING')
4545
})
4646

47-
it('should resolve defined tests correctly', async () => {
47+
it('should resolve defined tests correctly', async function () {
4848
const testingSection = await getTestingSection(sideBarView.getContent())
4949
const items = await testingSection.getVisibleItems()
5050

@@ -79,7 +79,7 @@ describe(`VS Code Extension Testing with ${targetFramework}`, function () {
7979
])
8080
})
8181

82-
it('should run at top Level', async () => {
82+
it('should run at top Level', async function () {
8383
const testingSection = await getTestingSection(sideBarView.getContent())
8484
const items = await testingSection.getVisibleItems()
8585

@@ -118,7 +118,7 @@ describe(`VS Code Extension Testing with ${targetFramework}`, function () {
118118
])
119119
})
120120

121-
it('should run at not top Level', async () => {
121+
it('should run at not top Level', async function () {
122122
const testingSection = await getTestingSection(sideBarView.getContent())
123123
const items = await testingSection.getVisibleItems()
124124

e2e/tests/basicCucumber.spec.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ describe(`VS Code Extension Testing with ${targetFramework}`, function () {
2020
let testingViewControl: ViewControl
2121
let sideBarView: SideBarView<any>
2222

23-
beforeEach(async () => {
23+
beforeEach(async function () {
2424
workbench = await browser.getWorkbench()
2525
testingViewControl = await openTestingView(workbench)
2626
sideBarView = workbench.getSideBar()
@@ -35,16 +35,16 @@ describe(`VS Code Extension Testing with ${targetFramework}`, function () {
3535
await browser.waitUntil(async () => (await testingSection.getVisibleItems()).length === 1)
3636
})
3737

38-
afterEach(async () => {
38+
afterEach(async function () {
3939
await clearAllTestResults(workbench)
4040
})
4141

42-
it('should be displayed the testing screen at the sideBar', async () => {
42+
it('should be displayed the testing screen at the sideBar', async function () {
4343
expect(await testingViewControl.getTitle()).toBe('Testing')
4444
expect(await sideBarView.getTitlePart().getTitle()).toBe('TESTING')
4545
})
4646

47-
it('should resolve defined tests correctly', async () => {
47+
it('should resolve defined tests correctly', async function () {
4848
const testingSection = await getTestingSection(sideBarView.getContent())
4949
const items = await testingSection.getVisibleItems()
5050

@@ -130,7 +130,7 @@ describe(`VS Code Extension Testing with ${targetFramework}`, function () {
130130
])
131131
})
132132

133-
it('should run at top Level', async () => {
133+
it('should run at top Level', async function () {
134134
const testingSection = await getTestingSection(sideBarView.getContent())
135135
const items = await testingSection.getVisibleItems()
136136

@@ -220,7 +220,7 @@ describe(`VS Code Extension Testing with ${targetFramework}`, function () {
220220
])
221221
})
222222

223-
it('should run Scenario level even if select step level test', async () => {
223+
it('should run Scenario level even if select step level test', async function () {
224224
const testingSection = await getTestingSection(sideBarView.getContent())
225225
const items = await testingSection.getVisibleItems()
226226

e2e/tests/updateConfig.spec.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// /Users/abetaiki/Documents/50_workspace/30_js/wdio-vscode/samples/smoke/mocha/wdio.conf.ts.tmplate
21
import path from 'node:path'
32
import url from 'node:url'
43

@@ -27,7 +26,7 @@ describe('VS Code Extension Testing (Update config)', function () {
2726
let workbench: Workbench
2827
let sideBarView: SideBarView<any>
2928

30-
beforeEach(async () => {
29+
beforeEach(async function () {
3130
workbench = await browser.getWorkbench()
3231
await openTestingView(workbench)
3332
sideBarView = workbench.getSideBar()
@@ -42,14 +41,15 @@ describe('VS Code Extension Testing (Update config)', function () {
4241
await browser.waitUntil(async () => (await testingSection.getVisibleItems()).length === 1)
4342
})
4443

45-
afterEach(async () => {
44+
afterEach(async function () {
4645
await clearAllTestResults(workbench)
4746
})
48-
this.afterAll(() => {
47+
48+
after(function () {
4949
shell.exec(`git checkout ${beforeConfig}`)
5050
})
5151

52-
it('should be resolved the defined tests after configuration changed', async () => {
52+
it('should be resolved the defined tests after configuration changed', async function () {
5353
const testingSection = await getTestingSection(sideBarView.getContent())
5454
const items = await testingSection.getVisibleItems()
5555

@@ -118,7 +118,7 @@ describe('VS Code Extension Testing (Update config)', function () {
118118
])
119119
})
120120

121-
it('should run tests successfully after changing the configuration', async () => {
121+
it('should run tests successfully after changing the configuration', async function () {
122122
const testingSection = await getTestingSection(sideBarView.getContent())
123123
const items = await testingSection.getVisibleItems()
124124

e2e/tests/updateSpec.spec.ts

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
import path from 'node:path'
2+
import url from 'node:url'
3+
4+
import { browser, expect } from '@wdio/globals'
5+
import shell from 'shelljs'
6+
7+
import {
8+
STATUS,
9+
clearAllTestResults,
10+
clickTreeItemButton,
11+
getTestingSection,
12+
openTestingView,
13+
waitForResolved,
14+
waitForTestStatus,
15+
} from '../helpers.ts'
16+
17+
import type { SideBarView, Workbench } from 'wdio-vscode-service'
18+
19+
const __dirname = path.dirname(url.fileURLToPath(import.meta.url))
20+
const rootDir = path.resolve(__dirname, '..', '..')
21+
const workspacePath = path.resolve(rootDir, 'samples/smoke/update-config/')
22+
23+
const testsPath = path.join(workspacePath, 'tests')
24+
const spec = {
25+
before: path.resolve(testsPath, 'before.spec.ts'),
26+
after: path.resolve(testsPath, 'after.test.ts.template'),
27+
}
28+
29+
describe('VS Code Extension Testing (Update config)', function () {
30+
let workbench: Workbench
31+
let sideBarView: SideBarView<any>
32+
33+
beforeEach(async function () {
34+
workbench = await browser.getWorkbench()
35+
await openTestingView(workbench)
36+
sideBarView = workbench.getSideBar()
37+
38+
const testingSection = await getTestingSection(sideBarView.getContent())
39+
const items = (await testingSection.getVisibleItems()).reverse()
40+
for (const item of items) {
41+
if ((await item.isExpandable()) && (await item.isExpanded())) {
42+
await item.collapse()
43+
}
44+
}
45+
await browser.waitUntil(async () => (await testingSection.getVisibleItems()).length === 1)
46+
})
47+
48+
afterEach(async function () {
49+
await clearAllTestResults(workbench)
50+
})
51+
52+
after(function () {
53+
shell.exec(`git checkout ${spec.before}`)
54+
})
55+
56+
it('should be resolved the defined tests after spec file is changed', async function () {
57+
const testingSection = await getTestingSection(sideBarView.getContent())
58+
const items = await testingSection.getVisibleItems()
59+
60+
await waitForResolved(browser, items[0])
61+
62+
await expect(items).toMatchTreeStructure([
63+
{
64+
text: 'wdio.conf.ts',
65+
status: STATUS.NOT_YET_RUN,
66+
children: [
67+
{
68+
text: 'before.spec.ts',
69+
status: STATUS.NOT_YET_RUN,
70+
children: [
71+
{
72+
text: 'Before Tests',
73+
status: STATUS.NOT_YET_RUN,
74+
children: [{ text: 'TEST BEFORE 1', status: STATUS.NOT_YET_RUN }],
75+
},
76+
],
77+
},
78+
],
79+
},
80+
])
81+
82+
// Emulate the changing configuration
83+
shell.cp('-f', spec.after, spec.before)
84+
await new Promise((resolve) => setTimeout(resolve, 3000))
85+
await browser.waitUntil(
86+
async () => {
87+
if (!(await items[0].isExpanded())) {
88+
await items[0].expand()
89+
}
90+
91+
const children = await items[0].getChildren()
92+
const target = children[0]
93+
if (!target) {
94+
return false
95+
}
96+
const regex = new RegExp('before.spec.ts')
97+
return regex.test(await target.getLabel())
98+
},
99+
{
100+
timeoutMsg: 'The label "after.test.ts" is not found.',
101+
}
102+
)
103+
104+
await expect(items).toMatchTreeStructure([
105+
{
106+
text: 'wdio.conf.ts',
107+
status: STATUS.NOT_YET_RUN,
108+
children: [
109+
{
110+
text: 'before.spec.ts',
111+
status: STATUS.NOT_YET_RUN,
112+
children: [
113+
{
114+
text: 'Updated Tests',
115+
status: STATUS.NOT_YET_RUN,
116+
children: [{ text: 'TEST UPDATE AFTER 1', status: STATUS.NOT_YET_RUN }],
117+
},
118+
],
119+
},
120+
],
121+
},
122+
])
123+
})
124+
125+
it('should run tests successfully after changing the spec file', async function () {
126+
const testingSection = await getTestingSection(sideBarView.getContent())
127+
const items = await testingSection.getVisibleItems()
128+
129+
await waitForResolved(browser, items[0])
130+
131+
await clickTreeItemButton(browser, items[0], 'Run Test')
132+
133+
await waitForTestStatus(browser, items[0], STATUS.PASSED)
134+
135+
await expect(items).toMatchTreeStructure([
136+
{
137+
text: 'wdio.conf.ts',
138+
status: STATUS.PASSED,
139+
children: [
140+
{
141+
text: 'before.spec.ts',
142+
status: STATUS.PASSED,
143+
children: [
144+
{
145+
text: 'Updated Tests',
146+
status: STATUS.PASSED,
147+
children: [{ text: 'TEST UPDATE AFTER 1', status: STATUS.PASSED }],
148+
},
149+
],
150+
},
151+
],
152+
},
153+
])
154+
})
155+
})

e2e/wdioSmoke.conf.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { createBaseConfig } from './wdio.conf.ts'
22

3-
const specs = ['./tests/updateConfig.spec.ts']
3+
const specs = ['./tests/updateConfig.spec.ts', './tests/updateSpec.spec.ts']
44

55
export const config: WebdriverIO.Config = {
66
...createBaseConfig('../samples/smoke/update-config'),
77
specs,
8+
maxInstances: 1,
89
}

eslint.config.mjs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import vitest from '@vitest/eslint-plugin'
22
import wdioEslint from '@wdio/eslint'
33
import * as pluginImportX from 'eslint-plugin-import-x'
4+
import mochaPlugin from 'eslint-plugin-mocha'
45

56
export default wdioEslint.config([
67
{
@@ -76,4 +77,11 @@ export default wdioEslint.config([
7677
'vitest/padding-around-test-blocks': 'error',
7778
},
7879
},
80+
{
81+
/**
82+
* Eslint configuration for the mocha test files
83+
*/
84+
files: ['e2e/**/*.spec.ts'],
85+
...mochaPlugin.configs.recommended,
86+
},
7987
])

0 commit comments

Comments
 (0)