Skip to content

Commit ff0660c

Browse files
committed
test: add e2e to update settings for glob pattern of configuration file
1 parent a0ae5e4 commit ff0660c

6 files changed

Lines changed: 248 additions & 0 deletions

File tree

e2e/locators/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export const ListSetting = {
2+
listSetting: '.setting-item-list',
3+
listRow: '.setting-list-row',
4+
ListRowEdit: '.setting-list-edit-row',
5+
ListRowTextSetting: 'input',
6+
ListRowOkButton: '.setting-list-ok-button',
7+
}

e2e/pageobjects/SettingsEditor.ts

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import { PageDecorator, SettingsEditor, BasePage, sleep } from 'wdio-vscode-service'
2+
3+
import { ListSetting as ListSettingLocators } from '../locators/index.js'
4+
import * as locatorMap from '../locators/index.js'
5+
import type { Workbench, IPageDecorator } from 'wdio-vscode-service'
6+
7+
class ExtendSettingsEditor extends SettingsEditor {
8+
extendedLocator = ListSettingLocators
9+
constructor(workbench: Workbench) {
10+
super(workbench.locatorMap)
11+
}
12+
13+
async findListSetting(title: string, ...categories: string[]): Promise<ListSetting> {
14+
const category = categories.join(' › ')
15+
const searchBox = await this.elem.$(this.locatorMap.Editor.inputArea)
16+
await searchBox.setValue(`${category}: ${title}`)
17+
const count = await this.itemCount$
18+
let textCount = await count.getText()
19+
await browser.waitUntil(async () => {
20+
await sleep(1500)
21+
const text = await count.getText()
22+
if (text !== textCount) {
23+
textCount = text
24+
return false
25+
}
26+
return true
27+
})
28+
const items = await this.itemRow$$
29+
for (const item of items) {
30+
try {
31+
return await (await this.createListSetting(item, title, category)).wait()
32+
} catch {
33+
// ignore
34+
}
35+
}
36+
throw new Error('The setting is not found.')
37+
}
38+
39+
private async createListSetting(element: WebdriverIO.Element, title: string, category: string) {
40+
if (!(await element.$(this.locators.settingConstructor(title, category)).isExisting())) {
41+
throw new Error('Setting not found')
42+
}
43+
// try a list setting
44+
if (await element.$(this.extendedLocator.listSetting).isExisting()) {
45+
return new ListSetting(locatorMap, title, category, this)
46+
}
47+
throw new Error('Setting type not supported')
48+
}
49+
}
50+
51+
export interface ListSetting extends IPageDecorator<typeof ListSettingLocators> {}
52+
53+
@PageDecorator(ListSettingLocators)
54+
export class ListSetting extends BasePage<typeof ListSettingLocators, typeof locatorMap> {
55+
constructor(
56+
locators: typeof locatorMap,
57+
title: string,
58+
category: string,
59+
public settings: SettingsEditor
60+
) {
61+
super(locators, settings.locators.settingConstructor(title, category))
62+
}
63+
64+
/**
65+
* @private
66+
*/
67+
public locatorKey = 'ListSetting' as const
68+
69+
async editValue(index: number, value: string) {
70+
const rows = this.listRow$$
71+
if (rows.length < index + 1) {
72+
throw new Error('invalid index')
73+
}
74+
await (rows[index] as WebdriverIO.Element).doubleClick()
75+
76+
const editRow = await this.elem.$(this.locators.ListRowEdit)
77+
78+
const input = await editRow.$(this.locators.ListRowTextSetting)
79+
const okBtn = editRow.$(this.locators.ListRowOkButton)
80+
81+
await input.setValue(value)
82+
await okBtn.click()
83+
}
84+
}
85+
86+
export { ExtendSettingsEditor as SettingsEditor }

