Skip to content

Commit

Permalink
modify approach
Browse files Browse the repository at this point in the history
  • Loading branch information
adonesky1 committed Dec 6, 2022
1 parent 93e7e6c commit 0cc437d
Show file tree
Hide file tree
Showing 6 changed files with 303 additions and 13 deletions.
1 change: 0 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ module.exports = {
'no-negated-condition': 'off',
'no-new': 'off',
'no-param-reassign': 'off',
'node/prefer-global/text-decoder': 'off',
radix: 'off',
'require-atomic-updates': 'off',
'jsdoc/match-description': [
Expand Down
2 changes: 1 addition & 1 deletion packages/assets-controllers/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ module.exports = merge(baseConfig, {
},

// We rely on `window` to make requests
testEnvironment: 'jsdom',
testEnvironment: '<rootDir>/jest.environment.js',
});
18 changes: 18 additions & 0 deletions packages/assets-controllers/jest.environment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/* eslint-disable */
const JSDOMEnvironment = require('jest-environment-jsdom');

// Custom test environment copied from https://github.com/jsdom/jsdom/issues/2524
// in order to add TextEncoder to jsdom. TextEncoder is expected by jose.

module.exports = class CustomTestEnvironment extends JSDOMEnvironment {
async setup() {
await super.setup();
if (typeof this.global.TextEncoder === 'undefined') {
const { TextEncoder, TextDecoder } = require('util');
this.global.TextEncoder = TextEncoder;
this.global.TextDecoder = TextDecoder;
this.global.ArrayBuffer = ArrayBuffer;
this.global.Uint8Array = Uint8Array;
}
}
};
1 change: 1 addition & 0 deletions packages/assets-controllers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"deepmerge": "^4.2.2",
"ethjs-provider-http": "^0.1.6",
"jest": "^26.4.2",
"jest-environment-jsdom": "^26.4.2",
"nock": "^13.0.7",
"sinon": "^9.2.4",
"ts-jest": "^26.5.2",
Expand Down
5 changes: 0 additions & 5 deletions tests/setup.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1 @@
import 'isomorphic-fetch';
// eslint-disable-next-line
import { TextDecoder } from 'util';

// not sure why this is a type mismatch and has to be type cast to any...?
global.TextDecoder = TextDecoder as any;
Loading

0 comments on commit 0cc437d

Please sign in to comment.