From 7e045caab1e1337b0e875821214e69ee358fc81a Mon Sep 17 00:00:00 2001 From: Andras Schmelczer Date: Sun, 5 Jan 2025 20:49:26 +0000 Subject: [PATCH] Fix Jest WASM tests --- .vscode/settings.json | 2 +- plugin/jest.config.js | 7 +- plugin/package.json | 3 +- plugin/webpack.config.js | 207 ++++++++++++++++++++------------------- 4 files changed, 110 insertions(+), 109 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 7528fff7..11cfe5c0 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,4 +1,4 @@ { - "jest.jestCommandLine": "npx jest", + "jest.jestCommandLine": "NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" npx jest", "jest.rootPath": "plugin" } \ No newline at end of file diff --git a/plugin/jest.config.js b/plugin/jest.config.js index 840a552a..8c1027ee 100644 --- a/plugin/jest.config.js +++ b/plugin/jest.config.js @@ -1,8 +1,3 @@ module.exports = { - testEnvironment: "node", - moduleFileExtensions: ["js", "ts"], - testMatch: ["**/src/**/*.test.ts"], - transform: { - "^.+\\.(ts|tsx)$": "ts-jest", - }, + preset: "ts-jest/presets/js-with-babel-esm" }; diff --git a/plugin/package.json b/plugin/package.json index acafe9da..997d4cd8 100644 --- a/plugin/package.json +++ b/plugin/package.json @@ -6,13 +6,12 @@ "scripts": { "dev": "webpack watch --mode development", "build": "webpack --mode production", - "test": "jest", + "test": "NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" jest", "lint": "eslint --fix src && prettier --write \"src/**/*.(ts|scss|json|html)\"", "version": "node version-bump.mjs" }, "keywords": [], "author": "", - "type": "commonjs", "license": "MIT", "prettier": { "trailingComma": "none", diff --git a/plugin/webpack.config.js b/plugin/webpack.config.js index c7f7e0b6..7f661243 100644 --- a/plugin/webpack.config.js +++ b/plugin/webpack.config.js @@ -4,106 +4,113 @@ const MiniCssExtractPlugin = require("mini-css-extract-plugin"); const fs = require("fs-extra"); module.exports = (env, argv) => ({ - devtool: argv.mode === "development" ? "inline-source-map" : false, - entry: { - index: "./src/vault-link-plugin.ts" - }, - watchOptions: { - ignored: "**/node_modules" - }, - externals: { - obsidian: "commonjs obsidian" - }, - optimization: { - minimizer: [ - new TerserPlugin({ - terserOptions: { - module: true - } - }) - ] - }, - plugins: [ - new MiniCssExtractPlugin({ - filename: "styles.css" - }), - new (require("webpack").DefinePlugin)({ - __CURRENT_DATE__: Date.now() - }), - { - apply: (compiler) => { - if (argv.mode !== "development") { - return; - } + devtool: argv.mode === "development" ? "inline-source-map" : false, + entry: { + index: "./src/vault-link-plugin.ts" + }, + watchOptions: { + ignored: "**/node_modules" + }, + externals: { + obsidian: "commonjs obsidian" + }, + optimization: { + minimizer: [ + new TerserPlugin({ + terserOptions: { + module: true + } + }) + ] + }, + plugins: [ + new MiniCssExtractPlugin({ + filename: "styles.css" + }), - compiler.hooks.done.tap("Copy Files Plugin", (stats) => { - const source = path.resolve(__dirname, "dist"); - const destinations = [ - "/mnt/c/Users/Andras/Desktop/test/test/.obsidian/plugins/my-plugin", - "/mnt/c/Users/Andras/Desktop/test/test2/.obsidian/plugins/my-plugin", - "/home/andras/obsidian-test/.obsidian/plugins/my-plugin" - ]; - destinations.forEach((destination) => { - fs.copy(source, destination) - .then(() => console.log("Files copied successfully after build!")) - .catch((err) => console.error("Error copying files:", err)); + new (require("webpack").DefinePlugin)({ + __CURRENT_DATE__: Date.now() + }), + { + apply: (compiler) => { + if (argv.mode !== "development") { + return; + } - fs.createFile(path.join(destination, ".hotreload")); - }); - }); - } - } - ], - module: { - rules: [ - { - test: /\.json$/i, - type: "asset/resource", - generator: { - filename: "[name][ext]" - } - }, - { - test: /\.scss$/i, - use: [ - MiniCssExtractPlugin.loader, - "css-loader", - "resolve-url-loader", - { - loader: "sass-loader", - options: { - sourceMap: true // required by resolve-url-loader - } - } - ] - }, - { - test: /\.ts$/, - use: ["ts-loader"] - }, - { - test: /\.wasm$/, - type: "asset/inline" - } - ] - }, - resolve: { - extensions: [ - ".ts", - ".js" // required for development - ], - alias: { - root: __dirname, - src: path.resolve(__dirname, "src") - } - }, - output: { - clean: true, - filename: "main.js", - library: { - type: "commonjs" // required for Obsidian - }, - path: path.resolve(__dirname, "dist"), - publicPath: "" - } + compiler.hooks.done.tap("Copy Files Plugin", (stats) => { + const source = path.resolve(__dirname, "dist"); + const destinations = [ + "/mnt/c/Users/Andras/Desktop/test/test/.obsidian/plugins/my-plugin", + "/mnt/c/Users/Andras/Desktop/test/test2/.obsidian/plugins/my-plugin", + "/home/andras/obsidian-test/.obsidian/plugins/my-plugin" + ]; + destinations.forEach((destination) => { + fs.copy(source, destination) + .then(() => + console.log( + "Files copied successfully after build!" + ) + ) + .catch((err) => + console.error("Error copying files:", err) + ); + + fs.createFile(path.join(destination, ".hotreload")); + }); + }); + } + } + ], + module: { + rules: [ + { + test: /\.json$/i, + type: "asset/resource", + generator: { + filename: "[name][ext]" + } + }, + { + test: /\.scss$/i, + use: [ + MiniCssExtractPlugin.loader, + "css-loader", + "resolve-url-loader", + { + loader: "sass-loader", + options: { + sourceMap: true // required by resolve-url-loader + } + } + ] + }, + { + test: /\.ts$/, + use: ["ts-loader"] + }, + { + test: /\.wasm$/, + type: "asset/inline" + } + ] + }, + resolve: { + extensions: [ + ".ts", + ".js" // required for development + ], + alias: { + root: __dirname, + src: path.resolve(__dirname, "src") + } + }, + output: { + clean: true, + filename: "main.js", + library: { + type: "commonjs" // required for Obsidian + }, + path: path.resolve(__dirname, "dist"), + publicPath: "" + } });