@@ -3,14 +3,13 @@ import * as path from "path";
33import * as vs from "vscode" ;
44import { FlutterCapabilities } from "../../shared/capabilities/flutter" ;
55import { noAction } from "../../shared/constants" ;
6- import { TestStatus } from "../../shared/enums" ;
76import { Logger } from "../../shared/interfaces" ;
87import { GroupNode , SuiteData , SuiteNode , TestModel , TestNode , TreeNode } from "../../shared/test/test_model" ;
98import { disposeAll , escapeDartString , generateTestNameFromFileName , uniq } from "../../shared/utils" ;
109import { sortBy } from "../../shared/utils/array" ;
1110import { fsPath , isWithinPath , mkDirRecursive } from "../../shared/utils/fs" ;
1211import { TestOutlineInfo } from "../../shared/utils/outline_das" ;
13- import { createTestFileAction , defaultTestFileContents , getLaunchConfig , TestName } from "../../shared/utils/test" ;
12+ import { TestSelection , createTestFileAction , defaultTestFileContents , getLaunchConfig , getTestSelectionForNodes , getTestSelectionForOutline } from "../../shared/utils/test" ;
1413import { getLaunchConfigDefaultTemplate } from "../../shared/vscode/debugger" ;
1514import { getAllProjectFolders } from "../../shared/vscode/utils" ;
1615import { WorkspaceContext } from "../../shared/workspace" ;
@@ -24,7 +23,7 @@ const CAN_JUMP_BETWEEN_TEST_IMPLEMENTATION = "dart-code:canGoToTestOrImplementat
2423export let isInTestFileThatHasImplementation = false ;
2524export let isInImplementationFileThatCanHaveTest = false ;
2625
27- export type SuiteList = [ SuiteNode , TestName [ ] ] ;
26+ export type SuiteList = [ SuiteNode , TestSelection [ ] ] ;
2827
2928export class TestCommands implements vs . Disposable {
3029 private disposables : vs . Disposable [ ] = [ ] ;
@@ -33,8 +32,8 @@ export class TestCommands implements vs.Disposable {
3332 this . disposables . push (
3433 vs . commands . registerCommand ( "_dart.startDebuggingTestFromOutline" , ( test : TestOutlineInfo , launchTemplate : any | undefined ) => this . startTestFromOutline ( false , test , launchTemplate ) ) ,
3534 vs . commands . registerCommand ( "_dart.startWithoutDebuggingTestFromOutline" , ( test : TestOutlineInfo , launchTemplate : any | undefined ) => this . startTestFromOutline ( true , test , launchTemplate ) ) ,
36- vs . commands . registerCommand ( "_dart.startDebuggingTestsFromVsTestController" , ( suiteData : SuiteData , treeNodes : Array < SuiteNode | GroupNode | TestNode > , suppressPrompts : boolean , testRun : vs . TestRun | undefined ) => this . runTestsForNode ( suiteData , this . getTestNamesForNodes ( treeNodes ) , true , suppressPrompts , treeNodes . length === 1 && treeNodes [ 0 ] instanceof TestNode , undefined , testRun ) ) ,
37- vs . commands . registerCommand ( "_dart.startWithoutDebuggingTestsFromVsTestController" , ( suiteData : SuiteData , treeNodes : Array < SuiteNode | GroupNode | TestNode > , suppressPrompts : boolean , testRun : vs . TestRun | undefined ) => this . runTestsForNode ( suiteData , this . getTestNamesForNodes ( treeNodes ) , false , suppressPrompts , treeNodes . length === 1 && treeNodes [ 0 ] instanceof TestNode , undefined , testRun ) ) ,
35+ vs . commands . registerCommand ( "_dart.startDebuggingTestsFromVsTestController" , ( suiteData : SuiteData , treeNodes : Array < SuiteNode | GroupNode | TestNode > , suppressPrompts : boolean , testRun : vs . TestRun | undefined ) => this . runTestsForNode ( suiteData , treeNodes , true , suppressPrompts , treeNodes . length === 1 && treeNodes [ 0 ] instanceof TestNode , undefined , testRun ) ) ,
36+ vs . commands . registerCommand ( "_dart.startWithoutDebuggingTestsFromVsTestController" , ( suiteData : SuiteData , treeNodes : Array < SuiteNode | GroupNode | TestNode > , suppressPrompts : boolean , testRun : vs . TestRun | undefined ) => this . runTestsForNode ( suiteData , treeNodes , false , suppressPrompts , treeNodes . length === 1 && treeNodes [ 0 ] instanceof TestNode , undefined , testRun ) ) ,
3837 vs . commands . registerCommand ( "_dart.runAllTestsWithoutDebugging" , ( suites : SuiteNode [ ] | undefined , testRun : vs . TestRun | undefined , isRunningAll : boolean ) => this . runAllTestsWithoutDebugging ( suites , testRun , isRunningAll ) ) ,
3938 vs . commands . registerCommand ( "dart.goToTests" , ( resource : vs . Uri | undefined ) => this . goToTestOrImplementationFile ( resource ) , this ) ,
4039 vs . commands . registerCommand ( "dart.goToTestOrImplementationFile" , ( ) => this . goToTestOrImplementationFile ( ) , this ) ,
@@ -112,15 +111,16 @@ export class TestCommands implements vs.Disposable {
112111 programPath : projectWithTests . tests [ 0 ] ,
113112 shouldRunSkippedTests : false ,
114113 suppressPrompts : suites ?. length !== 1 ,
115- testNames : undefined ,
116114 testRun,
115+ testSelection : undefined ,
117116 token : undefined ,
118117 useLaunchJsonTestTemplate : true ,
119118 } ) )
120119 ) ;
121120 }
122121
123- private async runTestsForNode ( suiteData : SuiteData , testNames : TestName [ ] | undefined , debug : boolean , suppressPrompts : boolean , runSkippedTests : boolean , token ?: vs . CancellationToken , testRun ?: vs . TestRun ) {
122+ private async runTestsForNode ( suiteData : SuiteData , nodes : TreeNode [ ] , debug : boolean , suppressPrompts : boolean , runSkippedTests : boolean , token ?: vs . CancellationToken , testRun ?: vs . TestRun ) {
123+ const testSelection = getTestSelectionForNodes ( nodes ) ;
124124 const programPath = fsPath ( suiteData . path ) ;
125125 const canRunSkippedTest = this . flutterCapabilities . supportsRunSkippedTests || ! isInsideFlutterProject ( vs . Uri . file ( suiteData . path ) ) ;
126126 const shouldRunSkippedTests = runSkippedTests && canRunSkippedTest ;
@@ -131,21 +131,24 @@ export class TestCommands implements vs.Disposable {
131131 programPath,
132132 shouldRunSkippedTests,
133133 suppressPrompts,
134- testNames,
135134 testRun,
135+ testSelection,
136136 token,
137137 useLaunchJsonTestTemplate : true ,
138138 } ) ;
139139 }
140140
141- private runTests ( { programPath, debug, testNames , shouldRunSkippedTests, suppressPrompts, launchTemplate, testRun, token, useLaunchJsonTestTemplate } : TestLaunchInfo ) : Promise < boolean > {
141+ private runTests ( { programPath, debug, testSelection , shouldRunSkippedTests, suppressPrompts, launchTemplate, testRun, token, useLaunchJsonTestTemplate } : TestLaunchInfo ) : Promise < boolean > {
142142 if ( useLaunchJsonTestTemplate ) {
143143 // Get the default Run/Debug template for running/debugging tests and use that as a base.
144144 const template = getLaunchConfigDefaultTemplate ( vs . Uri . file ( programPath ) , debug ) ;
145145 if ( template )
146146 launchTemplate = Object . assign ( { } , template , launchTemplate ) ;
147147 }
148148
149+ // TODO(dantup): Implement this!
150+ const runTestsByLine = true /* supportsRunTestByLine */ && config . testInvocationMode === "line" ;
151+
149152 const subs : vs . Disposable [ ] = [ ] ;
150153 return new Promise < boolean > ( async ( resolve , reject ) => {
151154 let testsName = path . basename ( programPath ) ;
@@ -157,7 +160,8 @@ export class TestCommands implements vs.Disposable {
157160 ...getLaunchConfig (
158161 ! debug ,
159162 programPath ,
160- testNames ,
163+ testSelection ,
164+ runTestsByLine ,
161165 shouldRunSkippedTests ,
162166 launchTemplate ,
163167 ) ,
@@ -198,40 +202,6 @@ export class TestCommands implements vs.Disposable {
198202 } ) ;
199203 }
200204
201- private getTestNamesForNodes ( nodes : TreeNode [ ] ) : TestName [ ] | undefined {
202- if ( nodes . find ( ( node ) => node instanceof SuiteNode ) )
203- return undefined ;
204-
205- return ( nodes as Array < GroupNode | TestNode > )
206- . filter ( ( treeNode ) => treeNode . name )
207- . map ( ( treeNode ) => ( { name : treeNode . name ! , isGroup : treeNode instanceof GroupNode } ) ) ;
208- }
209-
210- private getTestNames ( treeNode : TreeNode , onlyOfStatus ?: TestStatus ) : TestName [ ] | undefined {
211- // If we're getting all tests, we can just use the test name/group name (or undefined for suite) directly.
212- if ( onlyOfStatus === undefined ) {
213- if ( ( treeNode instanceof TestNode || treeNode instanceof GroupNode ) && treeNode . name !== undefined )
214- return [ { name : treeNode . name , isGroup : treeNode instanceof GroupNode } ] ;
215-
216- return undefined ;
217- }
218-
219- // Otherwise, collect all descendant tests that are of the specified type.
220- let names : TestName [ ] = [ ] ;
221- if ( treeNode instanceof SuiteNode || treeNode instanceof GroupNode ) {
222- for ( const child of treeNode . children ) {
223- const childNames = this . getTestNames ( child , onlyOfStatus ) ;
224- if ( childNames )
225- names = names . concat ( childNames ) ;
226- }
227- } else if ( treeNode instanceof TestNode && treeNode . name !== undefined ) {
228- if ( treeNode . status === onlyOfStatus )
229- names . push ( { name : treeNode . name , isGroup : treeNode instanceof GroupNode } ) ;
230- }
231-
232- return names ;
233- }
234-
235205 private startTestFromOutline ( noDebug : boolean , test : TestOutlineInfo , launchTemplate : any | undefined ) {
236206 const canRunSkippedTest = ! test . isGroup && ( this . flutterCapabilities . supportsRunSkippedTests || ! isInsideFlutterProject ( vs . Uri . file ( test . file ) ) ) ;
237207 const shouldRunSkippedTests = canRunSkippedTest ; // These are the same when running directly, since we always run skipped.
@@ -242,8 +212,8 @@ export class TestCommands implements vs.Disposable {
242212 programPath : test . file ,
243213 shouldRunSkippedTests,
244214 suppressPrompts : false ,
245- testNames : [ { name : test . fullName , isGroup : test . isGroup } ] ,
246215 testRun : undefined ,
216+ testSelection : [ getTestSelectionForOutline ( test ) ] ,
247217 token : undefined ,
248218 } ) ;
249219 }
@@ -352,7 +322,7 @@ export class TestCommands implements vs.Disposable {
352322interface TestLaunchInfo {
353323 programPath : string ;
354324 debug : boolean ;
355- testNames : TestName [ ] | undefined ;
325+ testSelection : TestSelection [ ] | undefined ;
356326 shouldRunSkippedTests : boolean ;
357327 suppressPrompts : boolean ;
358328 launchTemplate : any | undefined ;
0 commit comments