Skip to content

Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.

Add a file transform to jest to handle assets (#392)

Mateusz Burzyński2c39885160a3
diff --git a/apps/designer/jest.config.js b/apps/designer/jest.config.js
index 4bcfacedcd..1a2a0f591f 100644
--- a/apps/designer/jest.config.js
+++ b/apps/designer/jest.config.js
@@ -1,3 +1,6 @@
+/**
+ * @type {import('@jest/types').Config.InitialOptions}
+ */
module.exports = {
testEnvironment: "node",
testMatch: ["<rootDir>/app/**/*.test.ts"],
@@ -13,6 +16,7 @@ module.exports = {
},
},
],
+ "^.+\\.webp$": "@webstudio-is/jest-config/file-transform",
},
moduleNameMapper: {
"^~/(.*)$": "<rootDir>/app/$1",
diff --git a/packages/jest-config/file-transform.js b/packages/jest-config/file-transform.js
new file mode 100644
index 0000000000..7fe90190ed
--- /dev/null
+++ b/packages/jest-config/file-transform.js
@@ -0,0 +1,8 @@
+/* eslint-disable @typescript-eslint/no-var-requires */
+const path = require("path");
+
+module.exports = {
+ process(src, filename) {
+ return `module.exports = ${JSON.stringify(path.basename(filename))};`;
+ },
+};
diff --git a/packages/jest-config/index.js b/packages/jest-config/index.js
index 8c47238ded..007382ef4d 100644
--- a/packages/jest-config/index.js
+++ b/packages/jest-config/index.js
@@ -1,3 +1,6 @@
+/**
+ * @type {import('@jest/types').Config.InitialOptions}
+ */
module.exports = {
testEnvironment: "node",
testMatch: ["<rootDir>/src/**/*.test.ts"],
@@ -8,6 +11,7 @@ module.exports = {
sourcemap: true,
},
],
+ "^.+\\.webp$": require.resolve("./file-transform.js"),
},
moduleNameMapper: {
"^~/(.*)$": "<rootDir>/src/$1",