Skip to content

Commit

Permalink
[fix] browser package should be a module
Browse files Browse the repository at this point in the history
Adjusted tests accordingly
  • Loading branch information
bomgar committed Aug 3, 2022
1 parent c413516 commit 87275e9
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion jest.config.js → jest.config.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
export default {
preset: 'ts-jest',
collectCoverageFrom: ['<rootDir>/src/**/*.{js,ts}'],
coverageDirectory: 'coverage',
Expand Down
8 changes: 4 additions & 4 deletions packages/browser/jest-environment.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/no-var-requires */
const Environment = require('jest-environment-jsdom');
import Environment from 'jest-environment-jsdom';

/**
* Set up a custom JSDOM-based test environment for Jest so we can add things JSDOM doesn't support
Expand All @@ -13,18 +13,18 @@ class CustomTestEnvironment extends Environment {
* Solved thanks to https://stackoverflow.com/a/57713960/2133271
*/
if (typeof this.global.TextEncoder === 'undefined') {
const { TextEncoder } = require('util');
const { TextEncoder } = await import('util');
this.global.TextEncoder = TextEncoder;
}

/**
* Add support for TextDecoder to JSDOM
*/
if (typeof this.global.TextDecoder === 'undefined') {
const { TextDecoder } = require('util');
const { TextEncoder } = await import('util');
this.global.TextDecoder = TextDecoder;
}
}
}

module.exports = CustomTestEnvironment;
export default CustomTestEnvironment;
4 changes: 2 additions & 2 deletions packages/browser/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const rootConfig = require('../../jest.config');
import rootConfig from '../../jest.config.mjs';

module.exports = {
export default {
...rootConfig,
testEnvironment: '<rootDir>/jest-environment.js',
setupFilesAfterEnv: ['<rootDir>/src/setupTests.ts'],
Expand Down
1 change: 1 addition & 0 deletions packages/browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,6 @@
"rollup-plugin-terser": "^7.0.2",
"rollup-plugin-version-injector": "^1.3.3"
},
"type": "module",
"gitHead": "33ccf8c6c9add811c87d3089e24156c2342b3498"
}

0 comments on commit 87275e9

Please sign in to comment.