Victory-native: Jest encountered an unexpected token

Created on 2 Aug 2018  ·  4Comments  ·  Source: FormidableLabs/victory-native

Bugs and Questions

Checklist

  • [x] This is a victory-native specific issue. (Issues that _also_ appear in victory should be opened here)

  • [x] I have read through the FAQ and Guides before asking a question

  • [x] I am using the latest version of victory-native

  • [x] I have checked to make sure that my versions of react-native and react-native-svg are compatible with this version of victory-native. Read about version requirements

  • [x] I've searched open issues to make sure I'm not opening a duplicate issue

The Problem

Since introducing victory-native into my RN application all my unit tests break. I'm using typescript but I'm not sure if that is relevant.

Reproduction

Just re-run the tests.

Feature Requests

Checklist

  • [x] My feature request is specific to victory-native. (Feature requests that do not _specifically_ address native functionality should be opened here)

  • [x] I've read through the Docs and Guides to make sure this functionality doesn't already exist

  • [x] I've searched open issues to make sure I'm not opening a duplicate issue

Description

Error produced in console for every test:

```
FAIL src/appstate/assessments/models.test.ts
● Test suite failed to run

Jest encountered an unexpected token

This usually means that you are trying to import a file which Jest cannot parse, e.g. it's not plain JavaScript.

By default, if Jest sees a Babel config, it will use that to transform your files, ignoring "node_modules".

Here's what you can do:
 • To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
 • If you need a custom transformation specify a "transform" option in your config.
 • If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.

You'll find more details and examples of these config options in the docs:
https://facebook.github.io/jest/docs/en/configuration.html

Details:

/Users/jbradshaw7/ccf/node_modules/victory-native/lib/index.js:2
export {
^^^^^^

SyntaxError: Unexpected token export

   5 | import { logger } from '../services/logger';
   6 | // import { Radar } from 'react-native-pathjs-charts';
>  7 | import { VictoryChart, VictoryTheme, VictoryArea, VictoryPolarAxis, VictoryGroup, VictoryLabel, VictoryLegend, Border } from 'victory-native';
     | ^
   8 | import ScreenInfo from '../services/ScreenInfo';
   9 | import Util from '../services/Util';
  10 | import { $labels } from '../services/i18n';

  at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/script_transformer.js:402:17)
  at Object.<anonymous> (src/components/ScoringChart.tsx:7:1)
  at Object.<anonymous> (src/screens/Assessment/AssessmentScore/AssessmentScore.tsx:16:1)

console.warn node_modules/react-native-document-picker/index.js:8
RNDocumentPicker: Native module is not available, make sure you have finished the installation process and rebuilt your app

=============================== Coverage summary ===============================
Statements : 0% ( 0/1637 )
Branches : 0% ( 0/1235 )
Functions : 0% ( 0/303 )

Lines : 0% ( 0/1475 )

Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: 5.949s
Ran all test suites matching /src/appstate/assessments/models.test.ts/i with tests matching "deserialises empty array data correctly".

```

Most helpful comment

Found the solution I think. Added victory-* to jest transformIgnorePatterns config in package.json:

    "jest": {
        "preset": "react-native",
        "transformIgnorePatterns": [
            "node_modules/(?!native-base-shoutem-theme|native-base|react-native|react-navigation|react-native-fs|victory-*)"
        ],

All 4 comments

Found the solution I think. Added victory-* to jest transformIgnorePatterns config in package.json:

    "jest": {
        "preset": "react-native",
        "transformIgnorePatterns": [
            "node_modules/(?!native-base-shoutem-theme|native-base|react-native|react-navigation|react-native-fs|victory-*)"
        ],

For me specifying victory-* didn't work. I need to add the names of all modules (victory-native|victory-core|victory-shared-events|victory-area etc.)

Adding victory-.* worked for me (.* means match zero or more of any character in regex)

For anyone else running into this issue, @Artorp 's answer worked for me, but first I had to clear the cache (yarn cache clean).

Was this page helpful?
0 / 5 - 0 ratings