Skip to content

Commit

Permalink
fix(jsdom): cumulative Jest updates with support for TextEncoder/Text…
Browse files Browse the repository at this point in the history
…Decoder (#8111)
  • Loading branch information
tim-lai committed Jul 20, 2022
1 parent 516ea6a commit b89e885
Show file tree
Hide file tree
Showing 4 changed files with 6,608 additions and 1,725 deletions.
4 changes: 3 additions & 1 deletion config/jest/jest.unit.config.js
Expand Up @@ -2,16 +2,18 @@ const path = require('path');

module.exports = {
rootDir: path.join(__dirname, '..', '..'),
testEnvironment: 'jsdom',
testEnvironment: 'jest-environment-jsdom',
testMatch: [
'**/test/unit/*.js?(x)',
'**/test/unit/**/*.js?(x)',
],
setupFiles: ['<rootDir>/test/unit/jest-shim.js'],
setupFilesAfterEnv: ['<rootDir>/test/unit/setup.js'],
testPathIgnorePatterns: [
'<rootDir>/node_modules/',
'<rootDir>/test/build-artifacts/',
'<rootDir>/test/mocha',
'<rootDir>/test/unit/jest-shim.js',
'<rootDir>/test/unit/setup.js',
'<rootDir>/test/unit/xss/anchor-target-rel/online-validator-badge.jsx',
'<rootDir>/test/unit/components/online-validator-badge.jsx',
Expand Down

3 comments on commit b89e885

@char0n
Copy link
Member

@char0n char0n commented on b89e885 Aug 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @tim-lai,

Why using util? What is it's purpose here?

As jest runs in Node.js, TextEncoder and TextDecoder are part of global object in our lowest Node.js we claim to support - 12.4.x. Can you please elaborate about this change?

In order to fix the regression described in #8136, we have to uninstall the util npm package and use util directly from node. Modern versions of Node.js allow to use explicit schema to signify where the code comes from:

import { TextEncoder, TextDecoder } from 'node:util';

...but given our minimal supported version of Node.js is currently is 12.4.x which doesn't support explicit node: schema, we have to be careful and not install util npm package.

@tim-lai
Copy link
Contributor Author

@tim-lai tim-lai commented on b89e885 Aug 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@char0n util was added to make TextEncoder and TextDecoder work in Jest. If using an explicit schema node:util works, that's great.

My intention was to only support >Node 14.16, as Node 12.x is EOL and no longer in maintenance. I meant to update this in our docs. Also fyi, Jenkins jobs were recently updated to Node 14.19 as part of this change.

@char0n
Copy link
Member

@char0n char0n commented on b89e885 Aug 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@char0n util was added to make TextEncoder and TextDecoder work in Jest.

util vendor library is not needed, that's what I'm trying to say. TextEncoder and TextDecoder are native part of node.js versions we're using.

If using an explicit schema node:util works, that's great.

It will not work on Node.js 12.x, that's why I didn't use it now and we must make sure we don't install unneded util npm package.

My intention was to only support >Node 14.16, as Node 12.x is EOL and no longer in maintenance. I meant to update this in our docs. Also fyi, Jenkins jobs were recently updated to Node 14.19 as part of this change.

I've issued PR that should remedy this for future - #8142

One thing that we should add there explicitly is the information about what is minimal version of Node.js (from Maintenance LTS) that we support.

Please sign in to comment.