dirv / svelte-test-register

Compile imported Svelte 3 components on Node (e.g. for test runners like Mocha and Jasmine)
MIT License
2 stars 0 forks source link
jasmine mocha svelte testing

npm version install size build status license

svelte-test-register

If you're using Mocha or Jasmine to run tests against Svelte components, you'll need to configure Node to compile your .svelte files. That's what this script does. It registers Svelte compilation outside of the production Rollup build process.

It also installs source map support so that stack traces map back to the original .svelte file.

Installation

npm install --save-dev svelte-test-register

Usage with Mocha

In package.json, update the Mocha script entry to require svelte-test-register:

"scripts": {
  "mocha": "mocha --require svelte-test-register"
}

Usage with Jasmine

In spec/support/jasmine.json, update the helpers section to include the index.js from the svelt-test-register package:

"helpers": [
  "../node_modules/svelte-test-register/index.js"
]

What about Jest?

Jest has a different mechanism for transforming specific files. See jest-transform-svelte if you'd like to test Svelte components in Jest.

Known issues

Source map support does not yet work in Jasmine.

Contributing

All contributions are welcome. Please feel free to create issues or raise PRs.