-
Notifications
You must be signed in to change notification settings - Fork 250
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(init): add svelte custom initializer (#4625)
* Add svelte custom initializer * Add guide to configure Stryker for a svelte project
- Loading branch information
Showing
11 changed files
with
212 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
--- | ||
title: Svelte | ||
custom_edit_url: https://github.com/stryker-mutator/stryker-js/edit/master/docs/guides/svelte.md | ||
--- | ||
|
||
Stryker supports Svelte projects out-of-the-box as of Svelte version `>=3.30`. It will also mutate `.svelte` files using your installed version of the svelte compiler. | ||
|
||
<details> | ||
|
||
<summary>History</summary> | ||
|
||
| Version | Changes | | ||
| ------- | ---------------------------------------- | | ||
| 8.0 | Add support for mutating `.svelte` files | | ||
|
||
</details> | ||
|
||
|
||
## Vitest | ||
|
||
This guide assumes you're using the [vitest examples](https://vitest.dev/guide/#examples) as a starting point for unit testing svelte projects with vitest. | ||
|
||
### Install | ||
|
||
Recommended stryker packages: `npm i -D @stryker-mutator/core @stryker-mutator/vitest-runner` | ||
|
||
### Configuration | ||
|
||
After installing the recommended packages, create the `stryker.config.json` file in your repository. | ||
The configuration below contains a good starting point for Svelte projects. | ||
You may have to change some paths like the [mutate](../configuration.md#mutate-string) array. | ||
|
||
```json | ||
{ | ||
"testRunner": "vitest" | ||
} | ||
``` | ||
|
||
## Jest | ||
|
||
Using jest to test your svelte projects can be done using something like the [svelte-jester](https://github.com/svelteness/svelte-jester#svelte-jester) plugin. | ||
|
||
|
||
### Install | ||
|
||
Recommended stryker packages: `npm i -D @stryker-mutator/core @stryker-mutator/jest-runner` | ||
|
||
### Configuration | ||
|
||
After installing the recommended packages, create the `stryker.config.json` file in your repository. | ||
The configuration below contains a good starting point for Svelte projects. | ||
You may have to change some paths like the [mutate](../configuration.md#mutate-string) array. | ||
|
||
```json | ||
{ | ||
"testRunner": "jest" | ||
} | ||
``` | ||
|
||
If you're using native esm, you will also need to set the `--experimental-vm-modules` flag. | ||
|
||
```diff | ||
{ | ||
"testRunner": "jest", | ||
+ "testRunnerNodeArgs": ["--experimental-vm-modules"] | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
packages/core/src/initializer/custom-initializers/custom-initializer.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
packages/core/src/initializer/custom-initializers/svelte-initializer.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import inquirer from 'inquirer'; | ||
|
||
import { CustomInitializer, CustomInitializerConfiguration } from './custom-initializer.js'; | ||
|
||
const guideUrl = 'https://stryker-mutator.io/docs/stryker-js/guides/svelte'; | ||
const reporters = Object.freeze(['progress', 'clear-text', 'html']); | ||
|
||
export class SvelteInitializer implements CustomInitializer { | ||
public readonly name = 'svelte'; | ||
|
||
public async createConfig(): Promise<CustomInitializerConfiguration> { | ||
const testRunnerChoices = ['jest', 'vitest']; | ||
const testRunnerNodeArgs: string[] = []; | ||
const { testRunner } = await inquirer.prompt<{ testRunner: string }>({ | ||
choices: testRunnerChoices, | ||
message: 'Which test runner are you using?', | ||
name: 'testRunner', | ||
type: 'list', | ||
}); | ||
if (testRunner === 'jest') { | ||
const { nativeEsm } = await inquirer.prompt<{ nativeEsm: boolean }>({ | ||
type: 'confirm', | ||
name: 'nativeEsm', | ||
message: 'Are you using native EcmaScript modules? (see https://jestjs.io/docs/ecmascript-modules)', | ||
default: true, | ||
}); | ||
if (nativeEsm) { | ||
testRunnerNodeArgs.push('--experimental-vm-modules'); | ||
} | ||
} | ||
return { | ||
config: { | ||
testRunner, | ||
...(testRunnerNodeArgs.length ? { testRunnerNodeArgs } : {}), | ||
reporters, | ||
}, | ||
dependencies: [`@stryker-mutator/${testRunner}-runner`], | ||
guideUrl, | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters