11import * as vscode from "vscode" ;
22
33import { BaseNode } from "../basenode" ;
4- import { Test , Tests } from "../../types" ;
4+ import { Test , Tests , pseudoAllTarget } from "../../types" ;
55import { extensionRelative } from "../../utils" ;
6+ import { IRunnableNode } from "./base" ;
67
7- export class TestRootNode extends BaseNode {
8+ function getTestCommand ( isBenchmark : boolean ) : string {
9+ return isBenchmark ? "benchmark" : "test" ;
10+ }
11+
12+ export class TestRootNode extends BaseNode implements IRunnableNode {
813 constructor (
914 parentId : string ,
1015 private readonly tests : Tests ,
1116 private readonly isBenchmark : boolean ,
1217 ) {
13- super ( `${ parentId } -${ isBenchmark ? "benchmarks" : "tests" } ` ) ;
18+ super ( `${ parentId } -${ getTestCommand ( isBenchmark ) } ` ) ;
1419 }
1520
1621 override getTreeItem ( ) {
@@ -21,39 +26,58 @@ export class TestRootNode extends BaseNode {
2126 item . collapsibleState =
2227 this . tests . length === 0 ? vscode . TreeItemCollapsibleState . None : vscode . TreeItemCollapsibleState . Collapsed ;
2328
29+ // To key in to "when": "view == meson-project && viewItem == meson-test-root" in package.json.
30+ item . contextValue = "meson-test-root" ;
31+
2432 return item ;
2533 }
2634
2735 override getChildren ( ) {
2836 return this . tests . map ( ( test ) => new TestNode ( this . id , test , this . isBenchmark ) ) ;
2937 }
38+
39+ run ( ) {
40+ return vscode . commands . executeCommand ( `mesonbuild.${ getTestCommand ( this . isBenchmark ) } ` , pseudoAllTarget ) ;
41+ }
3042}
3143
32- class TestNode extends BaseNode {
44+ class TestNode extends BaseNode implements IRunnableNode {
45+ private readonly taskName : string ;
46+ private readonly command : string ;
47+
3348 constructor (
3449 parentId : string ,
3550 private readonly test : Test ,
3651 private readonly isBenchmark : boolean ,
3752 ) {
3853 super ( `${ parentId } -${ test . suite [ 0 ] } -${ test . name } ` ) ;
54+
55+ this . command = getTestCommand ( this . isBenchmark ) ;
56+ const project = this . test . suite [ 0 ] . split ( ":" ) [ 0 ] ;
57+ this . taskName = `${ project } :${ this . test . name } ` ;
3958 }
4059
4160 override getTreeItem ( ) {
4261 const item = super . getTreeItem ( ) as vscode . TreeItem ;
43- const project = this . test . suite [ 0 ] . split ( ":" ) [ 0 ] ;
44- const name = `${ project } :${ this . test . name } ` ;
4562
4663 item . label = this . test . name ;
4764 item . iconPath = extensionRelative ( "res/meson_32.svg" ) ;
4865 item . command = {
49- title : `Run ${ this . isBenchmark ? "benchmark" : "test" } ` ,
50- command : `mesonbuild.${ this . isBenchmark ? "benchmark" : "test" } ` ,
51- arguments : [ name ] ,
66+ title : `Run ${ this . command } ` ,
67+ command : `mesonbuild.${ this . command } ` ,
68+ arguments : [ this . taskName ] ,
5269 } ;
5370
5471 // No children currently, so don't display toggle.
5572 item . collapsibleState = vscode . TreeItemCollapsibleState . None ;
5673
74+ // To key in to "when": "view == meson-project && viewItem == meson-test" in package.json.
75+ item . contextValue = "meson-test" ;
76+
5777 return item ;
5878 }
79+
80+ run ( ) {
81+ return vscode . commands . executeCommand ( `mesonbuild.${ this . command } ` , this . taskName ) ;
82+ }
5983}
0 commit comments