However if you do not want to create a svelte.config.js at the root of your
project or you wish to use a custom config just for tests, you may pass the
path to the config file to the preprocess option thus:
Note that TypeScript supports ES modules, so if you were previously using babel-jest just for ES module transpilation, you can remove babel-jest, babel, and any associated presets and config.
By default, ts-jest will only transpile .ts files though, so if you want to continue using ES modules in .js files, you'll need to configure ts-jest to process .js files as well.
To do this, update the file glob above, and follow the instructions in the ts-jest docs.
Preprocess
Preprocessors are loaded from svelte.config.js or svelte.config.cjs.
rootMode (default: ""): Pass in upward to walk up from the transforming file's directory and use the first svelte.config.js or svelte.config.cjs found, or throw an error if no config file is discovered. This is particularly useful in a monorepo as it allows you to:
Run tests from the worktree root using Jest projects where you only want to put svelte.config.js in workspace folders, and not in the root.
Run tests from the worktree root using Jest projects, but have different svelte.config.js configurations for individual workspaces.
Have one common svelte.config.js in your worktree root (or any directory above the file being transformed) without needing individual svelte.config.js files in each workspace. Note - this root config file can be overriden if necessary by putting another config file into a workspace folder
The default mode is to load svelte.config.js or svelte.config.cjs from the current project root to avoid the risk of accidentally loading a config file from outside the current project folder.
When upward is set it will stop at the first config file it finds above the file being transformed, but will walk up the directory structure all the way to the filesystem root if it cannot find any config file. This means that if there is no svelte.config.js or svelte.config.cjs file in the project above the file being transformed, it is always possible that someone will have a forgotten config file in their home directory which could cause unexpected errors in your builds.
CJS mode options
showConsoleLog (default: false): If you'd like to see console.logs of the preprocessors then pass in true. Otherwise these will be surpressed, because the compiler could complain about unexpected tokens.
maxBuffer (default: 10485760): Sets limit for buffer when preprocess is true. It defines the largest amount of data in bytes allowed on stdout or stderr for child_process.spawnSync. If exceeded, the child process is terminated and any output is truncated. The default value of 10Mb overrides Node's default value of 1Mb.
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.