Skip to content

Commit 6a0e94c

Browse files
authored
fix: update error handling for loading wdio config file (#58)
## Proposed changes Fixed error handling when a configuration file is incomplete (e.g., has syntax errors). Fixed to delete the hierarchy under the subordinate SPEC file when the configuration file is changed to be incomplete, since it is not deleted. Added Smoke test for this case as well. ## 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) - [X] 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) - [ ] 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 15d1842 commit 6a0e94c

File tree

11 files changed

+463
-25
lines changed

11 files changed

+463
-25
lines changed

e2e/tests/updateConfig.spec.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,24 @@ describe('VS Code Extension Testing (Update config)', function () {
6868
},
6969
],
7070
},
71+
{
72+
text: 'sample.spec.ts',
73+
status: STATUS.NOT_YET_RUN,
74+
children: [
75+
{
76+
text: 'Sample 1',
77+
status: STATUS.NOT_YET_RUN,
78+
children: [{ text: 'TEST SAMPLE 1', status: STATUS.NOT_YET_RUN }],
79+
},
80+
],
81+
},
7182
],
7283
},
7384
])
7485

7586
// Emulate the changing configuration
7687
shell.cp('-f', afterConfig, beforeConfig)
77-
await new Promise((resolve) => setTimeout(resolve, 3000))
88+
await new Promise((resolve) => setTimeout(resolve, 1000))
7889
await browser.waitUntil(
7990
async () => {
8091
if (!(await items[0].isExpanded())) {
@@ -89,9 +100,7 @@ describe('VS Code Extension Testing (Update config)', function () {
89100
const regex = new RegExp('after.test.ts')
90101
return regex.test(await target.getLabel())
91102
},
92-
{
93-
timeoutMsg: 'The label "after.test.ts" is not found.',
94-
}
103+
{ timeoutMsg: 'The label "after.test.ts" is not found.' }
95104
)
96105

97106
await expect(items).toMatchTreeStructure([

e2e/tests/updateErrorConfig.spec.ts

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
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+
collapseAllTests,
12+
getTestingSection,
13+
openTestingView,
14+
waitForResolved,
15+
waitForTestStatus,
16+
} from '../helpers/index.ts'
17+
18+
import type { SideBarView, Workbench } from 'wdio-vscode-service'
19+
20+
const __dirname = path.dirname(url.fileURLToPath(import.meta.url))
21+
const rootDir = path.resolve(__dirname, '..', '..')
22+
const workspacePath = path.resolve(rootDir, 'samples/smoke/update-config/')
23+
const beforeConfig = path.resolve(workspacePath, 'wdio.conf.ts')
24+
const afterConfig = path.resolve(workspacePath, 'wdio-error.conf.ts.template')
25+
26+
describe('VS Code Extension Testing (Update config)', function () {
27+
let workbench: Workbench
28+
let sideBarView: SideBarView<any>
29+
30+
beforeEach(async function () {
31+
workbench = await browser.getWorkbench()
32+
await openTestingView(workbench)
33+
sideBarView = workbench.getSideBar()
34+
35+
const testingSection = await getTestingSection(sideBarView.getContent())
36+
await collapseAllTests(testingSection)
37+
38+
await browser.waitUntil(async () => (await testingSection.getVisibleItems()).length === 1)
39+
})
40+
41+
afterEach(async function () {
42+
await clearAllTestResults(workbench)
43+
})
44+
45+
after(function () {
46+
shell.exec(`git checkout ${beforeConfig}`)
47+
})
48+
49+
it('should be resolved the configuration file with no spec files', async function () {
50+
const testingSection = await getTestingSection(sideBarView.getContent())
51+
const items = await testingSection.getVisibleItems()
52+
53+
await waitForResolved(browser, items[0])
54+
55+
await expect(items).toMatchTreeStructure([
56+
{
57+
text: 'wdio.conf.ts',
58+
status: STATUS.NOT_YET_RUN,
59+
children: [
60+
{
61+
text: 'before.spec.ts',
62+
status: STATUS.NOT_YET_RUN,
63+
children: [
64+
{
65+
text: 'Before Tests',
66+
status: STATUS.NOT_YET_RUN,
67+
children: [{ text: 'TEST BEFORE 1', status: STATUS.NOT_YET_RUN }],
68+
},
69+
],
70+
},
71+
{
72+
text: 'sample.spec.ts',
73+
status: STATUS.NOT_YET_RUN,
74+
children: [
75+
{
76+
text: 'Sample 1',
77+
status: STATUS.NOT_YET_RUN,
78+
children: [{ text: 'TEST SAMPLE 1', status: STATUS.NOT_YET_RUN }],
79+
},
80+
],
81+
},
82+
],
83+
},
84+
])
85+
86+
// Emulate the changing configuration
87+
shell.cp('-f', afterConfig, beforeConfig)
88+
await new Promise((resolve) => setTimeout(resolve, 1000))
89+
await expect(items).toMatchTreeStructure([
90+
{
91+
text: 'wdio.conf.ts',
92+
status: STATUS.NOT_YET_RUN,
93+
children: [],
94+
},
95+
])
96+
})
97+
98+
it('should run tests successfully after changing the valid configuration', async function () {
99+
const testingSection = await getTestingSection(sideBarView.getContent())
100+
const items = await testingSection.getVisibleItems()
101+
102+
shell.exec(`git checkout ${beforeConfig}`)
103+
await new Promise((resolve) => setTimeout(resolve, 1000))
104+
105+
await clickTreeItemButton(browser, items[0], 'Run Test')
106+
107+
await waitForTestStatus(browser, items[0], STATUS.PASSED)
108+
109+
await expect(items).toMatchTreeStructure([
110+
{
111+
text: 'wdio.conf.ts',
112+
status: STATUS.PASSED,
113+
children: [
114+
{
115+
text: 'before.spec.ts',
116+
status: STATUS.PASSED,
117+
children: [
118+
{
119+
text: 'Before Tests',
120+
status: STATUS.PASSED,
121+
children: [{ text: 'TEST BEFORE 1', status: STATUS.PASSED }],
122+
},
123+
],
124+
},
125+
{
126+
text: 'sample.spec.ts',
127+
status: STATUS.PASSED,
128+
children: [
129+
{
130+
text: 'Sample 1',
131+
status: STATUS.PASSED,
132+
children: [{ text: 'TEST SAMPLE 1', status: STATUS.PASSED }],
133+
},
134+
],
135+
},
136+
],
137+
},
138+
])
139+
})
140+
})

e2e/tests/updateErrorSpec.spec.ts

Lines changed: 214 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,214 @@
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+
collapseAllTests,
12+
getTestingSection,
13+
openTestingView,
14+
waitForResolved,
15+
waitForTestStatus,
16+
} from '../helpers/index.ts'
17+
18+
import type { SideBarView, Workbench } from 'wdio-vscode-service'
19+
20+
const __dirname = path.dirname(url.fileURLToPath(import.meta.url))
21+
const rootDir = path.resolve(__dirname, '..', '..')
22+
const workspacePath = path.resolve(rootDir, 'samples/smoke/update-config/')
23+
24+
const testsPath = path.join(workspacePath, 'tests')
25+
const spec = {
26+
before: path.resolve(testsPath, 'before.spec.ts'),
27+
after: path.resolve(testsPath, 'error.spec.ts.template'),
28+
}
29+
30+
describe('VS Code Extension Testing (Update config)', function () {
31+
let workbench: Workbench
32+
let sideBarView: SideBarView<any>
33+
34+
beforeEach(async function () {
35+
workbench = await browser.getWorkbench()
36+
await openTestingView(workbench)
37+
sideBarView = workbench.getSideBar()
38+
39+
const testingSection = await getTestingSection(sideBarView.getContent())
40+
await collapseAllTests(testingSection)
41+
42+
await browser.waitUntil(async () => (await testingSection.getVisibleItems()).length === 1)
43+
})
44+
45+
afterEach(async function () {
46+
await clearAllTestResults(workbench)
47+
})
48+
49+
after(function () {
50+
shell.exec(`git checkout ${spec.before}`)
51+
})
52+
53+
it('should be resolved the no tests after spec file is changed with invalid syntax', async function () {
54+
const testingSection = await getTestingSection(sideBarView.getContent())
55+
const items = await testingSection.getVisibleItems()
56+
57+
await waitForResolved(browser, items[0])
58+
59+
await expect(items).toMatchTreeStructure([
60+
{
61+
text: 'wdio.conf.ts',
62+
status: STATUS.NOT_YET_RUN,
63+
children: [
64+
{
65+
text: 'before.spec.ts',
66+
status: STATUS.NOT_YET_RUN,
67+
children: [
68+
{
69+
text: 'Before Tests',
70+
status: STATUS.NOT_YET_RUN,
71+
children: [{ text: 'TEST BEFORE 1', status: STATUS.NOT_YET_RUN }],
72+
},
73+
],
74+
},
75+
{
76+
text: 'sample.spec.ts',
77+
status: STATUS.NOT_YET_RUN,
78+
children: [
79+
{
80+
text: 'Sample 1',
81+
status: STATUS.NOT_YET_RUN,
82+
children: [{ text: 'TEST SAMPLE 1', status: STATUS.NOT_YET_RUN }],
83+
},
84+
],
85+
},
86+
],
87+
},
88+
])
89+
90+
// Emulate the changing configuration
91+
shell.cp('-f', spec.after, spec.before)
92+
await new Promise((resolve) => setTimeout(resolve, 1000))
93+
await browser.waitUntil(
94+
async () => {
95+
if (!(await items[0].isExpanded())) {
96+
await items[0].expand()
97+
}
98+
99+
const children = await items[0].getChildren()
100+
const target = children[0]
101+
if (!target) {
102+
return false
103+
}
104+
const regex = new RegExp('before.spec.ts')
105+
return regex.test(await target.getLabel())
106+
},
107+
{
108+
timeoutMsg: 'The label "before.spec.ts" is not found.',
109+
}
110+
)
111+
112+
await expect(items).toMatchTreeStructure([
113+
{
114+
text: 'wdio.conf.ts',
115+
status: STATUS.NOT_YET_RUN,
116+
children: [
117+
{
118+
text: 'before.spec.ts',
119+
status: STATUS.NOT_YET_RUN,
120+
children: [],
121+
},
122+
{
123+
text: 'sample.spec.ts',
124+
status: STATUS.NOT_YET_RUN,
125+
children: [
126+
{
127+
text: 'Sample 1',
128+
status: STATUS.NOT_YET_RUN,
129+
children: [{ text: 'TEST SAMPLE 1', status: STATUS.NOT_YET_RUN }],
130+
},
131+
],
132+
},
133+
],
134+
},
135+
])
136+
})
137+
138+
it('should run tests successfully after changing the spec file', async function () {
139+
const testingSection = await getTestingSection(sideBarView.getContent())
140+
const items = await testingSection.getVisibleItems()
141+
142+
await waitForResolved(browser, items[0])
143+
144+
await clickTreeItemButton(browser, items[0], 'Run Test')
145+
146+
await waitForTestStatus(browser, items[0], STATUS.PASSED)
147+
148+
await expect(items).toMatchTreeStructure([
149+
{
150+
text: 'wdio.conf.ts',
151+
status: STATUS.PASSED,
152+
children: [
153+
{
154+
text: 'before.spec.ts',
155+
status: STATUS.NOT_YET_RUN,
156+
children: [],
157+
},
158+
{
159+
text: 'sample.spec.ts',
160+
status: STATUS.PASSED,
161+
children: [
162+
{
163+
text: 'Sample 1',
164+
status: STATUS.PASSED,
165+
children: [{ text: 'TEST SAMPLE 1', status: STATUS.PASSED }],
166+
},
167+
],
168+
},
169+
],
170+
},
171+
])
172+
})
173+
174+
it('should reload valid test files', async function () {
175+
const testingSection = await getTestingSection(sideBarView.getContent())
176+
const items = await testingSection.getVisibleItems()
177+
178+
shell.exec(`git checkout ${spec.before}`)
179+
await new Promise((resolve) => setTimeout(resolve, 1000))
180+
181+
await clickTreeItemButton(browser, items[0], 'Run Test')
182+
await waitForTestStatus(browser, items[0], STATUS.PASSED)
183+
await expect(items).toMatchTreeStructure([
184+
{
185+
text: 'wdio.conf.ts',
186+
status: STATUS.PASSED,
187+
children: [
188+
{
189+
text: 'before.spec.ts',
190+
status: STATUS.PASSED,
191+
children: [
192+
{
193+
text: 'Before Tests',
194+
status: STATUS.PASSED,
195+
children: [{ text: 'TEST BEFORE 1', status: STATUS.PASSED }],
196+
},
197+
],
198+
},
199+
{
200+
text: 'sample.spec.ts',
201+
status: STATUS.PASSED,
202+
children: [
203+
{
204+
text: 'Sample 1',
205+
status: STATUS.PASSED,
206+
children: [{ text: 'TEST SAMPLE 1', status: STATUS.PASSED }],
207+
},
208+
],
209+
},
210+
],
211+
},
212+
])
213+
})
214+
})

0 commit comments

Comments
 (0)