|
| 1 | +import { join } from "path"; |
| 2 | +import { findVariantAnalysisQlPackRoot } from "../../../src/variant-analysis/ql"; |
| 3 | +import "../../matchers/toEqualPath"; |
| 4 | + |
| 5 | +describe("findVariantAnalysisQlPackRoot", () => { |
| 6 | + const testDataDir = join( |
| 7 | + __dirname, |
| 8 | + "../../data/variant-analysis-query-packs", |
| 9 | + ); |
| 10 | + |
| 11 | + const workspaceFolders = [ |
| 12 | + getFullPath("workspace1"), |
| 13 | + getFullPath("workspace2"), |
| 14 | + ]; |
| 15 | + |
| 16 | + function getFullPath(relativePath: string) { |
| 17 | + return join(testDataDir, relativePath); |
| 18 | + } |
| 19 | + |
| 20 | + it("should throw an error if no query files are provided", async () => { |
| 21 | + await expect( |
| 22 | + findVariantAnalysisQlPackRoot([], workspaceFolders), |
| 23 | + ).rejects.toThrow("No query files provided"); |
| 24 | + }); |
| 25 | + |
| 26 | + it("should return the pack root of a single query in a pack", async () => { |
| 27 | + const queryFiles = [getFullPath("workspace1/pack1/query1.ql")]; |
| 28 | + |
| 29 | + const packRoot = await findVariantAnalysisQlPackRoot( |
| 30 | + queryFiles, |
| 31 | + workspaceFolders, |
| 32 | + ); |
| 33 | + |
| 34 | + expect(packRoot).toEqualPath(getFullPath("workspace1/pack1")); |
| 35 | + }); |
| 36 | + |
| 37 | + it("should return the pack root of a single query not in a pack", async () => { |
| 38 | + const queryFiles = [getFullPath("workspace1/query1.ql")]; |
| 39 | + |
| 40 | + const packRoot = await findVariantAnalysisQlPackRoot( |
| 41 | + queryFiles, |
| 42 | + workspaceFolders, |
| 43 | + ); |
| 44 | + |
| 45 | + expect(packRoot).toEqualPath(getFullPath("workspace1")); |
| 46 | + }); |
| 47 | + |
| 48 | + it("should return the pack root of a single query not in a pack or workspace", async () => { |
| 49 | + const queryFiles = [getFullPath("dir1/query1.ql")]; |
| 50 | + |
| 51 | + const packRoot = await findVariantAnalysisQlPackRoot( |
| 52 | + queryFiles, |
| 53 | + workspaceFolders, |
| 54 | + ); |
| 55 | + |
| 56 | + expect(packRoot).toEqualPath(getFullPath("dir1")); |
| 57 | + }); |
| 58 | + |
| 59 | + it("should throw an error if some queries are in a pack and some are not", async () => { |
| 60 | + const queryFiles = [ |
| 61 | + getFullPath("workspace1/pack1/query1.ql"), |
| 62 | + getFullPath("workspace1/query1.ql"), |
| 63 | + ]; |
| 64 | + |
| 65 | + await expect( |
| 66 | + findVariantAnalysisQlPackRoot(queryFiles, workspaceFolders), |
| 67 | + ).rejects.toThrow("Some queries are in a pack and some aren't"); |
| 68 | + }); |
| 69 | + |
| 70 | + it("should throw an error if queries are in different packs", async () => { |
| 71 | + const queryFiles = [ |
| 72 | + getFullPath("workspace1/pack1/query1.ql"), |
| 73 | + getFullPath("workspace1/pack2/query1.ql"), |
| 74 | + ]; |
| 75 | + |
| 76 | + await expect( |
| 77 | + findVariantAnalysisQlPackRoot(queryFiles, workspaceFolders), |
| 78 | + ).rejects.toThrow("Some queries are in different packs"); |
| 79 | + }); |
| 80 | + |
| 81 | + it("should throw an error if query files are not in a pack and in different workspace folders", async () => { |
| 82 | + const queryFiles = [ |
| 83 | + getFullPath("workspace1/query1.ql"), |
| 84 | + getFullPath("workspace2/query1.ql"), |
| 85 | + ]; |
| 86 | + |
| 87 | + await expect( |
| 88 | + findVariantAnalysisQlPackRoot(queryFiles, workspaceFolders), |
| 89 | + ).rejects.toThrow( |
| 90 | + "Queries that are not part of a pack need to be in the same workspace folder", |
| 91 | + ); |
| 92 | + }); |
| 93 | + |
| 94 | + it("should throw an error if query files are not part of any workspace folder", async () => { |
| 95 | + const queryFiles = [ |
| 96 | + getFullPath("workspace3/query1.ql"), |
| 97 | + getFullPath("workspace3/query2.ql"), |
| 98 | + ]; |
| 99 | + |
| 100 | + await expect( |
| 101 | + findVariantAnalysisQlPackRoot(queryFiles, workspaceFolders), |
| 102 | + ).rejects.toThrow( |
| 103 | + "Queries that are not part of a pack need to be part of the workspace", |
| 104 | + ); |
| 105 | + }); |
| 106 | + |
| 107 | + it("should return the common parent directory if no queries are in a pack", async () => { |
| 108 | + const queryFiles = [ |
| 109 | + getFullPath("workspace1/query1.ql"), |
| 110 | + getFullPath("workspace1/dir1/query1.ql"), |
| 111 | + ]; |
| 112 | + |
| 113 | + const result = await findVariantAnalysisQlPackRoot( |
| 114 | + queryFiles, |
| 115 | + workspaceFolders, |
| 116 | + ); |
| 117 | + |
| 118 | + expect(result).toEqualPath(getFullPath("workspace1")); |
| 119 | + }); |
| 120 | + |
| 121 | + it("should return the pack root if all query files are in the same pack", async () => { |
| 122 | + const queryFiles = [ |
| 123 | + getFullPath("workspace1/pack1/query1.ql"), |
| 124 | + getFullPath("workspace1/pack1/query2.ql"), |
| 125 | + ]; |
| 126 | + |
| 127 | + const result = await findVariantAnalysisQlPackRoot( |
| 128 | + queryFiles, |
| 129 | + workspaceFolders, |
| 130 | + ); |
| 131 | + |
| 132 | + expect(result).toEqualPath(getFullPath("workspace1/pack1")); |
| 133 | + }); |
| 134 | +}); |
0 commit comments