@zohodesk/codestandard-validator 1.2.4-exp-1 → 1.2.4-exp-3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,180 @@
1
+ "use strict";
2
+
3
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
4
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
5
+ var path = require('path');
6
+ var patternConfig = require('./mutatePattern.json');
7
+ var DEFAULT_MUTATE_PATTERN = patternConfig.defaultPattern;
8
+ function StrykerWrapper(options) {
9
+ options = options || {};
10
+ this._strykerModule = null;
11
+ this._defaultOptions = {
12
+ testRunner: 'jest',
13
+ coverageAnalysis: 'perTest',
14
+ reporters: ['json', 'clear-text'],
15
+ jsonReporter: {
16
+ fileName: options.reportPath || 'reports/mutation/mutation.json'
17
+ },
18
+ cleanTempDir: true,
19
+ concurrency: options.concurrency || Math.max(1, require('os').cpus().length - 1),
20
+ timeoutMS: options.timeoutMS || 60000,
21
+ timeoutFactor: options.timeoutFactor || 1.5,
22
+ logLevel: options.logLevel || 'info',
23
+ allowEmpty: true
24
+ };
25
+ }
26
+ StrykerWrapper.prototype._loadStryker = async function () {
27
+ if (!this._strykerModule) {
28
+ try {
29
+ this._strykerModule = await Promise.resolve().then(() => _interopRequireWildcard(require('@stryker-mutator/core')));
30
+ } catch (err) {
31
+ throw new Error('Failed to load @stryker-mutator/core. Install it: ' + 'npm i --save-dev @stryker-mutator/core @stryker-mutator/jest-runner\n' + err.message);
32
+ }
33
+ }
34
+ return this._strykerModule;
35
+ };
36
+ StrykerWrapper.prototype._buildMutatePatterns = function (sourceFiles) {
37
+ if (!sourceFiles || sourceFiles.length === 0) {
38
+ return [DEFAULT_MUTATE_PATTERN];
39
+ }
40
+ return sourceFiles.map(function (f) {
41
+ return f.replace(/\\/g, '/');
42
+ });
43
+ };
44
+ StrykerWrapper.prototype._buildStrykerConfig = function (sourceFiles, options) {
45
+ options = options || {};
46
+ var mutatePatterns = this._buildMutatePatterns(sourceFiles);
47
+ var config = Object.assign({}, this._defaultOptions, {
48
+ mutate: mutatePatterns
49
+ });
50
+ if (options.testFiles && options.testFiles.length > 0) {
51
+ config.testFiles = options.testFiles.map(function (f) {
52
+ return f.replace(/\\/g, '/');
53
+ });
54
+ }
55
+ if (options.jest) {
56
+ config.jest = Object.assign({
57
+ projectType: 'custom',
58
+ enableFindRelatedTests: true
59
+ }, options.jest);
60
+ }
61
+ if (options.configFile) {
62
+ config.configFile = options.configFile;
63
+ }
64
+ if (options.reportPath) {
65
+ config.jsonReporter = {
66
+ fileName: options.reportPath
67
+ };
68
+ }
69
+ if (options.tempDirName) {
70
+ config.tempDirName = options.tempDirName;
71
+ }
72
+ if (options.thresholds) {
73
+ config.thresholds = options.thresholds;
74
+ }
75
+ return config;
76
+ };
77
+ StrykerWrapper.prototype.run = async function (sourceFiles, options) {
78
+ options = options || {};
79
+ var strykerModule = await this._loadStryker();
80
+ var Stryker = strykerModule.Stryker || strykerModule.default || strykerModule;
81
+ var config = this._buildStrykerConfig(sourceFiles, options);
82
+ try {
83
+ var instance = new Stryker(config);
84
+ var result = await instance.runMutationTest();
85
+ return this._normalizeResult(result);
86
+ } catch (err) {
87
+ throw new Error('Stryker mutation test failed: ' + err.message);
88
+ }
89
+ };
90
+ StrykerWrapper.prototype._normalizeResult = function (rawResult) {
91
+ if (!rawResult) {
92
+ return this._emptyNormalizedResult();
93
+ }
94
+ var mutants = Array.isArray(rawResult) ? rawResult : rawResult.mutants || [];
95
+ var summary = this._buildSummary(mutants);
96
+ var fileMap = this._buildFileMap(mutants);
97
+ return {
98
+ files: fileMap,
99
+ schemaVersion: '1',
100
+ thresholds: {
101
+ high: 80,
102
+ low: 60,
103
+ break: null
104
+ },
105
+ projectRoot: process.cwd(),
106
+ mutants: mutants,
107
+ summary: summary
108
+ };
109
+ };
110
+ StrykerWrapper.prototype._buildSummary = function (mutants) {
111
+ var summary = {
112
+ totalMutants: mutants.length,
113
+ killed: 0,
114
+ survived: 0,
115
+ timeout: 0,
116
+ noCoverage: 0,
117
+ ignored: 0,
118
+ runtimeErrors: 0,
119
+ compileErrors: 0,
120
+ mutationScore: 0
121
+ };
122
+ for (var i = 0; i < mutants.length; i++) {
123
+ var status = (mutants[i].status || '').toLowerCase();
124
+ if (status === 'killed') summary.killed++;else if (status === 'survived') summary.survived++;else if (status === 'timeout') summary.timeout++;else if (status === 'nocoverage') summary.noCoverage++;else if (status === 'ignored') summary.ignored++;else if (status === 'runtimeerror') summary.runtimeErrors++;else if (status === 'compileerror') summary.compileErrors++;
125
+ }
126
+ var detected = summary.killed + summary.timeout;
127
+ var totalValid = summary.totalMutants - summary.ignored - summary.compileErrors - summary.runtimeErrors;
128
+ summary.mutationScore = totalValid > 0 ? parseFloat((detected / totalValid * 100).toFixed(2)) : 0;
129
+ return summary;
130
+ };
131
+ StrykerWrapper.prototype._buildFileMap = function (mutants) {
132
+ var fileMap = {};
133
+ for (var i = 0; i < mutants.length; i++) {
134
+ var mutant = mutants[i];
135
+ var fileName = mutant.fileName || mutant.sourceFile || 'unknown';
136
+ if (!fileMap[fileName]) {
137
+ fileMap[fileName] = [];
138
+ }
139
+ fileMap[fileName].push({
140
+ id: mutant.id,
141
+ mutatorName: mutant.mutatorName,
142
+ replacement: mutant.replacement,
143
+ status: mutant.status,
144
+ location: mutant.location,
145
+ killedBy: mutant.killedBy || [],
146
+ coveredBy: mutant.coveredBy || [],
147
+ description: mutant.description || ''
148
+ });
149
+ }
150
+ return fileMap;
151
+ };
152
+ StrykerWrapper.prototype._emptyNormalizedResult = function () {
153
+ return {
154
+ files: {},
155
+ schemaVersion: '1',
156
+ thresholds: {
157
+ high: 80,
158
+ low: 60,
159
+ break: null
160
+ },
161
+ projectRoot: process.cwd(),
162
+ mutants: [],
163
+ summary: {
164
+ totalMutants: 0,
165
+ killed: 0,
166
+ survived: 0,
167
+ timeout: 0,
168
+ noCoverage: 0,
169
+ ignored: 0,
170
+ runtimeErrors: 0,
171
+ compileErrors: 0,
172
+ mutationScore: 0
173
+ }
174
+ };
175
+ };
176
+ StrykerWrapper.prototype.getDefaultConfig = function () {
177
+ return Object.assign({}, this._defaultOptions);
178
+ };
179
+ module.exports = StrykerWrapper;
180
+ module.exports.DEFAULT_MUTATE_PATTERN = DEFAULT_MUTATE_PATTERN;
@@ -18,23 +18,34 @@ const {
18
18
  executeMethodsThatMayThrowException
19
19
  } = require("../General/wrapperFunctionToExecuteAFunction.js");
