diff --git a/jest.config.js b/jest.config.js index 4e38aae38..133cd9ef7 100644 --- a/jest.config.js +++ b/jest.config.js @@ -2,7 +2,7 @@ module.exports = { roots: ["/src/", "/test/"], moduleFileExtensions: ["ts", "tsx", "js", "jsx"], transform: { - "^.+\\.(js|jsx|ts|tsx)$": "babel-jest", + "^.+\\.(js|jsx|ts|tsx|cjs|mjs)$": "/test/jest/config/babelTransform.js", }, transformIgnorePatterns: ["node_modules/(?!react-markdown)/"], testPathIgnorePatterns: [".cypress", "node_modules", "dist"], @@ -15,7 +15,7 @@ module.exports = { ".*?raw$": "/test/__mocks__/fileMock.js", "@player": "/src/Player", "@enums": "/src/Enums", - "@nsdefs": "/src/ScriptEditor/NetscriptDefinitions", + "@nsdefs": "/src/ScriptEditor/NetscriptDefinitions.d.ts", "^monaco-editor$": "/test/__mocks__/NullMock.js", "^monaco-vim$": "/test/__mocks__/NullMock.js", "/utils/Protections$": "/test/__mocks__/NullMock.js", diff --git a/package-lock.json b/package-lock.json index ad1628276..f5b05cf12 100644 --- a/package-lock.json +++ b/package-lock.json @@ -73,6 +73,7 @@ "@typescript-eslint/parser": "^6.9.1", "babel-jest": "^29.7.0", "babel-loader": "^9.1.3", + "babel-plugin-transform-barrels": "github:cmfrydos/babel-plugin-transform-barrels#46a8aa71cf67a544f7144b47d67f3027424e5cdb", "copy-webpack-plugin": "^12.0.2", "css-loader": "^6.8.1", "electron": "^29.4.5", @@ -6313,6 +6314,16 @@ "@babel/core": "^7.4.0 || ^8.0.0-0 <8.0.0" } }, + "node_modules/babel-plugin-transform-barrels": { + "version": "1.0.16", + "resolved": "git+ssh://git@github.com/cmfrydos/babel-plugin-transform-barrels.git#46a8aa71cf67a544f7144b47d67f3027424e5cdb", + "integrity": "sha512-/W8yq9bmjGmwZB3KH3np0aj2Kwq1glFSR8mlvb1LMALpNOO24XWfCTZDPO1saqR8HTcF8ZS5Gk+WSq2FeT84ZQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "fast-glob": "^3.3.2" + } + }, "node_modules/babel-preset-current-node-syntax": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/babel-preset-current-node-syntax/-/babel-preset-current-node-syntax-1.0.1.tgz", diff --git a/package.json b/package.json index f2750c64e..a3b310be0 100644 --- a/package.json +++ b/package.json @@ -74,6 +74,7 @@ "@typescript-eslint/parser": "^6.9.1", "babel-jest": "^29.7.0", "babel-loader": "^9.1.3", + "babel-plugin-transform-barrels": "github:cmfrydos/babel-plugin-transform-barrels#46a8aa71cf67a544f7144b47d67f3027424e5cdb", "copy-webpack-plugin": "^12.0.2", "css-loader": "^6.8.1", "electron": "^29.4.5", diff --git a/test/jest/config/babelTransform.js b/test/jest/config/babelTransform.js new file mode 100644 index 000000000..1212483c3 --- /dev/null +++ b/test/jest/config/babelTransform.js @@ -0,0 +1,16 @@ +const babelJest = require("babel-jest").default; + +module.exports = { + process(sourceText, sourcePath, options) { + const alias = options?.config?.moduleNameMapper; + const extensions = options.config.moduleFileExtensions; + const babelTransformer = babelJest.createTransformer({ + presets: [["@babel/preset-react"], ["@babel/preset-env"], ["@babel/preset-typescript"]], + plugins: [["transform-barrels", { executorName: "jest", alias: alias, extensions: extensions }]], + babelrc: false, + configFile: false, + }); + + return babelTransformer.process(sourceText, sourcePath, options); + }, +};