From f0fe7dce02b21515c8aec88ce58d1f386884be86 Mon Sep 17 00:00:00 2001 From: Franck Royer Date: Fri, 30 Jul 2021 16:32:02 +1000 Subject: [PATCH] Fix TextDecoder error in tests --- .gitignore | 1 - examples/min-js-web-chat/package.json | 2 +- examples/min-js-web-chat/test/custom-test-env.js | 12 ++++++++++++ 3 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 examples/min-js-web-chat/test/custom-test-env.js diff --git a/.gitignore b/.gitignore index c9c3cfdef..4d34676c5 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 46ee30c69..2c5723d1c 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 000000000..e24fa776a --- /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; + } + } +};