Skip to content

"npm start" app works, "npm test" fails test with syntax error on export  #4974

Closed
@JoeCodeswell

Description

@JoeCodeswell

Is this a bug report?

yes

Did you try recovering your dependencies?

yes
(Write your answer here.)

Which terms did you search for in User Guide?

(Write your answer here if relevant.)

Environment

PS ../gold-line-sac > npx create-react-app --info

Environment:
OS: Windows 10
Node: 10.9.0
Yarn: 1.9.4
npm: 6.2.0
Watchman: Not Found
Xcode: N/A
Android Studio: Version 3.1.0.0 AI-173.4819257

Packages: (wanted => installed)
react: ^16.4.2 => 16.4.2
react-dom: ^16.4.2 => 16.4.2
react-scripts: 1.1.5 => 1.1.5

PS ../gold-line-sac >
(paste the output of the command here)

Steps to Reproduce

(Write your steps here:)

  1. cd to my-app

  2. npm start

  3. notice app works importing testobj successfully. Browser displays:
    'testob: '+JSON.stringify(testob)
    testob: {"k1":"v1","k2":"v2","k3":"v3"}

  4. npm test
    FAIL src\App.test.js
    ● Test suite failed to run

    PATH\gold-line-sac\src\m\gold-line-data.mjs:48
    export const testobj = {"k1":"v1", "k2":"v2", "k3":"v3"};
    ^^^^^^

    SyntaxError: Unexpected token export

    at new Script (vm.js:73:7)
    at Object. (src/App.js:9:194)

Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: 1.83s
Ran all test suites.

Expected Behavior

I thought the test would pass

Actual Behavior

the test failed saying it encountered a syntax error:

  1. npm test
    FAIL src\App.test.js
    ● Test suite failed to run

    PATH\gold-line-sac\src\m\gold-line-data.mjs:48
    export const testobj = {"k1":"v1", "k2":"v2", "k3":"v3"};
    ^^^^^^

    SyntaxError: Unexpected token export

    at new Script (vm.js:73:7)
    at Object. (src/App.js:9:194)

Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: 1.83s
Ran all test suites.

Reproducible Demo

(Paste the link to an example project and exact instructions to reproduce the issue.)
Here is the Reproducible Demo Link
https://github.com/JoeCodeswell/react-test-prob-demo

Instructions to reproduce:

  1. install the demo code
  2. run npm start
  3. NOTICE app works importing testobj, etc successfully. Browser displays:
    'testob: '+JSON.stringify(testob)
    testob: {"k1":"v1","k2":"v2","k3":"v3"}
  4. run npm test
  5. NOTICE test FAILS saying "SyntaxError: Unexpected token export.." When this WORKED in the npm start command:
FAIL  src\App.test.js
   Test suite failed to run

    PATH\gold-line-sac\src\m\gold-line-data.mjs:48
    export const testobj =  {"k1":"v1", "k2":"v2", "k3":"v3"};
    ^^^^^^

    SyntaxError: Unexpected token export

      at new Script (vm.js:73:7)
      at Object.<anonymous> (src/App.js:9:194)

Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        1.83s
Ran all test suites.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions