|
3 | 3 | * Licensed under the MIT License. See License.txt in the project root for license information. |
4 | 4 | *--------------------------------------------------------------------------------------------*/ |
5 | 5 |
|
6 | | -import { AzExtFsExtra } from '@microsoft/vscode-azext-utils'; |
7 | 6 | import * as assert from 'assert'; |
8 | | -import * as vscode from 'vscode'; |
9 | 7 | import { getPreLaunchTaskChain } from '../src/debug/getPreLaunchTaskChain'; |
10 | 8 | import type { ITask } from '../src/vsCodeConfig/tasks'; |
11 | | -import { getTestWorkspaceFolder } from './global.test'; |
12 | 9 |
|
13 | | -suite.only('getPreLaunchTaskChain', () => { |
14 | | - let workspaceFolder: vscode.WorkspaceFolder; |
15 | | - |
16 | | - suiteSetup(async function (): Promise<void> { |
17 | | - const testPath = getTestWorkspaceFolder(); |
18 | | - const folders = vscode.workspace.workspaceFolders; |
19 | | - const folder = folders?.find(f => f.uri.fsPath === testPath); |
20 | | - if (!folder) { |
21 | | - throw new Error(`Could not find workspace folder for path: ${testPath}`); |
22 | | - } |
23 | | - |
24 | | - await AzExtFsExtra.emptyDir(workspaceFolder.uri.fsPath); |
25 | | - workspaceFolder = folder; |
26 | | - }); |
27 | | - |
28 | | - async function setTasks(tasks: ITask[]): Promise<void> { |
29 | | - await vscode.workspace.getConfiguration('tasks', workspaceFolder.uri).update('tasks', tasks, vscode.ConfigurationTarget.WorkspaceFolder); |
30 | | - } |
31 | | - |
32 | | - teardown(async () => { |
33 | | - await AzExtFsExtra.emptyDir(workspaceFolder.uri.fsPath); |
34 | | - }); |
35 | | - |
36 | | - test('returns only the preLaunchTask when it has no dependencies', async () => { |
37 | | - await setTasks([ |
| 10 | +suite('getPreLaunchTaskChain', () => { |
| 11 | + test('returns only the preLaunchTask when it has no dependencies', () => { |
| 12 | + const tasks: ITask[] = [ |
38 | 13 | { type: 'shell', label: 'build', command: 'npm run build' } |
39 | | - ]); |
40 | | - const result = getPreLaunchTaskChain(workspaceFolder, 'build'); |
| 14 | + ]; |
| 15 | + const result = getPreLaunchTaskChain(tasks, 'build'); |
41 | 16 | assert.deepStrictEqual(result, ['build']); |
42 | 17 | }); |
43 | 18 |
|
44 | | - test('returns empty array when preLaunchTask is not found in tasks list', async () => { |
45 | | - await setTasks([]); |
46 | | - const result = getPreLaunchTaskChain(workspaceFolder, 'nonexistent'); |
| 19 | + test('returns empty array when preLaunchTask is not found in tasks list', () => { |
| 20 | + const result = getPreLaunchTaskChain([], 'nonexistent'); |
47 | 21 | assert.deepStrictEqual(result, []); |
48 | 22 | }); |
49 | 23 |
|
50 | | - test('resolves a single string dependsOn', async () => { |
51 | | - await setTasks([ |
| 24 | + test('resolves a single string dependsOn', () => { |
| 25 | + const tasks: ITask[] = [ |
52 | 26 | { type: 'shell', label: 'build', command: 'npm run build', dependsOn: 'compile' }, |
53 | 27 | { type: 'shell', label: 'compile', command: 'tsc' } |
54 | | - ]); |
55 | | - const result = getPreLaunchTaskChain(workspaceFolder, 'build'); |
| 28 | + ]; |
| 29 | + const result = getPreLaunchTaskChain(tasks, 'build'); |
56 | 30 | assert.deepStrictEqual(result, ['build', 'compile']); |
57 | 31 | }); |
58 | 32 |
|
59 | | - test('resolves an array dependsOn', async () => { |
60 | | - await setTasks([ |
| 33 | + test('resolves an array dependsOn', () => { |
| 34 | + const tasks: ITask[] = [ |
61 | 35 | { type: 'shell', label: 'build', command: 'npm run build', dependsOn: ['compile', 'lint'] }, |
62 | 36 | { type: 'shell', label: 'compile', command: 'tsc' }, |
63 | 37 | { type: 'shell', label: 'lint', command: 'eslint .' } |
64 | | - ]); |
65 | | - const result = getPreLaunchTaskChain(workspaceFolder, 'build'); |
| 38 | + ]; |
| 39 | + const result = getPreLaunchTaskChain(tasks, 'build'); |
66 | 40 | assert.deepStrictEqual(result, ['build', 'compile', 'lint']); |
67 | 41 | }); |
68 | 42 |
|
69 | | - test('resolves chained dependencies', async () => { |
70 | | - await setTasks([ |
| 43 | + test('resolves chained dependencies', () => { |
| 44 | + const tasks: ITask[] = [ |
71 | 45 | { type: 'shell', label: 'build', dependsOn: 'compile' }, |
72 | 46 | { type: 'shell', label: 'compile', dependsOn: 'clean' }, |
73 | 47 | { type: 'shell', label: 'clean', command: 'rm -rf dist' } |
74 | | - ]); |
75 | | - const result = getPreLaunchTaskChain(workspaceFolder, 'build'); |
| 48 | + ]; |
| 49 | + const result = getPreLaunchTaskChain(tasks, 'build'); |
76 | 50 | assert.deepStrictEqual(result, ['build', 'compile', 'clean']); |
77 | 51 | }); |
78 | 52 |
|
79 | | - test('handles circular dependencies without infinite loop', async () => { |
80 | | - await setTasks([ |
| 53 | + test('handles circular dependencies without infinite loop', () => { |
| 54 | + const tasks: ITask[] = [ |
81 | 55 | { type: 'shell', label: 'a', dependsOn: 'b' }, |
82 | 56 | { type: 'shell', label: 'b', dependsOn: 'a' } |
83 | | - ]); |
84 | | - const result = getPreLaunchTaskChain(workspaceFolder, 'a'); |
| 57 | + ]; |
| 58 | + const result = getPreLaunchTaskChain(tasks, 'a'); |
85 | 59 | assert.deepStrictEqual(result, ['a', 'b']); |
86 | 60 | }); |
87 | 61 |
|
88 | | - test('excludes dependency names when they are not defined tasks', async () => { |
89 | | - await setTasks([ |
| 62 | + test('excludes dependency names when they are not defined tasks', () => { |
| 63 | + const tasks: ITask[] = [ |
90 | 64 | { type: 'shell', label: 'build', dependsOn: 'unknown-task' } |
91 | | - ]); |
92 | | - const result = getPreLaunchTaskChain(workspaceFolder, 'build'); |
| 65 | + ]; |
| 66 | + const result = getPreLaunchTaskChain(tasks, 'build'); |
93 | 67 | assert.deepStrictEqual(result, ['build']); |
94 | 68 | }); |
95 | 69 |
|
96 | | - test('skips non-string values in dependsOn array', async () => { |
97 | | - await setTasks([ |
| 70 | + test('skips non-string values in dependsOn array', () => { |
| 71 | + const tasks: ITask[] = [ |
98 | 72 | { type: 'shell', label: 'build', dependsOn: ['compile', 42, null, 'lint'] } as unknown as ITask, |
99 | 73 | { type: 'shell', label: 'compile', command: 'tsc' }, |
100 | 74 | { type: 'shell', label: 'lint', command: 'eslint .' } |
101 | | - ]); |
102 | | - const result = getPreLaunchTaskChain(workspaceFolder, 'build'); |
| 75 | + ]; |
| 76 | + const result = getPreLaunchTaskChain(tasks, 'build'); |
103 | 77 | assert.deepStrictEqual(result, ['build', 'compile', 'lint']); |
104 | 78 | }); |
105 | 79 |
|
106 | | - test('skips tasks without labels when building task map', async () => { |
107 | | - await setTasks([ |
| 80 | + test('skips tasks without labels when building task map', () => { |
| 81 | + const tasks: ITask[] = [ |
108 | 82 | { type: 'shell', label: 'build', dependsOn: 'compile' }, |
109 | 83 | { type: 'shell', command: 'tsc' } // no label - should not be in the task map |
110 | | - ]); |
111 | | - const result = getPreLaunchTaskChain(workspaceFolder, 'build'); |
| 84 | + ]; |
| 85 | + const result = getPreLaunchTaskChain(tasks, 'build'); |
112 | 86 | assert.deepStrictEqual(result, ['build']); |
113 | 87 | }); |
114 | 88 |
|
115 | | - test('returns empty array for empty string preLaunchTask', async () => { |
116 | | - await setTasks([]); |
117 | | - const result = getPreLaunchTaskChain(workspaceFolder, ''); |
| 89 | + test('returns empty array for empty string preLaunchTask', () => { |
| 90 | + const result = getPreLaunchTaskChain([], ''); |
118 | 91 | assert.deepStrictEqual(result, []); |
119 | 92 | }); |
120 | 93 | }); |
0 commit comments