gertqin / vuex-class-modules

Typescript class decorators for vuex modules
MIT License
194 stars 20 forks source link

jest typescript fails #42

Closed vandriesh closed 3 years ago

vandriesh commented 4 years ago

after deciding to use vuex-class-modules this happened :

● 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:

/Users/vandries/workspaces/rba.ui/node_modules/vuex-class-modules/lib/index.js:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){export { Action } from "./actions";
                                                                                         ^^^^^^

SyntaxError: Unexpected token 'export'

  2 | // import ... // removed
  3 | // import ...// removed
> 4 | import { VuexModule, Module, Mutation, Action } from 'vuex-class-modules';
    | ^
  5 | import store from '../index';
  6 | 
  7 | @Module

  at ScriptTransformer._transformAndBuildScript (node_modules/@jest/transform/build/ScriptTransformer.js:537:17)
  at ScriptTransformer.transform (node_modules/@jest/transform/build/ScriptTransformer.js:579:25)

the app works as expected vue,typescript,vuex (default generated by vue cli)

bodograumann commented 4 years ago

Oh yeah, I had the same problem. It does tell you what to do, kinda:

To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.

In other words: you need to tell jest to transform the vuex-class-modules dependency with babel, because it provides esm format only. When I hit this problem I could not find out how to do it in the context of vue-cli though...

Related; there was an effort to add commonjs support: https://github.com/gertqin/vuex-class-modules/pull/26

gertqin commented 3 years ago

Now that commonjs is supported, this issue should be solved, right @bodograumann ?

bodograumann commented 3 years ago

I would think so. @vandriesh can you please update to version 1.2.0 and retry the tests?

vandriesh commented 3 years ago

@bodograumann I'm sorry - I've moved a long time ago from the project where I used vue. - next time... (will close for now)

thanks everyone! and a Happy New Year!