|
| 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 { |
| 17 | + PackageDependenciesProvider, |
| 18 | + PackageNode, |
| 19 | +} from "../../../src/ui/PackageDependencyProvider"; |
| 20 | +import { folderContextPromise, globalWorkspaceContextPromise } from "../extension.test"; |
| 21 | +import { executeTaskAndWaitForResult, waitForNoRunningTasks } from "../../utilities"; |
| 22 | +import { getBuildAllTask, SwiftTask } from "../../../src/tasks/SwiftTaskProvider"; |
| 23 | +import { testAssetPath } from "../../fixtures"; |
| 24 | +import { Version } from "../../../src/utilities/version"; |
| 25 | + |
| 26 | +suite("PackageDependencyProvider Test Suite", function () { |
| 27 | + let treeProvider: PackageDependenciesProvider; |
| 28 | + this.timeout(2 * 60 * 1000); // Allow up to 2 minutes to build |
| 29 | + |
| 30 | + suiteSetup(async function () { |
| 31 | + const workspaceContext = await globalWorkspaceContextPromise; |
| 32 | + // workspace-state.json was not introduced until swift 5.7 |
| 33 | + if (workspaceContext.toolchain.swiftVersion.isLessThan(new Version(5, 7, 0))) { |
| 34 | + this.skip(); |
| 35 | + } |
| 36 | + await waitForNoRunningTasks(); |
| 37 | + const folderContext = await folderContextPromise("dependencies"); |
| 38 | + await executeTaskAndWaitForResult((await getBuildAllTask(folderContext)) as SwiftTask); |
| 39 | + await workspaceContext.focusFolder(folderContext); |
| 40 | + treeProvider = new PackageDependenciesProvider(workspaceContext); |
| 41 | + }); |
| 42 | + |
| 43 | + suiteTeardown(() => { |
| 44 | + treeProvider?.dispose(); |
| 45 | + }); |
| 46 | + |
| 47 | + test("Includes remote dependency", async () => { |
| 48 | + const items = await treeProvider.getChildren(); |
| 49 | + |
| 50 | + const dep = items.find(n => n.name === "swift-markdown") as PackageNode; |
| 51 | + expect(dep).to.not.be.undefined; |
| 52 | + expect(dep?.location).to.equal("https://github.com/swiftlang/swift-markdown.git"); |
| 53 | + expect(dep?.path).to.equal( |
| 54 | + `${testAssetPath("dependencies")}/.build/checkouts/swift-markdown` |
| 55 | + ); |
| 56 | + }); |
| 57 | + |
| 58 | + test("Includes local dependency", async () => { |
| 59 | + const items = await treeProvider.getChildren(); |
| 60 | + |
| 61 | + const dep = items.find(n => n.name === "defaultpackage") as PackageNode; |
| 62 | + expect(dep).to.not.be.undefined; |
| 63 | + expect(dep?.location).to.equal(testAssetPath("defaultPackage")); |
| 64 | + expect(dep?.path).to.equal(testAssetPath("defaultPackage")); |
| 65 | + }); |
| 66 | + |
| 67 | + test("Lists local dependency file structure", async () => { |
| 68 | + const items = await treeProvider.getChildren(); |
| 69 | + |
| 70 | + const dep = items.find(n => n.name === "defaultpackage") as PackageNode; |
| 71 | + expect(dep).to.not.be.undefined; |
| 72 | + |
| 73 | + const folders = await treeProvider.getChildren(dep); |
| 74 | + const folder = folders.find(n => n.name === "Sources"); |
| 75 | + expect(folder).to.not.be.undefined; |
| 76 | + |
| 77 | + expect(folder?.path).to.equal(`${testAssetPath("defaultPackage")}/Sources`); |
| 78 | + |
| 79 | + const childFolders = await treeProvider.getChildren(folder); |
| 80 | + const childFolder = childFolders.find(n => n.name === "PackageExe"); |
| 81 | + expect(childFolder).to.not.be.undefined; |
| 82 | + |
| 83 | + expect(childFolder?.path).to.equal(`${testAssetPath("defaultPackage")}/Sources/PackageExe`); |
| 84 | + |
| 85 | + const files = await treeProvider.getChildren(childFolder); |
| 86 | + const file = files.find(n => n.name === "main.swift"); |
| 87 | + expect(file).to.not.be.undefined; |
| 88 | + |
| 89 | + expect(file?.path).to.equal( |
| 90 | + `${testAssetPath("defaultPackage")}/Sources/PackageExe/main.swift` |
| 91 | + ); |
| 92 | + }); |
| 93 | + |
| 94 | + test("Lists remote dependency file structure", async () => { |
| 95 | + const items = await treeProvider.getChildren(); |
| 96 | + |
| 97 | + const dep = items.find(n => n.name === "swift-markdown") as PackageNode; |
| 98 | + expect(dep).to.not.be.undefined; |
| 99 | + |
| 100 | + const folders = await treeProvider.getChildren(dep); |
| 101 | + const folder = folders.find(n => n.name === "Sources"); |
| 102 | + expect(folder).to.not.be.undefined; |
| 103 | + |
| 104 | + const path = `${testAssetPath("dependencies")}/.build/checkouts/swift-markdown`; |
| 105 | + expect(folder?.path).to.equal(`${path}/Sources`); |
| 106 | + |
| 107 | + const childFolders = await treeProvider.getChildren(folder); |
| 108 | + const childFolder = childFolders.find(n => n.name === "CAtomic"); |
| 109 | + expect(childFolder).to.not.be.undefined; |
| 110 | + |
| 111 | + expect(childFolder?.path).to.equal(`${path}/Sources/CAtomic`); |
| 112 | + |
| 113 | + const files = await treeProvider.getChildren(childFolder); |
| 114 | + const file = files.find(n => n.name === "CAtomic.c"); |
| 115 | + expect(file).to.not.be.undefined; |
| 116 | + |
| 117 | + expect(file?.path).to.equal(`${path}/Sources/CAtomic/CAtomic.c`); |
| 118 | + }); |
| 119 | +}); |
0 commit comments