joseluisq / hyperapp-starter

Minimal Hyperapp, Typescript and Parcel starter. :package::rocket::tada:
MIT License
42 stars 6 forks source link

Jest error #2

Closed SteveALee closed 6 years ago

SteveALee commented 6 years ago

Jest is continually starting in the codes status bar and the errors are as follows. Perhaps jest not configured correctly for TS?

FAIL test/app.spec.tsx

  ● 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://jestjs.io/docs/en/configuration.html

    Details:

    C:\projects\hyperapp-starter-master\test\app.spec.tsx:1
    ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import { app, h } from 'hyperapp';
                                                                                             ^^^^^^

    SyntaxError: Unexpected token import

      at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/script_transformer.js:403:17)

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

Test results written to: ..\..\Users\steve\AppData\Local\Temp\jest_runner.json

Finished running all tests. Starting watch mode.
FAIL test/app.spec.tsx

  ● 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://jestjs.io/docs/en/configuration.html

    Details:

    C:\projects\hyperapp-starter-master\test\app.spec.tsx:1
    ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import { app, h } from 'hyperapp';
                                                                                             ^^^^^^

    SyntaxError: Unexpected token import

      at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/script_transformer.js:403:17)

Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        3.046s
Ran all test suites related to changed files.

Test results written to: ..\..\Users\steve\AppData\Local\Temp\jest_runner.json
SteveALee commented 6 years ago

Looks like a module problem

So obviously node doesn't like ES6 imports but I thought tsc should be compiling to ES5 modules

Did this ever work and something with tsc options has changed?

SteveALee commented 6 years ago

Ah - it's only when using the vs code jest extension - running the test script from CLI is fine.

It would be good to get the jest extension to work - but I'm not too bothered right now.

joseluisq commented 6 years ago

I really don't know about the Jest extension in VS Code. sure in the future we can investigate about it.