|
| 1 | +import { FolderStructureRule } from "../src/rules/folder-structure.js"; |
| 2 | +import { TsvTestHost } from "./tsv-test-host.js"; |
| 3 | +import { strict as assert } from "node:assert"; |
| 4 | + |
| 5 | +describe("folder-structure", function () { |
| 6 | + it("should fail if tspconfig has incorrect extension", async function () { |
| 7 | + let host = new TsvTestHost(); |
| 8 | + host.globby = async () => { |
| 9 | + return ["/foo/bar/tspconfig.yml"]; |
| 10 | + }; |
| 11 | + |
| 12 | + const result = await new FolderStructureRule().execute(host, TsvTestHost.folder); |
| 13 | + assert(result.errorOutput); |
| 14 | + assert(result.errorOutput.includes("Invalid config file")); |
| 15 | + }); |
| 16 | + |
| 17 | + it("should fail if folder under specification/ is capitalized", async function () { |
| 18 | + let host = new TsvTestHost(); |
| 19 | + host.globby = async () => { |
| 20 | + return ["/foo/bar/tspconfig.yaml"]; |
| 21 | + }; |
| 22 | + host.normalizePath = () => { |
| 23 | + return "/gitroot"; |
| 24 | + }; |
| 25 | + |
| 26 | + const result = await new FolderStructureRule().execute(host, "/gitroot/specification/Foo/Foo"); |
| 27 | + assert(result.errorOutput); |
| 28 | + assert(result.errorOutput.includes("must be lower case")); |
| 29 | + }); |
| 30 | + |
| 31 | + it("should fail if package folder is more than 3 levels deep", async function () { |
| 32 | + let host = new TsvTestHost(); |
| 33 | + host.globby = async () => { |
| 34 | + return ["/foo/bar/tspconfig.yaml"]; |
| 35 | + }; |
| 36 | + host.normalizePath = () => { |
| 37 | + return "/gitroot"; |
| 38 | + }; |
| 39 | + |
| 40 | + const result = await new FolderStructureRule().execute( |
| 41 | + host, |
| 42 | + "/gitroot/specification/foo/Foo/Foo/Foo", |
| 43 | + ); |
| 44 | + assert(result.errorOutput); |
| 45 | + assert(result.errorOutput.includes("3 levels or less")); |
| 46 | + }); |
| 47 | + |
| 48 | + it("should fail if second level folder not capitalized at after each '.' ", async function () { |
| 49 | + let host = new TsvTestHost(); |
| 50 | + host.globby = async () => { |
| 51 | + return ["/foo/bar/tspconfig.yaml"]; |
| 52 | + }; |
| 53 | + host.normalizePath = () => { |
| 54 | + return "/gitroot"; |
| 55 | + }; |
| 56 | + |
| 57 | + const result = await new FolderStructureRule().execute( |
| 58 | + host, |
| 59 | + "/gitroot/specification/foo/Foo.foo", |
| 60 | + ); |
| 61 | + assert(result.errorOutput); |
| 62 | + assert(result.errorOutput.includes("must be capitalized")); |
| 63 | + }); |
| 64 | + |
| 65 | + it("should fail if Shared does not follow Management ", async function () { |
| 66 | + let host = new TsvTestHost(); |
| 67 | + host.globby = async () => { |
| 68 | + return ["/foo/bar/tspconfig.yaml"]; |
| 69 | + }; |
| 70 | + host.normalizePath = () => { |
| 71 | + return "/gitroot"; |
| 72 | + }; |
| 73 | + |
| 74 | + const result = await new FolderStructureRule().execute( |
| 75 | + host, |
| 76 | + "/gitroot/specification/foo/Foo.Management.Foo.Shared", |
| 77 | + ); |
| 78 | + assert(result.errorOutput); |
| 79 | + assert(result.errorOutput.includes("should follow")); |
| 80 | + }); |
| 81 | + |
| 82 | + it("should fail if folder doesn't contain main.tsp nor client.tsp", async function () { |
| 83 | + let host = new TsvTestHost(); |
| 84 | + host.globby = async () => { |
| 85 | + return ["/foo/bar/tspconfig.yaml"]; |
| 86 | + }; |
| 87 | + host.normalizePath = () => { |
| 88 | + return "/gitroot"; |
| 89 | + }; |
| 90 | + host.checkFileExists = async (file: string) => { |
| 91 | + if (file.includes("main.tsp")) { |
| 92 | + return false; |
| 93 | + } else if (file.includes("client.tsp")) { |
| 94 | + return false; |
| 95 | + } |
| 96 | + return true; |
| 97 | + }; |
| 98 | + |
| 99 | + const result = await new FolderStructureRule().execute( |
| 100 | + host, |
| 101 | + "/gitroot/specification/foo/Foo.Management", |
| 102 | + ); |
| 103 | + |
| 104 | + assert(result.errorOutput); |
| 105 | + assert(result.errorOutput.includes("must contain")); |
| 106 | + }); |
| 107 | + |
| 108 | + it("should fail if folder doesn't contain examples when main.tsp exists", async function () { |
| 109 | + let host = new TsvTestHost(); |
| 110 | + host.globby = async () => { |
| 111 | + return ["/foo/bar/tspconfig.yaml"]; |
| 112 | + }; |
| 113 | + host.normalizePath = () => { |
| 114 | + return "/gitroot"; |
| 115 | + }; |
| 116 | + host.checkFileExists = async (file: string) => { |
| 117 | + if (file.includes("main.tsp")) { |
| 118 | + return true; |
| 119 | + } else if (file.includes("examples")) { |
| 120 | + return false; |
| 121 | + } |
| 122 | + return true; |
| 123 | + }; |
| 124 | + |
| 125 | + const result = await new FolderStructureRule().execute( |
| 126 | + host, |
| 127 | + "/gitroot/specification/foo/Foo.Management", |
| 128 | + ); |
| 129 | + |
| 130 | + assert(result.errorOutput); |
| 131 | + assert(result.errorOutput.includes("must contain")); |
| 132 | + }); |
| 133 | + |
| 134 | + it("should fail if non-shared folder doesn't contain tspconfig", async function () { |
| 135 | + let host = new TsvTestHost(); |
| 136 | + host.globby = async () => { |
| 137 | + return ["/foo/bar/tspconfig.yaml"]; |
| 138 | + }; |
| 139 | + host.normalizePath = () => { |
| 140 | + return "/gitroot"; |
| 141 | + }; |
| 142 | + host.checkFileExists = async (file: string) => { |
| 143 | + if (file.includes("tspconfig.yaml")) { |
| 144 | + return false; |
| 145 | + } |
| 146 | + return true; |
| 147 | + }; |
| 148 | + |
| 149 | + const result = await new FolderStructureRule().execute( |
| 150 | + host, |
| 151 | + "/gitroot/specification/foo/Foo.Management", |
| 152 | + ); |
| 153 | + |
| 154 | + assert(result.errorOutput); |
| 155 | + assert(result.errorOutput.includes("must contain")); |
| 156 | + }); |
| 157 | +}); |
0 commit comments