Home

Awesome

<h1 align="center">๐Ÿงช Add Jest to Sveltekit</h1>

โ“ What is this?

This is an experimental command to run to add Jest to your SvelteKit project.

๐Ÿ›  Usage

You must start with a fresh copy of the official SvelteKit template, which is currently created by running this command:

npm create svelte@latest <app-name>

Once that is set up, run this command in your project directory to set up Jest:

โ—๏ธ When running with TypeScript support enabled, remove comments within tsconfig.json or the adder will fail. This is a known limitation of Preset, as it relies upon JSON.parse.

npx apply rossyman/svelte-add-jest # --no-ssh

After the preset runs,

โš™๏ธ Options

DescriptionFlagNegatedDefault
Interactive Mode--interaction--no-interactionTrue
Jest DOM Support--jest-dom--no-jest-domTrue
Typescript Support--ts--no-tsFalse
JSDOM Jest Env by Default--jsdom--jsdomTrue
Generate Example--examples--no-examplesTrue

๐Ÿ“‘ Relevant Documentation

Routed Tests

If you run into an issue when writing tests for routed svelte components or files (Reference error: describe is not defined), this is a known issue. To fix it, you must modify your svelte.config.js (Specifically the routes property) with the following modification:

kit: {
    // Prior svelte configuration goes here...
    routes: filepath => {
        return ![
            // Exclude spec files
            /\.spec\.(ts|js)$/,
            // Original routes
            /(?:(?:^_|\/_)|(?:^\.|\/\.)(?!well-known))/,
        ].some(regex => regex.test(filepath))
    },
}

The reason we cannot perform this change directly for you, is due to a limitation within Preset.

๐Ÿ˜ต Help! I have a question

Create an issue and we'll try to help.

๐Ÿ˜ก Fix! There is something that needs improvement

Create an issue or pull request and we'll try to fix.

These are new tools, so there are likely to be problems in this project. Thank you for bringing them to our attention or fixing them for us.

๐Ÿ“„ License

MIT


Repository preview image generated with GitHub Social Preview

This README was generated with โค๏ธ by readme-md-generator