diff --git a/.gitignore b/.gitignore index 1c905308..1bee3e4c 100644 --- a/.gitignore +++ b/.gitignore @@ -41,17 +41,13 @@ jspm_packages .DS_Store /dist -# Test Build Directories -/dist_test -/sample_react_project/ -/sample_custom_react_project/ /keycloakify_starter_test/ +/sample_custom_react_project/ +/sample_react_project/ /.yarn_home/ .idea -/keycloak_email -/build_keycloak /src/login/i18n/baseMessages/ /src/account/i18n/baseMessages/ diff --git a/scripts/test-keycloakify-starter.ts b/scripts/test-keycloakify-starter.ts index f443fa39..af512083 100644 --- a/scripts/test-keycloakify-starter.ts +++ b/scripts/test-keycloakify-starter.ts @@ -18,12 +18,12 @@ writeFileSync(path.join(process.cwd(), "dist", "package.json"), JSON.stringify(p try { execSync("yarn unlink"); } catch {} -execSync("yarn link", { cwd: path.join(process.cwd(), "dist") }); +execSync("yarn link", { "cwd": path.join(process.cwd(), "dist") }); // Clone latest keycloakify-starter and link to keycloakify output execSync(`git clone https://github.com/keycloakify/keycloakify-starter.git ${testDir}`); -execSync("yarn install", { cwd: path.join(process.cwd(), testDir) }); -execSync("yarn link keycloakify", { cwd: path.join(process.cwd(), testDir) }); +execSync("yarn install", { "cwd": path.join(process.cwd(), testDir) }); +execSync("yarn link keycloakify", { "cwd": path.join(process.cwd(), testDir) }); //Ensure keycloak theme can be built -execSync("yarn build-keycloak-theme", { cwd: path.join(process.cwd(), testDir) }); +execSync("yarn build-keycloak-theme", { "cwd": path.join(process.cwd(), testDir) }); diff --git a/test/bin/setupCustomReactProject.spec.ts b/test/bin/setupCustomReactProject.spec.ts index 3a4dc069..9d14c6e0 100644 --- a/test/bin/setupCustomReactProject.spec.ts +++ b/test/bin/setupCustomReactProject.spec.ts @@ -19,16 +19,16 @@ const nativeCwd = process.cwd; vi.mock("keycloakify/bin/keycloakify/parsed-package-json", async () => ({ ...((await vi.importActual("keycloakify/bin/keycloakify/parsed-package-json")) as Record), getParsedPackageJson: () => ({ - keycloakify: { - appInputPath: "./custom_input/build", - keycloakBuildDir: "./custom_output" + "keycloakify": { + "appInputPath": "./custom_input/build", + "keycloakBuildDir": "./custom_output" } }) })); vi.mock("keycloakify/bin/promptKeycloakVersion", async () => ({ ...((await vi.importActual("keycloakify/bin/promptKeycloakVersion")) as Record), - promptKeycloakVersion: () => ({ keycloakVersion: "11.0.3" }) + promptKeycloakVersion: () => ({ "keycloakVersion": "11.0.3" }) })); describe("Sample Project", () => { @@ -38,6 +38,7 @@ describe("Sample Project", () => { }); afterAll(() => { + fs.rmSync(sampleReactProjectDirPath, { "recursive": true }); process.cwd = nativeCwd; }); beforeEach(() => { diff --git a/test/bin/setupSampleReactProject.spec.ts b/test/bin/setupSampleReactProject.spec.ts index 5d85993a..7c6143a4 100644 --- a/test/bin/setupSampleReactProject.spec.ts +++ b/test/bin/setupSampleReactProject.spec.ts @@ -35,6 +35,7 @@ describe("Sample Project", () => { }); afterAll(() => { + fs.rmSync(sampleReactProjectDirPath, { "recursive": true }); process.cwd = nativeCwd; }); beforeEach(() => { diff --git a/test/lib/tools/AndByDiscriminatingKey.ts b/test/lib/tools/AndByDiscriminatingKey.ts new file mode 100644 index 00000000..3c3f73a0 --- /dev/null +++ b/test/lib/tools/AndByDiscriminatingKey.ts @@ -0,0 +1,91 @@ +import { AndByDiscriminatingKey } from "keycloakify/tools/AndByDiscriminatingKey"; +import { assert } from "tsafe/assert"; +import type { Equals } from "tsafe"; + +{ + type Base = { pageId: "a"; onlyA: string } | { pageId: "b"; onlyB: string } | { pageId: "only base"; onlyBase: string }; + + type Extension = { pageId: "a"; onlyExtA: string } | { pageId: "b"; onlyExtB: string } | { pageId: "only ext"; onlyExt: string }; + + type Got = AndByDiscriminatingKey<"pageId", Extension, Base>; + + type Expected = + | { pageId: "a"; onlyA: string; onlyExtA: string } + | { pageId: "b"; onlyB: string; onlyExtB: string } + | { pageId: "only base"; onlyBase: string } + | { pageId: "only ext"; onlyExt: string }; + + assert>(); + + const x: Got = null as any; + + if (x.pageId === "a") { + x.onlyA; + x.onlyExtA; + + //@ts-expect-error + x.onlyB; + + //@ts-expect-error + x.onlyBase; + + //@ts-expect-error + x.onlyExt; + } + + if (x.pageId === "b") { + x.onlyB; + x.onlyExtB; + + //@ts-expect-error + x.onlyA; + + //@ts-expect-error + x.onlyBase; + + //@ts-expect-error + x.onlyExt; + } + + if (x.pageId === "only base") { + x.onlyBase; + + //@ts-expect-error + x.onlyA; + + //@ts-expect-error + x.onlyB; + + //@ts-expect-error + x.onlyExt; + } + + if (x.pageId === "only ext") { + x.onlyExt; + + //@ts-expect-error + x.onlyA; + + //@ts-expect-error + x.onlyB; + + //@ts-expect-error + x.onlyBase; + } +} + +{ + type Base = { pageId: "a"; onlyA: string } | { pageId: "b"; onlyB: string } | { pageId: "only base"; onlyBase: string }; + + type Extension = { pageId: "only ext"; onlyExt: string }; + + type Got = AndByDiscriminatingKey<"pageId", Extension, Base>; + + type Expected = + | { pageId: "a"; onlyA: string } + | { pageId: "b"; onlyB: string } + | { pageId: "only base"; onlyBase: string } + | { pageId: "only ext"; onlyExt: string }; + + assert>(); +} diff --git a/test/lib/tools/AndByDiscriminatingKey.type.spec.ts b/test/lib/tools/AndByDiscriminatingKey.type.spec.ts deleted file mode 100644 index 8edb9f87..00000000 --- a/test/lib/tools/AndByDiscriminatingKey.type.spec.ts +++ /dev/null @@ -1,94 +0,0 @@ -import { AndByDiscriminatingKey } from "keycloakify/tools/AndByDiscriminatingKey"; -import { assert } from "tsafe/assert"; -import type { Equals } from "tsafe"; -import { it, describe } from "vitest"; - -// These test case names are intentionally vague, because I'm not sure what each are testing individually -describe("AndByDiscriminatingKey", () => { - it("Test Case 1", () => { - type Base = { pageId: "a"; onlyA: string } | { pageId: "b"; onlyB: string } | { pageId: "only base"; onlyBase: string }; - - type Extension = { pageId: "a"; onlyExtA: string } | { pageId: "b"; onlyExtB: string } | { pageId: "only ext"; onlyExt: string }; - - type Got = AndByDiscriminatingKey<"pageId", Extension, Base>; - - type Expected = - | { pageId: "a"; onlyA: string; onlyExtA: string } - | { pageId: "b"; onlyB: string; onlyExtB: string } - | { pageId: "only base"; onlyBase: string } - | { pageId: "only ext"; onlyExt: string }; - - assert>(); - - const x: Got = {} as any; - - if (x.pageId === "a") { - x.onlyA; - x.onlyExtA; - - //@ts-expect-error - x.onlyB; - - //@ts-expect-error - x.onlyBase; - - //@ts-expect-error - x.onlyExt; - } - - if (x.pageId === "b") { - x.onlyB; - x.onlyExtB; - - //@ts-expect-error - x.onlyA; - - //@ts-expect-error - x.onlyBase; - - //@ts-expect-error - x.onlyExt; - } - - if (x.pageId === "only base") { - x.onlyBase; - - //@ts-expect-error - x.onlyA; - - //@ts-expect-error - x.onlyB; - - //@ts-expect-error - x.onlyExt; - } - - if (x.pageId === "only ext") { - x.onlyExt; - - //@ts-expect-error - x.onlyA; - - //@ts-expect-error - x.onlyB; - - //@ts-expect-error - x.onlyBase; - } - }); - it("Test Case 2", () => { - type Base = { pageId: "a"; onlyA: string } | { pageId: "b"; onlyB: string } | { pageId: "only base"; onlyBase: string }; - - type Extension = { pageId: "only ext"; onlyExt: string }; - - type Got = AndByDiscriminatingKey<"pageId", Extension, Base>; - - type Expected = - | { pageId: "a"; onlyA: string } - | { pageId: "b"; onlyB: string } - | { pageId: "only base"; onlyBase: string } - | { pageId: "only ext"; onlyExt: string }; - - assert>(); - }); -}); diff --git a/test/tsconfig.json b/test/tsconfig.json index 7239f999..8c6c685d 100644 --- a/test/tsconfig.json +++ b/test/tsconfig.json @@ -10,7 +10,7 @@ "newLine": "LF", "noUnusedLocals": true, "noUnusedParameters": true, - "incremental": true, + "incremental": false, "strict": true, "downlevelIteration": true, "jsx": "react-jsx", diff --git a/vitest.config.ts b/vitest.config.ts index aec1da63..1af3eb95 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -3,10 +3,10 @@ import { defineConfig } from "vite"; import path from "path"; export default defineConfig({ - test: { - alias: { + "test": { + "alias": { "keycloakify": path.resolve(__dirname, "./src") }, - watchExclude: ["**/node_modules/**", "**/dist/**", "**/sample_react_project/**", "**/sample_custom_react_project/**"] + "watchExclude": ["**/node_modules/**", "**/dist/**", "**/sample_react_project/**", "**/sample_custom_react_project/**"] } });