Unit test passing
This commit is contained in:
parent
884b701fc6
commit
5076c1e93f
@ -14,7 +14,7 @@
|
||||
"generate:json-schema": "ts-node scripts/generate-json-schema.ts",
|
||||
"grant-exec-perms": "node dist/bin/tools/grant-exec-perms.js",
|
||||
"copy-files": "copyfiles -u 1 src/**/*.ftl src/**/*.java",
|
||||
"test": "echo 'yarn test:types && vitest run'",
|
||||
"test": "yarn test:types && vitest run",
|
||||
"test:keycloakify-starter": "ts-node scripts/test-keycloakify-starter",
|
||||
"test:types": "tsc -p test/tsconfig.json --noEmit",
|
||||
"_format": "prettier '**/*.{ts,tsx,json,md}'",
|
||||
|
@ -82,7 +82,7 @@ export function replaceImportsInJsCode_webpack(params: { jsCode: string; buildOp
|
||||
.replace(...getReplaceArgs("js"))
|
||||
.replace(...getReplaceArgs("css"))
|
||||
.replace(
|
||||
new RegExp(`[a-zA-Z]+\\.[a-zA-Z]+\\+"${staticDir.replace(/\//g, "\\/")}"`, "g"),
|
||||
new RegExp(`[a-zA-Z]+\\.[a-zA-Z]+\\+"${staticDir.replace(/\//g, "\\/")}`, "g"),
|
||||
`window.${nameOfTheGlobal}.url.resourcesPath + "/${basenameOfTheKeycloakifyResourcesDir}/${staticDir}`
|
||||
)
|
||||
//TODO: Write a test case for this
|
||||
|
@ -1,104 +0,0 @@
|
||||
import { readPaths } from "keycloakify/bin/keycloakify/generateTheme/readStaticResourcesUsage";
|
||||
import { same } from "evt/tools/inDepth/same";
|
||||
import { expect, it, describe } from "vitest";
|
||||
|
||||
describe("Ensure it's able to extract used Keycloak resources", () => {
|
||||
const expectedPaths = {
|
||||
"resourcesCommonFilePaths": [
|
||||
"node_modules/patternfly/dist/css/patternfly.min.css",
|
||||
"node_modules/patternfly/dist/css/patternfly-additions.min.css",
|
||||
"lib/zocial/zocial.css",
|
||||
"node_modules/jquery/dist/jquery.min.js"
|
||||
]
|
||||
};
|
||||
|
||||
it("works with coding style n°1", () => {
|
||||
const paths = readPaths({
|
||||
"rawSourceFile": `
|
||||
const { isReady } = usePrepareTemplate({
|
||||
"doFetchDefaultThemeResources": doUseDefaultCss,
|
||||
"styles": [
|
||||
\`\${url.resourcesCommonPath}/node_modules/patternfly/dist/css/patternfly.min.css\`,
|
||||
\`\${
|
||||
url.resourcesCommonPath
|
||||
}/node_modules/patternfly/dist/css/patternfly-additions.min.css\`,
|
||||
\`\${resourcesCommonPath }/lib/zocial/zocial.css\`,
|
||||
\`\${url.resourcesPath}/css/login.css\`
|
||||
],
|
||||
"htmlClassName": getClassName("kcHtmlClass"),
|
||||
"bodyClassName": undefined
|
||||
});
|
||||
|
||||
const { prLoaded, remove } = headInsert({
|
||||
"type": "javascript",
|
||||
"src": \`\${kcContext.url.resourcesCommonPath}/node_modules/jquery/dist/jquery.min.js\`
|
||||
});
|
||||
|
||||
`
|
||||
});
|
||||
|
||||
expect(same(paths, expectedPaths)).toBe(true);
|
||||
});
|
||||
|
||||
it("works with coding style n°2", () => {
|
||||
const paths = readPaths({
|
||||
"rawSourceFile": `
|
||||
|
||||
const { isReady } = usePrepareTemplate({
|
||||
"doFetchDefaultThemeResources": doUseDefaultCss,
|
||||
"styles": [
|
||||
url.resourcesCommonPath + "/node_modules/patternfly/dist/css/patternfly.min.css",
|
||||
url.resourcesCommonPath + '/node_modules/patternfly/dist/css/patternfly-additions.min.css',
|
||||
url.resourcesCommonPath
|
||||
+ "/lib/zocial/zocial.css",
|
||||
url.resourcesPath +
|
||||
'/css/login.css'
|
||||
],
|
||||
"htmlClassName": getClassName("kcHtmlClass"),
|
||||
"bodyClassName": undefined
|
||||
});
|
||||
|
||||
const { prLoaded, remove } = headInsert({
|
||||
"type": "javascript",
|
||||
"src": kcContext.url.resourcesCommonPath + "/node_modules/jquery/dist/jquery.min.js\"
|
||||
});
|
||||
|
||||
|
||||
`
|
||||
});
|
||||
|
||||
expect(same(paths, expectedPaths)).toBe(true);
|
||||
});
|
||||
|
||||
it("works with coding style n°3", () => {
|
||||
const paths = readPaths({
|
||||
"rawSourceFile": `
|
||||
|
||||
const { isReady } = usePrepareTemplate({
|
||||
"doFetchDefaultThemeResources": doUseDefaultCss,
|
||||
"styles": [
|
||||
path.join(resourcesCommonPath,"/node_modules/patternfly/dist/css/patternfly.min.css"),
|
||||
path.join(url.resourcesCommonPath, '/node_modules/patternfly/dist/css/patternfly-additions.min.css'),
|
||||
path.join(url.resourcesCommonPath,
|
||||
"/lib/zocial/zocial.css"),
|
||||
pathJoin(
|
||||
url.resourcesPath,
|
||||
'css/login.css'
|
||||
)
|
||||
],
|
||||
"htmlClassName": getClassName("kcHtmlClass"),
|
||||
"bodyClassName": undefined
|
||||
});
|
||||
|
||||
const { prLoaded, remove } = headInsert({
|
||||
"type": "javascript",
|
||||
"src": path.join(kcContext.url.resourcesCommonPath, "/node_modules/jquery/dist/jquery.min.js")
|
||||
});
|
||||
|
||||
|
||||
`
|
||||
});
|
||||
|
||||
expect(same(paths, expectedPaths)).toBe(true);
|
||||
});
|
||||
});
|
@ -74,7 +74,7 @@ describe("js replacer - vite", () => {
|
||||
] as const) {
|
||||
const { fixedJsCode } = replaceImportsInJsCode_vite({
|
||||
"jsCode": jsCodeUntransformed,
|
||||
"basenameOfAssetsFiles": ["Login-dJpPRzM4.js", "index-XwzrZ5Gu.js"],
|
||||
"basenameOfAssetsFiles": ["Login-dJpPRzM4.js", "index-XwzrZ5Gu.js", "keycloakify-logo-mqjydaoZ.png"],
|
||||
"buildOptions": {
|
||||
reactAppBuildDirPath,
|
||||
assetsDirPath,
|
||||
@ -84,13 +84,13 @@ describe("js replacer - vite", () => {
|
||||
});
|
||||
|
||||
const fixedJsCodeExpected = `
|
||||
S=(window.${nameOfTheGlobal}.url + "/${basenameOfTheKeycloakifyResourcesDir}/assets/keycloakify-logo-mqjydaoZ.png"),H=(()=>{
|
||||
S=(window.${nameOfTheGlobal}.url.resourcesPath + "/${basenameOfTheKeycloakifyResourcesDir}/assets/keycloakify-logo-mqjydaoZ.png"),H=(()=>{
|
||||
|
||||
function __vite__mapDeps(indexes) {
|
||||
if (!__vite__mapDeps.viteFileDeps) {
|
||||
__vite__mapDeps.viteFileDeps = [
|
||||
(window.${nameOfTheGlobal}.url.resourcesPath.substring(1) + "/${basenameOfTheKeycloakifyResourcesDir}/assets/Login-dJpPRzM4.js)",
|
||||
(window.${nameOfTheGlobal}.url.resourcesPath.substring(1) + "/${basenameOfTheKeycloakifyResourcesDir}/assets/index-XwzrZ5Gu.js)"
|
||||
(window.${nameOfTheGlobal}.url.resourcesPath.substring(1) + "/${basenameOfTheKeycloakifyResourcesDir}/assets/Login-dJpPRzM4.js"),
|
||||
(window.${nameOfTheGlobal}.url.resourcesPath.substring(1) + "/${basenameOfTheKeycloakifyResourcesDir}/assets/index-XwzrZ5Gu.js")
|
||||
]
|
||||
}
|
||||
return indexes.map((i) => __vite__mapDeps.viteFileDeps[i])
|
||||
@ -103,11 +103,11 @@ describe("js replacer - vite", () => {
|
||||
|
||||
it("replaceImportsInJsCode_vite - 4", () => {
|
||||
const jsCodeUntransformed = `
|
||||
S="/assets/keycloakify-logo-mqjydaoZ.png",H=(()=>{
|
||||
S="/foo/bar/keycloakify-logo-mqjydaoZ.png",H=(()=>{
|
||||
|
||||
function __vite__mapDeps(indexes) {
|
||||
if (!__vite__mapDeps.viteFileDeps) {
|
||||
__vite__mapDeps.viteFileDeps = ["assets/Login-dJpPRzM4.js", "assets/index-XwzrZ5Gu.js"]
|
||||
__vite__mapDeps.viteFileDeps = ["foo/bar/Login-dJpPRzM4.js", "foo/bar/index-XwzrZ5Gu.js"]
|
||||
}
|
||||
return indexes.map((i) => __vite__mapDeps.viteFileDeps[i])
|
||||
}
|
||||
@ -127,7 +127,7 @@ describe("js replacer - vite", () => {
|
||||
] as const) {
|
||||
const { fixedJsCode } = replaceImportsInJsCode_vite({
|
||||
"jsCode": jsCodeUntransformed,
|
||||
"basenameOfAssetsFiles": ["Login-dJpPRzM4.js", "index-XwzrZ5Gu.js"],
|
||||
"basenameOfAssetsFiles": ["Login-dJpPRzM4.js", "index-XwzrZ5Gu.js", "keycloakify-logo-mqjydaoZ.png"],
|
||||
"buildOptions": {
|
||||
reactAppBuildDirPath,
|
||||
assetsDirPath,
|
||||
@ -137,13 +137,13 @@ describe("js replacer - vite", () => {
|
||||
});
|
||||
|
||||
const fixedJsCodeExpected = `
|
||||
S=(window.${nameOfTheGlobal}.url + "/${basenameOfTheKeycloakifyResourcesDir}/foo/bar/keycloakify-logo-mqjydaoZ.png"),H=(()=>{
|
||||
S=(window.${nameOfTheGlobal}.url.resourcesPath + "/${basenameOfTheKeycloakifyResourcesDir}/foo/bar/keycloakify-logo-mqjydaoZ.png"),H=(()=>{
|
||||
|
||||
function __vite__mapDeps(indexes) {
|
||||
if (!__vite__mapDeps.viteFileDeps) {
|
||||
__vite__mapDeps.viteFileDeps = [
|
||||
(window.${nameOfTheGlobal}.url.resourcesPath.substring(1) + "/${basenameOfTheKeycloakifyResourcesDir}/foo/bar/Login-dJpPRzM4.js)",
|
||||
(window.${nameOfTheGlobal}.url.resourcesPath.substring(1) + "/${basenameOfTheKeycloakifyResourcesDir}/foo/bar/index-XwzrZ5Gu.js)"
|
||||
(window.${nameOfTheGlobal}.url.resourcesPath.substring(1) + "/${basenameOfTheKeycloakifyResourcesDir}/foo/bar/Login-dJpPRzM4.js"),
|
||||
(window.${nameOfTheGlobal}.url.resourcesPath.substring(1) + "/${basenameOfTheKeycloakifyResourcesDir}/foo/bar/index-XwzrZ5Gu.js")
|
||||
]
|
||||
}
|
||||
return indexes.map((i) => __vite__mapDeps.viteFileDeps[i])
|
||||
@ -180,7 +180,7 @@ describe("js replacer - vite", () => {
|
||||
] as const) {
|
||||
const { fixedJsCode } = replaceImportsInJsCode_vite({
|
||||
"jsCode": jsCodeUntransformed,
|
||||
"basenameOfAssetsFiles": ["Login-dJpPRzM4.js", "index-XwzrZ5Gu.js"],
|
||||
"basenameOfAssetsFiles": ["Login-dJpPRzM4.js", "index-XwzrZ5Gu.js", "keycloakify-logo-mqjydaoZ.png"],
|
||||
"buildOptions": {
|
||||
reactAppBuildDirPath,
|
||||
assetsDirPath,
|
||||
@ -190,13 +190,13 @@ describe("js replacer - vite", () => {
|
||||
});
|
||||
|
||||
const fixedJsCodeExpected = `
|
||||
S=(window.${nameOfTheGlobal}.url + "/${basenameOfTheKeycloakifyResourcesDir}/assets/keycloakify-logo-mqjydaoZ.png"),H=(()=>{
|
||||
S=(window.${nameOfTheGlobal}.url.resourcesPath + "/${basenameOfTheKeycloakifyResourcesDir}/assets/keycloakify-logo-mqjydaoZ.png"),H=(()=>{
|
||||
|
||||
function __vite__mapDeps(indexes) {
|
||||
if (!__vite__mapDeps.viteFileDeps) {
|
||||
__vite__mapDeps.viteFileDeps = [
|
||||
(window.${nameOfTheGlobal}.url.resourcesPath.substring(1) + "/${basenameOfTheKeycloakifyResourcesDir}/assets/Login-dJpPRzM4.js)",
|
||||
(window.${nameOfTheGlobal}.url.resourcesPath.substring(1) + "/${basenameOfTheKeycloakifyResourcesDir}/assets/index-XwzrZ5Gu.js)"
|
||||
(window.${nameOfTheGlobal}.url.resourcesPath.substring(1) + "/${basenameOfTheKeycloakifyResourcesDir}/assets/Login-dJpPRzM4.js"),
|
||||
(window.${nameOfTheGlobal}.url.resourcesPath.substring(1) + "/${basenameOfTheKeycloakifyResourcesDir}/assets/index-XwzrZ5Gu.js")
|
||||
]
|
||||
}
|
||||
return indexes.map((i) => __vite__mapDeps.viteFileDeps[i])
|
||||
@ -245,7 +245,7 @@ describe("js replacer - webpack", () => {
|
||||
"jsCode": jsCodeUntransformed,
|
||||
"buildOptions": {
|
||||
"reactAppBuildDirPath": "/Users/someone/github/keycloakify-starter/build",
|
||||
"assetsDirPath": "/Users/someone/github/keycloakify-starter/dist/build/static",
|
||||
"assetsDirPath": "/Users/someone/github/keycloakify-starter/build/static",
|
||||
"urlPathname": undefined
|
||||
}
|
||||
});
|
||||
@ -332,7 +332,7 @@ describe("js replacer - webpack", () => {
|
||||
"jsCode": jsCodeUntransformed,
|
||||
"buildOptions": {
|
||||
"reactAppBuildDirPath": "/Users/someone/github/keycloakify-starter/build",
|
||||
"assetsDirPath": "/Users/someone/github/keycloakify-starter/dist/build/static",
|
||||
"assetsDirPath": "/Users/someone/github/keycloakify-starter/build/static",
|
||||
"urlPathname": "/foo-bar/"
|
||||
}
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user