-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Fix open handles to improve test lisibility
We have a lot of open handles flooding the end of our test results. It seems that they are due to a React issue fixed in 18+. Dan Abramov wrote a small package to fix the issue temporarly. I added it here manually because it has an error in the semver version check. This code should be removed when upgrading React to 18+. facebook/react#20756 (comment)
- Loading branch information
Showing
2 changed files
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* eslint-disable no-console */ | ||
/* eslint-disable prettier/prettier */ | ||
'use strict'; | ||
|
||
// -- Added by Cozy -- | ||
// This code is taken from react-16-node-hanging-test-fix package | ||
// which has an error in the semver version check | ||
// -- Added by Cozy -- | ||
|
||
// See https://github.com/facebook/react/issues/20756 | ||
// This fix is only useful in a test environment with | ||
// Node 15+, jsdom, and React < 17.1.0. | ||
|
||
// It must be imported *before* any imports of 'react-dom'. | ||
|
||
const version = require('react').version; | ||
const semverGt = require('semver/functions/gt'); | ||
|
||
if (Object.prototype.toString.call(process) !== '[object process]') { | ||
throw Error( | ||
'The `react-16-node-hanging-test-fix` package must only be used in a Node environment. ' + | ||
'Remove this import from your application code.' | ||
); | ||
} | ||
|
||
if (semverGt(version, '18.0.0')) { | ||
console.error( | ||
'The `react-16-node-hanging-test-fix` package is no longer needed ' + | ||
'with React ' + version + ' and may cause issues. Remove this import.' | ||
) | ||
} | ||
|
||
// This is the "fix". | ||
delete global.MessageChannel; |