20
20
 
21
+ /**
22
+ * Resolve a file from service-specific dir if it exists, otherwise fall back to common dir.
23
+ * @param {string} baseDir
24
+ * @param {string|undefined} repoName
25
+ * @param {string} fileName
26
+ * @param {*} [fallback] - fallback value if no common path desired (e.g. undefined for pluginVersion)
27
+ * @returns {string|undefined}
28
+ */
29
+ function resolveServiceOrCommon(baseDir, repoName, fileName, fallback) {
30
+ if (repoName) {
31
+ const servicePath = path.join(baseDir, 'services', repoName, fileName);
32
+ if (existsSync(servicePath)) return servicePath;
33
+ }
34
+ return fallback !== undefined ? fallback : path.join(baseDir, 'common', fileName);
35
+ }
36
+
21
37
  /**
22
38
  * @function getLintConfiguration - returns eslint configuration file from common linters repo
23
39
  * @returns {object} - containing properties of the eslint configuration file
24
40
  */
25
41
  function getServicePathElseCommon() {
26
42
  const repoName = getRepoName();
27
- const libraryInstalledLocation = getLibraryInstalledLocation();
28
- let commonConfigPath = path.join(libraryInstalledLocation, commonLinterRepoName, 'common', 'index.js');
29
- const _configurationPath = repoName && existsSync(path.join(libraryInstalledLocation, commonLinterRepoName, 'services', repoName, 'index.js')) ? path.join(libraryInstalledLocation, commonLinterRepoName, 'services', repoName, 'index.js') : commonConfigPath;
30
- let _pathOfServiceSpecificEslintConfigFile = repoName && existsSync(path.join(libraryInstalledLocation, commonLinterRepoName, 'services', repoName, '.eslintrc.js')) ? path.join(libraryInstalledLocation, commonLinterRepoName, 'services', repoName, '.eslintrc.js') : path.join(libraryInstalledLocation, commonLinterRepoName, 'common', '.eslintrc.js');
31
- let _pluginVersionPath = repoName && existsSync(path.join(libraryInstalledLocation, commonLinterRepoName, 'services', repoName, 'pluginVersion.js')) ? path.join(libraryInstalledLocation, commonLinterRepoName, 'services', repoName, 'pluginVersion.js') : undefined;
32
- let _cssLintConfig = repoName && existsSync(path.join(libraryInstalledLocation, commonLinterRepoName, 'services', repoName, '.stylelintrc.js')) ? path.join(libraryInstalledLocation, commonLinterRepoName, 'services', repoName, '.stylelintrc.js') : path.join(libraryInstalledLocation, commonLinterRepoName, 'common', '.stylelintrc.js');
43
+ const baseDir = path.join(getLibraryInstalledLocation(), commonLinterRepoName);
33
44
  return {
34
- configurationPath: _configurationPath,
35
- pathOfServiceSpecificEslintConfigFile: _pathOfServiceSpecificEslintConfigFile,
36
- pluginVersionPath: _pluginVersionPath,
37
- pathOfServiceSpecificCssConfigFile: _cssLintConfig
45
+ configurationPath: resolveServiceOrCommon(baseDir, repoName, 'index.js'),
46
+ pathOfServiceSpecificEslintConfigFile: resolveServiceOrCommon(baseDir, repoName, '.eslintrc.js'),
47
+ pluginVersionPath: resolveServiceOrCommon(baseDir, repoName, 'pluginVersion.js', null) || undefined,
48
+ pathOfServiceSpecificCssConfigFile: resolveServiceOrCommon(baseDir, repoName, '.stylelintrc.js')
38
49
  };
39
50
  }
