fix TextEncoder/TextDecoder on CI

was working locally but not on CI for some reason
This commit is contained in:
David Lechner
2020-06-10 21:59:34 -05:00
committed by David Lechner
parent ba14910dae
commit c3d4a07053
+6 -7
View File
@@ -1,19 +1,18 @@
const Environment = require('jest-environment-jsdom');
const { TextEncoder, TextDecoder } = require('util')
/**
* A custom environment to set TextDecoder/TextEncoder
* A custom environment to set TextEncoder/TextDecoder
* Thanks https://stackoverflow.com/a/57713960/1976323
*/
module.exports = class CustomTestEnvironment extends Environment {
async setup() {
await super.setup();
if (typeof TextDecoder === 'undefined') {
const { TextDecoder } = require('util');
this.global.TextDecoder = TextDecoder;
}
if (typeof TextEncoder === 'undefined') {
const { TextEncoder } = require('util');
if (this.global.TextEncoder === undefined) {
this.global.TextEncoder = TextEncoder;
}
if (this.global.TextDecoder === undefined) {
this.global.TextDecoder = TextDecoder;
}
}
};