React/Jasmine - SyntaxError: Cannot use import statement outside a module

已回答

Hi! I'm trying to configure the Jasmine test runner in IntelliJ. 

/Users/clairenguyen/.nvm/versions/node/v14.17.0/bin/node /Users/clairenguyen/workspace/FLA/flash-docker-development-environment/dice/node_modules/jasmine/bin/jasmine.js --config=/Users/clairenguyen/workspace/FLA/flash-docker-development-environment/dice/spec/support/jasmine.json "--reporter=/Users/clairenguyen/Library/Application Support/JetBrains/IntelliJIdea2022.2/plugins/IdeaJasmine/lib/intellij_reporter.js"
/Users/clairenguyen/workspace/FLA/flash-docker-development-environment/dice/spec/helpers/SpecHelper.ts:1
import * as Enzyme from "enzyme";
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at wrapSafe (internal/modules/cjs/loader.js:984:16)
    at Module._compile (internal/modules/cjs/loader.js:1032:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1097:10)
    at Module.load (internal/modules/cjs/loader.js:933:32)
    at Function.Module._load (internal/modules/cjs/loader.js:774:14)
    at Module.require (internal/modules/cjs/loader.js:957:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at /Users/clairenguyen/workspace/FLA/flash-docker-development-environment/dice/node_modules/jasmine/lib/jasmine.js:99:5
    at Array.forEach (<anonymous>)
    at Jasmine.loadHelpers (/Users/clairenguyen/workspace/FLA/flash-docker-development-environment/dice/node_modules/jasmine/lib/jasmine.js:98:20)

Process finished with exit code 4





package.json:

{
....
"scripts": {
"build": "webpack -p",
"fix": "tslint --project tsconfig.json --fix",
"lint": "tslint --project tsconfig.json",
"start": "webpack-dev-server",
"test": "nyc ts-node node_modules/jasmine/bin/jasmine",
"test-nocov": "ts-node node_modules/jasmine/bin/jasmine --random=false",
"prettier-check": "prettier --check .",
"prettier-write": "prettier --write .",
"watch": "webpack --watch",
"prepare": "husky install"
},
....


I noticed in we have the `nyc ts-node` as part of the `test` script but I'm not sure how to include that in the intellij configs. Advice appreciated!

0

Wow nevermind. I answered my own question... 

I added `./node_modules/nyc/bin/nyc.js ./node_modules/ts-node/dist/bin.js` to the Node Options. 

0

If you have any other questions, please, let us know; we will be happy to help.

0

Hi! I'm running into this error:

Test framework quit unexpectedly

I ended up creating a new stripped down version of my app with the package versions I'm using. It works in the terminal but not in the IDE;  I'm getting the same error as above with this output:  

/Users/clairenguyen/.nvm/versions/node/v14.17.0/bin/node ./node_modules/ts-node/dist/bin.js /Users/clairenguyen/workspace/test/jasmine/jasmine-test/node_modules/jasmine/bin/jasmine.js "--reporter=/Users/clairenguyen/Library/Application Support/JetBrains/IntelliJIdea2022.2/plugins/IdeaJasmine/lib/intellij_reporter.js" /Users/clairenguyen/workspace/test/jasmine/jasmine-test/spec/AppSpec.tsx "--filter=app.runs in intellij using jasmine runner"
Randomized with seed 39117
Started
.


1 spec, 0 failures
Finished in 0.004 seconds

Randomized with seed 39117

Process finished with exit code 0

Advice appreciated! 

The app: https://github.com/clairenguyen/jasmine-test 

0

Please report the issue to the plugin vendor, https://github.com/jasmine/IdeaJasmine/issues

For now, I can only suggest running tests with npm test or using Node.js run configuration:

0

请先登录再写评论。