|
| 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