1212//
1313//===----------------------------------------------------------------------===//
1414import { expect } from "chai" ;
15+ import { stub } from "sinon" ;
1516import * as vscode from "vscode" ;
1617
1718import { FolderContext } from "@src/FolderContext" ;
1819import { WorkspaceContext } from "@src/WorkspaceContext" ;
1920import { Commands } from "@src/commands" ;
21+ import { runPlayground } from "@src/commands/runPlayground" ;
2022import { SwiftTask } from "@src/tasks/SwiftTaskProvider" ;
23+ import { TaskManager } from "@src/tasks/TaskManager" ;
2124
22- import { mockGlobalObject } from "../../MockUtils" ;
25+ import { MockedObject , instance , mockObject } from "../../MockUtils" ;
2326import { activateExtensionForSuite , folderInRootWorkspace } from "../utilities/testutilities" ;
2427
2528suite ( "Run Playground Command" , function ( ) {
2629 let folderContext : FolderContext ;
2730 let workspaceContext : WorkspaceContext ;
28-
29- const mockTasks = mockGlobalObject ( vscode , "tasks" ) ;
31+ let mockTaskManager : MockedObject < TaskManager > ;
3032
3133 activateExtensionForSuite ( {
3234 async setup ( ctx ) {
@@ -37,60 +39,71 @@ suite("Run Playground Command", function () {
3739
3840 setup ( async ( ) => {
3941 await workspaceContext . focusFolder ( folderContext ) ;
42+ mockTaskManager = mockObject < TaskManager > ( { executeTaskAndWait : stub ( ) . resolves ( ) } ) ;
4043 } ) ;
4144
42- test ( "No playground item provided" , async ( ) => {
43- expect ( await vscode . commands . executeCommand ( Commands . PLAY ) , undefined ) . to . be . false ;
44- expect ( mockTasks . executeTask ) . to . not . have . been . called ;
45- } ) ;
45+ suite ( "Command" , ( ) => {
46+ test ( "Succeeds" , async ( ) => {
47+ expect (
48+ await vscode . commands . executeCommand ( Commands . PLAY , {
49+ id : "PackageLib/PackageLib.swift:3" ,
50+ } )
51+ ) . to . be . true ;
52+ } ) ;
53+
54+ test ( "No playground item provided" , async ( ) => {
55+ expect ( await vscode . commands . executeCommand ( Commands . PLAY ) , undefined ) . to . be . false ;
56+ } ) ;
4657
47- test ( "No folder focussed" , async ( ) => {
48- await workspaceContext . focusFolder ( null ) ;
49- expect (
50- await vscode . commands . executeCommand ( Commands . PLAY , {
51- id : "PackageLib/PackageLib.swift:3" ,
52- } )
53- ) . to . be . false ;
54- expect ( mockTasks . executeTask ) . to . not . have . been . called ;
58+ test ( "No folder focussed" , async ( ) => {
59+ await workspaceContext . focusFolder ( null ) ;
60+ expect (
61+ await vscode . commands . executeCommand ( Commands . PLAY , {
62+ id : "PackageLib/PackageLib.swift:3" ,
63+ } )
64+ ) . to . be . false ;
65+ } ) ;
5566 } ) ;
5667
57- test ( 'Runs "swift play" on "id"' , async ( ) => {
58- expect (
59- await vscode . commands . executeCommand ( Commands . PLAY , {
60- id : "PackageLib/PackageLib.swift:3" ,
61- } )
62- ) . to . be . true ;
63- expect ( mockTasks . executeTask ) . to . have . been . calledOnce ;
68+ suite ( "Arguments" , ( ) => {
69+ test ( 'Runs "swift play" on "id"' , async ( ) => {
70+ expect (
71+ await runPlayground ( folderContext , instance ( mockTaskManager ) , {
72+ id : "PackageLib/PackageLib.swift:3" ,
73+ } )
74+ ) . to . be . true ;
75+ expect ( mockTaskManager . executeTaskAndWait ) . to . have . been . calledOnce ;
6476
65- const task = mockTasks . executeTask . args [ 0 ] [ 0 ] as SwiftTask ;
66- expect ( task . execution . args ) . to . deep . equal ( [ "play" , "PackageLib/PackageLib.swift:3" ] ) ;
67- expect ( task . execution . options . cwd ) . to . equal ( folderContext . folder . fsPath ) ;
68- } ) ;
77+ const task = mockTaskManager . executeTaskAndWait . args [ 0 ] [ 0 ] as SwiftTask ;
78+ expect ( task . execution . args ) . to . deep . equal ( [ "play" , "PackageLib/PackageLib.swift:3" ] ) ;
79+ expect ( task . execution . options . cwd ) . to . equal ( folderContext . folder . fsPath ) ;
80+ } ) ;
6981
70- test ( 'Runs "swift play" on "id" with space in path' , async ( ) => {
71- expect (
72- await vscode . commands . executeCommand ( Commands . PLAY , {
73- id : "PackageLib/Package Lib.swift:3" ,
74- } )
75- ) . to . be . true ;
76- expect ( mockTasks . executeTask ) . to . have . been . calledOnce ;
82+ test ( 'Runs "swift play" on "id" with space in path' , async ( ) => {
83+ expect (
84+ await runPlayground ( folderContext , instance ( mockTaskManager ) , {
85+ id : "PackageLib/Package Lib.swift:3" ,
86+ } )
87+ ) . to . be . true ;
88+ expect ( mockTaskManager . executeTaskAndWait ) . to . have . been . calledOnce ;
7789
78- const task = mockTasks . executeTask . args [ 0 ] [ 0 ] as SwiftTask ;
79- expect ( task . execution . args ) . to . deep . equal ( [ "play" , "PackageLib/Package Lib.swift:3" ] ) ;
80- expect ( task . execution . options . cwd ) . to . equal ( folderContext . folder . fsPath ) ;
81- } ) ;
90+ const task = mockTaskManager . executeTaskAndWait . args [ 0 ] [ 0 ] as SwiftTask ;
91+ expect ( task . execution . args ) . to . deep . equal ( [ "play" , "PackageLib/Package Lib.swift:3" ] ) ;
92+ expect ( task . execution . options . cwd ) . to . equal ( folderContext . folder . fsPath ) ;
93+ } ) ;
8294
83- test ( 'Runs "swift play" on "label"' , async ( ) => {
84- expect (
85- await vscode . commands . executeCommand ( Commands . PLAY , {
86- id : "PackageLib/PackageLib.swift:3" ,
87- label : "bar" ,
88- } )
89- ) . to . be . true ;
90- expect ( mockTasks . executeTask ) . to . have . been . calledOnce ;
95+ test ( 'Runs "swift play" on "label"' , async ( ) => {
96+ expect (
97+ await runPlayground ( folderContext , instance ( mockTaskManager ) , {
98+ id : "PackageLib/PackageLib.swift:3" ,
99+ label : "bar" ,
100+ } )
101+ ) . to . be . true ;
102+ expect ( mockTaskManager . executeTaskAndWait ) . to . have . been . calledOnce ;
91103
92- const task = mockTasks . executeTask . args [ 0 ] [ 0 ] as SwiftTask ;
93- expect ( task . execution . args ) . to . deep . equal ( [ "play" , "bar" ] ) ;
94- expect ( task . execution . options . cwd ) . to . equal ( folderContext . folder . fsPath ) ;
104+ const task = mockTaskManager . executeTaskAndWait . args [ 0 ] [ 0 ] as SwiftTask ;
105+ expect ( task . execution . args ) . to . deep . equal ( [ "play" , "bar" ] ) ;
106+ expect ( task . execution . options . cwd ) . to . equal ( folderContext . folder . fsPath ) ;
107+ } ) ;
95108 } ) ;
96109} ) ;
0 commit comments