|
| 1 | +//===----------------------------------------------------------------------===// |
| 2 | +// |
| 3 | +// This source file is part of the VS Code Swift open source project |
| 4 | +// |
| 5 | +// Copyright (c) 2024 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 | + |
| 15 | +import { expect } from "chai"; |
| 16 | +import * as vscode from "vscode"; |
| 17 | +import { |
| 18 | + PackageDependenciesProvider, |
| 19 | + PackageNode, |
| 20 | +} from "../../../src/ui/PackageDependencyProvider"; |
| 21 | +import { folderContextPromise, globalWorkspaceContextPromise } from "../extension.test"; |
| 22 | +import { executeTaskAndWaitForResult, waitForNoRunningTasks } from "../../utilities"; |
| 23 | +import { getBuildAllTask, SwiftTask } from "../../../src/tasks/SwiftTaskProvider"; |
| 24 | +import { testAssetUri } from "../../fixtures"; |
| 25 | +import { FolderContext } from "../../../src/FolderContext"; |
| 26 | +import { WorkspaceContext } from "../../../src/WorkspaceContext"; |
| 27 | +import * as sinon from "sinon"; |
| 28 | +import { Commands } from "../../../src/commands"; |
| 29 | + |
| 30 | +suite("Dependency Commmands Test Suite", function () { |
| 31 | + // full workflow's interaction with spm is also longer than the default timeout |
| 32 | + this.timeout(2 * 60 * 1000); |
| 33 | + |
| 34 | + suite("spm Resolve Update Contract Tests", function () { |
| 35 | + let folderContext: FolderContext; |
| 36 | + let workspaceContext: WorkspaceContext; |
| 37 | + |
| 38 | + suiteSetup(async function () { |
| 39 | + workspaceContext = await globalWorkspaceContextPromise; |
| 40 | + await waitForNoRunningTasks(); |
| 41 | + folderContext = await folderContextPromise("dependencies"); |
| 42 | + await workspaceContext.focusFolder(folderContext); |
| 43 | + }); |
| 44 | + |
| 45 | + test("Contract: spm resolve", async () => { |
| 46 | + const result = await vscode.commands.executeCommand(Commands.ResolveDependencies); |
| 47 | + expect(result).to.be.true; |
| 48 | + }); |
| 49 | + |
| 50 | + test("Contract: spm update", async () => { |
| 51 | + const result = await vscode.commands.executeCommand(Commands.UpdateDependencies); |
| 52 | + expect(result).to.be.true; |
| 53 | + }); |
| 54 | + }); |
| 55 | + |
| 56 | + suite("Full Work Flow Test Suite", function () { |
| 57 | + let folderContext: FolderContext; |
| 58 | + let workspaceContext: WorkspaceContext; |
| 59 | + let tasks: SwiftTask; |
| 60 | + let treeProvider: PackageDependenciesProvider; |
| 61 | + let item: PackageNode; |
| 62 | + |
| 63 | + suiteSetup(async function () { |
| 64 | + workspaceContext = await globalWorkspaceContextPromise; |
| 65 | + await waitForNoRunningTasks(); |
| 66 | + folderContext = await folderContextPromise("dependencies"); |
| 67 | + await workspaceContext.focusFolder(folderContext); |
| 68 | + treeProvider = new PackageDependenciesProvider(workspaceContext); |
| 69 | + |
| 70 | + const items = await treeProvider.getChildren(); |
| 71 | + item = items.find(n => n.name === "swift-markdown") as PackageNode; |
| 72 | + }); |
| 73 | + |
| 74 | + suiteTeardown(() => { |
| 75 | + treeProvider?.dispose(); |
| 76 | + }); |
| 77 | + |
| 78 | + setup(async function () { |
| 79 | + // Check before each test case start: |
| 80 | + // Expect to fail without setting up local version |
| 81 | + tasks = (await getBuildAllTask(folderContext)) as SwiftTask; |
| 82 | + const { exitCode, output } = await executeTaskAndWaitForResult(tasks); |
| 83 | + expect(exitCode).to.not.equal(0); |
| 84 | + expect(output).to.include("PackageLib"); |
| 85 | + expect(output).to.include("required"); |
| 86 | + }); |
| 87 | + |
| 88 | + teardown(async function () { |
| 89 | + // Expect to fail again now dependency is missing |
| 90 | + const { exitCode, output } = await executeTaskAndWaitForResult(tasks); |
| 91 | + expect(exitCode).to.not.equal(0); |
| 92 | + expect(output).to.include("PackageLib"); |
| 93 | + expect(output).to.include("required"); |
| 94 | + }); |
| 95 | + |
| 96 | + const useLocalDependencyTest = async () => { |
| 97 | + // Contract: spm edit with user supplied local version of dependency |
| 98 | + const windowMock = sinon.stub(vscode.window, "showOpenDialog"); |
| 99 | + windowMock.resolves([testAssetUri("Swift-Markdown")]); |
| 100 | + const result = await vscode.commands.executeCommand(Commands.UseLocalDependency, item); |
| 101 | + expect(result).to.be.true; |
| 102 | + windowMock.restore(); |
| 103 | + |
| 104 | + // This will now pass as we have the required library |
| 105 | + const { exitCode, output } = await executeTaskAndWaitForResult(tasks); |
| 106 | + expect(exitCode).to.equal(0); |
| 107 | + expect(output).to.include("defaultpackage"); |
| 108 | + expect(output).to.include("not used by any target"); |
| 109 | + }; |
| 110 | + |
| 111 | + test("Use local dependency - Reset", async () => { |
| 112 | + await useLocalDependencyTest(); |
| 113 | + |
| 114 | + // Contract: spm reset |
| 115 | + const result = await vscode.commands.executeCommand(Commands.ResetPackage); |
| 116 | + expect(result).to.be.true; |
| 117 | + }); |
| 118 | + |
| 119 | + test("Use local dependency - Add to workspace - Unedit", async () => { |
| 120 | + await useLocalDependencyTest(); |
| 121 | + |
| 122 | + // Contract: spm unedit |
| 123 | + const result = await vscode.commands.executeCommand(Commands.UneditDependency, item); |
| 124 | + expect(result).to.be.true; |
| 125 | + }); |
| 126 | + }); |
| 127 | +}); |
0 commit comments