|
| 1 | +import { deepStrictEqual } from "assert"; |
| 2 | +import { dirname } from "path"; |
| 3 | +import { fileURLToPath } from "url"; |
| 4 | +import { resolveCompilerOptions } from "../../src/config/index.js"; |
| 5 | +import { NodeHost } from "../../src/core/node-host.js"; |
| 6 | +import { resolvePath } from "../../src/index.js"; |
| 7 | +import { expectDiagnosticEmpty, expectDiagnostics } from "../../src/testing/expect.js"; |
| 8 | + |
| 9 | +const scenarioRoot = resolvePath( |
| 10 | + dirname(fileURLToPath(import.meta.url)), |
| 11 | + "../../../test/config/scenarios" |
| 12 | +); |
| 13 | + |
| 14 | +describe("compiler: resolve compiler options", () => { |
| 15 | + const tspOutputPath = resolvePath(`${process.cwd()}/tsp-output`); |
| 16 | + describe("specifying explicit config file", () => { |
| 17 | + const resolveOptions = async (path: string) => { |
| 18 | + const fullPath = resolvePath(scenarioRoot, path); |
| 19 | + return await resolveCompilerOptions(NodeHost, { |
| 20 | + entrypoint: fullPath, // not really used here |
| 21 | + configPath: fullPath, |
| 22 | + }); |
| 23 | + }; |
| 24 | + |
| 25 | + it("loads config at the given path", async () => { |
| 26 | + const [options, diagnostics] = await resolveOptions("custom/myConfig.yaml"); |
| 27 | + expectDiagnosticEmpty(diagnostics); |
| 28 | + |
| 29 | + deepStrictEqual(options, { |
| 30 | + config: resolvePath(scenarioRoot, "custom/myConfig.yaml"), |
| 31 | + emit: ["openapi"], |
| 32 | + options: {}, |
| 33 | + outputDir: tspOutputPath, |
| 34 | + }); |
| 35 | + }); |
| 36 | + |
| 37 | + it("emit diagnostics", async () => { |
| 38 | + const [_, diagnostics] = await resolveOptions("not-found.yaml"); |
| 39 | + expectDiagnostics(diagnostics, { |
| 40 | + code: "file-not-found", |
| 41 | + message: `File ${resolvePath(scenarioRoot, "not-found.yaml")} not found.`, |
| 42 | + }); |
| 43 | + }); |
| 44 | + }); |
| 45 | +}); |
0 commit comments