Jest: ScriptTransformer.js fails loading identity-obj-proxy checking for transform.process

Created on 24 May 2017  ยท  8Comments  ยท  Source: facebook/jest

Do you want to request a feature or report a bug?
bug

What is the current behavior?
While trying to run tests using jest, enzyme and identity-obj-proxy I'm getting an error when jest-runtime tries to load identity-obj-proxy as a transformer.

Output:

    TypeError: Jest: a transform must export a `process` function.

      at ScriptTransformer._getTransformer (node_modules/jest-runtime/build/ScriptTransformer.js:140:15)
      at Object.<anonymous> (src/app/components/video-player/index.jsx:5:20)

Log:

transformPath: <full_and_correct_path>/node_modules/identity-obj-proxy/src/index.js
transform: {}

Please provide your exact Jest configuration and mention your Jest, node, yarn/npm version and operating system.
OSX 10.12.5
```node -v
v7.8.0


"jest": {
"setupFiles": [
"/webpack/jest/jest.js"
],
"collectCoverageFrom": [
"src/*/.{js,jsx}"
],
"testPathIgnorePatterns": [
"/\\[/\\]"
],
"snapshotSerializers": [
"/node_modules/enzyme-to-json/serializer"
],
"testEnvironment": "node",
"testURL": "http://localhost",
"transform": {
"^.+\.(js|jsx)$": "babel-jest",
"\.(css)$": "identity-obj-proxy",
"^(?!.*\.(js|jsx|css|json)$)": "/webpack/jest/file-transform.js"
},
"transformIgnorePatterns": [
"[/\\]node_modules[/\\].+\.(js|jsx)$"
],
"moduleNameMapper": {
"^react-native$": "react-native-web"
}
}
```

Most helpful comment

@pedrombafonso

fixed

How? ))

All 8 comments

identity-obj-proxy is not a transformer package like babel-jest, so the error seems correct. It seems to be something lower-level a transformer could be built on. Nvm, it's supposed to be used with moduleNameMapper. https://github.com/keyanzhang/jest-css-modules-example/blob/74d381d00922d0d3d4b52818a1b1a5b5b25bc586/package.json#L51

@jwbay thanks for looking into it!
@pedrombafonso move identity-obj-proxy to moduleNameMapper and it will work.

@jwbay @thymikee thanks.

Indeed that solved the error. But probably I'm still missing something, since I'm getting this issue now:

   <full_and_correct_path>styles.css:1
    ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){.className {
                                                                                             ^
    SyntaxError: Unexpected token .

      at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/ScriptTransformer.js:289:17)
      at Object.<anonymous> (src/app/components/component/index.jsx:5:20)
      at Object.<anonymous> (src/app/components/component/__tests__/index.test.js:4:14)

Any idea?

Run with --no-cache flag once.

@thymikee still getting that

$ ./node_modules/.bin/jest --no-cache
 FAIL  src/app/components/component/__tests__/index.test.js
  โ— Test suite failed to run

    <full_and_correct_path>styles.css:1
    ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){.className {
                                                                                             ^
    SyntaxError: Unexpected token .

      at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/ScriptTransformer.js:289:17)
      at Object.<anonymous> (src/app/components/component/index.jsx:5:20)
      at Object.<anonymous> (src/app/components/component/__tests__/index.test.js:4:14)

Jest config

"jest": {
    "setupFiles": [
      "<rootDir>/webpack/jest/jest.js"
    ],
    "collectCoverageFrom": [
      "src/**/*.{js,jsx}"
    ],
    "testPathIgnorePatterns": [
      "<rootDir>[/\\\\](build|docs|node_modules|scripts)[/\\\\]"
    ],
    "testEnvironment": "node",
    "testURL": "http://localhost",
    "transform": {
      "^.+\\.(js|jsx)$": "babel-jest"
    },
    "transformIgnorePatterns": [
      "[/\\\\]node_modules[/\\\\].+\\.(js|jsx)$"
    ],
    "moduleNameMapper": {n
      "\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/webpack/jest/file-transform.js",
      "^.+\\.css$": "identity-obj-proxy",
      "^react-native$": "react-native-web"
    }
  }

.babelrc

{
  "presets": [
    [
      "es2015",
      {
        "modules": false
      }
    ],
    // webpack understands the native import syntax, and uses it for tree shaking
    "react",
    // Transpile React components to JavaScript,
    "stage-2"
  ],
  "plugins": [
    "react-hot-loader/babel"
    // Enables React code to work with HMR.
  ],
  "env": {
    "test": {
      "plugins": [
        "transform-es2015-modules-commonjs"
      ]
    }
  }
}

It runs without errors if I replace identity-obj-proxy by a cssTransformer... although, will get undefined classes.

fixed

@pedrombafonso

fixed

How? ))

bump

Was this page helpful?
0 / 5 - 0 ratings