Skip to content

Commit 5ae36d6

Browse files
committed
Update task inject pattern for tests
1 parent 4e65473 commit 5ae36d6

File tree

3 files changed

+41
-69
lines changed

3 files changed

+41
-69
lines changed

src/debug/getPreLaunchTaskChain.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,13 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import * as vscode from 'vscode';
7-
import { getTasks, ITask } from '../vsCodeConfig/tasks';
6+
import { ITask } from '../vsCodeConfig/tasks';
87

98
/**
109
* Resolves the full chain of tasks associated with a given `preLaunchTask`.
1110
* Recursively follows the `dependsOn` references found in the `tasks.json`.
1211
*/
13-
export function getPreLaunchTaskChain(workspace: vscode.WorkspaceFolder, preLaunchTask: string): string[] {
14-
const allTasks: ITask[] = getTasks(workspace);
12+
export function getPreLaunchTaskChain(allTasks: ITask[], preLaunchTask: string): string[] {
1513
const allTasksMap = new Map<string, ITask>();
1614

1715
for (const task of allTasks) {

src/debug/validatePreDebug.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { durableUtils } from '../utils/durableUtils';
1818
import { isPythonV2Plus } from '../utils/programmingModelUtils';
1919
import { getDebugConfigs, isDebugConfigEqual } from '../vsCodeConfig/launch';
2020
import { getWorkspaceSetting, tryGetFunctionsWorkerRuntimeForProject } from "../vsCodeConfig/settings";
21+
import { getTasks } from '../vsCodeConfig/tasks';
2122
import { getPreLaunchTaskChain } from './getPreLaunchTaskChain';
2223
import { validateDTSConnectionPreDebug } from './storageProviders/validateDTSConnectionPreDebug';
2324
import { validateNetheriteConnectionPreDebug } from './storageProviders/validateNetheriteConnectionPreDebug';
@@ -43,7 +44,7 @@ export async function preDebugValidate(actionContext: IActionContext, debugConfi
4344

4445
// If one of the `preLaunchTasks` already handles starting emulators, assume the user is already on top of automating this part of the setup
4546
const preLaunchTaskName: string | undefined = debugConfig.preLaunchTask;
46-
const preLaunchTaskChain: string[] = preLaunchTaskName ? getPreLaunchTaskChain(workspace, preLaunchTaskName) : [];
47+
const preLaunchTaskChain: string[] = preLaunchTaskName ? getPreLaunchTaskChain(getTasks(workspace), preLaunchTaskName) : [];
4748
const hasEmulatorTask: boolean = preLaunchTaskChain.some(label => emulatorTaskRegExp.test(label));
4849
context.telemetry.properties.hasEmulatorTask = String(hasEmulatorTask);
4950

test/getPreLaunchTaskChain.test.ts

Lines changed: 37 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -3,118 +3,91 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import { AzExtFsExtra } from '@microsoft/vscode-azext-utils';
76
import * as assert from 'assert';
8-
import * as vscode from 'vscode';
97
import { getPreLaunchTaskChain } from '../src/debug/getPreLaunchTaskChain';
108
import type { ITask } from '../src/vsCodeConfig/tasks';
11-
import { getTestWorkspaceFolder } from './global.test';
129

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[] = [
3813
{ type: 'shell', label: 'build', command: 'npm run build' }
39-
]);
40-
const result = getPreLaunchTaskChain(workspaceFolder, 'build');
14+
];
15+
const result = getPreLaunchTaskChain(tasks, 'build');
4116
assert.deepStrictEqual(result, ['build']);
4217
});
4318

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');
4721
assert.deepStrictEqual(result, []);
4822
});
4923

50-
test('resolves a single string dependsOn', async () => {
51-
await setTasks([
24+
test('resolves a single string dependsOn', () => {
25+
const tasks: ITask[] = [
5226
{ type: 'shell', label: 'build', command: 'npm run build', dependsOn: 'compile' },
5327
{ type: 'shell', label: 'compile', command: 'tsc' }
54-
]);
55-
const result = getPreLaunchTaskChain(workspaceFolder, 'build');
28+
];
29+
const result = getPreLaunchTaskChain(tasks, 'build');
5630
assert.deepStrictEqual(result, ['build', 'compile']);
5731
});
5832

59-
test('resolves an array dependsOn', async () => {
60-
await setTasks([
33+
test('resolves an array dependsOn', () => {
34+
const tasks: ITask[] = [
6135
{ type: 'shell', label: 'build', command: 'npm run build', dependsOn: ['compile', 'lint'] },
6236
{ type: 'shell', label: 'compile', command: 'tsc' },
6337
{ type: 'shell', label: 'lint', command: 'eslint .' }
64-
]);
65-
const result = getPreLaunchTaskChain(workspaceFolder, 'build');
38+
];
39+
const result = getPreLaunchTaskChain(tasks, 'build');
6640
assert.deepStrictEqual(result, ['build', 'compile', 'lint']);
6741
});
6842

69-
test('resolves chained dependencies', async () => {
70-
await setTasks([
43+
test('resolves chained dependencies', () => {
44+
const tasks: ITask[] = [
7145
{ type: 'shell', label: 'build', dependsOn: 'compile' },
7246
{ type: 'shell', label: 'compile', dependsOn: 'clean' },
7347
{ type: 'shell', label: 'clean', command: 'rm -rf dist' }
74-
]);
75-
const result = getPreLaunchTaskChain(workspaceFolder, 'build');
48+
];
49+
const result = getPreLaunchTaskChain(tasks, 'build');
7650
assert.deepStrictEqual(result, ['build', 'compile', 'clean']);
7751
});
7852

79-
test('handles circular dependencies without infinite loop', async () => {
80-
await setTasks([
53+
test('handles circular dependencies without infinite loop', () => {
54+
const tasks: ITask[] = [
8155
{ type: 'shell', label: 'a', dependsOn: 'b' },
8256
{ type: 'shell', label: 'b', dependsOn: 'a' }
83-
]);
84-
const result = getPreLaunchTaskChain(workspaceFolder, 'a');
57+
];
58+
const result = getPreLaunchTaskChain(tasks, 'a');
8559
assert.deepStrictEqual(result, ['a', 'b']);
8660
});
8761

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[] = [
9064
{ type: 'shell', label: 'build', dependsOn: 'unknown-task' }
91-
]);
92-
const result = getPreLaunchTaskChain(workspaceFolder, 'build');
65+
];
66+
const result = getPreLaunchTaskChain(tasks, 'build');
9367
assert.deepStrictEqual(result, ['build']);
9468
});
9569

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[] = [
9872
{ type: 'shell', label: 'build', dependsOn: ['compile', 42, null, 'lint'] } as unknown as ITask,
9973
{ type: 'shell', label: 'compile', command: 'tsc' },
10074
{ type: 'shell', label: 'lint', command: 'eslint .' }
101-
]);
102-
const result = getPreLaunchTaskChain(workspaceFolder, 'build');
75+
];
76+
const result = getPreLaunchTaskChain(tasks, 'build');
10377
assert.deepStrictEqual(result, ['build', 'compile', 'lint']);
10478
});
10579

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[] = [
10882
{ type: 'shell', label: 'build', dependsOn: 'compile' },
10983
{ 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');
11286
assert.deepStrictEqual(result, ['build']);
11387
});
11488

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([], '');
11891
assert.deepStrictEqual(result, []);
11992
});
12093
});

0 commit comments

Comments
 (0)