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