Using a bare react-native project and the jest react-native tutorial (https://facebook.github.io/jest/docs/tutorial-react-native.html), it seems modules imported according to the current platform cannot be found.
Here is a repository to reproduce the issue: https://github.com/shaoner/reactnativetest
[email protected] test /home/user/Workspace/tests/reactnativetest
jestFAIL tests/Intro-test.js
● Test suite failed to runCannot find module './foo' from 'Intro.js' at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:144:17) at Object.<anonymous> (Intro.js:9:10) at Object.<anonymous> (__tests__/Intro-test.js:3:12)Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: 0.727s
Ran all test suites.
The only interesting line in Intro.js is:
import foo from './foo'
which should by default import foo.ios.js using the options from jest-react-native
Versions and OS:
# npm --version
3.8.6
# node --version
v6.0.0
# react-native --version
react-native-cli: 1.0.0
react-native: 0.34.1
# uname -a
Linux soprano.lan 4.7.2-201.fc24.x86_64 #1 SMP Fri Aug 26 15:58:40 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
With --debug:
# ./node_modules/jest/bin/jest.js --no-cache --debug
jest version = 16.0.1
test framework = jasmine2
config = {
"haste": {
"defaultPlatform": "ios",
"platforms": [
"android",
"ios"
],
"providesModuleNodeModules": [
"react",
"react-native"
]
},
"moduleNameMapper": [
[
"^image![a-zA-Z0-9$_-]+$",
"GlobalImageStub"
],
[
"^[./a-zA-Z0-9$_-]+\\.(bmp|gif|jpg|jpeg|png|psd|svg|webp)$",
"RelativeImageStub"
]
],
"modulePathIgnorePatterns": [
"/home/user/Workspace/tests/reactnativetest/node_modules/react-native/Libraries/react-native/",
"/home/user/Workspace/tests/reactnativetest/node_modules/react-native/packager/"
],
"preprocessorIgnorePatterns": [
"node_modules/(?!(jest-)?react-native|react-clone-referenced-element)"
],
"setupFiles": [
"/home/user/Workspace/tests/reactnativetest/node_modules/babel-polyfill/lib/index.js",
"/home/user/Workspace/tests/reactnativetest/node_modules/jest-react-native/build/setup.js"
],
"testEnvironment": "/home/user/Workspace/tests/reactnativetest/node_modules/jest-environment-node/build/index.js",
"preset": "jest-react-native",
"rootDir": "/home/user/Workspace/tests/reactnativetest",
"name": "-home-user-Workspace-tests-reactnativetest",
"testRunner": "/home/user/Workspace/tests/reactnativetest/node_modules/jest-jasmine2/build/index.js",
"scriptPreprocessor": "/home/user/Workspace/tests/reactnativetest/node_modules/babel-jest/build/index.js",
"usesBabelJest": true,
"automock": false,
"bail": false,
"browser": false,
"cacheDirectory": "/tmp/jest",
"clearMocks": false,
"coveragePathIgnorePatterns": [
"/node_modules/"
],
"coverageReporters": [
"json",
"text",
"lcov",
"clover"
],
"globals": {},
"mocksPattern": "__mocks__",
"moduleDirectories": [
"node_modules"
],
"moduleFileExtensions": [
"js",
"json",
"jsx",
"node"
],
"noStackTrace": false,
"notify": false,
"resetModules": false,
"testPathDirs": [
"/home/user/Workspace/tests/reactnativetest"
],
"testPathIgnorePatterns": [
"/node_modules/"
],
"testRegex": "(/__tests__/.*|\\.(test|spec))\\.jsx?$",
"testURL": "about:blank",
"timers": "real",
"useStderr": false,
"verbose": null,
"watch": false,
"cache": false,
"watchman": true,
"testcheckOptions": {
"times": 100,
"maxSize": 200
}
}
FAIL __tests__/Intro-test.js
● Test suite failed to run
Cannot find module './foo' from 'Intro.js'
at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:144:17)
at Object.<anonymous> (Intro.js:9:10)
at Object.<anonymous> (__tests__/Intro-test.js:3:12)
Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: 2.714s
Ran all test suites.
After investigating a bit, I've found that the HasteMap instance (from jest-haste-map) does not actually register foo in the map object (see _buildHasteMap), therefore the jest module Resolver is not able to find the actual module.
Am I missing something?
The associated pull request: #1947
This will be fixed in the next release. Yay!
Most helpful comment
This will be fixed in the next release. Yay!