Update prettier configuration
This commit is contained in:
@ -1,11 +1,17 @@
|
||||
import { replaceImportsInJsCode_vite } from "keycloakify/bin/keycloakify/replacers/replaceImportsInJsCode/vite";
|
||||
import { replaceImportsInJsCode_webpack } from "keycloakify/bin/keycloakify/replacers/replaceImportsInJsCode/webpack";
|
||||
import { generateCssCodeToDefineGlobals, replaceImportsInCssCode } from "keycloakify/bin/keycloakify/replacers/replaceImportsInCssCode";
|
||||
import {
|
||||
generateCssCodeToDefineGlobals,
|
||||
replaceImportsInCssCode
|
||||
} from "keycloakify/bin/keycloakify/replacers/replaceImportsInCssCode";
|
||||
import { replaceImportsInInlineCssCode } from "keycloakify/bin/keycloakify/replacers/replaceImportsInInlineCssCode";
|
||||
import { same } from "evt/tools/inDepth/same";
|
||||
import { expect, it, describe } from "vitest";
|
||||
import { isSameCode } from "../tools/isSameCode";
|
||||
import { basenameOfTheKeycloakifyResourcesDir, nameOfTheGlobal } from "keycloakify/bin/shared/constants";
|
||||
import {
|
||||
basenameOfTheKeycloakifyResourcesDir,
|
||||
nameOfTheGlobal
|
||||
} from "keycloakify/bin/shared/constants";
|
||||
|
||||
describe("js replacer - vite", () => {
|
||||
it("replaceImportsInJsCode_vite - 1", () => {
|
||||
@ -14,12 +20,12 @@ describe("js replacer - vite", () => {
|
||||
const jsCodeUntransformed = `${before}Hv=function(e){return"/foo-bar-baz/"+e}${after}`;
|
||||
|
||||
const { fixedJsCode } = replaceImportsInJsCode_vite({
|
||||
"jsCode": jsCodeUntransformed,
|
||||
"basenameOfAssetsFiles": [],
|
||||
"buildOptions": {
|
||||
"reactAppBuildDirPath": "/Users/someone/github/keycloakify-starter/dist/",
|
||||
"assetsDirPath": "/Users/someone/github/keycloakify-starter/dist/assets/",
|
||||
"urlPathname": "/foo-bar-baz/"
|
||||
jsCode: jsCodeUntransformed,
|
||||
basenameOfAssetsFiles: [],
|
||||
buildOptions: {
|
||||
reactAppBuildDirPath: "/Users/someone/github/keycloakify-starter/dist/",
|
||||
assetsDirPath: "/Users/someone/github/keycloakify-starter/dist/assets/",
|
||||
urlPathname: "/foo-bar-baz/"
|
||||
}
|
||||
});
|
||||
|
||||
@ -34,12 +40,12 @@ describe("js replacer - vite", () => {
|
||||
const jsCodeUntransformed = `${before}Hv=function(e){return"/foo/bar/baz/"+e}${after}`;
|
||||
|
||||
const { fixedJsCode } = replaceImportsInJsCode_vite({
|
||||
"jsCode": jsCodeUntransformed,
|
||||
"basenameOfAssetsFiles": [],
|
||||
"buildOptions": {
|
||||
"reactAppBuildDirPath": "/Users/someone/github/keycloakify-starter/dist/",
|
||||
"assetsDirPath": "/Users/someone/github/keycloakify-starter/dist/assets/",
|
||||
"urlPathname": "/foo/bar/baz/"
|
||||
jsCode: jsCodeUntransformed,
|
||||
basenameOfAssetsFiles: [],
|
||||
buildOptions: {
|
||||
reactAppBuildDirPath: "/Users/someone/github/keycloakify-starter/dist/",
|
||||
assetsDirPath: "/Users/someone/github/keycloakify-starter/dist/assets/",
|
||||
urlPathname: "/foo/bar/baz/"
|
||||
}
|
||||
});
|
||||
|
||||
@ -62,23 +68,29 @@ describe("js replacer - vite", () => {
|
||||
|
||||
for (const { reactAppBuildDirPath, assetsDirPath, systemType } of [
|
||||
{
|
||||
"systemType": "posix",
|
||||
"reactAppBuildDirPath": "/Users/someone/github/keycloakify-starter/dist",
|
||||
"assetsDirPath": "/Users/someone/github/keycloakify-starter/dist/assets"
|
||||
systemType: "posix",
|
||||
reactAppBuildDirPath: "/Users/someone/github/keycloakify-starter/dist",
|
||||
assetsDirPath: "/Users/someone/github/keycloakify-starter/dist/assets"
|
||||
},
|
||||
{
|
||||
"systemType": "win32",
|
||||
"reactAppBuildDirPath": "C:\\\\Users\\someone\\github\\keycloakify-starter\\dist",
|
||||
"assetsDirPath": "C:\\\\Users\\someone\\github\\keycloakify-starter\\dist\\assets"
|
||||
systemType: "win32",
|
||||
reactAppBuildDirPath:
|
||||
"C:\\\\Users\\someone\\github\\keycloakify-starter\\dist",
|
||||
assetsDirPath:
|
||||
"C:\\\\Users\\someone\\github\\keycloakify-starter\\dist\\assets"
|
||||
}
|
||||
] as const) {
|
||||
const { fixedJsCode } = replaceImportsInJsCode_vite({
|
||||
"jsCode": jsCodeUntransformed,
|
||||
"basenameOfAssetsFiles": ["Login-dJpPRzM4.js", "index-XwzrZ5Gu.js", "keycloakify-logo-mqjydaoZ.png"],
|
||||
"buildOptions": {
|
||||
jsCode: jsCodeUntransformed,
|
||||
basenameOfAssetsFiles: [
|
||||
"Login-dJpPRzM4.js",
|
||||
"index-XwzrZ5Gu.js",
|
||||
"keycloakify-logo-mqjydaoZ.png"
|
||||
],
|
||||
buildOptions: {
|
||||
reactAppBuildDirPath,
|
||||
assetsDirPath,
|
||||
"urlPathname": undefined
|
||||
urlPathname: undefined
|
||||
},
|
||||
systemType
|
||||
});
|
||||
@ -115,23 +127,29 @@ describe("js replacer - vite", () => {
|
||||
|
||||
for (const { reactAppBuildDirPath, assetsDirPath, systemType } of [
|
||||
{
|
||||
"systemType": "posix",
|
||||
"reactAppBuildDirPath": "/Users/someone/github/keycloakify-starter/dist",
|
||||
"assetsDirPath": "/Users/someone/github/keycloakify-starter/dist/foo/bar"
|
||||
systemType: "posix",
|
||||
reactAppBuildDirPath: "/Users/someone/github/keycloakify-starter/dist",
|
||||
assetsDirPath: "/Users/someone/github/keycloakify-starter/dist/foo/bar"
|
||||
},
|
||||
{
|
||||
"systemType": "win32",
|
||||
"reactAppBuildDirPath": "C:\\\\Users\\someone\\github\\keycloakify-starter\\dist",
|
||||
"assetsDirPath": "C:\\\\Users\\someone\\github\\keycloakify-starter\\dist\\foo\\bar"
|
||||
systemType: "win32",
|
||||
reactAppBuildDirPath:
|
||||
"C:\\\\Users\\someone\\github\\keycloakify-starter\\dist",
|
||||
assetsDirPath:
|
||||
"C:\\\\Users\\someone\\github\\keycloakify-starter\\dist\\foo\\bar"
|
||||
}
|
||||
] as const) {
|
||||
const { fixedJsCode } = replaceImportsInJsCode_vite({
|
||||
"jsCode": jsCodeUntransformed,
|
||||
"basenameOfAssetsFiles": ["Login-dJpPRzM4.js", "index-XwzrZ5Gu.js", "keycloakify-logo-mqjydaoZ.png"],
|
||||
"buildOptions": {
|
||||
jsCode: jsCodeUntransformed,
|
||||
basenameOfAssetsFiles: [
|
||||
"Login-dJpPRzM4.js",
|
||||
"index-XwzrZ5Gu.js",
|
||||
"keycloakify-logo-mqjydaoZ.png"
|
||||
],
|
||||
buildOptions: {
|
||||
reactAppBuildDirPath,
|
||||
assetsDirPath,
|
||||
"urlPathname": undefined
|
||||
urlPathname: undefined
|
||||
},
|
||||
systemType
|
||||
});
|
||||
@ -168,23 +186,29 @@ describe("js replacer - vite", () => {
|
||||
|
||||
for (const { reactAppBuildDirPath, assetsDirPath, systemType } of [
|
||||
{
|
||||
"systemType": "posix",
|
||||
"reactAppBuildDirPath": "/Users/someone/github/keycloakify-starter/dist",
|
||||
"assetsDirPath": "/Users/someone/github/keycloakify-starter/dist/assets"
|
||||
systemType: "posix",
|
||||
reactAppBuildDirPath: "/Users/someone/github/keycloakify-starter/dist",
|
||||
assetsDirPath: "/Users/someone/github/keycloakify-starter/dist/assets"
|
||||
},
|
||||
{
|
||||
"systemType": "win32",
|
||||
"reactAppBuildDirPath": "C:\\\\Users\\someone\\github\\keycloakify-starter\\dist",
|
||||
"assetsDirPath": "C:\\\\Users\\someone\\github\\keycloakify-starter\\dist\\assets"
|
||||
systemType: "win32",
|
||||
reactAppBuildDirPath:
|
||||
"C:\\\\Users\\someone\\github\\keycloakify-starter\\dist",
|
||||
assetsDirPath:
|
||||
"C:\\\\Users\\someone\\github\\keycloakify-starter\\dist\\assets"
|
||||
}
|
||||
] as const) {
|
||||
const { fixedJsCode } = replaceImportsInJsCode_vite({
|
||||
"jsCode": jsCodeUntransformed,
|
||||
"basenameOfAssetsFiles": ["Login-dJpPRzM4.js", "index-XwzrZ5Gu.js", "keycloakify-logo-mqjydaoZ.png"],
|
||||
"buildOptions": {
|
||||
jsCode: jsCodeUntransformed,
|
||||
basenameOfAssetsFiles: [
|
||||
"Login-dJpPRzM4.js",
|
||||
"index-XwzrZ5Gu.js",
|
||||
"keycloakify-logo-mqjydaoZ.png"
|
||||
],
|
||||
buildOptions: {
|
||||
reactAppBuildDirPath,
|
||||
assetsDirPath,
|
||||
"urlPathname": "/foo-bar-baz/"
|
||||
urlPathname: "/foo-bar-baz/"
|
||||
},
|
||||
systemType
|
||||
});
|
||||
@ -242,11 +266,11 @@ describe("js replacer - webpack", () => {
|
||||
`;
|
||||
|
||||
const { fixedJsCode } = replaceImportsInJsCode_webpack({
|
||||
"jsCode": jsCodeUntransformed,
|
||||
"buildOptions": {
|
||||
"reactAppBuildDirPath": "/Users/someone/github/keycloakify-starter/build",
|
||||
"assetsDirPath": "/Users/someone/github/keycloakify-starter/build/static",
|
||||
"urlPathname": undefined
|
||||
jsCode: jsCodeUntransformed,
|
||||
buildOptions: {
|
||||
reactAppBuildDirPath: "/Users/someone/github/keycloakify-starter/build",
|
||||
assetsDirPath: "/Users/someone/github/keycloakify-starter/build/static",
|
||||
urlPathname: undefined
|
||||
}
|
||||
});
|
||||
|
||||
@ -329,11 +353,11 @@ describe("js replacer - webpack", () => {
|
||||
const jsCodeUntransformed = `${before},n.p="/foo-bar/",${after}`;
|
||||
|
||||
const { fixedJsCode } = replaceImportsInJsCode_webpack({
|
||||
"jsCode": jsCodeUntransformed,
|
||||
"buildOptions": {
|
||||
"reactAppBuildDirPath": "/Users/someone/github/keycloakify-starter/build",
|
||||
"assetsDirPath": "/Users/someone/github/keycloakify-starter/build/static",
|
||||
"urlPathname": "/foo-bar/"
|
||||
jsCode: jsCodeUntransformed,
|
||||
buildOptions: {
|
||||
reactAppBuildDirPath: "/Users/someone/github/keycloakify-starter/build",
|
||||
assetsDirPath: "/Users/someone/github/keycloakify-starter/build/static",
|
||||
urlPathname: "/foo-bar/"
|
||||
}
|
||||
});
|
||||
|
||||
@ -349,11 +373,12 @@ describe("js replacer - webpack", () => {
|
||||
const jsCodeUntransformed = `${before},n.p="/foo/bar/",${after}`;
|
||||
|
||||
const { fixedJsCode } = replaceImportsInJsCode_webpack({
|
||||
"jsCode": jsCodeUntransformed,
|
||||
"buildOptions": {
|
||||
"reactAppBuildDirPath": "/Users/someone/github/keycloakify-starter/build",
|
||||
"assetsDirPath": "/Users/someone/github/keycloakify-starter/dist/build/static",
|
||||
"urlPathname": "/foo/bar/"
|
||||
jsCode: jsCodeUntransformed,
|
||||
buildOptions: {
|
||||
reactAppBuildDirPath: "/Users/someone/github/keycloakify-starter/build",
|
||||
assetsDirPath:
|
||||
"/Users/someone/github/keycloakify-starter/dist/build/static",
|
||||
urlPathname: "/foo/bar/"
|
||||
}
|
||||
});
|
||||
|
||||
@ -366,7 +391,7 @@ describe("js replacer - webpack", () => {
|
||||
describe("css replacer", () => {
|
||||
it("transforms absolute urls to css globals properly with no urlPathname", () => {
|
||||
const { fixedCssCode, cssGlobalsToDefine } = replaceImportsInCssCode({
|
||||
"cssCode": `
|
||||
cssCode: `
|
||||
.my-div {
|
||||
background: url(/logo192.png) no-repeat center center;
|
||||
}
|
||||
@ -398,16 +423,16 @@ describe("css replacer", () => {
|
||||
expect(isSameCode(fixedCssCode, fixedCssCodeExpected)).toBe(true);
|
||||
|
||||
const cssGlobalsToDefineExpected = {
|
||||
"urla882a969fd39473": "url(/logo192.png)",
|
||||
"urldd75cab58377c19": "url(/static/media/something.svg)"
|
||||
urla882a969fd39473: "url(/logo192.png)",
|
||||
urldd75cab58377c19: "url(/static/media/something.svg)"
|
||||
};
|
||||
|
||||
expect(same(cssGlobalsToDefine, cssGlobalsToDefineExpected)).toBe(true);
|
||||
|
||||
const { cssCodeToPrependInHead } = generateCssCodeToDefineGlobals({
|
||||
cssGlobalsToDefine,
|
||||
"buildOptions": {
|
||||
"urlPathname": undefined
|
||||
buildOptions: {
|
||||
urlPathname: undefined
|
||||
}
|
||||
});
|
||||
|
||||
@ -418,11 +443,13 @@ describe("css replacer", () => {
|
||||
}
|
||||
`;
|
||||
|
||||
expect(isSameCode(cssCodeToPrependInHead, cssCodeToPrependInHeadExpected)).toBe(true);
|
||||
expect(isSameCode(cssCodeToPrependInHead, cssCodeToPrependInHeadExpected)).toBe(
|
||||
true
|
||||
);
|
||||
});
|
||||
it("transforms absolute urls to css globals properly with custom urlPathname", () => {
|
||||
const { fixedCssCode, cssGlobalsToDefine } = replaceImportsInCssCode({
|
||||
"cssCode": `
|
||||
cssCode: `
|
||||
.my-div {
|
||||
background: url(/x/y/z/logo192.png) no-repeat center center;
|
||||
}
|
||||
@ -454,16 +481,16 @@ describe("css replacer", () => {
|
||||
expect(isSameCode(fixedCssCode, fixedCssCodeExpected)).toBe(true);
|
||||
|
||||
const cssGlobalsToDefineExpected = {
|
||||
"url749a3139386b2c8": "url(/x/y/z/logo192.png)",
|
||||
"url8bdc0887b97ac9a": "url(/x/y/z/static/media/something.svg)"
|
||||
url749a3139386b2c8: "url(/x/y/z/logo192.png)",
|
||||
url8bdc0887b97ac9a: "url(/x/y/z/static/media/something.svg)"
|
||||
};
|
||||
|
||||
expect(same(cssGlobalsToDefine, cssGlobalsToDefineExpected)).toBe(true);
|
||||
|
||||
const { cssCodeToPrependInHead } = generateCssCodeToDefineGlobals({
|
||||
cssGlobalsToDefine,
|
||||
"buildOptions": {
|
||||
"urlPathname": "/x/y/z/"
|
||||
buildOptions: {
|
||||
urlPathname: "/x/y/z/"
|
||||
}
|
||||
});
|
||||
|
||||
@ -474,7 +501,9 @@ describe("css replacer", () => {
|
||||
}
|
||||
`;
|
||||
|
||||
expect(isSameCode(cssCodeToPrependInHead, cssCodeToPrependInHeadExpected)).toBe(true);
|
||||
expect(isSameCode(cssCodeToPrependInHead, cssCodeToPrependInHeadExpected)).toBe(
|
||||
true
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@ -513,8 +542,8 @@ describe("inline css replacer", () => {
|
||||
it("transforms css for standalone app properly", () => {
|
||||
const { fixedCssCode } = replaceImportsInInlineCssCode({
|
||||
cssCode,
|
||||
"buildOptions": {
|
||||
"urlPathname": undefined
|
||||
buildOptions: {
|
||||
urlPathname: undefined
|
||||
}
|
||||
});
|
||||
|
||||
@ -591,8 +620,8 @@ describe("inline css replacer", () => {
|
||||
it("transforms css for standalone app properly", () => {
|
||||
const { fixedCssCode } = replaceImportsInInlineCssCode({
|
||||
cssCode,
|
||||
"buildOptions": {
|
||||
"urlPathname": "/x/y/z/"
|
||||
buildOptions: {
|
||||
urlPathname: "/x/y/z/"
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -6,11 +6,16 @@ export async function setupSampleReactProject(destDirPath: string) {
|
||||
const thisCodebaseRootDirPath = getThisCodebaseRootDirPath();
|
||||
|
||||
await downloadAndUnzip({
|
||||
"url": "https://github.com/keycloakify/keycloakify/releases/download/v0.0.1/sample_build_dir_and_package_json.zip",
|
||||
"destDirPath": destDirPath,
|
||||
"buildOptions": {
|
||||
"cacheDirPath": pathJoin(thisCodebaseRootDirPath, "node_modules", ".cache", "keycloakify"),
|
||||
"npmWorkspaceRootDirPath": thisCodebaseRootDirPath
|
||||
url: "https://github.com/keycloakify/keycloakify/releases/download/v0.0.1/sample_build_dir_and_package_json.zip",
|
||||
destDirPath: destDirPath,
|
||||
buildOptions: {
|
||||
cacheDirPath: pathJoin(
|
||||
thisCodebaseRootDirPath,
|
||||
"node_modules",
|
||||
".cache",
|
||||
"keycloakify"
|
||||
),
|
||||
npmWorkspaceRootDirPath: thisCodebaseRootDirPath
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -20,7 +20,9 @@ describe("crawl", () => {
|
||||
case path.join("root_dir", "sub_2_dir"):
|
||||
return [];
|
||||
default: {
|
||||
const enoent = new Error(`ENOENT: no such file or directory, scandir '${dir_path}'`);
|
||||
const enoent = new Error(
|
||||
`ENOENT: no such file or directory, scandir '${dir_path}'`
|
||||
);
|
||||
// @ts-ignore
|
||||
enoent.code = "ENOENT";
|
||||
// @ts-ignore
|
||||
@ -32,7 +34,9 @@ describe("crawl", () => {
|
||||
}
|
||||
}),
|
||||
lstatSync: vi.fn().mockImplementation((file_path: string) => {
|
||||
return { isDirectory: () => file_path.endsWith("_dir") };
|
||||
return {
|
||||
isDirectory: () => file_path.endsWith("_dir")
|
||||
};
|
||||
})
|
||||
};
|
||||
});
|
||||
@ -41,11 +45,17 @@ describe("crawl", () => {
|
||||
vi.resetAllMocks();
|
||||
});
|
||||
it("returns files under a given dir_path", async () => {
|
||||
const paths = crawl({ "dirPath": "root_dir/sub_1_dir/sub_3_dir", "returnedPathsType": "absolute" });
|
||||
const paths = crawl({
|
||||
dirPath: "root_dir/sub_1_dir/sub_3_dir",
|
||||
returnedPathsType: "absolute"
|
||||
});
|
||||
expect(paths).toEqual(["root_dir/sub_1_dir/sub_3_dir/file_5"]);
|
||||
});
|
||||
it("returns files recursively under a given dir_path", async () => {
|
||||
const paths = crawl({ "dirPath": "root_dir", "returnedPathsType": "absolute" });
|
||||
const paths = crawl({
|
||||
dirPath: "root_dir",
|
||||
returnedPathsType: "absolute"
|
||||
});
|
||||
expect(paths).toEqual([
|
||||
"root_dir/sub_1_dir/file_3",
|
||||
"root_dir/sub_1_dir/sub_3_dir/file_5",
|
||||
@ -56,7 +66,7 @@ describe("crawl", () => {
|
||||
});
|
||||
it("throw dir_path does not exist", async () => {
|
||||
try {
|
||||
crawl({ "dirPath": "404", "returnedPathsType": "absolute" });
|
||||
crawl({ dirPath: "404", returnedPathsType: "absolute" });
|
||||
} catch {
|
||||
expect(true);
|
||||
return;
|
||||
|
@ -4,12 +4,21 @@ import type { KcContext } from "keycloakify/login/kcContext";
|
||||
import { same } from "evt/tools/inDepth";
|
||||
import { assert } from "tsafe/assert";
|
||||
import type { Equals } from "tsafe";
|
||||
import { kcContextMocks, kcContextCommonMock } from "keycloakify/login/kcContext/kcContextMocks";
|
||||
import {
|
||||
kcContextMocks,
|
||||
kcContextCommonMock
|
||||
} from "keycloakify/login/kcContext/kcContextMocks";
|
||||
import { deepClone } from "keycloakify/tools/deepClone";
|
||||
import { expect, it, describe } from "vitest";
|
||||
|
||||
describe("createGetKcContext", () => {
|
||||
const authorizedMailDomains = ["example.com", "another-example.com", "*.yet-another-example.com", "*.example.com", "hello-world.com"];
|
||||
const authorizedMailDomains = [
|
||||
"example.com",
|
||||
"another-example.com",
|
||||
"*.yet-another-example.com",
|
||||
"*.example.com",
|
||||
"hello-world.com"
|
||||
];
|
||||
|
||||
const displayName = "this is an overwritten common value";
|
||||
|
||||
@ -33,25 +42,27 @@ describe("createGetKcContext", () => {
|
||||
aNonStandardValue2: string;
|
||||
};
|
||||
|
||||
const getKcContextProxy = (params: { mockPageId: ExtendKcContext<KcContextExtension>["pageId"] }) => {
|
||||
const getKcContextProxy = (params: {
|
||||
mockPageId: ExtendKcContext<KcContextExtension>["pageId"];
|
||||
}) => {
|
||||
const { mockPageId } = params;
|
||||
|
||||
const { getKcContext } = createGetKcContext<KcContextExtension>({
|
||||
"mockData": [
|
||||
mockData: [
|
||||
{
|
||||
"pageId": "login.ftl",
|
||||
"realm": { displayName }
|
||||
pageId: "login.ftl",
|
||||
realm: { displayName }
|
||||
},
|
||||
{
|
||||
"pageId": "info.ftl",
|
||||
pageId: "info.ftl",
|
||||
aNonStandardValue1
|
||||
},
|
||||
{
|
||||
"pageId": "register.ftl",
|
||||
pageId: "register.ftl",
|
||||
authorizedMailDomains
|
||||
},
|
||||
{
|
||||
"pageId": "my-extra-page-2.ftl",
|
||||
pageId: "my-extra-page-2.ftl",
|
||||
aNonStandardValue2
|
||||
}
|
||||
]
|
||||
@ -66,7 +77,7 @@ describe("createGetKcContext", () => {
|
||||
it("has proper API for login.ftl", () => {
|
||||
const pageId = "login.ftl";
|
||||
|
||||
const { kcContext } = getKcContextProxy({ "mockPageId": pageId });
|
||||
const { kcContext } = getKcContextProxy({ mockPageId: pageId });
|
||||
|
||||
assert(kcContext?.pageId === pageId);
|
||||
|
||||
@ -77,7 +88,11 @@ describe("createGetKcContext", () => {
|
||||
//NOTE: deepClone for printIfExists or other functions...
|
||||
deepClone(kcContext),
|
||||
(() => {
|
||||
const mock = deepClone(kcContextMocks.find(({ pageId: pageId_i }) => pageId_i === pageId)!);
|
||||
const mock = deepClone(
|
||||
kcContextMocks.find(
|
||||
({ pageId: pageId_i }) => pageId_i === pageId
|
||||
)!
|
||||
);
|
||||
|
||||
mock.realm.displayName = displayName;
|
||||
|
||||
@ -90,7 +105,7 @@ describe("createGetKcContext", () => {
|
||||
it("has a proper API for info.ftl", () => {
|
||||
const pageId = "info.ftl";
|
||||
|
||||
const { kcContext } = getKcContextProxy({ "mockPageId": pageId });
|
||||
const { kcContext } = getKcContextProxy({ mockPageId: pageId });
|
||||
|
||||
assert(kcContext?.pageId === pageId);
|
||||
|
||||
@ -109,7 +124,11 @@ describe("createGetKcContext", () => {
|
||||
same(
|
||||
deepClone(kcContext),
|
||||
(() => {
|
||||
const mock = deepClone(kcContextMocks.find(({ pageId: pageId_i }) => pageId_i === pageId)!);
|
||||
const mock = deepClone(
|
||||
kcContextMocks.find(
|
||||
({ pageId: pageId_i }) => pageId_i === pageId
|
||||
)!
|
||||
);
|
||||
|
||||
Object.assign(mock, { aNonStandardValue1 });
|
||||
|
||||
@ -121,7 +140,7 @@ describe("createGetKcContext", () => {
|
||||
it("has a proper API for register.ftl", () => {
|
||||
const pageId = "register.ftl";
|
||||
|
||||
const { kcContext } = getKcContextProxy({ "mockPageId": pageId });
|
||||
const { kcContext } = getKcContextProxy({ mockPageId: pageId });
|
||||
|
||||
assert(kcContext?.pageId === pageId);
|
||||
|
||||
@ -140,7 +159,11 @@ describe("createGetKcContext", () => {
|
||||
same(
|
||||
deepClone(kcContext),
|
||||
(() => {
|
||||
const mock = deepClone(kcContextMocks.find(({ pageId: pageId_i }) => pageId_i === pageId)!);
|
||||
const mock = deepClone(
|
||||
kcContextMocks.find(
|
||||
({ pageId: pageId_i }) => pageId_i === pageId
|
||||
)!
|
||||
);
|
||||
|
||||
Object.assign(mock, { authorizedMailDomains });
|
||||
|
||||
@ -152,7 +175,7 @@ describe("createGetKcContext", () => {
|
||||
it("has a proper API for my-extra-page-2.ftl", () => {
|
||||
const pageId = "my-extra-page-2.ftl";
|
||||
|
||||
const { kcContext } = getKcContextProxy({ "mockPageId": pageId });
|
||||
const { kcContext } = getKcContextProxy({ mockPageId: pageId });
|
||||
|
||||
assert(kcContext?.pageId === pageId);
|
||||
|
||||
@ -186,7 +209,7 @@ describe("createGetKcContext", () => {
|
||||
|
||||
console.log("We expect a warning here =>");
|
||||
|
||||
const { kcContext } = getKcContextProxy({ "mockPageId": pageId });
|
||||
const { kcContext } = getKcContextProxy({ mockPageId: pageId });
|
||||
|
||||
assert(kcContext?.pageId === pageId);
|
||||
|
||||
@ -211,12 +234,19 @@ describe("createGetKcContext", () => {
|
||||
const { getKcContext } = createGetKcContext();
|
||||
|
||||
const { kcContext } = getKcContext({
|
||||
"mockPageId": pageId
|
||||
mockPageId: pageId
|
||||
});
|
||||
|
||||
assert<Equals<typeof kcContext, KcContext.Login>>();
|
||||
|
||||
assert(same(deepClone(kcContext), deepClone(kcContextMocks.find(({ pageId: pageId_i }) => pageId_i === pageId)!)));
|
||||
assert(
|
||||
same(
|
||||
deepClone(kcContext),
|
||||
deepClone(
|
||||
kcContextMocks.find(({ pageId: pageId_i }) => pageId_i === pageId)!
|
||||
)
|
||||
)
|
||||
);
|
||||
});
|
||||
it("returns undefined when no mock is specified", () => {
|
||||
const { getKcContext } = createGetKcContext();
|
||||
@ -234,9 +264,9 @@ describe("createGetKcContext", () => {
|
||||
const displayName = "myDisplayName";
|
||||
|
||||
const { kcContext } = getKcContext({
|
||||
"mockPageId": "login.ftl",
|
||||
"storyPartialKcContext": {
|
||||
"realm": {
|
||||
mockPageId: "login.ftl",
|
||||
storyPartialKcContext: {
|
||||
realm: {
|
||||
displayName
|
||||
}
|
||||
}
|
||||
|
@ -4,12 +4,21 @@ import type { KcContext } from "keycloakify/login/kcContext";
|
||||
import { same } from "evt/tools/inDepth";
|
||||
import { assert } from "tsafe/assert";
|
||||
import type { Equals } from "tsafe";
|
||||
import { kcContextMocks, kcContextCommonMock } from "keycloakify/login/kcContext/kcContextMocks";
|
||||
import {
|
||||
kcContextMocks,
|
||||
kcContextCommonMock
|
||||
} from "keycloakify/login/kcContext/kcContextMocks";
|
||||
import { deepClone } from "keycloakify/tools/deepClone";
|
||||
import { expect, it, describe } from "vitest";
|
||||
|
||||
describe("getKcContext", () => {
|
||||
const authorizedMailDomains = ["example.com", "another-example.com", "*.yet-another-example.com", "*.example.com", "hello-world.com"];
|
||||
const authorizedMailDomains = [
|
||||
"example.com",
|
||||
"another-example.com",
|
||||
"*.yet-another-example.com",
|
||||
"*.example.com",
|
||||
"hello-world.com"
|
||||
];
|
||||
|
||||
const displayName = "this is an overwritten common value";
|
||||
|
||||
@ -33,26 +42,28 @@ describe("getKcContext", () => {
|
||||
aNonStandardValue2: string;
|
||||
};
|
||||
|
||||
const getKcContextProxy = (params: { mockPageId: ExtendKcContext<KcContextExtension>["pageId"] }) => {
|
||||
const getKcContextProxy = (params: {
|
||||
mockPageId: ExtendKcContext<KcContextExtension>["pageId"];
|
||||
}) => {
|
||||
const { mockPageId } = params;
|
||||
|
||||
const { kcContext } = getKcContext<KcContextExtension>({
|
||||
mockPageId,
|
||||
"mockData": [
|
||||
mockData: [
|
||||
{
|
||||
"pageId": "login.ftl",
|
||||
"realm": { displayName }
|
||||
pageId: "login.ftl",
|
||||
realm: { displayName }
|
||||
},
|
||||
{
|
||||
"pageId": "info.ftl",
|
||||
pageId: "info.ftl",
|
||||
aNonStandardValue1
|
||||
},
|
||||
{
|
||||
"pageId": "register.ftl",
|
||||
pageId: "register.ftl",
|
||||
authorizedMailDomains
|
||||
},
|
||||
{
|
||||
"pageId": "my-extra-page-2.ftl",
|
||||
pageId: "my-extra-page-2.ftl",
|
||||
aNonStandardValue2
|
||||
}
|
||||
]
|
||||
@ -63,7 +74,7 @@ describe("getKcContext", () => {
|
||||
it("has proper API for login.ftl", () => {
|
||||
const pageId = "login.ftl";
|
||||
|
||||
const { kcContext } = getKcContextProxy({ "mockPageId": pageId });
|
||||
const { kcContext } = getKcContextProxy({ mockPageId: pageId });
|
||||
|
||||
assert(kcContext?.pageId === pageId);
|
||||
|
||||
@ -74,7 +85,11 @@ describe("getKcContext", () => {
|
||||
//NOTE: deepClone for printIfExists or other functions...
|
||||
deepClone(kcContext),
|
||||
(() => {
|
||||
const mock = deepClone(kcContextMocks.find(({ pageId: pageId_i }) => pageId_i === pageId)!);
|
||||
const mock = deepClone(
|
||||
kcContextMocks.find(
|
||||
({ pageId: pageId_i }) => pageId_i === pageId
|
||||
)!
|
||||
);
|
||||
|
||||
mock.realm.displayName = displayName;
|
||||
|
||||
@ -87,7 +102,7 @@ describe("getKcContext", () => {
|
||||
it("has a proper API for info.ftl", () => {
|
||||
const pageId = "info.ftl";
|
||||
|
||||
const { kcContext } = getKcContextProxy({ "mockPageId": pageId });
|
||||
const { kcContext } = getKcContextProxy({ mockPageId: pageId });
|
||||
|
||||
assert(kcContext?.pageId === pageId);
|
||||
|
||||
@ -106,7 +121,11 @@ describe("getKcContext", () => {
|
||||
same(
|
||||
deepClone(kcContext),
|
||||
(() => {
|
||||
const mock = deepClone(kcContextMocks.find(({ pageId: pageId_i }) => pageId_i === pageId)!);
|
||||
const mock = deepClone(
|
||||
kcContextMocks.find(
|
||||
({ pageId: pageId_i }) => pageId_i === pageId
|
||||
)!
|
||||
);
|
||||
|
||||
Object.assign(mock, { aNonStandardValue1 });
|
||||
|
||||
@ -118,7 +137,7 @@ describe("getKcContext", () => {
|
||||
it("has a proper API for register.ftl", () => {
|
||||
const pageId = "register.ftl";
|
||||
|
||||
const { kcContext } = getKcContextProxy({ "mockPageId": pageId });
|
||||
const { kcContext } = getKcContextProxy({ mockPageId: pageId });
|
||||
|
||||
assert(kcContext?.pageId === pageId);
|
||||
|
||||
@ -137,7 +156,11 @@ describe("getKcContext", () => {
|
||||
same(
|
||||
deepClone(kcContext),
|
||||
(() => {
|
||||
const mock = deepClone(kcContextMocks.find(({ pageId: pageId_i }) => pageId_i === pageId)!);
|
||||
const mock = deepClone(
|
||||
kcContextMocks.find(
|
||||
({ pageId: pageId_i }) => pageId_i === pageId
|
||||
)!
|
||||
);
|
||||
|
||||
Object.assign(mock, { authorizedMailDomains });
|
||||
|
||||
@ -149,7 +172,7 @@ describe("getKcContext", () => {
|
||||
it("has a proper API for my-extra-page-2.ftl", () => {
|
||||
const pageId = "my-extra-page-2.ftl";
|
||||
|
||||
const { kcContext } = getKcContextProxy({ "mockPageId": pageId });
|
||||
const { kcContext } = getKcContextProxy({ mockPageId: pageId });
|
||||
|
||||
assert(kcContext?.pageId === pageId);
|
||||
|
||||
@ -183,7 +206,7 @@ describe("getKcContext", () => {
|
||||
|
||||
console.log("We expect a warning here =>");
|
||||
|
||||
const { kcContext } = getKcContextProxy({ "mockPageId": pageId });
|
||||
const { kcContext } = getKcContextProxy({ mockPageId: pageId });
|
||||
|
||||
assert(kcContext?.pageId === pageId);
|
||||
|
||||
@ -206,12 +229,19 @@ describe("getKcContext", () => {
|
||||
const pageId = "login.ftl";
|
||||
|
||||
const { kcContext } = getKcContext({
|
||||
"mockPageId": pageId
|
||||
mockPageId: pageId
|
||||
});
|
||||
|
||||
assert<Equals<typeof kcContext, KcContext | undefined>>();
|
||||
|
||||
assert(same(deepClone(kcContext), deepClone(kcContextMocks.find(({ pageId: pageId_i }) => pageId_i === pageId)!)));
|
||||
assert(
|
||||
same(
|
||||
deepClone(kcContext),
|
||||
deepClone(
|
||||
kcContextMocks.find(({ pageId: pageId_i }) => pageId_i === pageId)!
|
||||
)
|
||||
)
|
||||
);
|
||||
});
|
||||
it("returns undefined when no mock is specified", () => {
|
||||
const { kcContext } = getKcContext();
|
||||
|
@ -3,9 +3,15 @@ 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 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 Extension =
|
||||
| { pageId: "a"; onlyExtA: string }
|
||||
| { pageId: "b"; onlyExtB: string }
|
||||
| { pageId: "only ext"; onlyExt: string };
|
||||
|
||||
type Got = AndByDiscriminatingKey<"pageId", Extension, Base>;
|
||||
|
||||
@ -75,7 +81,10 @@ import type { Equals } from "tsafe";
|
||||
}
|
||||
|
||||
{
|
||||
type Base = { pageId: "a"; onlyA: string } | { pageId: "b"; onlyB: string } | { pageId: "only base"; onlyBase: string };
|
||||
type Base =
|
||||
| { pageId: "a"; onlyA: string }
|
||||
| { pageId: "b"; onlyB: string }
|
||||
| { pageId: "only base"; onlyBase: string };
|
||||
|
||||
type Extension = { pageId: "only ext"; onlyExt: string };
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
export function isSameCode(code1: string, code2: string): boolean {
|
||||
const removeSpacesAndNewLines = (code: string) => code.replace(/\s/g, "").replace(/\n/g, "");
|
||||
const removeSpacesAndNewLines = (code: string) =>
|
||||
code.replace(/\s/g, "").replace(/\n/g, "");
|
||||
|
||||
return removeSpacesAndNewLines(code1) === removeSpacesAndNewLines(code2);
|
||||
}
|
||||
|
Reference in New Issue
Block a user