Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix open handles in tests and update testing tools #1028

Merged
merged 7 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions __tests__/jestSetupFile.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import './openHandleFix'

import mockNotifee from '@notifee/react-native/jest-mock'
import mockAsyncStorage from '@react-native-async-storage/async-storage/jest/async-storage-mock'
import mockRNCameraRoll from '@react-native-camera-roll/camera-roll/src/__mocks__/nativeInterface'
Expand Down Expand Up @@ -118,3 +120,10 @@ jest.mock('../src/app/view/OsReceive/state/OsReceiveState', () => ({
candidateApps: undefined
})
}))

jest.mock('react-native/Libraries/Components/Switch/Switch', () => {
const mockComponent = require('react-native/jest/mockComponent')
return {
default: mockComponent('react-native/Libraries/Components/Switch/Switch')
}
})
34 changes: 34 additions & 0 deletions __tests__/openHandleFix.js
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;
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -117,17 +117,17 @@
"@babel/preset-typescript": "7.18.6",
"@babel/runtime": "^7.17.9",
"@svgr/webpack": "5.5.0",
"@testing-library/jest-native": "5.4.2",
"@testing-library/jest-native": "5.4.3",
"@testing-library/react-hooks": "8.0.1",
"@testing-library/react-native": "11.5.0",
"@testing-library/react-native": "12.4.0",
"@types/fs-extra": "9.0.13",
"@types/mime": "^3.0.1",
"@types/react-native": "0.66.4",
"@types/redux-logger": "3.0.9",
"@types/tar": "6.1.3",
"@typescript-eslint/eslint-plugin": "5.54.0",
"@typescript-eslint/parser": "5.54.0",
"babel-jest": "29.4.3",
"babel-jest": "29.7.0",
"babel-loader": "8.2.2",
"babel-plugin-module-resolver": "4.1.0",
"babel-plugin-optional-require": "0.3.1",
Expand All @@ -146,15 +146,15 @@
"eslint-plugin-react-hooks": "4.6.0",
"file-loader": "6.2.0",
"fs-extra": "^11.1.1",
"jest": "29.4.3",
"jest": "29.7.0",
"metro-react-native-babel-preset": "^0.73.6",
"nock": "13.2.9",
"pod-install": "0.1.39",
"prettier": "2.8.4",
"react-app-rewired": "2.1.8",
"react-native-svg-transformer": "1.0.0",
"react-test-renderer": "17.0.2",
"ts-jest": "29.0.5",
"ts-jest": "29.1.1",
"typescript": "4.9.5",
"url-loader": "4.1.1",
"webpack": "5.75.0",
Expand Down
16 changes: 7 additions & 9 deletions src/hooks/useCookieResyncOnResume.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,13 @@ jest.mock('cozy-client', () => ({
function AppStateMock() {}
MicroEE.mixin(AppStateMock)
const mockAppState = new AppStateMock()
jest.mock('react-native', () => ({
AppState: {
currentState: '',
addEventListener: jest.fn().mockImplementation((name, fn) => {
mockAppState.on(name, fn)

return () => mockAppState.removeListener(name, fn)
})
}
jest.mock('react-native/Libraries/AppState/AppState', () => ({
currentState: '',
addEventListener: jest.fn().mockImplementation((name, fn) => {
mockAppState.on(name, fn)

return () => mockAppState.removeListener(name, fn)
})
}))

const FakeApp = () => {
Expand Down
2 changes: 1 addition & 1 deletion src/libs/defaultRedirection/defaultRedirection.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ describe('getOrFetchDefaultRedirectionUrl', () => {
>

beforeAll(() => {
jest.resetAllMocks()
jest.restoreAllMocks()

spyFetchAndSetDefaultRedirectionUrlInBackground = jest
.spyOn(DefaultRedirection, 'fetchAndSetDefaultRedirectionUrlInBackground')
Expand Down
Loading
Loading