|
| 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 | +}) |
0 commit comments