Skip to content

Add back process method for CJS support #71

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 20 commits into from
Sep 11, 2021
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,10 @@ Add the following to your Jest config
Create a `svelte.config.js` file and configure it, see
[svelte-preprocess](https://github.com/kaisermann/svelte-preprocess) for more information.

In CJS mode, `svelte-jester` must start a new a process for each file needing to be preprocessed, which adds a performance overheads.

In ESM mode, this isn't necessary. You can set `NODE_OPTIONS=--experimental-vm-modules` and `"extensionsToTreatAsEsm": [".svelte"]` to run in ESM mode. However, [mocking support is limited, experimental, and undocumented in ESM mode with `unstable_mockModule`](https://github.com/facebook/jest/issues/10025).

## Options

`preprocess` (default: false): Pass in `true` if you are using Svelte preprocessors.
Expand All @@ -176,6 +180,25 @@ The default mode is to load `svelte.config.js` or `svelte.config.cjs` from the c

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](https://nodejs.org/api/child_process.html#child_process_child_process_spawnsync_command_args_options). If exceeded, the child process is terminated and any output is truncated. The default value of 10Mb overrides Node's default value of 1Mb.

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

## Testing Library

This package is required when using Svelte with the [Testing Library](https://testing-library.com/).
Expand Down
10 changes: 2 additions & 8 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,7 @@
export default {
coverageProvider: 'v8',

extensionsToTreatAsEsm: ['.ts'],
moduleFileExtensions: ['js', 'cjs'],

moduleFileExtensions: ['js', 'ts', 'cjs'],

testMatch: ['**/?(*.)+(spec|test).?(c)[tj]s?(x)'],

transform: {
'^.+\\.ts$': 'esbuild-jest'
}
testMatch: ['**/?(*.)+(spec|test).?(c)[j]s?(x)'],
}
Loading