I have freshly generated React-Native project and yarn test is failing.
jest-expo preset is present in package.json file.
FAIL ./App.test.js
● Test suite failed to run
/Users/haito/Projects/react-native/TalkToMe/node_modules/react-router-native/main.js:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){export * from 'react-router'
^^^^^^
SyntaxError: Unexpected token export
at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/script_transformer.js:305:17)
at Object.<anonymous> (App.js:2:24)
at Object.<anonymous> (App.test.js:2:10)
Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: 0.071s
Ran all test suites.
Edit added babel preset:
FAIL ./App.test.js
● Test suite failed to run
[BABEL] /Users/haito/Projects/react-native/TalkToMe/node_modules/react-native/jest/setup.js: Plugin/Preset files are not allowed to export objects, only functions.
at createDescriptor (node_modules/#babel/core/lib/config/option-manager.js:303:11)
at node_modules/#babel/core/lib/config/option-manager.js:154:12
at Array.map (<anonymous>)
at node_modules/#babel/core/lib/config/option-manager.js:153:48
at cachedFunction (node_modules/#babel/core/lib/config/caching.js:48:17)
at OptionManager.mergeOptions (node_modules/#babel/core/lib/config/option-manager.js:47:18)
at OptionManager.init (node_modules/#babel/core/lib/config/option-manager.js:115:14)
at manageOptions (node_modules/#babel/core/lib/config/option-manager.js:31:30)
at loadConfig (node_modules/#babel/core/lib/config/index.js:15:37)
at transformSync (node_modules/#babel/core/lib/transform-sync.js:13:36)
Related
Description
Getting the following messages during build with hermesEnabled set to true
('...' represent removed text):
(full error log is here)
android\app\build\generated\assets\react\release\index.android.bundle:13:134: warning: the variable "Promise" was not declared in function "isBoldTextEnabled"
...
android\app\build\generated\assets\react\release\index.android.bundle:27:2907: warning: the variable "DebuggerInternal" was not declared in function "value 14#"
...
android\app\build\generated\assets\react\release\index.android.bundle:92:57773: warning: the variable "setTimeout" was not declared in function "wi"
...
fs.js:114
throw err;
^
Error: ENOENT: no such file or directory, open 'android\app\build\intermediates\sourcemaps\react\release\index.android.bundle.packager.map'
at Object.openSync (fs.js:443:3)
at Object.readFileSync (fs.js:343:35)
at Object.<anonymous> (C:\esites-grocery\test2.hermes\plumpclient\node_modules\react-native\scripts\compose-source-maps.js:33:43)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
at startup (internal/bootstrap/node.js:283:19)
FAILURE: Build failed with an exception.
* Where:
Script 'node_modules\react-native\react.gradle' line: 191
* What went wrong:
Execution failed for task ':app:bundleReleaseJsAndAssets'.
> Process 'command 'cmd'' finished with non-zero exit value 1
(The referenced file exists, at least after the build failed).
Environment
Building on Windows 10
React Native version: 0.62.2
What I tried to do
Tried to bump soLoader to 0.8.0 and to 0.8.2 (although this is not supposed to be needed in RN 0.62.2) as suggested in https://github.com/facebook/react-native/issues/25927#issuecomment-539415154
Modifying the following extra packages definition in build.gradle:
extraPackagerArgs: ["--sourcemap-output", "$buildDir/intermediates/assets/release/index.android.bundle.map"]
to
extraPackagerArgs: ["--sourcemap-output", "$buildDir/intermediates/sourcemaps/react/release/index.android.bundle.packager.map"]
Fixed the error (the warnings are still there).
An APK is created and is running..
./gradlew clean
After doing the ./gradlew clean It worked for me.
OR
For Windows:
gralde clean
I am getting an error which in turns return test failed. Not able to find out the solution to it. Have checked but did not found an appropriate answer for it
I have tried following things:
1. Check babel version :using 7.5.5
2. https://github.com/GeekyAnts/NativeBase/issues/977
3. https://gist.github.com/iamvery/4d4b0ef68cd1f2de81b858fe3a2d08c5
4. https://github.com/GeekyAnts/NativeBase/issues/2579
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import connectStyle, { clearThemeCache } from "./src/connectStyle";
SyntaxError: Unexpected identifier
at ScriptTransformer._transformAndBuildScript (../../node_modules/#jest/transform/build/ScriptTransformer.js:471:17)
at ScriptTransformer.transform (../../node_modules/#jest/transform/build/ScriptTransformer.js:513:25)
at Object.<anonymous> (../../node_modules/native-base/src/index.js:1:1)
Test Suites: 1 failed, 1 passed, 2 total
Tests: 4 passed, 4 total
Snapshots: 1 passed, 1 total
Time: 2.022s
Ran all test suites.
npm ERR! Test failed. See above for more details.
Actual result is test failed as have shown above
Expected result is test should pass
you can add this to your jest config file
"transformIgnorePatterns": [ "node_modules/(?!react-native|#shoutem|react-clone-referenced-element|native-base-shoutem-theme)" ]
I am getting the below error while running npm test using jest . I have express app inside which there is client folder which is a create-react-app-2 and when I ejected it the problem is showing up . what to do now ??
Test suite failed to run
ReferenceError: [BABEL] /home/sriram/Desktop/gooodbet/client/scripts/test.js: Unknown option: /home/sriram/Desktop/gooodbet/client/node_modules/babel-preset-react-app/index.js.overrides. Check out http://babeljs.io/docs/usage/options/ for more information about options.
A common cause of this error is the presence of a configuration options object without the corresponding preset name. Example:
Invalid:
`{ presets: [{option: value}] }`
Valid:
`{ presets: [['presetName', {option: value}]] }`
For more detailed information on preset configuration, please see https://babeljs.io/docs/en/plugins#pluginpresets-options. (While processing preset: "/home/sriram/Desktop/gooodbet/client/node_modules/babel-preset-react-app/index.js")
at Logger.error (node_modules/babel-core/lib/transformation/file/logger.js:41:11)
at OptionManager.mergeOptions (node_modules/babel-core/lib/transformation/file/options/option-manager.js:226:20)
at node_modules/babel-core/lib/transformation/file/options/option-manager.js:265:14
at node_modules/babel-core/lib/transformation/file/options/option-manager.js:323:22
at Array.map (<anonymous>)
at OptionManager.resolvePresets (node_modules/babel-core/lib/transformation/file/options/option-manager.js:275:20)
at OptionManager.mergePresets (node_modules/babel-core/lib/transformation/file/options/option-manager.js:264:10)
at OptionManager.mergeOptions (node_modules/babel-core/lib/transformation/file/options/option-manager.js:249:14)
at OptionManager.init (node_modules/babel-core/lib/transformation/file/options/option-manager.js:368:12)
at File.initOptions (node_modules/babel-core/lib/transformation/file/index.js:212:65)
RUNS tests/integration/localAuth.test.js
FAIL tests/integration/localAuth.test.js
localAuth
POST /api/signup
✓ should signup successfully (536ms)
✕ should send 400 for not having email (8ms)
● localAuth › POST /api/signup › should send 400 for not having email
Bad Request
at Test.Object.<anonymous>.Request.callback (node_modules/superagent/lib/node/index.js:804:15)
at IncomingMessage.parser (node_modules/superagent/lib/node/index.js:1036:18)
Test Suites: 2 failed, 2 total
Tests: 1 failed, 1 passed, 2 total
Snapshots: 0 total
Time: 2.378s
Ran all test suites.
I followed this link to
and undo eject of create-react-app and everything works now
I've installed gulp-npm-test following their documentation, that is, in my gulp directory I've got a file test.js that looks like this:
var gulp = require('gulp')
require('gulp-npm-test')(gulp)
var gulp = require('gulp-npm-test')(gulp, {
withoutNpmRun: false
})
But when I run gulp test I get the output like the following:
[17:12:41] Using gulpfile ~/my-project/gulpfile.js
[17:12:41] Starting 'test'...
> my-project#0.0.1 test /Users/wogsland/my-project
> jest
PASS frontend/tests/components/atoms/InputText.test.js
.
.
(many more Jest test passes, no fails)
.
.
FAIL gulp/tasks/test.js
● Test suite failed to run
Your test suite must contain at least one test.
at onResult (node_modules/jest/node_modules/jest-cli/build/TestRunner.js:192:18)
Test Suites: 1 failed, 135 passed, 136 total
Tests: 135 passed, 135 total
Snapshots: 209 passed, 209 total
Time: 92.237s
Ran all test suites.
npm ERR! Test failed. See above for more details.
What am I missing here? I've go a bunch of tests
Looks like the matcher that figures out which files are tests, matches everything that includes in the filename test.js. The default is [ '**/__tests__/**/*.js?(x)', '**/?(*.)(spec|test).js?(x)' ]. So either adapt this one, its testMatch in your jest settings. Or use testPathIgnorePatterns to exclude the /gulp folder.
When running react-native tests in mocha, I'm getting the following error:
> mocha --require test/init.js --compilers js:test/compiler.js 'src/**/*.spec.js'
Initializing tap mocha reporter...
1..7
ok 1 test1
…
not ok 7 test7
ReferenceError: fetch is not defined
at foo (src/foo.js:59:8)
at Context.<anonymous> (src/__specs__/foo.spec.js:9:30)
# tests 7
# pass 6
# fail 1
npm ERR! Test failed. See above for more details.
The problem was that fetch isn't available in a node environment like mocha. I'm not sure why react-native-mock (which I'm also using) doesn't have a mock for it, but the solution was to require isomorphic-fetch when initializing my mocha tests.
Specifically, add an init file to your mocha command-line if you don't have one already:
> mocha --require init.js …
and in init.js, require isomorphic-fetch:
require('isomorphic-fetch')
Then re-run mocha:
> mocha --require test/init.js --compilers js:test/compiler.js 'src/**/*.spec.js' && standard
Initializing tap mocha reporter...
1..7
ok 1 test1
…
ok 7 test7
# tests 7
# pass 7
# fail 0