-
Notifications
You must be signed in to change notification settings - Fork 28k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add CustomExecution2 test and make start fire after onDidOpenTerminal #77839
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
9d43802
Create CustomExecution2 test, make start fire after onDidOpenTerminal
Tyriar 1061411
Merge remote-tracking branch 'origin/master' into tyriar/task_vp_fix
Tyriar 7be4894
Remove unused exit emitter
Tyriar 0950523
Use const
Tyriar b060301
Fail test if resolveTask is called
Tyriar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
62 changes: 62 additions & 0 deletions
62
extensions/vscode-api-tests/src/singlefolder-tests/workspace.tasks.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import * as assert from 'assert'; | ||
import * as vscode from 'vscode'; | ||
|
||
suite.only('workspace-namespace', () => { | ||
|
||
suite('Tasks', () => { | ||
|
||
test('CustomExecution2 task should start and shutdown successfully', (done) => { | ||
interface CustomTestingTaskDefinition extends vscode.TaskDefinition { | ||
/** | ||
* One of the task properties. This can be used to customize the task in the tasks.json | ||
*/ | ||
customProp1: string; | ||
} | ||
const taskType: string = 'customTesting'; | ||
const taskName = 'First custom task'; | ||
const reg1 = vscode.window.onDidOpenTerminal(term => { | ||
reg1.dispose(); | ||
const reg2 = term.onDidWriteData(e => { | ||
reg2.dispose(); | ||
assert.equal(e, 'testing\r\n'); | ||
term.dispose(); | ||
}); | ||
}); | ||
const taskProvider = vscode.tasks.registerTaskProvider(taskType, { | ||
provideTasks: () => { | ||
const result: vscode.Task[] = []; | ||
const kind: CustomTestingTaskDefinition = { | ||
type: taskType, | ||
customProp1: 'testing task one' | ||
}; | ||
const writeEmitter = new vscode.EventEmitter<string>(); | ||
const execution = new vscode.CustomExecution2((): Thenable<vscode.TerminalVirtualProcess> => { | ||
return Promise.resolve(<vscode.TerminalVirtualProcess>{ | ||
onDidWrite: writeEmitter.event, | ||
start: () => { | ||
writeEmitter.fire('testing\r\n'); | ||
}, | ||
shutdown: () => { | ||
taskProvider.dispose(); | ||
done(); | ||
} | ||
}); | ||
}); | ||
const task = new vscode.Task2(kind, vscode.TaskScope.Workspace, taskName, taskType, execution); | ||
result.push(task); | ||
return result; | ||
}, | ||
resolveTask(_task: vscode.Task): vscode.Task | undefined { | ||
assert.fail('resolveTask should not trigger during the test'); | ||
return undefined; | ||
Tyriar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
}); | ||
vscode.commands.executeCommand('workbench.action.tasks.runTask', `${taskType}: ${taskName}`); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be great if the test code could demonstrate the use of the value of 'customProp1'.
When I used this in my project, I ended up creating some wrapper classes around the use of virtual terminal process and custom executions so I could get the custom execution data (the properties) back into the execution of the extension code in a seemingly clean way.
When the code is all in one test like this, the "capturing" works just fine, but when you do things like put your task definition in one file, execution of the code in another, etc. it becomes a bit cumbersome.
I can point you to what I ended up doing if you want.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would this be as easy as just adding an assertion somewhere?