test: refactor existing tests to vitest
This commit is contained in:
parent
e4725c23eb
commit
58bb403787
@ -1 +0,0 @@
|
|||||||
import "./replaceImportFromStatic";
|
|
@ -1,4 +1,3 @@
|
|||||||
import "./replaceImportFromStatic";
|
|
||||||
import { setupSampleReactProject, sampleReactProjectDirPath } from "./setupSampleReactProject";
|
import { setupSampleReactProject, sampleReactProjectDirPath } from "./setupSampleReactProject";
|
||||||
import * as st from "scripting-tools";
|
import * as st from "scripting-tools";
|
||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
import { replaceImportsFromStaticInJsCode } from "keycloakify/bin/keycloakify/replacers/replaceImportsFromStaticInJsCode";
|
import { replaceImportsFromStaticInJsCode } from "keycloakify/bin/keycloakify/replacers/replaceImportsFromStaticInJsCode";
|
||||||
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 { replaceImportsInInlineCssCode } from "keycloakify/bin/keycloakify/replacers/replaceImportsInInlineCssCode";
|
||||||
import { assert } from "tsafe/assert";
|
|
||||||
import { same } from "evt/tools/inDepth/same";
|
import { same } from "evt/tools/inDepth/same";
|
||||||
import { assetIsSameCode } from "../tools/assertIsSameCode";
|
import { expect, it, describe } from "vitest";
|
||||||
|
|
||||||
{
|
import { isSameCode } from "../tools/isSameCode";
|
||||||
|
|
||||||
|
describe("bin/js-transforms", () => {
|
||||||
const jsCodeUntransformed = `
|
const jsCodeUntransformed = `
|
||||||
function f() {
|
function f() {
|
||||||
return a.p+"static/js/" + ({}[e] || e) + "." + {
|
return a.p+"static/js/" + ({}[e] || e) + "." + {
|
||||||
@ -32,8 +33,7 @@ import { assetIsSameCode } from "../tools/assertIsSameCode";
|
|||||||
}[e]+".chunk.css"
|
}[e]+".chunk.css"
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
it("transforms standalone code properly", () => {
|
||||||
{
|
|
||||||
const { fixedJsCode } = replaceImportsFromStaticInJsCode({
|
const { fixedJsCode } = replaceImportsFromStaticInJsCode({
|
||||||
"jsCode": jsCodeUntransformed,
|
"jsCode": jsCodeUntransformed,
|
||||||
"buildOptions": {
|
"buildOptions": {
|
||||||
@ -89,10 +89,9 @@ import { assetIsSameCode } from "../tools/assertIsSameCode";
|
|||||||
|
|
||||||
`;
|
`;
|
||||||
|
|
||||||
assetIsSameCode(fixedJsCode, fixedJsCodeExpected);
|
expect(isSameCode(fixedJsCode, fixedJsCodeExpected)).toBe(true);
|
||||||
}
|
});
|
||||||
|
it("transforms external app code properly", () => {
|
||||||
{
|
|
||||||
const { fixedJsCode } = replaceImportsFromStaticInJsCode({
|
const { fixedJsCode } = replaceImportsFromStaticInJsCode({
|
||||||
"jsCode": jsCodeUntransformed,
|
"jsCode": jsCodeUntransformed,
|
||||||
"buildOptions": {
|
"buildOptions": {
|
||||||
@ -150,126 +149,128 @@ import { assetIsSameCode } from "../tools/assertIsSameCode";
|
|||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
assetIsSameCode(fixedJsCode, fixedJsCodeExpected);
|
expect(isSameCode(fixedJsCode, fixedJsCodeExpected)).toBe(true);
|
||||||
}
|
});
|
||||||
}
|
});
|
||||||
|
|
||||||
{
|
describe("bin/css-transforms", () => {
|
||||||
const { fixedCssCode, cssGlobalsToDefine } = replaceImportsInCssCode({
|
it("transforms absolute urls to css globals properly with no urlPathname", () => {
|
||||||
"cssCode": `
|
const { fixedCssCode, cssGlobalsToDefine } = replaceImportsInCssCode({
|
||||||
|
"cssCode": `
|
||||||
|
.my-div {
|
||||||
|
background: url(/logo192.png) no-repeat center center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.my-div2 {
|
||||||
|
background: url(/logo192.png) no-repeat center center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.my-div {
|
||||||
|
background-image: url(/static/media/something.svg);
|
||||||
|
}
|
||||||
|
`
|
||||||
|
});
|
||||||
|
|
||||||
|
const fixedCssCodeExpected = `
|
||||||
.my-div {
|
.my-div {
|
||||||
background: url(/logo192.png) no-repeat center center;
|
background: var(--url1f9ef5a892c104c);
|
||||||
}
|
}
|
||||||
|
|
||||||
.my-div2 {
|
.my-div2 {
|
||||||
background: url(/logo192.png) no-repeat center center;
|
background: var(--url1f9ef5a892c104c);
|
||||||
}
|
}
|
||||||
|
|
||||||
.my-div {
|
.my-div {
|
||||||
background-image: url(/static/media/something.svg);
|
background-image: var(--urldd75cab58377c19);
|
||||||
}
|
}
|
||||||
`
|
`;
|
||||||
|
|
||||||
|
expect(isSameCode(fixedCssCode, fixedCssCodeExpected)).toBe(true);
|
||||||
|
|
||||||
|
const cssGlobalsToDefineExpected = {
|
||||||
|
"url1f9ef5a892c104c": "url(/logo192.png) no-repeat center center",
|
||||||
|
"urldd75cab58377c19": "url(/static/media/something.svg)"
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(same(cssGlobalsToDefine, cssGlobalsToDefineExpected)).toBe(true);
|
||||||
|
|
||||||
|
const { cssCodeToPrependInHead } = generateCssCodeToDefineGlobals({
|
||||||
|
cssGlobalsToDefine,
|
||||||
|
"buildOptions": {
|
||||||
|
"urlPathname": undefined
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const cssCodeToPrependInHeadExpected = `
|
||||||
|
:root {
|
||||||
|
--url1f9ef5a892c104c: url(\${url.resourcesPath}/build/logo192.png) no-repeat center center;
|
||||||
|
--urldd75cab58377c19: url(\${url.resourcesPath}/build/static/media/something.svg);
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
expect(isSameCode(cssCodeToPrependInHead, cssCodeToPrependInHeadExpected)).toBe(true);
|
||||||
});
|
});
|
||||||
|
it("transforms absolute urls to css globals properly with custom urlPathname", () => {
|
||||||
|
const { fixedCssCode, cssGlobalsToDefine } = replaceImportsInCssCode({
|
||||||
|
"cssCode": `
|
||||||
|
.my-div {
|
||||||
|
background: url(/x/y/z/logo192.png) no-repeat center center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.my-div2 {
|
||||||
|
background: url(/x/y/z/logo192.png) no-repeat center center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.my-div {
|
||||||
|
background-image: url(/x/y/z/static/media/something.svg);
|
||||||
|
}
|
||||||
|
`
|
||||||
|
});
|
||||||
|
|
||||||
const fixedCssCodeExpected = `
|
const fixedCssCodeExpected = `
|
||||||
.my-div {
|
|
||||||
background: var(--url1f9ef5a892c104c);
|
|
||||||
}
|
|
||||||
|
|
||||||
.my-div2 {
|
|
||||||
background: var(--url1f9ef5a892c104c);
|
|
||||||
}
|
|
||||||
|
|
||||||
.my-div {
|
|
||||||
background-image: var(--urldd75cab58377c19);
|
|
||||||
}
|
|
||||||
`;
|
|
||||||
|
|
||||||
assetIsSameCode(fixedCssCode, fixedCssCodeExpected);
|
|
||||||
|
|
||||||
const cssGlobalsToDefineExpected = {
|
|
||||||
"url1f9ef5a892c104c": "url(/logo192.png) no-repeat center center",
|
|
||||||
"urldd75cab58377c19": "url(/static/media/something.svg)"
|
|
||||||
};
|
|
||||||
|
|
||||||
assert(same(cssGlobalsToDefine, cssGlobalsToDefineExpected));
|
|
||||||
|
|
||||||
const { cssCodeToPrependInHead } = generateCssCodeToDefineGlobals({
|
|
||||||
cssGlobalsToDefine,
|
|
||||||
"buildOptions": {
|
|
||||||
"urlPathname": undefined
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
const cssCodeToPrependInHeadExpected = `
|
|
||||||
:root {
|
|
||||||
--url1f9ef5a892c104c: url(\${url.resourcesPath}/build/logo192.png) no-repeat center center;
|
|
||||||
--urldd75cab58377c19: url(\${url.resourcesPath}/build/static/media/something.svg);
|
|
||||||
}
|
|
||||||
`;
|
|
||||||
|
|
||||||
assetIsSameCode(cssCodeToPrependInHead, cssCodeToPrependInHeadExpected);
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
const { fixedCssCode, cssGlobalsToDefine } = replaceImportsInCssCode({
|
|
||||||
"cssCode": `
|
|
||||||
.my-div {
|
.my-div {
|
||||||
background: url(/x/y/z/logo192.png) no-repeat center center;
|
background: var(--urlf8277cddaa2be78);
|
||||||
}
|
}
|
||||||
|
|
||||||
.my-div2 {
|
.my-div2 {
|
||||||
background: url(/x/y/z/logo192.png) no-repeat center center;
|
background: var(--urlf8277cddaa2be78);
|
||||||
}
|
}
|
||||||
|
|
||||||
.my-div {
|
.my-div {
|
||||||
background-image: url(/x/y/z/static/media/something.svg);
|
background-image: var(--url8bdc0887b97ac9a);
|
||||||
}
|
}
|
||||||
`
|
`;
|
||||||
|
|
||||||
|
expect(isSameCode(fixedCssCode, fixedCssCodeExpected)).toBe(true);
|
||||||
|
|
||||||
|
const cssGlobalsToDefineExpected = {
|
||||||
|
"urlf8277cddaa2be78": "url(/x/y/z/logo192.png) no-repeat center center",
|
||||||
|
"url8bdc0887b97ac9a": "url(/x/y/z/static/media/something.svg)"
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(same(cssGlobalsToDefine, cssGlobalsToDefineExpected)).toBe(true);
|
||||||
|
|
||||||
|
const { cssCodeToPrependInHead } = generateCssCodeToDefineGlobals({
|
||||||
|
cssGlobalsToDefine,
|
||||||
|
"buildOptions": {
|
||||||
|
"urlPathname": "/x/y/z/"
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const cssCodeToPrependInHeadExpected = `
|
||||||
|
:root {
|
||||||
|
--urlf8277cddaa2be78: url(\${url.resourcesPath}/build/logo192.png) no-repeat center center;
|
||||||
|
--url8bdc0887b97ac9a: url(\${url.resourcesPath}/build/static/media/something.svg);
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
expect(isSameCode(cssCodeToPrependInHead, cssCodeToPrependInHeadExpected)).toBe(true);
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
const fixedCssCodeExpected = `
|
describe("bin/css-inline-transforms", () => {
|
||||||
.my-div {
|
describe("no url pathName", () => {
|
||||||
background: var(--urlf8277cddaa2be78);
|
const cssCode = `
|
||||||
}
|
|
||||||
|
|
||||||
.my-div2 {
|
|
||||||
background: var(--urlf8277cddaa2be78);
|
|
||||||
}
|
|
||||||
|
|
||||||
.my-div {
|
|
||||||
background-image: var(--url8bdc0887b97ac9a);
|
|
||||||
}
|
|
||||||
`;
|
|
||||||
|
|
||||||
assetIsSameCode(fixedCssCode, fixedCssCodeExpected);
|
|
||||||
|
|
||||||
const cssGlobalsToDefineExpected = {
|
|
||||||
"urlf8277cddaa2be78": "url(/x/y/z/logo192.png) no-repeat center center",
|
|
||||||
"url8bdc0887b97ac9a": "url(/x/y/z/static/media/something.svg)"
|
|
||||||
};
|
|
||||||
|
|
||||||
assert(same(cssGlobalsToDefine, cssGlobalsToDefineExpected));
|
|
||||||
|
|
||||||
const { cssCodeToPrependInHead } = generateCssCodeToDefineGlobals({
|
|
||||||
cssGlobalsToDefine,
|
|
||||||
"buildOptions": {
|
|
||||||
"urlPathname": "/x/y/z/"
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
const cssCodeToPrependInHeadExpected = `
|
|
||||||
:root {
|
|
||||||
--urlf8277cddaa2be78: url(\${url.resourcesPath}/build/logo192.png) no-repeat center center;
|
|
||||||
--url8bdc0887b97ac9a: url(\${url.resourcesPath}/build/static/media/something.svg);
|
|
||||||
}
|
|
||||||
`;
|
|
||||||
|
|
||||||
assetIsSameCode(cssCodeToPrependInHead, cssCodeToPrependInHeadExpected);
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
const cssCode = `
|
|
||||||
@font-face {
|
@font-face {
|
||||||
font-family: "Work Sans";
|
font-family: "Work Sans";
|
||||||
font-style: normal;
|
font-style: normal;
|
||||||
@ -299,17 +300,16 @@ import { assetIsSameCode } from "../tools/assertIsSameCode";
|
|||||||
src: url("/fonts/WorkSans/worksans-bold-webfont.woff2") format("woff2");
|
src: url("/fonts/WorkSans/worksans-bold-webfont.woff2") format("woff2");
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
it("transforms css for standalone app properly", () => {
|
||||||
|
const { fixedCssCode } = replaceImportsInInlineCssCode({
|
||||||
|
cssCode,
|
||||||
|
"buildOptions": {
|
||||||
|
"isStandalone": true,
|
||||||
|
"urlPathname": undefined
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
{
|
const fixedCssCodeExpected = `
|
||||||
const { fixedCssCode } = replaceImportsInInlineCssCode({
|
|
||||||
cssCode,
|
|
||||||
"buildOptions": {
|
|
||||||
"isStandalone": true,
|
|
||||||
"urlPathname": undefined
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
const fixedCssCodeExpected = `
|
|
||||||
@font-face {
|
@font-face {
|
||||||
font-family: "Work Sans";
|
font-family: "Work Sans";
|
||||||
font-style: normal;
|
font-style: normal;
|
||||||
@ -344,20 +344,19 @@ import { assetIsSameCode } from "../tools/assertIsSameCode";
|
|||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
assetIsSameCode(fixedCssCode, fixedCssCodeExpected);
|
expect(isSameCode(fixedCssCode, fixedCssCodeExpected)).toBe(true);
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
const { fixedCssCode } = replaceImportsInInlineCssCode({
|
|
||||||
cssCode,
|
|
||||||
"buildOptions": {
|
|
||||||
"isStandalone": false,
|
|
||||||
"urlOrigin": "https://demo-app.keycloakify.dev",
|
|
||||||
"urlPathname": undefined
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
it("transforms css for external app properly", () => {
|
||||||
|
const { fixedCssCode } = replaceImportsInInlineCssCode({
|
||||||
|
cssCode,
|
||||||
|
"buildOptions": {
|
||||||
|
"isStandalone": false,
|
||||||
|
"urlOrigin": "https://demo-app.keycloakify.dev",
|
||||||
|
"urlPathname": undefined
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
const fixedCssCodeExpected = `
|
const fixedCssCodeExpected = `
|
||||||
@font-face {
|
@font-face {
|
||||||
font-family: "Work Sans";
|
font-family: "Work Sans";
|
||||||
font-style: normal;
|
font-style: normal;
|
||||||
@ -392,12 +391,12 @@ import { assetIsSameCode } from "../tools/assertIsSameCode";
|
|||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
assetIsSameCode(fixedCssCode, fixedCssCodeExpected);
|
expect(isSameCode(fixedCssCode, fixedCssCodeExpected)).toBe(true);
|
||||||
}
|
});
|
||||||
}
|
});
|
||||||
|
|
||||||
{
|
describe("with url pathName", () => {
|
||||||
const cssCode = `
|
const cssCode = `
|
||||||
@font-face {
|
@font-face {
|
||||||
font-family: "Work Sans";
|
font-family: "Work Sans";
|
||||||
font-style: normal;
|
font-style: normal;
|
||||||
@ -427,101 +426,98 @@ import { assetIsSameCode } from "../tools/assertIsSameCode";
|
|||||||
src: url("/x/y/z/fonts/WorkSans/worksans-bold-webfont.woff2") format("woff2");
|
src: url("/x/y/z/fonts/WorkSans/worksans-bold-webfont.woff2") format("woff2");
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
it("transforms css for standalone app properly", () => {
|
||||||
|
const { fixedCssCode } = replaceImportsInInlineCssCode({
|
||||||
|
cssCode,
|
||||||
|
"buildOptions": {
|
||||||
|
"isStandalone": true,
|
||||||
|
"urlPathname": "/x/y/z/"
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
{
|
const fixedCssCodeExpected = `
|
||||||
const { fixedCssCode } = replaceImportsInInlineCssCode({
|
@font-face {
|
||||||
cssCode,
|
font-family: "Work Sans";
|
||||||
"buildOptions": {
|
font-style: normal;
|
||||||
"isStandalone": true,
|
font-weight: 400;
|
||||||
"urlPathname": "/x/y/z/"
|
font-display: swap;
|
||||||
}
|
src: url(\${url.resourcesPath}/build/fonts/WorkSans/worksans-regular-webfont.woff2)
|
||||||
|
format("woff2");
|
||||||
|
}
|
||||||
|
@font-face {
|
||||||
|
font-family: "Work Sans";
|
||||||
|
font-style: normal;
|
||||||
|
font-weight: 500;
|
||||||
|
font-display: swap;
|
||||||
|
src: url(\${url.resourcesPath}/build/fonts/WorkSans/worksans-medium-webfont.woff2)
|
||||||
|
format("woff2");
|
||||||
|
}
|
||||||
|
@font-face {
|
||||||
|
font-family: "Work Sans";
|
||||||
|
font-style: normal;
|
||||||
|
font-weight: 600;
|
||||||
|
font-display: swap;
|
||||||
|
src: url(\${url.resourcesPath}/build/fonts/WorkSans/worksans-semibold-webfont.woff2)
|
||||||
|
format("woff2");
|
||||||
|
}
|
||||||
|
@font-face {
|
||||||
|
font-family: "Work Sans";
|
||||||
|
font-style: normal;
|
||||||
|
font-weight: 700;
|
||||||
|
font-display: swap;
|
||||||
|
src: url(\${url.resourcesPath}/build/fonts/WorkSans/worksans-bold-webfont.woff2)
|
||||||
|
format("woff2");
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
expect(isSameCode(fixedCssCode, fixedCssCodeExpected)).toBe(true);
|
||||||
});
|
});
|
||||||
|
it("transforms css for external app properly", () => {
|
||||||
|
const { fixedCssCode } = replaceImportsInInlineCssCode({
|
||||||
|
cssCode,
|
||||||
|
"buildOptions": {
|
||||||
|
"isStandalone": false,
|
||||||
|
"urlOrigin": "https://demo-app.keycloakify.dev",
|
||||||
|
"urlPathname": "/x/y/z/"
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
const fixedCssCodeExpected = `
|
const fixedCssCodeExpected = `
|
||||||
@font-face {
|
@font-face {
|
||||||
font-family: "Work Sans";
|
font-family: "Work Sans";
|
||||||
font-style: normal;
|
font-style: normal;
|
||||||
font-weight: 400;
|
font-weight: 400;
|
||||||
font-display: swap;
|
font-display: swap;
|
||||||
src: url(\${url.resourcesPath}/build/fonts/WorkSans/worksans-regular-webfont.woff2)
|
src: url(https://demo-app.keycloakify.dev/x/y/z/fonts/WorkSans/worksans-regular-webfont.woff2)
|
||||||
format("woff2");
|
format("woff2");
|
||||||
}
|
}
|
||||||
@font-face {
|
@font-face {
|
||||||
font-family: "Work Sans";
|
font-family: "Work Sans";
|
||||||
font-style: normal;
|
font-style: normal;
|
||||||
font-weight: 500;
|
font-weight: 500;
|
||||||
font-display: swap;
|
font-display: swap;
|
||||||
src: url(\${url.resourcesPath}/build/fonts/WorkSans/worksans-medium-webfont.woff2)
|
src: url(https://demo-app.keycloakify.dev/x/y/z/fonts/WorkSans/worksans-medium-webfont.woff2)
|
||||||
format("woff2");
|
format("woff2");
|
||||||
}
|
}
|
||||||
@font-face {
|
@font-face {
|
||||||
font-family: "Work Sans";
|
font-family: "Work Sans";
|
||||||
font-style: normal;
|
font-style: normal;
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
font-display: swap;
|
font-display: swap;
|
||||||
src: url(\${url.resourcesPath}/build/fonts/WorkSans/worksans-semibold-webfont.woff2)
|
src: url(https://demo-app.keycloakify.dev/x/y/z/fonts/WorkSans/worksans-semibold-webfont.woff2)
|
||||||
format("woff2");
|
format("woff2");
|
||||||
}
|
}
|
||||||
@font-face {
|
@font-face {
|
||||||
font-family: "Work Sans";
|
font-family: "Work Sans";
|
||||||
font-style: normal;
|
font-style: normal;
|
||||||
font-weight: 700;
|
font-weight: 700;
|
||||||
font-display: swap;
|
font-display: swap;
|
||||||
src: url(\${url.resourcesPath}/build/fonts/WorkSans/worksans-bold-webfont.woff2)
|
src: url(https://demo-app.keycloakify.dev/x/y/z/fonts/WorkSans/worksans-bold-webfont.woff2)
|
||||||
format("woff2");
|
format("woff2");
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
assetIsSameCode(fixedCssCode, fixedCssCodeExpected);
|
expect(isSameCode(fixedCssCode, fixedCssCodeExpected)).toBe(true);
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
const { fixedCssCode } = replaceImportsInInlineCssCode({
|
|
||||||
cssCode,
|
|
||||||
"buildOptions": {
|
|
||||||
"isStandalone": false,
|
|
||||||
"urlOrigin": "https://demo-app.keycloakify.dev",
|
|
||||||
"urlPathname": "/x/y/z/"
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
});
|
||||||
const fixedCssCodeExpected = `
|
});
|
||||||
@font-face {
|
|
||||||
font-family: "Work Sans";
|
|
||||||
font-style: normal;
|
|
||||||
font-weight: 400;
|
|
||||||
font-display: swap;
|
|
||||||
src: url(https://demo-app.keycloakify.dev/x/y/z/fonts/WorkSans/worksans-regular-webfont.woff2)
|
|
||||||
format("woff2");
|
|
||||||
}
|
|
||||||
@font-face {
|
|
||||||
font-family: "Work Sans";
|
|
||||||
font-style: normal;
|
|
||||||
font-weight: 500;
|
|
||||||
font-display: swap;
|
|
||||||
src: url(https://demo-app.keycloakify.dev/x/y/z/fonts/WorkSans/worksans-medium-webfont.woff2)
|
|
||||||
format("woff2");
|
|
||||||
}
|
|
||||||
@font-face {
|
|
||||||
font-family: "Work Sans";
|
|
||||||
font-style: normal;
|
|
||||||
font-weight: 600;
|
|
||||||
font-display: swap;
|
|
||||||
src: url(https://demo-app.keycloakify.dev/x/y/z/fonts/WorkSans/worksans-semibold-webfont.woff2)
|
|
||||||
format("woff2");
|
|
||||||
}
|
|
||||||
@font-face {
|
|
||||||
font-family: "Work Sans";
|
|
||||||
font-style: normal;
|
|
||||||
font-weight: 700;
|
|
||||||
font-display: swap;
|
|
||||||
src: url(https://demo-app.keycloakify.dev/x/y/z/fonts/WorkSans/worksans-bold-webfont.woff2)
|
|
||||||
format("woff2");
|
|
||||||
}
|
|
||||||
`;
|
|
||||||
|
|
||||||
assetIsSameCode(fixedCssCode, fixedCssCodeExpected);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log("PASS replace import from static");
|
|
@ -1,13 +1,14 @@
|
|||||||
import { getKcContext } from "../../src/login/kcContext/getKcContext";
|
import { getKcContext } from "keycloakify/login/kcContext/getKcContext";
|
||||||
import type { ExtendKcContext } from "../../src/login/kcContext/getKcContextFromWindow";
|
import type { ExtendKcContext } from "keycloakify/login/kcContext/getKcContextFromWindow";
|
||||||
import type { KcContext } from "../../src/login/kcContext";
|
import type { KcContext } from "keycloakify/login/kcContext";
|
||||||
import { same } from "evt/tools/inDepth";
|
import { same } from "evt/tools/inDepth";
|
||||||
import { assert } from "tsafe/assert";
|
import { assert } from "tsafe/assert";
|
||||||
import type { Equals } from "tsafe";
|
import type { Equals } from "tsafe";
|
||||||
import { kcContextMocks, kcContextCommonMock } from "../../src/login/kcContext/kcContextMocks";
|
import { kcContextMocks, kcContextCommonMock } from "keycloakify/login/kcContext/kcContextMocks";
|
||||||
import { deepClone } from "../../src/tools/deepClone";
|
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";
|
const displayName = "this is an overwritten common value";
|
||||||
@ -59,8 +60,7 @@ import { deepClone } from "../../src/tools/deepClone";
|
|||||||
|
|
||||||
return { kcContext };
|
return { kcContext };
|
||||||
};
|
};
|
||||||
|
it("has proper API for login.ftl", () => {
|
||||||
{
|
|
||||||
const pageId = "login.ftl";
|
const pageId = "login.ftl";
|
||||||
|
|
||||||
const { kcContext } = getKcContextProxy({ "mockPageId": pageId });
|
const { kcContext } = getKcContextProxy({ "mockPageId": pageId });
|
||||||
@ -69,7 +69,7 @@ import { deepClone } from "../../src/tools/deepClone";
|
|||||||
|
|
||||||
assert<Equals<typeof kcContext, KcContext.Login>>();
|
assert<Equals<typeof kcContext, KcContext.Login>>();
|
||||||
|
|
||||||
assert(
|
expect(
|
||||||
same(
|
same(
|
||||||
//NOTE: deepClone for printIfExists or other functions...
|
//NOTE: deepClone for printIfExists or other functions...
|
||||||
deepClone(kcContext),
|
deepClone(kcContext),
|
||||||
@ -81,12 +81,10 @@ import { deepClone } from "../../src/tools/deepClone";
|
|||||||
return mock;
|
return mock;
|
||||||
})()
|
})()
|
||||||
)
|
)
|
||||||
);
|
).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
console.log(`PASS ${pageId}`);
|
it("has a proper API for info.ftl", () => {
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
const pageId = "info.ftl";
|
const pageId = "info.ftl";
|
||||||
|
|
||||||
const { kcContext } = getKcContextProxy({ "mockPageId": pageId });
|
const { kcContext } = getKcContextProxy({ "mockPageId": pageId });
|
||||||
@ -104,7 +102,7 @@ import { deepClone } from "../../src/tools/deepClone";
|
|||||||
>
|
>
|
||||||
>();
|
>();
|
||||||
|
|
||||||
assert(
|
expect(
|
||||||
same(
|
same(
|
||||||
deepClone(kcContext),
|
deepClone(kcContext),
|
||||||
(() => {
|
(() => {
|
||||||
@ -115,12 +113,9 @@ import { deepClone } from "../../src/tools/deepClone";
|
|||||||
return mock;
|
return mock;
|
||||||
})()
|
})()
|
||||||
)
|
)
|
||||||
);
|
).toBe(true);
|
||||||
|
});
|
||||||
console.log(`PASS ${pageId}`);
|
it("has a proper API for register.ftl", () => {
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
const pageId = "register.ftl";
|
const pageId = "register.ftl";
|
||||||
|
|
||||||
const { kcContext } = getKcContextProxy({ "mockPageId": pageId });
|
const { kcContext } = getKcContextProxy({ "mockPageId": pageId });
|
||||||
@ -138,7 +133,7 @@ import { deepClone } from "../../src/tools/deepClone";
|
|||||||
>
|
>
|
||||||
>();
|
>();
|
||||||
|
|
||||||
assert(
|
expect(
|
||||||
same(
|
same(
|
||||||
deepClone(kcContext),
|
deepClone(kcContext),
|
||||||
(() => {
|
(() => {
|
||||||
@ -149,12 +144,9 @@ import { deepClone } from "../../src/tools/deepClone";
|
|||||||
return mock;
|
return mock;
|
||||||
})()
|
})()
|
||||||
)
|
)
|
||||||
);
|
).toBe(true);
|
||||||
|
});
|
||||||
console.log(`PASS ${pageId}`);
|
it("has a proper API for my-extra-page-2.ftl", () => {
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
const pageId = "my-extra-page-2.ftl";
|
const pageId = "my-extra-page-2.ftl";
|
||||||
|
|
||||||
const { kcContext } = getKcContextProxy({ "mockPageId": pageId });
|
const { kcContext } = getKcContextProxy({ "mockPageId": pageId });
|
||||||
@ -173,7 +165,7 @@ import { deepClone } from "../../src/tools/deepClone";
|
|||||||
|
|
||||||
kcContext.aNonStandardValue2;
|
kcContext.aNonStandardValue2;
|
||||||
|
|
||||||
assert(
|
expect(
|
||||||
same(
|
same(
|
||||||
deepClone(kcContext),
|
deepClone(kcContext),
|
||||||
(() => {
|
(() => {
|
||||||
@ -184,12 +176,9 @@ import { deepClone } from "../../src/tools/deepClone";
|
|||||||
return mock;
|
return mock;
|
||||||
})()
|
})()
|
||||||
)
|
)
|
||||||
);
|
).toBe(true);
|
||||||
|
});
|
||||||
console.log(`PASS ${pageId}`);
|
it("has a proper API for my-extra-page-1.ftl", () => {
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
const pageId = "my-extra-page-1.ftl";
|
const pageId = "my-extra-page-1.ftl";
|
||||||
|
|
||||||
console.log("We expect a warning here =>");
|
console.log("We expect a warning here =>");
|
||||||
@ -200,7 +189,7 @@ import { deepClone } from "../../src/tools/deepClone";
|
|||||||
|
|
||||||
assert<Equals<typeof kcContext, KcContext.Common & { pageId: typeof pageId }>>();
|
assert<Equals<typeof kcContext, KcContext.Common & { pageId: typeof pageId }>>();
|
||||||
|
|
||||||
assert(
|
expect(
|
||||||
same(
|
same(
|
||||||
deepClone(kcContext),
|
deepClone(kcContext),
|
||||||
(() => {
|
(() => {
|
||||||
@ -211,32 +200,24 @@ import { deepClone } from "../../src/tools/deepClone";
|
|||||||
return mock;
|
return mock;
|
||||||
})()
|
})()
|
||||||
)
|
)
|
||||||
);
|
).toBe(true);
|
||||||
|
|
||||||
console.log(`PASS ${pageId}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
const pageId = "login.ftl";
|
|
||||||
|
|
||||||
const { kcContext } = getKcContext({
|
|
||||||
"mockPageId": pageId
|
|
||||||
});
|
});
|
||||||
|
it("returns the proper mock for login.ftl", () => {
|
||||||
|
const pageId = "login.ftl";
|
||||||
|
|
||||||
assert<Equals<typeof kcContext, KcContext | undefined>>();
|
const { kcContext } = getKcContext({
|
||||||
|
"mockPageId": pageId
|
||||||
|
});
|
||||||
|
|
||||||
assert(same(deepClone(kcContext), deepClone(kcContextMocks.find(({ pageId: pageId_i }) => pageId_i === pageId)!)));
|
assert<Equals<typeof kcContext, KcContext | undefined>>();
|
||||||
|
|
||||||
console.log("PASS no extension");
|
assert(same(deepClone(kcContext), deepClone(kcContextMocks.find(({ pageId: pageId_i }) => pageId_i === pageId)!)));
|
||||||
}
|
});
|
||||||
|
it("returns the proper mock for login.ftl", () => {
|
||||||
|
const { kcContext } = getKcContext();
|
||||||
|
|
||||||
{
|
assert<Equals<typeof kcContext, KcContext | undefined>>();
|
||||||
const { kcContext } = getKcContext();
|
|
||||||
|
|
||||||
assert<Equals<typeof kcContext, KcContext | undefined>>();
|
assert(kcContext === undefined);
|
||||||
|
});
|
||||||
assert(kcContext === undefined);
|
});
|
||||||
|
|
||||||
console.log("PASS no extension, no mock");
|
|
||||||
}
|
|
@ -1 +0,0 @@
|
|||||||
import "./getKcContext";
|
|
94
test/lib/tools/AndByDiscriminatingKey.type.spec.ts
Normal file
94
test/lib/tools/AndByDiscriminatingKey.type.spec.ts
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
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<Equals<Got, Expected>>();
|
||||||
|
|
||||||
|
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<Equals<Got, Expected>>();
|
||||||
|
});
|
||||||
|
});
|
@ -1,91 +0,0 @@
|
|||||||
import { AndByDiscriminatingKey } from "../../../src/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<Equals<Got, Expected>>();
|
|
||||||
|
|
||||||
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<Equals<Got, Expected>>();
|
|
||||||
}
|
|
@ -1,7 +0,0 @@
|
|||||||
import { assert } from "tsafe/assert";
|
|
||||||
|
|
||||||
export function assetIsSameCode(code1: string, code2: string, message?: string): void {
|
|
||||||
const removeSpacesAndNewLines = (code: string) => code.replace(/\s/g, "").replace(/\n/g, "");
|
|
||||||
|
|
||||||
assert(removeSpacesAndNewLines(code1) === removeSpacesAndNewLines(code2), message);
|
|
||||||
}
|
|
5
test/tools/isSameCode.ts
Normal file
5
test/tools/isSameCode.ts
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
export function isSameCode(code1: string, code2: string): boolean {
|
||||||
|
const removeSpacesAndNewLines = (code: string) => code.replace(/\s/g, "").replace(/\n/g, "");
|
||||||
|
|
||||||
|
return removeSpacesAndNewLines(code1) === removeSpacesAndNewLines(code2);
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user