|
| 1 | +//===----------------------------------------------------------------------===// |
| 2 | +// |
| 3 | +// This source file is part of the VS Code Swift open source project |
| 4 | +// |
| 5 | +// Copyright (c) 2025 the VS Code Swift project authors |
| 6 | +// Licensed under Apache License v2.0 |
| 7 | +// |
| 8 | +// See LICENSE.txt for license information |
| 9 | +// See CONTRIBUTORS.txt for the list of VS Code Swift project authors |
| 10 | +// |
| 11 | +// SPDX-License-Identifier: Apache-2.0 |
| 12 | +// |
| 13 | +//===----------------------------------------------------------------------===// |
| 14 | +import { expect } from "chai"; |
| 15 | +import * as vscode from "vscode"; |
| 16 | + |
| 17 | +import { FolderContext } from "@src/FolderContext"; |
| 18 | +import { WorkspaceContext } from "@src/WorkspaceContext"; |
| 19 | +import { Commands } from "@src/commands"; |
| 20 | +import { SwiftTask } from "@src/tasks/SwiftTaskProvider"; |
| 21 | + |
| 22 | +import { mockGlobalObject } from "../../MockUtils"; |
| 23 | +import { activateExtensionForSuite, folderInRootWorkspace } from "../utilities/testutilities"; |
| 24 | + |
| 25 | +suite("Run Playground Command", function () { |
| 26 | + let folderContext: FolderContext; |
| 27 | + let workspaceContext: WorkspaceContext; |
| 28 | + |
| 29 | + const mockTasks = mockGlobalObject(vscode, "tasks"); |
| 30 | + |
| 31 | + activateExtensionForSuite({ |
| 32 | + async setup(ctx) { |
| 33 | + workspaceContext = ctx; |
| 34 | + folderContext = await folderInRootWorkspace("defaultPackage", workspaceContext); |
| 35 | + }, |
| 36 | + }); |
| 37 | + |
| 38 | + setup(async () => { |
| 39 | + await workspaceContext.focusFolder(folderContext); |
| 40 | + }); |
| 41 | + |
| 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 | + }); |
| 46 | + |
| 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; |
| 55 | + }); |
| 56 | + |
| 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; |
| 64 | + |
| 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 | + }); |
| 69 | + |
| 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; |
| 77 | + |
| 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 | + }); |
| 82 | + |
| 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; |
| 91 | + |
| 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); |
| 95 | + }); |
| 96 | +}); |
0 commit comments