Closed jljorgenson18 closed 3 years ago
PASS tests/native/specs/SanityCheck.ts
PASS tests/web/specs/SanityCheck.ts
PASS tests/common/specs/SanityCheck.ts
PASS src/web/components/pages/Dashboards/Widget/SingleNumber/__tests__/View.spec.tsx
PASS src/web/components/__tests__/App.spec.tsx
PASS src/native/components/__tests__/App.spec.tsx
I don't have a root jest config, just this is in package.json
"jest": {
"projects": [
"tests/common/jest.config.js",
"tests/native/jest.config.js",
"tests/web/jest.config.js"
]
},
The test that fails is PASS src/native/components/__tests__/App.spec.tsx
and all it fails at importing
import {
NavigationContainer,
Theme as NavTheme
} from '@react-navigation/native';
Inside of the root App component. Here are the three jest configs
module.exports = {
preset: 'jest-expo',
clearMocks: true,
testMatch: [
'<rootDir>/specs/**/*.[tj]s?(x)',
'**/src/native/**/__tests__/**/*.spec.[jt]s?(x)'
],
roots: ['<rootDir>', '../../'],
setupFiles: ['../../node_modules/react-native-gesture-handler/jestSetup.js'],
setupFilesAfterEnv: ['<rootDir>/setup.ts'],
moduleNameMapper: {},
transform: {
'^.+\\.[jt]sx?$': ['babel-jest', { envName: 'test-expo' }]
},
transformIgnorePatterns: [
'node_modules/(?!(jest-)?react-native' +
'|@react-native-community' +
'|@react-navigation' +
'|native-base' +
'|@expo(nent)?/.*' +
'|expo-.*/.*' +
'|@unimodules' +
'|@codler/react-native-keyboard-aware-scroll-view' +
'|@react-native-picker' +
'|victory-.*/.*' +
'/)'
]
};
module.exports = {
clearMocks: true,
testMatch: [
'<rootDir>/specs/**/*.[tj]s?(x)',
'**/src/common/**/__tests__/**/*.spec.[jt]s?(x)'
],
roots: ['<rootDir>', '../../'],
setupFilesAfterEnv: ['<rootDir>/setup.ts'],
moduleNameMapper: {},
transform: {
'^.+\\.[jt]sx?$': 'babel-jest'
}
};
module.exports = {
clearMocks: true,
testMatch: [
'<rootDir>/specs/**/*.[tj]s?(x)',
'**/src/web/**/__tests__/**/*.spec.[jt]s?(x)'
],
roots: ['<rootDir>', '../../'],
setupFilesAfterEnv: ['<rootDir>/setup.ts'],
moduleNameMapper: {
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$':
'<rootDir>/mocks/fileMock.ts',
'\\.(css|scss)$': '<rootDir>/mocks/styleMock.ts'
},
transform: {
'^.+\\.worker\\.[jt]s$': '<rootDir>/mocks/workerize-jest.js',
'^.+\\.[jt]sx?$': 'babel-jest'
}
};
Thanks, I'm trying to reproduce the issue by creating a sample project, but looks like I'm still missing some configs because running jest from command line is throwing some errors. Can you please share your Babel config and tsconfig.json
?
Here is the babel config
module.exports = api => {
const env = process.env.NODE_ENV;
const isNative = Boolean(process.env.EXPO_TARGET || api.env('test-expo'));
const isTest = api.env('test') || api.env('test-expo');
const isDev = !api.env('production');
api.cache.using(() => env + '-' + isNative);
const aliases = {
src: './src',
tests: './tests'
};
if (!isNative) {
aliases['^react-native$'] = 'react-native-web';
}
const moduleResolverConfig = [
'module-resolver',
{
alias: aliases
}
];
if (isNative) {
return {
presets: ['babel-preset-expo'],
plugins: [moduleResolverConfig]
};
}
return {
presets: [
'@babel/preset-typescript',
[
'@babel/preset-env',
isTest
? {
debug: false,
useBuiltIns: 'usage',
corejs: '3',
targets: {
node: 'current'
}
}
: {
modules: false,
debug: false,
useBuiltIns: 'usage',
corejs: '3'
}
],
'@babel/preset-react'
],
plugins: [
moduleResolverConfig,
'@babel/plugin-proposal-class-properties',
'@babel/plugin-proposal-object-rest-spread',
'lodash',
isDev && !isNative && !isTest ? 'react-refresh/babel' : null,
'babel-plugin-styled-components'
].filter(Boolean)
};
};
I can give the tsconfigs but I don't think they could play a role here as they are only doing type checks and they are a bit complicated. All transpiling is done through babel
Thanks, babel config was enough to reproduce.
Wallaby is using Jest API internally to resolve configs and it looks like the external API may be working slightly differently from the internal Jest config resolution.
The issue is that for some reason Jest seems to either resolve tests/native/jest.config.js
config first or use its transformIgnorePatterns
for the src/native/components/__tests__/*
tests.
Either way, there's a simple solution to make it work, just change your package.json
Jest config to have the tests/native/jest.config.js
project to be the first in the list:
"jest": {
"projects": [
"tests/native/jest.config.js",
"tests/common/jest.config.js",
"tests/web/jest.config.js"
]
},
and everything should work in both Jest CLI and Wallaby Jest.
So actually changing the order somehow screws up the web config which causes JSDom to not be loaded for the web specific tests
nfo]β console.log: Jest: β should render the App
[Info]β The error below may be caused by using the wrong test environment, see https://jestjs.io/docs/en/configuration#testenvironment-string.
[Info]β Consider using the "jsdom" test environment.
[Info]β ReferenceError: document is not defined
[Info]β at render (../../node_modules/@testing-library/react/dist/pure.js:81:5)
This brought me from 1/7 failing tests to 3/7 π
I guess if the external API is not doing the right stuff, there isn't a whole lot that can be done except filing a bug for Jest.
So actually changing the order somehow screws up the web config which causes JSDom to not be loaded for the web specific tests
Hmm, interesting... Let me investigate it a bit more then.
While we're further investigating the issue, here's a workaround that may help: add the same transformIgnorePatterns
as in your tests/native
Jest config to the 2 other Jest configs:
transformIgnorePatterns: [
'node_modules/(?!(jest-)?react-native' +
'|@react-native-community' +
'|@react-navigation' +
'|native-base' +
'|@expo(nent)?/.*' +
'|expo-.*/.*' +
'|@unimodules' +
'|@codler/react-native-keyboard-aware-scroll-view' +
'|@react-native-picker' +
'|victory-.*/.*' +
'/)'
]
Let us know if the workaround works for you.
Adding the additional transformIgnorePatterns didn't seem to change anything. The issue seems to stem more from the presets being slightly off so maybe jest-expo isn't being applied somehow?
I found the issue earlier today which might be related https://github.com/facebook/jest/issues/10111
maybe there was a recent Jest regression?
We've been able to identify the root cause of the issue and fix it. Please force update to the latest Wallaby core v1.0.1062.
@ArtemGovorov Everything seems to be working perfectly now. Thank you so much!
@ArtemGovorov do you have the specific PR or commit that fixes the issue? I am experiencing it as well but with Expo
@trajano Please create a separate issue and provide the details requested in the new issue template, we are happy to take a look and investigate.
Issue description or question
(it's me again, but this time it's a different project so I can share everything)
I'm seeing an odd error related to module processing that I only see in Wallaby when running tests but not when I run jest manually. Even stranger, the issue only started occurring when I moved a test file out of the "tests/native/specs" directory and into the source code under a
__tests__
dir. If I move the file back to the test/native directory, the problem goes away π€·π»ββοΈAnd here it is running just fine when I run jest by itself
It seems like there is something subtly wrong with the Jest Wallaby autoconfiguration but I'm not sure what it is.
Wallaby diagnostics report