From bd23aafc7f699176ed52352732109cc52ddae920 Mon Sep 17 00:00:00 2001 From: frederikprijck Date: Thu, 20 Jul 2023 15:42:48 +0200 Subject: [PATCH] Fix jest tests for ESM --- jest.config.js | 41 +++++++++++++++++++++-------------------- package.json | 4 ++-- 2 files changed, 23 insertions(+), 22 deletions(-) diff --git a/jest.config.js b/jest.config.js index 28a2af0..7a6e53c 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,21 +1,22 @@ -module.exports = { - rootDir: './', - moduleFileExtensions: ['ts', 'js'], - testMatch: ['**/test/**/*.test.ts', '**/test/tests.ts'], - coverageProvider: 'v8', - coveragePathIgnorePatterns: [ - '/node_modules/', - './jest.config.js', - './test', +/** @type {import('ts-jest').JestConfigWithTsJest} */ +export default { + rootDir: "./", + moduleFileExtensions: ["ts", "js"], + testMatch: ["**/test/**/*.test.ts", "**/test/tests.ts"], + coverageProvider: "v8", + coveragePathIgnorePatterns: ["/node_modules/", "./jest.config.js", "./test"], + extensionsToTreatAsEsm: ['.ts'], + reporters: [ + "default", + ["jest-junit", { outputDirectory: "test-results/jest" }], + ], + coverageReporters: ["lcov", "text", "text-summary"], + setupFiles: [], + preset: 'ts-jest/presets/default-esm', + transform: { + "^.+\\.ts?$": [ + "ts-jest", + { useESM: true, tsconfig: "./tsconfig.test.json" }, ], - reporters: [ - 'default', - ['jest-junit', { outputDirectory: 'test-results/jest' }] - ], - coverageReporters: ['lcov', 'text', 'text-summary'], - setupFiles: [], - preset: 'ts-jest', - transform: { - '^.+\\.ts?$': ['ts-jest', {tsconfig: './tsconfig.test.json'}] - }, - }; \ No newline at end of file + }, +}; diff --git a/package.json b/package.json index 2932ea4..a96461f 100644 --- a/package.json +++ b/package.json @@ -20,8 +20,8 @@ "build": "rimraf dist && rollup -m -c --environment NODE_ENV:production", "postbuild": "echo '{\"type\": \"commonjs\"}'> dist/cjs/package.json", "test": "npm run test:node && npm run test:browser", - "test:node": "jest --coverage", - "test:browser": "jest --coverage --testEnvironment=jsdom" + "test:node": "NODE_OPTIONS='--experimental-vm-modules --no-warnings' jest --coverage", + "test:browser": "NODE_OPTIONS='--experimental-vm-modules --no-warnings' jest --coverage --testEnvironment=jsdom" }, "author": "Jose F. Romaniello (http://joseoncode.com)", "contributors": [