e2e/tests/updateSettings.spec.ts

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
import { browser, expect } from '@wdio/globals'
2+
3+
import {
4+
STATUS,
5+
clearAllTestResults,
6+
clickTreeItemButton,
7+
collapseAllTests,
8+
getTestingSection,
9+
openTestingView,
10+
waitForResolved,
11+
waitForTestStatus,
12+
} from '../helpers/index.js'
13+
import { SettingsEditor as ExtendSettingsEditor } from '../pageobjects/SettingsEditor.js'
14+
15+
import type { SideBarView, ViewControl, Workbench } from 'wdio-vscode-service'
16+
17+
describe('VS Code Extension Testing (Update config)', function () {
18+
let workbench: Workbench
19+
let sideBarView: SideBarView<any>
20+
let testingVew: ViewControl
21+
22+
beforeEach(async function () {
23+
workbench = await browser.getWorkbench()
24+
testingVew = await openTestingView(workbench)
25+
sideBarView = workbench.getSideBar()
26+
27+
const testingSection = await getTestingSection(sideBarView.getContent())
28+
await collapseAllTests(testingSection)
29+
30+
await browser.waitUntil(async () => (await testingSection.getVisibleItems()).length === 1)
31+
})
32+
33+
afterEach(async function () {
34+
await clearAllTestResults(workbench)
35+
})
36+
37+
it('should be resolved the defined tests after configuration changed', async function () {
38+
const testingSection = await getTestingSection(sideBarView.getContent())
39+
const items = await testingSection.getVisibleItems()
40+
41+
await waitForResolved(browser, items[0])
42+
43+
await expect(items).toMatchTreeStructure([
44+
{
45+
text: 'wdio.conf.ts',
46+
status: STATUS.NOT_YET_RUN,
47+
children: [
48+
{
49+
text: 'before.spec.ts',
50+
status: STATUS.NOT_YET_RUN,
51+
children: [
52+
{
53+
text: 'Before Tests',
54+
status: STATUS.NOT_YET_RUN,
55+
children: [{ text: 'TEST BEFORE 1', status: STATUS.NOT_YET_RUN }],
56+
},
57+
],
58+
},
59+
{
60+
text: 'sample.spec.ts',
61+
status: STATUS.NOT_YET_RUN,
62+
children: [
63+
{
64+
text: 'Sample 1',
65+
status: STATUS.NOT_YET_RUN,
66+
children: [{ text: 'TEST SAMPLE 1', status: STATUS.NOT_YET_RUN }],
67+
},
68+
],
69+
},
70+
],
71+
},
72+
])
73+
74+
// Emulate the changing configuration
75+
await workbench.openSettings()
76+
77+
await testingVew.closeView()
78+
const setting2 = new ExtendSettingsEditor(workbench)
79+
const listSetting = await setting2.findListSetting('Config File Pattern', 'Webdriverio')
80+
await listSetting.editValue(0, '**/webdriverio.conf.ts')
81+
82+
await workbench.getEditorView().closeAllEditors()
83+
await testingVew.openView()
84+
85+
await waitForResolved(browser, items[0])
86+
87+
await expect(items).toMatchTreeStructure([
88+
{
89+
text: 'webdriverio.conf.ts',
90+
status: STATUS.NOT_YET_RUN,
91+
children: [
92+
{
93+
text: 'after.test.ts',
94+
status: STATUS.NOT_YET_RUN,
95+
children: [
96+
{
97+
text: 'After Tests',
98+
status: STATUS.NOT_YET_RUN,
99+
children: [{ text: 'TEST AFTER 1', status: STATUS.NOT_YET_RUN }],
100+
},
101+
],
102+
},
103+
],
104+
},
105+
])
106+
})
107+
108+
it('should run tests successfully after changing the settings', async function () {
109+
const testingSection = await getTestingSection(sideBarView.getContent())
110+
const items = await testingSection.getVisibleItems()
111+
112+
await waitForResolved(browser, items[0])
113+
114+
await clickTreeItemButton(browser, items[0], 'Run Test')
115+
116+
await waitForTestStatus(browser, items[0], STATUS.PASSED)
117+
118+
await expect(items).toMatchTreeStructure([
119+
{
120+
text: 'webdriverio.conf.ts',
121+
status: STATUS.PASSED,
122+
children: [
123+
{
124+
text: 'after.test.ts',
125+
status: STATUS.PASSED,
126+
children: [
127+
{
128+
text: 'After Tests',
129+
status: STATUS.PASSED,
130+
children: [{ text: 'TEST AFTER 1', status: STATUS.PASSED }],
131+
},
132+
],
133+
},
134+
],
135+
},
136+
])
137+
})
138+
})

e2e/wdioSmoke.conf.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ function defineSmokePrams(target: TestTargets) {
1313
'./tests/updateSpec.spec.ts',
1414
'./tests/updateErrorSpec.spec.ts',
1515
'./tests/updateErrorConfig.spec.ts',
16+
'./tests/updateSettings.spec.ts',
1617
],
1718
workspace: '../samples/smoke/update-config',
1819
settings: {},

eslint.config.mjs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,13 @@ export default wdioEslint.config([
9191
files: ['e2e/**/*.spec.ts'],
9292
...mochaPlugin.configs.recommended,
9393
},
94+
{
95+
/**
96+
* for extension of wdio-vscode-service
97+
*/
98+
files: ['e2e/pageobjects/**/*.ts'],
99+
rules: {
100+
'@typescript-eslint/no-unsafe-declaration-merging': 'off',
101+
},
102+
},
94103
])
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import '@wdio/types'
2+
import { config as baseConfig } from './wdio.conf.ts'
3+
4+
export const config = {
5+
...baseConfig,
6+
specs: ['tests/*.test.ts'],
7+
}

0 commit comments

Comments
 (0)