diff --git a/.gitignore b/.gitignore index c9c3cfdefd..4d34676c59 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,6 @@ .nyc_output build node_modules -test src/**.js coverage *.log diff --git a/examples/min-js-web-chat/package.json b/examples/min-js-web-chat/package.json index 46ee30c699..2c5723d1c0 100644 --- a/examples/min-js-web-chat/package.json +++ b/examples/min-js-web-chat/package.json @@ -16,7 +16,7 @@ "scripts": { "start": "react-scripts start", "build": "react-scripts build", - "test": "react-scripts test", + "test": "react-scripts test --env=./test/custom-test-env.js", "eject": "react-scripts eject" }, "eslintConfig": { diff --git a/examples/min-js-web-chat/test/custom-test-env.js b/examples/min-js-web-chat/test/custom-test-env.js new file mode 100644 index 0000000000..e24fa776a4 --- /dev/null +++ b/examples/min-js-web-chat/test/custom-test-env.js @@ -0,0 +1,12 @@ +const Environment = require('jest-environment-jsdom'); + +module.exports = class CustomTestEnvironment extends Environment { + async setup() { + await super.setup(); + if (typeof this.global.TextEncoder === 'undefined') { + const { TextEncoder, TextDecoder } = require('util'); + this.global.TextEncoder = TextEncoder; + this.global.TextDecoder = TextDecoder; + } + } +};