40
51
  function getLintConfigurationUtil() {
@@ -3,9 +3,7 @@
3
3
  const {
4
4
  Logger
5
5
  } = require('../Logger/Logger');
6
- const {
7
- existsSync
8
- } = require("fs");
6
+ const path = require('path');
9
7
  /**
10
8
  * @function filterFiles - removes certain files from set of source files
11
9
  * @param {Array} arrayOfFilesToBeFiltered - array of files which must be filtered
@@ -20,14 +18,18 @@ function filterFiles(arrayOfFilesToBeFiltered, filesToBeRemoved, isConfigFileNee
20
18
  * @returns {Array<String>}
21
19
  * */
22
20
  function filterFilesByExtension(lintFiles) {
21
+ const ext = file => path.extname(file).toLowerCase();
23
22
  return lintFiles.reduce((files, currentFile) => {
24
- if (currentFile.includes('.feature') && existsSync(currentFile)) {
23
+ // if (!existsSync(currentFile)) return files;
24
+
25
+ const e = ext(currentFile);
26
+ if (e === '.feature') {
25
27
  files.featureFiles.push(currentFile);
26
28
  }
27
- if (currentFile.includes('.js') || currentFile.includes('.ts') || currentFile.includes('.tsx') || currentFile.includes('.jsx') || currentFile.includes('.properties') && existsSync(currentFile)) {
29
+ if (['.js', '.ts', '.tsx', '.jsx', '.properties'].includes(e)) {
28
30
  files.JsFiles.push(currentFile);
29
31
  }
30
- if (currentFile.includes('.css') && existsSync(currentFile)) {
32
+ if (e === '.css') {
31
33
  files.CssFiles.push(currentFile);
32
34
  }
33
35
  return files;
@@ -2,7 +2,7 @@
2
2
 
3
3
  const {
4
4
  existsSync,
5
- rmSync
5
+ rm
6
6
  } = require('fs');
7
7
  const {
8
8
  Logger
@@ -20,7 +20,7 @@ function removeFolder(folderPath) {
20
20
  try {
21
21
  let isCommonConfigFolderPresent = existsSync(folderPath);
22
22
  if (isCommonConfigFolderPresent) {
23
- executeSynchronizedCommands(rmSync, [folderPath, {
23
+ executeSynchronizedCommands(rm, [folderPath, {
24
24
  recursive: true,
25
25
  force: true
26
26
  }], 'common linter configuration folder removed successfully', 'Unable to remove the common linter configuration folder', false, false);
@@ -1,12 +1,29 @@
1
1
  "use strict";
2
2
 
3
3
  const path = require('path');
4
+ const {
5
+ getServicePathElseCommon
6
+ } = require('../ConfigFileUtils/getLintConfiguration');
7
+ const {
8
+ Logger
9
+ } = require('../Logger/Logger');
4
10
  function initConfig(actualConfigPath) {
5
- const config = require(path.join(actualConfigPath, 'lint.config.js'));
11
+ const config = getConfigObject(actualConfigPath);
6
12
  process.env.SONARQUBE_EXTERNAL = config.metric_token;
7
13
  process.env.SONARQUBE = config.meticHandler_api_token;
8
14
  process.env.ZGIT_TOKEN = config.token;
9
15
  process.env.TOOL_TOKEN = config.toolToken;
16
+ try {
17
+ const {
18
+ configurationPath
19
+ } = getServicePathElseCommon();
20
+ const {
21
+ intialize
22
+ } = require(configurationPath);
23
+ intialize();
24
+ } catch (error) {
25
+ Logger.log(Logger.FAILURE_TYPE, `Error while initialize configuration: ${error}`);
26
+ }
10
27
  }
11
28
  function getConfigPathPostInstall() {
12
29
  return path.resolve(process.cwd(), '..', '..', '..');
@@ -14,8 +31,12 @@ function getConfigPathPostInstall() {
14
31
  function getConfigPathExecute() {
15
32
  return path.resolve(process.cwd());
16
33
  }
34
+ function getConfigObject(actualConfigPath) {
35
+ return require(path.join(actualConfigPath, 'lint.config.js'));
36
+ }
17
37
  module.exports = {
18
38
  initConfig,
19
39
  getConfigPathExecute,
20
- getConfigPathPostInstall
40
+ getConfigPathPostInstall,
41
+ getConfigObject
21
42
  };
@@ -1,3 +1,3 @@
1
- const MandatoryListRules = ["@zohodesk/fitnessfunction/chunk-size"]
1
+ const MandatoryListRules = JSON.parse(process.env.MANDARORY_RULES || '[]')
2
2
 
3
3
  module.exports = MandatoryListRules
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zohodesk/codestandard-validator",
3
- "version": "1.2.4-exp-1",
3
+ "version": "1.2.4-exp-3",
4
4
  "description": "library to enforce code standard using eslint",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -18,6 +18,7 @@
18
18
  "dependencies": {
19
19
  "@zohodesk-private/client_deployment_tool": "0.0.5",
20
20
  "@zohodesk/codestandard-analytics": "1.1.4-exp-2",
21
+ "@stryker-mutator/core": "5.0.0",
21
22
  "eslint": "8.26.0",
22
23
  "marked": "9.1.6",
23
24
  "marked-terminal": "6.2.0",
@@ -0,0 +1,34 @@
1
+ // Usage: node samples/sample-branch-mode.js
2
+
3
+ var MutationCli = require('../src/mutation').MutationCli;
4
+
5
+ var cli = new MutationCli({ cwd: process.cwd() });
6
+
7
+ console.log('Running mutation testing in branch diff mode...');
8
+ console.log('Diffing current branch against: main');
9
+ console.log('');
10
+
11
+ cli.execute(['mutate', '--branch=main']).then(function (result) {
12
+ if (result.success) {
13
+ console.log('=== SUCCESS ===');
14
+ console.log('Report file: ', result.filePath);
15
+ console.log('Score: ', result.report.summary.mutationScore + '%');
16
+ console.log('Total: ', result.report.summary.totalMutants);
17
+ console.log('Killed: ', result.report.summary.killed);
18
+ console.log('Survived: ', result.report.summary.survived);
19
+ console.log('No Coverage: ', result.report.summary.noCoverage);
20
+ if (result.message) {
21
+ console.log('Note: ', result.message);
22
+ }
23
+ console.log('');
24
+ console.log('File pairs tested:');
25
+ result.report.filePairs.forEach(function (pair) {
26
+ console.log(' Source: ' + pair.source + ' -> Test: ' + (pair.test || 'NONE'));
27
+ });
28
+ } else {
29
+ console.error('=== FAILED ===');
30
+ console.error('Error:', result.error);
31
+ }
32
+ }).catch(function (err) {
33
+ console.error('Unexpected error:', err);
34
+ });
@@ -0,0 +1,34 @@
1
+ // Usage: node samples/sample-cli-entry.js
2
+ // Tests CLI argument parsing and validation only (no Stryker run)
3
+
4
+ var MutationCli = require('../src/mutation').MutationCli;
5
+
6
+ var testCases = [
7
+ { name: 'Directory mode', args: ['mutate', '--src=src', '--test=test'] },
8
+ { name: 'Branch mode', args: ['mutate', '--branch=main'] },
9
+ { name: 'Missing args (should fail)', args: ['mutate'] },
10
+ { name: 'Both modes (should fail)', args: ['mutate', '--branch=main', '--src=src', '--test=test'] },
11
+ { name: 'Unknown command (should fail)', args: ['lint'] },
12
+ { name: 'With optional flags', args: ['mutate', '--src=src', '--test=test', '--outputDir=custom-reports', '--logLevel=debug'] },
13
+ { name: 'Branch with useApi', args: ['mutate', '--branch=develop', '--useApi'] },
14
+ ];
15
+
16
+ var cli = new MutationCli({ cwd: process.cwd() });
17
+
18
+ console.log('=== CLI Argument Parsing Tests ===');
19
+ console.log('');
20
+
21
+ testCases.forEach(function (tc) {
22
+ console.log('Test: ' + tc.name);
23
+ console.log(' Args: ' + tc.args.join(' '));
24
+
25
+ var parsed = cli.parseArgs(tc.args);
26
+ console.log(' Parsed:', JSON.stringify(parsed));
27
+
28
+ var validation = cli.validate(parsed);
29
+ console.log(' Valid:', validation.valid);
30
+ if (!validation.valid) {
31
+ console.log(' Error:', validation.error.split('\n')[0]);
32
+ }
33
+ console.log('');
34
+ });
@@ -0,0 +1,63 @@
1
+ // Usage: node samples/sample-components.js
2
+
3
+ var mutation = require('../src/mutation');
4
+
5
+ console.log('=== 1. Testing BranchDiff ===');
6
+ var branchDiff = new mutation.BranchDiff({ cwd: process.cwd() });
7
+
8
+ branchDiff.getChangedFiles('main').then(function (changed) {
9
+ console.log('Source files changed:', changed.sourceFiles);
10
+ console.log('Test files changed:', changed.testFiles);
11
+ console.log('');
12
+
13
+ console.log('=== 2. Testing FileResolver ===');
14
+ var resolver = new mutation.FileResolver({ cwd: process.cwd() });
15
+ var pairs = resolver.resolveSourceTestPairs(changed.sourceFiles, changed.testFiles);
16
+ console.log('Resolved pairs:');
17
+ pairs.forEach(function (pair) {
18
+ console.log(' ' + pair.source + ' -> ' + (pair.test || 'NO TEST'));
19
+ });
20
+ console.log('');
21
+
22
+ console.log('=== 3. Testing StrykerWrapper config ===');
23
+ var stryker = new mutation.StrykerWrapper({
24
+ reportPath: 'reports/mutation/sample-report.json',
25
+ });
26
+ var config = stryker.getDefaultConfig();
27
+ console.log('Default config:');
28
+ console.log(' testRunner:', config.testRunner);
29
+ console.log(' coverageAnalysis:', config.coverageAnalysis);
30
+ console.log('');
31
+
32
+ console.log('=== 4. Testing ReportGenerator ===');
33
+ var reporter = new mutation.ReportGenerator({
34
+ cwd: process.cwd(),
35
+ outputDir: 'reports/mutation',
36
+ outputFileName: 'sample-component-report.json',
37
+ });
38
+
39
+ var fakeResult = {
40
+ summary: {
41
+ totalMutants: 5, killed: 3, survived: 1, timeout: 0,
42
+ noCoverage: 1, ignored: 0, runtimeErrors: 0, compileErrors: 0,
43
+ mutationScore: 60,
44
+ },
45
+ files: {},
46
+ mutants: [
47
+ { id: '1', status: 'Killed', fileName: 'src/app.js', mutatorName: 'StringLiteral' },
48
+ { id: '2', status: 'Survived', fileName: 'src/app.js', mutatorName: 'BooleanLiteral' },
49
+ ],
50
+ };
51
+
52
+ var output = reporter.generateAndWrite(fakeResult, {
53
+ command: 'sample-components test',
54
+ branch: 'main',
55
+ filePairs: pairs,
56
+ });
57
+ console.log('Report written to:', output.filePath);
58
+ console.log('Report summary:', output.report.summary);
59
+ console.log('');
60
+ console.log('=== All component tests complete ===');
61
+ }).catch(function (err) {
62
+ console.error('Error:', err.message);
63
+ });
@@ -0,0 +1,30 @@
1
+ // Usage: node samples/sample-directory-mode.js
2
+
3
+ var MutationCli = require('../src/mutation').MutationCli;
4
+
5
+ var cli = new MutationCli({ cwd: process.cwd() });
6
+
7
+ console.log('Running mutation testing in directory mode...');
8
+ console.log('Source dir: src');
9
+ console.log('Test dir: test');
10
+ console.log('');
11
+
12
+ cli.execute(['mutate', '--src=src', '--test=test']).then(function (result) {
13
+ if (result.success) {
14
+ console.log('=== SUCCESS ===');
15
+ console.log('Report file: ', result.filePath);
16
+ console.log('Score: ', result.report.summary.mutationScore + '%');
17
+ console.log('Total: ', result.report.summary.totalMutants);
18
+ console.log('Killed: ', result.report.summary.killed);
19
+ console.log('Survived: ', result.report.summary.survived);
20
+ console.log('No Coverage: ', result.report.summary.noCoverage);
21
+ if (result.message) {
22
+ console.log('Note: ', result.message);
23
+ }
24
+ } else {
25
+ console.error('=== FAILED ===');
26
+ console.error('Error:', result.error);
27
+ }
28
+ }).catch(function (err) {
29
+ console.error('Unexpected error:', err);
30
+ });
@@ -0,0 +1,32 @@
1
+ // Usage: node samples/sample-runner-direct.js
2
+
3
+ var MutationRunner = require('../src/mutation').MutationRunner;
4
+
5
+ var runner = new MutationRunner({
6
+ cwd: process.cwd(),
7
+ outputDir: 'reports/mutation',
8
+ outputFileName: 'direct-runner-report.json',
9
+ });
10
+
11
+ console.log('=== Testing runByBranch ===');
12
+ runner.runByBranch('main').then(function (result) {
13
+ console.log('Branch mode result:');
14
+ console.log(' Report:', result.filePath);
15
+ console.log(' Score:', result.report.summary.mutationScore + '%');
16
+ if (result.message) {
17
+ console.log(' Note:', result.message);
18
+ }
19
+
20
+ console.log('');
21
+ console.log('=== Testing runByDirectory ===');
22
+ return runner.runByDirectory('src', 'test');
23
+ }).then(function (result) {
24
+ console.log('Directory mode result:');
25
+ console.log(' Report:', result.filePath);
26
+ console.log(' Score:', result.report.summary.mutationScore + '%');
27
+ if (result.message) {
28
+ console.log(' Note:', result.message);
29
+ }
30
+ }).catch(function (err) {
31
+ console.error('Error:', err.message);
32
+ });
@@ -0,0 +1,44 @@
1
+ // Usage: PAT_TOKEN=your_token node samples/sample-with-api.js
2
+
3
+ var MutationCli = require('../src/mutation').MutationCli;
4
+
5
+ var myApi = {
6
+ getChangedFiles: function (targetBranch, patToken) {
7
+ console.log('API called with branch:', targetBranch);
8
+ console.log('PAT token provided:', patToken ? 'yes' : 'no');
9
+ return Promise.resolve([
10
+ 'src/services/auth.js',
11
+ 'src/services/auth.test.js',
12
+ 'src/utils/format.js',
13
+ 'src/utils/format.test.js',
14
+ 'src/config.js',
15
+ ]);
16
+ },
17
+ };
18
+
19
+ var cli = new MutationCli({
20
+ cwd: process.cwd(),
21
+ api: myApi,
22
+ patToken: process.env.PAT_TOKEN || 'mock-token',
23
+ });
24
+
25
+ console.log('Running mutation testing with API-based branch diff...');
26
+ console.log('');
27
+
28
+ cli.execute(['mutate', '--branch=main', '--useApi']).then(function (result) {
29
+ if (result.success) {
30
+ console.log('=== SUCCESS ===');
31
+ console.log('Report:', result.filePath);
32
+ console.log('Score:', result.report.summary.mutationScore + '%');
33
+ console.log('');
34
+ console.log('File pairs:');
35
+ result.report.filePairs.forEach(function (pair) {
36
+ console.log(' ' + pair.source + ' -> ' + (pair.test || 'NO TEST'));
37
+ });
38
+ } else {
39
+ console.error('=== FAILED ===');
40
+ console.error('Error:', result.error);
41
+ }
42
+ }).catch(function (err) {
43
+ console.error('Unexpected error:', err);
44
+ });