diff --git a/tests/config.test.ts b/tests/config.test.ts index 9e11b7c..60148d4 100644 --- a/tests/config.test.ts +++ b/tests/config.test.ts @@ -4,9 +4,9 @@ import { Console } from "console" import { LogLevel, ScaffoldCmdConfig } from "../src/types" import * as config from "../src/config" import { resolve } from "../src/utils" -// @ts-ignore -import * as configFile from "../scaffold.config" +import configFile from "./test-config" import { findConfigFile } from "../src/config" +import path from "path" jest.mock("../src/git", () => { return { @@ -69,7 +69,7 @@ describe("config", () => { describe("parseConfigFile", () => { test("normal config does not change", async () => { const tmpDir = `/tmp/scaffold-config-${Date.now()}` - const { quiet, tmpDir: _tmpDir, version, ...conf } = blankCliConf + const { quiet: _, tmpDir: _tmpDir, version: __, ...conf } = blankCliConf expect( await parseConfigFile({ ...blankCliConf, @@ -98,6 +98,20 @@ describe("config", () => { }) expect(result?.data?.num).toEqual("1234") }) + test("CLI output overrides config file output", async () => { + const tmpDir = `/tmp/scaffold-config-${Date.now()}` + + const result = await parseConfigFile({ + ...blankCliConf, + config: path.resolve(__dirname, "test-config.js"), + key: "component", + output: "examples/test-output/override", + name: "Component", + tmpDir, + }) + + expect(result.output).toEqual("examples/test-output/override") + }) }) }) @@ -114,10 +128,10 @@ describe("config", () => { test("gets local file config", async () => { const resultFn = await config.getLocalConfig({ - config: "scaffold.config.js", + config: path.join(__dirname, "test-config.js"), logLevel: LogLevel.none, }) - const result = await resolve(resultFn, {} as any) + const result = (await resolve(resultFn, {} as ScaffoldCmdConfig)).default expect(result).toEqual(configFile) }) }) diff --git a/tests/test-config.d.ts b/tests/test-config.d.ts new file mode 100644 index 0000000..ab05321 --- /dev/null +++ b/tests/test-config.d.ts @@ -0,0 +1,3 @@ +declare const config: import("../dist").ScaffoldConfigFile; +export = config; + diff --git a/tests/test-config.js b/tests/test-config.js new file mode 100644 index 0000000..56c7ccd --- /dev/null +++ b/tests/test-config.js @@ -0,0 +1,24 @@ +// @ts-check +/** @type {import('../dist').ScaffoldConfigFile} */ +// eslint-disable-next-line no-undef +module.exports = (conf) => { + // eslint-disable-next-line no-undef + console.log("Config:", conf) + return { + default: { + templates: ["examples/test-input/Component"], + output: "examples/test-output", + data: { property: "myProp", value: "10" }, + }, + component: { + templates: ["examples/test-input/Component"], + output: "examples/test-output/component", + data: { property: "myProp", value: "10" }, + }, + configs: { + templates: ["examples/test-input/**/.*"], + output: "examples/test-output/configs", + name: "---", + }, + } +}