JSPM

  • Created
  • Published
  • Downloads 18181
  • Score
    100M100P100Q151104F
  • License MIT

A Jest transformer for Svelte - compile your components before importing them into tests

Package Exports

  • svelte-jester

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (svelte-jester) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

svelte-jester

Simply precompiles Svelte components before importing them into Jest tests.

version MIT License


Table of Contents

Why not just use x?

Seems like other libraries won't working with preprocessors, won't maintained actively or didn't have proper licensing.

Installation

This library has peerDependencies listings for svelte >= 3.

npm install svelte-jester -D

Add the following to your Jest config

{
  "transform": {
    "^.+\\.svelte$": "svelte-jester"
  },
  "moduleFileExtensions": [
    "js",
    "svelte"
  ]
}

Babel

npm install @babel/core @babel/preset-env babel-jest -D

Add the following to your Jest config

"transform": {
  "^.+\\.js$": "babel-jest",
  "^.+\\.svelte$": "svelte-jester"
}

Create a .babelrc and add the following

{
  "presets": [["@babel/preset-env", { "targets": { "node": "current" } }]]
}

Preprocess

Preprocessors are loaded from svelte.config.js.

Add the following to your Jest config

"transform": {
  "^.+\\.js$": "babel-jest",
  "^.+\\.svelte$": ["svelte-jester", { "preprocess": true }]
}

Create a svelte.config.js file and configure it, see svelte-preprocess for more information.

Options

preprocess (default: false): Pass in true if you are using Svelte preprocessors. They are loaded from svelte.config.js.

debug (default: false): If you'd like to see the output of the compiled code then pass in true.

compilerOptions (default: {}): Use this to pass in Svelte compiler options.

"transform": {
  "^.+\\.js$": "babel-jest",
  "^.+\\.svelte$": ["svelte-jester", { 
    "preprocess": false,
    "debug": false,
    "compilerOptions": {}
  }]
}

Testing Library

This package is required when using Svelte with the Testing Library. If you'd like to avoid including implementation details in your tests, and making them more maintainble in the long run, then consider checking out @testing-library/svelte.

Credits

Thanks to all contributors, inspired by:

LICENSE

MIT