|
| 1 | +import assert from 'assert'; |
| 2 | +import { commands, TestItem, TestItemCollection, Uri, workspace } from 'vscode'; |
| 3 | +import { CancellationTokenSource } from 'vscode-languageclient'; |
| 4 | +import * as e3 from '../../src/e3Testsuite'; |
| 5 | +import { activate } from '../utils'; |
| 6 | + |
| 7 | +suite('e3-testsuite', function () { |
| 8 | + this.beforeAll(async function () { |
| 9 | + await activate(); |
| 10 | + }); |
| 11 | + |
| 12 | + test('Test list', async function () { |
| 13 | + await e3.controller.refreshHandler!(new CancellationTokenSource().token); |
| 14 | + |
| 15 | + assert.deepStrictEqual(toTestResult(e3.controller.items), [ |
| 16 | + { |
| 17 | + id: Uri.joinPath(workspace.workspaceFolders![0].uri, 'testsuite.py').toString(), |
| 18 | + label: 'testsuite.py', |
| 19 | + children: [ |
| 20 | + { |
| 21 | + id: '01-test-one-result', |
| 22 | + label: '01-test-one-result', |
| 23 | + children: [], |
| 24 | + }, |
| 25 | + { |
| 26 | + id: '02-test-multiple-results', |
| 27 | + label: '02-test-multiple-results', |
| 28 | + children: [], |
| 29 | + }, |
| 30 | + { |
| 31 | + id: '03-test-multiple-passing-results', |
| 32 | + label: '03-test-multiple-passing-results', |
| 33 | + children: [], |
| 34 | + }, |
| 35 | + { |
| 36 | + id: '04-test-only-passing-sub-results', |
| 37 | + label: '04-test-only-passing-sub-results', |
| 38 | + children: [], |
| 39 | + }, |
| 40 | + { |
| 41 | + id: '05-test-only-sub-results-one-failing', |
| 42 | + label: '05-test-only-sub-results-one-failing', |
| 43 | + children: [], |
| 44 | + }, |
| 45 | + { |
| 46 | + id: '06-test-with-diff', |
| 47 | + label: '06-test-with-diff', |
| 48 | + children: [], |
| 49 | + }, |
| 50 | + { |
| 51 | + id: '07-test-with-no-results', |
| 52 | + label: '07-test-with-no-results', |
| 53 | + children: [], |
| 54 | + }, |
| 55 | + ], |
| 56 | + }, |
| 57 | + ]); |
| 58 | + }); |
| 59 | + |
| 60 | + test('Test list after run', async function () { |
| 61 | + await e3.controller.refreshHandler!(new CancellationTokenSource().token); |
| 62 | + await commands.executeCommand('testing.runAll'); |
| 63 | + |
| 64 | + assert.deepStrictEqual(toTestResult(e3.controller.items), [ |
| 65 | + { |
| 66 | + id: Uri.joinPath(workspace.workspaceFolders![0].uri, 'testsuite.py').toString(), |
| 67 | + label: 'testsuite.py', |
| 68 | + children: [ |
| 69 | + { |
| 70 | + id: '01-test-one-result', |
| 71 | + label: '01-test-one-result', |
| 72 | + children: [], |
| 73 | + }, |
| 74 | + { |
| 75 | + id: '02-test-multiple-results', |
| 76 | + label: '02-test-multiple-results', |
| 77 | + /** |
| 78 | + * We expect these sub-results to appear after the test run |
| 79 | + */ |
| 80 | + children: [ |
| 81 | + { |
| 82 | + id: '02-test-multiple-results.sub3', |
| 83 | + label: '02-test-multiple-results.sub3', |
| 84 | + children: [], |
| 85 | + }, |
| 86 | + { |
| 87 | + id: '02-test-multiple-results.sub2', |
| 88 | + label: '02-test-multiple-results.sub2', |
| 89 | + children: [], |
| 90 | + }, |
| 91 | + { |
| 92 | + id: '02-test-multiple-results.sub1', |
| 93 | + label: '02-test-multiple-results.sub1', |
| 94 | + children: [], |
| 95 | + }, |
| 96 | + ], |
| 97 | + }, |
| 98 | + { |
| 99 | + id: '03-test-multiple-passing-results', |
| 100 | + label: '03-test-multiple-passing-results', |
| 101 | + /** |
| 102 | + * We expect these sub-results to appear after the test run |
| 103 | + */ |
| 104 | + children: [ |
| 105 | + { |
| 106 | + id: '03-test-multiple-passing-results.sub3', |
| 107 | + label: '03-test-multiple-passing-results.sub3', |
| 108 | + children: [], |
| 109 | + }, |
| 110 | + { |
| 111 | + id: '03-test-multiple-passing-results.sub2', |
| 112 | + label: '03-test-multiple-passing-results.sub2', |
| 113 | + children: [], |
| 114 | + }, |
| 115 | + { |
| 116 | + id: '03-test-multiple-passing-results.sub1', |
| 117 | + label: '03-test-multiple-passing-results.sub1', |
| 118 | + children: [], |
| 119 | + }, |
| 120 | + ], |
| 121 | + }, |
| 122 | + { |
| 123 | + id: '04-test-only-passing-sub-results', |
| 124 | + label: '04-test-only-passing-sub-results', |
| 125 | + /** |
| 126 | + * We expect these sub-results to appear after the test run |
| 127 | + */ |
| 128 | + children: [ |
| 129 | + { |
| 130 | + id: '04-test-only-passing-sub-results.sub3', |
| 131 | + label: '04-test-only-passing-sub-results.sub3', |
| 132 | + children: [], |
| 133 | + }, |
| 134 | + { |
| 135 | + id: '04-test-only-passing-sub-results.sub2', |
| 136 | + label: '04-test-only-passing-sub-results.sub2', |
| 137 | + children: [], |
| 138 | + }, |
| 139 | + { |
| 140 | + id: '04-test-only-passing-sub-results.sub1', |
| 141 | + label: '04-test-only-passing-sub-results.sub1', |
| 142 | + children: [], |
| 143 | + }, |
| 144 | + ], |
| 145 | + }, |
| 146 | + { |
| 147 | + id: '05-test-only-sub-results-one-failing', |
| 148 | + label: '05-test-only-sub-results-one-failing', |
| 149 | + /** |
| 150 | + * We expect these sub-results to appear after the test run |
| 151 | + */ |
| 152 | + children: [ |
| 153 | + { |
| 154 | + id: '05-test-only-sub-results-one-failing.sub3', |
| 155 | + label: '05-test-only-sub-results-one-failing.sub3', |
| 156 | + children: [], |
| 157 | + }, |
| 158 | + { |
| 159 | + id: '05-test-only-sub-results-one-failing.sub2', |
| 160 | + label: '05-test-only-sub-results-one-failing.sub2', |
| 161 | + children: [], |
| 162 | + }, |
| 163 | + { |
| 164 | + id: '05-test-only-sub-results-one-failing.sub1', |
| 165 | + label: '05-test-only-sub-results-one-failing.sub1', |
| 166 | + children: [], |
| 167 | + }, |
| 168 | + ], |
| 169 | + }, |
| 170 | + { |
| 171 | + id: '06-test-with-diff', |
| 172 | + label: '06-test-with-diff', |
| 173 | + children: [], |
| 174 | + }, |
| 175 | + { |
| 176 | + id: '07-test-with-no-results', |
| 177 | + label: '07-test-with-no-results', |
| 178 | + children: [], |
| 179 | + }, |
| 180 | + ], |
| 181 | + }, |
| 182 | + ]); |
| 183 | + }); |
| 184 | +}); |
| 185 | + |
| 186 | +interface TestResultItem { |
| 187 | + id: string; |
| 188 | + label: string; |
| 189 | + children: TestResultItem[]; |
| 190 | +} |
| 191 | + |
| 192 | +function toTestResult(items: TestItemCollection): TestResultItem[] { |
| 193 | + const res: TestResultItem[] = []; |
| 194 | + function process(item: TestItem): void { |
| 195 | + res.push({ |
| 196 | + id: item.id, |
| 197 | + label: item.label, |
| 198 | + children: toTestResult(item.children), |
| 199 | + }); |
| 200 | + } |
| 201 | + items.forEach(process); |
| 202 | + return res; |
| 203 | +} |
0 commit comments