2024-01-30 00:06:17 +01:00
|
|
|
import { replaceImportsInJsCode_vite } from "keycloakify/bin/keycloakify/replacers/replaceImportsInJsCode/vite";
|
2023-03-18 15:49:45 +01:00
|
|
|
import { generateCssCodeToDefineGlobals, replaceImportsInCssCode } from "keycloakify/bin/keycloakify/replacers/replaceImportsInCssCode";
|
|
|
|
import { replaceImportsInInlineCssCode } from "keycloakify/bin/keycloakify/replacers/replaceImportsInInlineCssCode";
|
2022-07-22 15:35:23 +02:00
|
|
|
import { same } from "evt/tools/inDepth/same";
|
2023-03-30 02:46:25 -06:00
|
|
|
import { expect, it, describe } from "vitest";
|
|
|
|
import { isSameCode } from "../tools/isSameCode";
|
2024-01-30 00:06:17 +01:00
|
|
|
import { basenameOfTheKeycloakifyResourcesDir, nameOfTheGlobal } from "keycloakify/bin/constants";
|
|
|
|
|
|
|
|
describe("bin/js-transforms - vite", () => {
|
|
|
|
it("replaceImportsInJsCode_vite - 1", () => {
|
|
|
|
const before = `Uv="modulepreload",`;
|
|
|
|
const after = `,Wc={},`;
|
|
|
|
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/"
|
|
|
|
}
|
|
|
|
});
|
2023-03-30 02:46:25 -06:00
|
|
|
|
2024-01-30 00:06:17 +01:00
|
|
|
const fixedJsCodeExpected = `${before}Hv=function(e){return"/"+e}${after}`;
|
|
|
|
|
|
|
|
expect(isSameCode(fixedJsCode, fixedJsCodeExpected)).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("replaceImportsInJsCode_vite - 2", () => {
|
|
|
|
const before = `Uv="modulepreload",`;
|
|
|
|
const after = `,Wc={},`;
|
|
|
|
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/"
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
const fixedJsCodeExpected = `${before}Hv=function(e){return"/"+e}${after}`;
|
|
|
|
|
|
|
|
expect(isSameCode(fixedJsCode, fixedJsCodeExpected)).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("replaceImportsInJsCode_vite - 3", () => {
|
2024-01-27 18:49:29 +01:00
|
|
|
const jsCodeUntransformed = `
|
2024-01-30 00:06:17 +01:00
|
|
|
S="/assets/keycloakify-logo-mqjydaoZ.png",H=(()=>{
|
|
|
|
|
2024-01-27 18:49:29 +01:00
|
|
|
function __vite__mapDeps(indexes) {
|
|
|
|
if (!__vite__mapDeps.viteFileDeps) {
|
|
|
|
__vite__mapDeps.viteFileDeps = ["assets/Login-dJpPRzM4.js", "assets/index-XwzrZ5Gu.js"]
|
|
|
|
}
|
|
|
|
return indexes.map((i) => __vite__mapDeps.viteFileDeps[i])
|
|
|
|
}
|
|
|
|
`;
|
2024-01-30 00:06:17 +01:00
|
|
|
|
|
|
|
for (const { reactAppBuildDirPath, assetsDirPath, systemType } of [
|
|
|
|
{
|
|
|
|
"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"
|
|
|
|
}
|
|
|
|
] as const) {
|
|
|
|
const { fixedJsCode } = replaceImportsInJsCode_vite({
|
2024-01-27 18:49:29 +01:00
|
|
|
"jsCode": jsCodeUntransformed,
|
2024-01-30 00:06:17 +01:00
|
|
|
"basenameOfAssetsFiles": ["Login-dJpPRzM4.js", "index-XwzrZ5Gu.js"],
|
|
|
|
"buildOptions": {
|
|
|
|
reactAppBuildDirPath,
|
|
|
|
assetsDirPath,
|
|
|
|
"urlPathname": undefined
|
|
|
|
},
|
|
|
|
systemType
|
2024-01-27 18:49:29 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
const fixedJsCodeExpected = `
|
2024-01-30 00:06:17 +01:00
|
|
|
S=(window.${nameOfTheGlobal}.url + "/${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)"
|
|
|
|
]
|
|
|
|
}
|
|
|
|
return indexes.map((i) => __vite__mapDeps.viteFileDeps[i])
|
2024-01-27 18:49:29 +01:00
|
|
|
}
|
2024-01-30 00:06:17 +01:00
|
|
|
`;
|
|
|
|
|
|
|
|
expect(isSameCode(fixedJsCode, fixedJsCodeExpected)).toBe(true);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
it("replaceImportsInJsCode_vite - 4", () => {
|
|
|
|
const jsCodeUntransformed = `
|
|
|
|
S="/assets/keycloakify-logo-mqjydaoZ.png",H=(()=>{
|
|
|
|
|
|
|
|
function __vite__mapDeps(indexes) {
|
|
|
|
if (!__vite__mapDeps.viteFileDeps) {
|
|
|
|
__vite__mapDeps.viteFileDeps = ["assets/Login-dJpPRzM4.js", "assets/index-XwzrZ5Gu.js"]
|
2024-01-27 18:49:29 +01:00
|
|
|
}
|
2024-01-30 00:06:17 +01:00
|
|
|
return indexes.map((i) => __vite__mapDeps.viteFileDeps[i])
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
|
|
|
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": "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"],
|
|
|
|
"buildOptions": {
|
|
|
|
reactAppBuildDirPath,
|
|
|
|
assetsDirPath,
|
|
|
|
"urlPathname": undefined
|
|
|
|
},
|
|
|
|
systemType
|
|
|
|
});
|
|
|
|
|
|
|
|
const fixedJsCodeExpected = `
|
|
|
|
S=(window.${nameOfTheGlobal}.url + "/${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)"
|
|
|
|
]
|
|
|
|
}
|
|
|
|
return indexes.map((i) => __vite__mapDeps.viteFileDeps[i])
|
|
|
|
}
|
|
|
|
`;
|
2024-01-27 18:49:29 +01:00
|
|
|
|
|
|
|
expect(isSameCode(fixedJsCode, fixedJsCodeExpected)).toBe(true);
|
2024-01-30 00:06:17 +01:00
|
|
|
}
|
|
|
|
});
|
2024-01-27 18:49:29 +01:00
|
|
|
|
2024-01-30 00:06:17 +01:00
|
|
|
it("replaceImportsInJsCode_vite - 5", () => {
|
2024-01-27 18:49:29 +01:00
|
|
|
const jsCodeUntransformed = `
|
2024-01-30 00:06:17 +01:00
|
|
|
S="/foo-bar-baz/assets/keycloakify-logo-mqjydaoZ.png",H=(()=>{
|
|
|
|
|
|
|
|
function __vite__mapDeps(indexes) {
|
|
|
|
if (!__vite__mapDeps.viteFileDeps) {
|
|
|
|
__vite__mapDeps.viteFileDeps = ["assets/Login-dJpPRzM4.js", "assets/index-XwzrZ5Gu.js"]
|
|
|
|
}
|
|
|
|
return indexes.map((i) => __vite__mapDeps.viteFileDeps[i])
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
|
|
|
for (const { reactAppBuildDirPath, assetsDirPath, systemType } of [
|
|
|
|
{
|
|
|
|
"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"
|
|
|
|
}
|
|
|
|
] as const) {
|
|
|
|
const { fixedJsCode } = replaceImportsInJsCode_vite({
|
|
|
|
"jsCode": jsCodeUntransformed,
|
|
|
|
"basenameOfAssetsFiles": ["Login-dJpPRzM4.js", "index-XwzrZ5Gu.js"],
|
|
|
|
"buildOptions": {
|
|
|
|
reactAppBuildDirPath,
|
|
|
|
assetsDirPath,
|
|
|
|
"urlPathname": "/foo-bar-baz/"
|
|
|
|
},
|
|
|
|
systemType
|
|
|
|
});
|
|
|
|
|
|
|
|
const fixedJsCodeExpected = `
|
|
|
|
S=(window.${nameOfTheGlobal}.url + "/${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)"
|
|
|
|
]
|
|
|
|
}
|
|
|
|
return indexes.map((i) => __vite__mapDeps.viteFileDeps[i])
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
|
|
|
expect(isSameCode(fixedJsCode, fixedJsCodeExpected)).toBe(true);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("bin/js-transforms - webpack", () => {
|
|
|
|
const jsCodeUntransformed = `
|
2021-02-21 17:38:59 +01:00
|
|
|
function f() {
|
2021-04-11 18:18:52 +02:00
|
|
|
return a.p+"static/js/" + ({}[e] || e) + "." + {
|
2021-02-21 17:38:59 +01:00
|
|
|
3: "0664cdc0"
|
|
|
|
}[e] + ".chunk.js"
|
|
|
|
}
|
2022-07-22 15:35:23 +02:00
|
|
|
|
2022-07-28 04:24:10 +02:00
|
|
|
function sameAsF() {
|
2021-04-11 18:18:52 +02:00
|
|
|
return a.p+"static/js/" + ({}[e] || e) + "." + {
|
2021-02-21 17:38:59 +01:00
|
|
|
3: "0664cdc0"
|
|
|
|
}[e] + ".chunk.js"
|
|
|
|
}
|
2022-07-22 18:20:50 +02:00
|
|
|
|
2022-09-05 00:08:50 +02:00
|
|
|
__webpack_require__.u=function(e){return"static/js/" + e + "." + {
|
2022-07-22 18:20:50 +02:00
|
|
|
147: "6c5cee76",
|
|
|
|
787: "8da10fcf",
|
|
|
|
922: "be170a73"
|
|
|
|
} [e] + ".chunk.js"
|
|
|
|
}
|
2022-08-02 21:00:52 +02:00
|
|
|
|
|
|
|
t.miniCssF=function(e){return"static/css/"+e+"."+{
|
|
|
|
164:"dcfd7749",
|
|
|
|
908:"67c9ed2c"
|
|
|
|
}[e]+".chunk.css"
|
|
|
|
}
|
2023-09-24 23:42:10 +02:00
|
|
|
|
|
|
|
n.u=e=>"static/js/"+e+"."+{69:"4f205f87",128:"49264537",453:"b2fed72e",482:"f0106901"}[e]+".chunk.js"
|
|
|
|
|
|
|
|
t.miniCssF=e=>"static/css/"+e+"."+{164:"dcfd7749",908:"67c9ed2c"}[e]+".chunk.css"
|
2022-07-22 15:35:23 +02:00
|
|
|
`;
|
2024-01-30 00:06:17 +01:00
|
|
|
it("Correctly replace import path in Webpack build/static/js/xxx.js files", () => {
|
|
|
|
const { fixedJsCode } = replaceImportsFromStaticInJsCode({
|
|
|
|
"jsCode": jsCodeUntransformed,
|
|
|
|
"bundler": "webpack"
|
|
|
|
});
|
2022-07-22 15:35:23 +02:00
|
|
|
|
2024-01-30 00:06:17 +01:00
|
|
|
const fixedJsCodeExpected = `
|
2022-07-22 15:35:23 +02:00
|
|
|
function f() {
|
|
|
|
return window.kcContext.url.resourcesPath + "/build/static/js/" + ({}[e] || e) + "." + {
|
|
|
|
3: "0664cdc0"
|
|
|
|
}[e] + ".chunk.js"
|
|
|
|
}
|
|
|
|
|
2022-07-28 04:24:10 +02:00
|
|
|
function sameAsF() {
|
2022-07-22 15:35:23 +02:00
|
|
|
return window.kcContext.url.resourcesPath + "/build/static/js/" + ({}[e] || e) + "." + {
|
|
|
|
3: "0664cdc0"
|
|
|
|
}[e] + ".chunk.js"
|
|
|
|
}
|
2022-07-22 18:20:50 +02:00
|
|
|
|
2022-09-05 00:08:50 +02:00
|
|
|
__webpack_require__[(function (){
|
2023-09-24 23:42:10 +02:00
|
|
|
var pd = Object.getOwnPropertyDescriptor(__webpack_require__, "p");
|
2022-09-01 17:22:15 +02:00
|
|
|
if( pd === undefined || pd.configurable ){
|
2022-09-05 00:08:50 +02:00
|
|
|
Object.defineProperty(__webpack_require__, "p", {
|
2022-09-01 17:22:15 +02:00
|
|
|
get: function() { return window.kcContext.url.resourcesPath; },
|
2023-09-24 23:42:10 +02:00
|
|
|
set: function() {}
|
2022-09-01 17:22:15 +02:00
|
|
|
});
|
|
|
|
}
|
2022-07-28 04:24:10 +02:00
|
|
|
return "u";
|
|
|
|
})()] = function(e) {
|
2022-07-22 18:20:50 +02:00
|
|
|
return "/build/static/js/" + e + "." + {
|
|
|
|
147: "6c5cee76",
|
|
|
|
787: "8da10fcf",
|
|
|
|
922: "be170a73"
|
|
|
|
} [e] + ".chunk.js"
|
|
|
|
}
|
2022-08-02 21:00:52 +02:00
|
|
|
|
|
|
|
t[(function (){
|
2023-09-24 23:42:10 +02:00
|
|
|
var pd = Object.getOwnPropertyDescriptor(t, "p");
|
2022-09-01 17:22:15 +02:00
|
|
|
if( pd === undefined || pd.configurable ){
|
|
|
|
Object.defineProperty(t, "p", {
|
|
|
|
get: function() { return window.kcContext.url.resourcesPath; },
|
2023-09-24 23:42:10 +02:00
|
|
|
set: function() {}
|
2022-09-01 17:22:15 +02:00
|
|
|
});
|
|
|
|
}
|
2022-08-02 21:00:52 +02:00
|
|
|
return "miniCssF";
|
|
|
|
})()] = function(e) {
|
|
|
|
return "/build/static/css/" + e + "." + {
|
|
|
|
164:"dcfd7749",
|
|
|
|
908:"67c9ed2c"
|
|
|
|
} [e] + ".chunk.css"
|
|
|
|
}
|
2023-09-24 23:42:10 +02:00
|
|
|
|
|
|
|
n[(function(){
|
|
|
|
var pd = Object.getOwnPropertyDescriptor(n, "p");
|
|
|
|
if( pd === undefined || pd.configurable ){
|
|
|
|
Object.defineProperty(n, "p", {
|
|
|
|
get: function() { return window.kcContext.url.resourcesPath; },
|
|
|
|
set: function() {}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return "u";
|
|
|
|
})()] = e => "/build/static/js/"+e+"."+{69:"4f205f87",128:"49264537",453:"b2fed72e",482:"f0106901"}[e]+".chunk.js"
|
|
|
|
|
|
|
|
t[(function(){
|
|
|
|
var pd = Object.getOwnPropertyDescriptor(t, "p");
|
|
|
|
if( pd === undefined || pd.configurable ){
|
|
|
|
Object.defineProperty(t, "p", {
|
|
|
|
get: function() { return window.kcContext.url.resourcesPath; },
|
|
|
|
set: function() {}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return "miniCssF";
|
|
|
|
})()] = e => "/build/static/css/"+e+"."+{164:"dcfd7749",908:"67c9ed2c"}[e]+".chunk.css"
|
2022-07-22 15:35:23 +02:00
|
|
|
`;
|
|
|
|
|
2024-01-30 00:06:17 +01:00
|
|
|
expect(isSameCode(fixedJsCode, fixedJsCodeExpected)).toBe(true);
|
|
|
|
});
|
2023-03-30 02:46:25 -06:00
|
|
|
});
|
|
|
|
|
|
|
|
describe("bin/css-transforms", () => {
|
|
|
|
it("transforms absolute urls to css globals properly with no urlPathname", () => {
|
|
|
|
const { fixedCssCode, cssGlobalsToDefine } = replaceImportsInCssCode({
|
|
|
|
"cssCode": `
|
|
|
|
.my-div {
|
|
|
|
background: url(/logo192.png) no-repeat center center;
|
|
|
|
}
|
|
|
|
|
|
|
|
.my-div2 {
|
2023-12-14 15:33:57 +01:00
|
|
|
background: url(/logo192.png) repeat center center;
|
2023-03-30 02:46:25 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
.my-div {
|
|
|
|
background-image: url(/static/media/something.svg);
|
|
|
|
}
|
|
|
|
`
|
|
|
|
});
|
2022-07-22 15:35:23 +02:00
|
|
|
|
2023-03-30 02:46:25 -06:00
|
|
|
const fixedCssCodeExpected = `
|
2022-07-22 15:35:23 +02:00
|
|
|
.my-div {
|
2023-12-14 15:33:57 +01:00
|
|
|
background: var(--urla882a969fd39473) no-repeat center center;
|
2022-07-22 15:35:23 +02:00
|
|
|
}
|
2023-03-30 02:46:25 -06:00
|
|
|
|
2022-07-22 15:35:23 +02:00
|
|
|
.my-div2 {
|
2023-12-14 15:33:57 +01:00
|
|
|
background: var(--urla882a969fd39473) repeat center center;
|
2022-07-22 15:35:23 +02:00
|
|
|
}
|
2023-03-30 02:46:25 -06:00
|
|
|
|
2022-07-22 15:35:23 +02:00
|
|
|
.my-div {
|
2023-03-30 02:46:25 -06:00
|
|
|
background-image: var(--urldd75cab58377c19);
|
2022-07-22 15:35:23 +02:00
|
|
|
}
|
2023-03-30 02:46:25 -06:00
|
|
|
`;
|
2021-04-11 18:18:52 +02:00
|
|
|
|
2023-03-30 02:46:25 -06:00
|
|
|
expect(isSameCode(fixedCssCode, fixedCssCodeExpected)).toBe(true);
|
2021-02-21 17:38:59 +01:00
|
|
|
|
2023-03-30 02:46:25 -06:00
|
|
|
const cssGlobalsToDefineExpected = {
|
2023-12-14 15:33:57 +01:00
|
|
|
"urla882a969fd39473": "url(/logo192.png)",
|
2023-03-30 02:46:25 -06:00
|
|
|
"urldd75cab58377c19": "url(/static/media/something.svg)"
|
|
|
|
};
|
2021-02-21 17:38:59 +01:00
|
|
|
|
2023-03-30 02:46:25 -06:00
|
|
|
expect(same(cssGlobalsToDefine, cssGlobalsToDefineExpected)).toBe(true);
|
2021-02-21 17:38:59 +01:00
|
|
|
|
2023-03-30 02:46:25 -06:00
|
|
|
const { cssCodeToPrependInHead } = generateCssCodeToDefineGlobals({
|
|
|
|
cssGlobalsToDefine,
|
|
|
|
"buildOptions": {
|
|
|
|
"urlPathname": undefined
|
|
|
|
}
|
|
|
|
});
|
2021-02-21 17:38:59 +01:00
|
|
|
|
2023-03-30 02:46:25 -06:00
|
|
|
const cssCodeToPrependInHeadExpected = `
|
|
|
|
:root {
|
2023-12-14 15:33:57 +01:00
|
|
|
--urla882a969fd39473: url(\${url.resourcesPath}/build/logo192.png);
|
2023-03-30 02:46:25 -06:00
|
|
|
--urldd75cab58377c19: url(\${url.resourcesPath}/build/static/media/something.svg);
|
|
|
|
}
|
|
|
|
`;
|
2021-02-21 17:38:59 +01:00
|
|
|
|
2023-03-30 02:46:25 -06:00
|
|
|
expect(isSameCode(cssCodeToPrependInHead, cssCodeToPrependInHeadExpected)).toBe(true);
|
2022-07-22 15:35:23 +02:00
|
|
|
});
|
2023-03-30 02:46:25 -06:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
`
|
|
|
|
});
|
2021-02-21 17:38:59 +01:00
|
|
|
|
2023-03-30 02:46:25 -06:00
|
|
|
const fixedCssCodeExpected = `
|
2022-07-22 17:22:23 +02:00
|
|
|
.my-div {
|
2023-12-14 15:33:57 +01:00
|
|
|
background: var(--url749a3139386b2c8) no-repeat center center;
|
2022-07-22 17:22:23 +02:00
|
|
|
}
|
2023-03-30 02:46:25 -06:00
|
|
|
|
2022-07-22 17:22:23 +02:00
|
|
|
.my-div2 {
|
2023-12-14 15:33:57 +01:00
|
|
|
background: var(--url749a3139386b2c8) no-repeat center center;
|
2022-07-22 17:22:23 +02:00
|
|
|
}
|
2023-03-30 02:46:25 -06:00
|
|
|
|
2022-07-22 17:22:23 +02:00
|
|
|
.my-div {
|
2023-03-30 02:46:25 -06:00
|
|
|
background-image: var(--url8bdc0887b97ac9a);
|
2022-07-22 17:22:23 +02:00
|
|
|
}
|
2023-03-30 02:46:25 -06:00
|
|
|
`;
|
2022-07-22 17:22:23 +02:00
|
|
|
|
2023-03-30 02:46:25 -06:00
|
|
|
expect(isSameCode(fixedCssCode, fixedCssCodeExpected)).toBe(true);
|
2022-07-22 17:22:23 +02:00
|
|
|
|
2023-03-30 02:46:25 -06:00
|
|
|
const cssGlobalsToDefineExpected = {
|
2023-12-14 15:33:57 +01:00
|
|
|
"url749a3139386b2c8": "url(/x/y/z/logo192.png)",
|
2023-03-30 02:46:25 -06:00
|
|
|
"url8bdc0887b97ac9a": "url(/x/y/z/static/media/something.svg)"
|
|
|
|
};
|
2022-07-22 17:22:23 +02:00
|
|
|
|
2023-03-30 02:46:25 -06:00
|
|
|
expect(same(cssGlobalsToDefine, cssGlobalsToDefineExpected)).toBe(true);
|
2022-07-22 17:22:23 +02:00
|
|
|
|
2023-03-30 02:46:25 -06:00
|
|
|
const { cssCodeToPrependInHead } = generateCssCodeToDefineGlobals({
|
|
|
|
cssGlobalsToDefine,
|
|
|
|
"buildOptions": {
|
|
|
|
"urlPathname": "/x/y/z/"
|
|
|
|
}
|
|
|
|
});
|
2022-07-22 17:22:23 +02:00
|
|
|
|
2023-03-30 02:46:25 -06:00
|
|
|
const cssCodeToPrependInHeadExpected = `
|
|
|
|
:root {
|
2023-12-14 15:33:57 +01:00
|
|
|
--url749a3139386b2c8: url(\${url.resourcesPath}/build/logo192.png);
|
2023-03-30 02:46:25 -06:00
|
|
|
--url8bdc0887b97ac9a: url(\${url.resourcesPath}/build/static/media/something.svg);
|
|
|
|
}
|
|
|
|
`;
|
2022-07-22 17:22:23 +02:00
|
|
|
|
2023-03-30 02:46:25 -06:00
|
|
|
expect(isSameCode(cssCodeToPrependInHead, cssCodeToPrependInHeadExpected)).toBe(true);
|
2022-07-22 17:22:23 +02:00
|
|
|
});
|
2023-03-30 02:46:25 -06:00
|
|
|
});
|
2022-07-22 17:22:23 +02:00
|
|
|
|
2023-03-30 02:46:25 -06:00
|
|
|
describe("bin/css-inline-transforms", () => {
|
|
|
|
describe("no url pathName", () => {
|
|
|
|
const cssCode = `
|
2022-07-22 16:38:44 +02:00
|
|
|
@font-face {
|
|
|
|
font-family: "Work Sans";
|
|
|
|
font-style: normal;
|
|
|
|
font-weight: 400;
|
|
|
|
font-display: swap;
|
|
|
|
src: url("/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("/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("/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("/fonts/WorkSans/worksans-bold-webfont.woff2") format("woff2");
|
|
|
|
}
|
|
|
|
`;
|
2023-03-30 02:46:25 -06:00
|
|
|
it("transforms css for standalone app properly", () => {
|
|
|
|
const { fixedCssCode } = replaceImportsInInlineCssCode({
|
|
|
|
cssCode,
|
|
|
|
"buildOptions": {
|
|
|
|
"urlPathname": undefined
|
|
|
|
}
|
|
|
|
});
|
2022-07-22 16:38:44 +02:00
|
|
|
|
2023-03-30 02:46:25 -06:00
|
|
|
const fixedCssCodeExpected = `
|
2022-07-22 16:38:44 +02:00
|
|
|
@font-face {
|
|
|
|
font-family: "Work Sans";
|
|
|
|
font-style: normal;
|
|
|
|
font-weight: 400;
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
2023-03-30 02:46:25 -06:00
|
|
|
expect(isSameCode(fixedCssCode, fixedCssCodeExpected)).toBe(true);
|
|
|
|
});
|
|
|
|
});
|
2022-07-22 16:38:44 +02:00
|
|
|
|
2023-03-30 02:46:25 -06:00
|
|
|
describe("with url pathName", () => {
|
|
|
|
const cssCode = `
|
2022-07-22 17:33:53 +02:00
|
|
|
@font-face {
|
|
|
|
font-family: "Work Sans";
|
|
|
|
font-style: normal;
|
|
|
|
font-weight: 400;
|
|
|
|
font-display: swap;
|
|
|
|
src: url("/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("/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("/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("/x/y/z/fonts/WorkSans/worksans-bold-webfont.woff2") format("woff2");
|
|
|
|
}
|
|
|
|
`;
|
2023-03-30 02:46:25 -06:00
|
|
|
it("transforms css for standalone app properly", () => {
|
|
|
|
const { fixedCssCode } = replaceImportsInInlineCssCode({
|
|
|
|
cssCode,
|
|
|
|
"buildOptions": {
|
|
|
|
"urlPathname": "/x/y/z/"
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
const fixedCssCodeExpected = `
|
|
|
|
@font-face {
|
|
|
|
font-family: "Work Sans";
|
|
|
|
font-style: normal;
|
|
|
|
font-weight: 400;
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
`;
|
2022-07-22 17:33:53 +02:00
|
|
|
|
2023-03-30 02:46:25 -06:00
|
|
|
expect(isSameCode(fixedCssCode, fixedCssCodeExpected)).toBe(true);
|
2022-07-22 17:33:53 +02:00
|
|
|
});
|
2023-03-30 02:46:25 -06:00
|
|
|
});
|
|
|
|
});
|