/
VueJsPreset.ts
106 lines (97 loc) · 3.47 KB
/
VueJsPreset.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import Preset from './Preset';
import inquirer = require('inquirer');
import PresetConfiguration from './PresetConfiguration';
const handbookUrl = 'https://github.com/stryker-mutator/stryker-handbook/blob/master/stryker/guides/vuejs.md#vuejs';
/**
* More information can be found in the Stryker handbook:
* https://github.com/stryker-mutator/stryker-handbook/blob/master/stryker/guides/vuejs.md#vuejs
*/
export class VueJsPreset implements Preset {
public readonly name = 'vueJs';
private readonly generalDependencies = [
'@stryker-mutator/core',
'@stryker-mutator/vue-mutator',
'@stryker-mutator/html-reporter'
];
private readonly jestDependency = '@stryker-mutator/jest-runner';
private readonly jestConf = `{
mutate: ['src/**/*.js', 'src/**/*.ts', 'src/**/*.vue'],
mutator: 'vue',
testRunner: 'jest',
jest: {
// config: require('path/to/your/custom/jestConfig.js')
},
reporters: ['progress', 'clear-text', 'html'],
coverageAnalysis: 'off'
}`;
private readonly karmaDependency = '@stryker-mutator/karma-runner';
private readonly karmaConf = `{
mutate: ['src/**/*.js', 'src/**/*.ts', 'src/**/*.vue'],
mutator: 'vue',
testRunner: 'karma',
karma: {
configFile: 'test/unit/karma.conf.js',
config: {
browsers: ['ChromeHeadless']
}
},
reporters: ['progress', 'clear-text', 'html'],
coverageAnalysis: 'off'
}`;
public async createConfig(): Promise<PresetConfiguration> {
const testRunnerChoices: inquirer.ChoiceType[] = ['karma', 'jest'];
const testRunnerAnswers = await inquirer.prompt<{ testRunner: string }>({
choices: testRunnerChoices,
message: 'Which test runner do you want to use?',
name: 'testRunner',
type: 'list'
});
const scriptChoices: inquirer.ChoiceType[] = ['typescript', 'javascript'];
const scriptAnswers = await inquirer.prompt<{ script: string }>({
choices: scriptChoices,
message: 'Which language does your project use?',
name: 'script',
type: 'list'
});
const chosenTestRunner = testRunnerAnswers.testRunner;
const chosenScript = scriptAnswers.script;
return {
config: this.getConfigString(chosenTestRunner),
dependencies: this.createDependencies(chosenTestRunner, chosenScript),
handbookUrl
};
}
private getConfigString(testRunner: string) {
if (testRunner === 'karma') {
return this.karmaConf;
} else if (testRunner === 'jest') {
return this.jestConf;
} else {
throw new Error(`Invalid test runner chosen: ${testRunner}`);
}
}
private createDependencies(testRunner: string, script: string): string[] {
const dependencies = this.generalDependencies;
dependencies.push(this.getTestRunnerDependency(testRunner));
dependencies.push(this.getScriptDependency(script));
return dependencies;
}
private getScriptDependency(script: string): string {
if (script === 'typescript') {
return '@stryker-mutator/typescript';
} else if (script === 'javascript') {
return '@stryker-mutator/javascript-mutator';
} else {
throw new Error(`Invalid script chosen: ${script}`);
}
}
private getTestRunnerDependency(testRunner: string): string {
if (testRunner === 'karma') {
return this.karmaDependency;
} else if (testRunner === 'jest') {
return this.jestDependency;
} else {
throw new Error(`Invalid test runner chosen: ${testRunner}`);
}
}
}