Skip to content

Commit

Permalink
v0.0.13
Browse files Browse the repository at this point in the history
  • Loading branch information
Anthony Heber committed Jan 29, 2024
1 parent 5ab5ef8 commit c3fd000
Show file tree
Hide file tree
Showing 8 changed files with 18,628 additions and 22,120 deletions.
20,327 changes: 9,284 additions & 11,043 deletions oclif.lock

Large diffs are not rendered by default.

50 changes: 24 additions & 26 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,45 +1,44 @@
{
"name": "sf-warp",
"description": "Warp your code and see if your tests notice",
"version": "0.0.9",
"packageManager": "[email protected]+sha256.825003a0f561ad09a3b1ac4a3b3ea6207af2796d54f62a9420520915721f5186",
"version": "0.0.13",
"dependencies": {
"@oclif/core": "^3.9.2",
"@salesforce/core": "^5.3.16",
"@oclif/core": "^3.15.1",
"@salesforce/core": "^6.4.2",
"@salesforce/kit": "^3.0.15",
"@salesforce/sf-plugins-core": "^4.0.0",
"tslib": "^2",
"@salesforce/sf-plugins-core": "^5.0.13",
"tslib": "^2.6.2",
"web-tree-sitter-sfapex": "^0.0.11"
},
"devDependencies": {
"@oclif/test": "^3.1.0",
"@salesforce/cli-plugins-testkit": "^4.4.12",
"@oclif/test": "^3.1.7",
"@salesforce/cli-plugins-testkit": "^5.1.3",
"@salesforce/dev-config": "^4.1.0",
"@salesforce/dev-scripts": "^6.0.3",
"@salesforce/dev-scripts": "^8.1.3",
"@salesforce/prettier-config": "^0.0.3",
"@salesforce/ts-sinon": "1.4.19",
"@typescript-eslint/eslint-plugin": "^6.9.1",
"@typescript-eslint/parser": "^6.9.1",
"chai": "^4.3.6",
"eslint": "^8.52.0",
"eslint-config-prettier": "^9.0.0",
"@typescript-eslint/eslint-plugin": "^6.16.0",
"@typescript-eslint/parser": "^6.16.0",
"chai": "^5.0.0",
"eslint": "^8.56.0",
"eslint-config-prettier": "^9.1.0",
"eslint-config-salesforce": "^2.0.2",
"eslint-config-salesforce-typescript": "^3.0.2",
"eslint-plugin-header": "^3.0.0",
"eslint-plugin-import": "2.29.0",
"eslint-plugin-jsdoc": "^46.8.2",
"eslint-plugin-prettier": "^5.0.1",
"eslint-plugin-sf-plugin": "^1.1.0",
"eslint-config-salesforce-typescript": "^3.0.18",
"eslint-plugin-header": "^3.1.1",
"eslint-plugin-import": "2.29.1",
"eslint-plugin-jsdoc": "^46.9.1",
"eslint-plugin-prettier": "^5.1.2",
"eslint-plugin-sf-plugin": "^1.17.0",
"husky": "^8.0.3",
"mocha": "^10.0.0",
"mocha": "^10.2.0",
"nyc": "^15.1.0",
"oclif": "^4.0.3",
"prettier": "^3.0.3",
"oclif": "^4.1.0",
"prettier": "^3.1.1",
"pretty-quick": "^3.1.3",
"shx": "0.3.4",
"sinon": "17.0.1",
"ts-node": "^10.9.1",
"typescript": "^5.2.2"
"ts-node": "^10.9.2",
"typescript": "^5.3.3"
},
"engines": {
"node": ">=14.0.0"
Expand Down Expand Up @@ -83,7 +82,6 @@
"docs": "sf-docs",
"format": "wireit",
"lint": "wireit",
"postinstall": "yarn husky install",
"postpack": "shx rm -f oclif.manifest.json",
"prepack": "sf-prepack",
"test": "wireit",
Expand Down
38 changes: 31 additions & 7 deletions src/lib/commands/apex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import * as fs from 'node:fs';
import * as path from 'node:path';
import { Connection } from '@salesforce/core';
import { ux } from '@oclif/core';
import { getApexParser } from 'web-tree-sitter-sfapex';
// eslint-disable-next-line import/no-extraneous-dependencies
import { Query, QueryCapture, Tree } from 'web-tree-sitter';
import { getApexClasses, executeTests, writeApexClassesToOrg, ApexClassRecord } from '../sf';
import { getTextParts, Lines, isTestClass } from '../ts_tools';
Expand Down Expand Up @@ -96,7 +98,12 @@ export default class ApexWarper {
if (classUnderTest.testClasses.length === 0) {
throw new Error('No test classes identified, unable to continue');
}

// run tests first to ensure they are valid and passing in the current config

if (this.atLeastVerbosity(Verbosity.full)) {
ux.action.start('Executing tests before making changes');
}
// eslint-disable-next-line no-await-in-loop
let testResults = await executeTests(this.conn, classUnderTest.testClasses, this.config.timeoutMs);
if (testResults.MethodsFailed > 0) {
Expand Down Expand Up @@ -126,10 +133,17 @@ export default class ApexWarper {
const query = this.parser.getLanguage().query(queries);

// TODO: Need to figure out how to block mutants inside of "ignore" sections
const captures = this.getCaptures(tree, query).filter(
(c) => !(this.config.suppressedRuleNames ?? []).includes(c.name),
);

const captures = this.getCaptures(tree, query)
.filter((c) => !(this.config.suppressedRuleNames ?? []).includes(c.name))
.filter((c) => {
const oldLines: Lines = {};
for (let i = c.node.startPosition.row; i <= c.node.endPosition.row; i++) {
oldLines[i] = lines[i];
}
const textParts = getMutatedParts(c, oldLines);
// filter out changes where our mutation has no effect
return Object.values(oldLines).join('\n') !== textParts.join('');
});
if (this.atLeastVerbosity(Verbosity.minimal)) {
console.log(
`Found ${captures.length} candidates in ${className}, testing with ${classUnderTest.testClasses.join(', ')}`,
Expand All @@ -140,6 +154,9 @@ export default class ApexWarper {
const mutantList: Mutant[] = [];
this.mutants.set(className, mutantList);
for (const capture of captures) {
if (this.atLeastVerbosity(Verbosity.full)) {
ux.action.start(`Build Mutant (${count + 1}/${captures.length})`);
}
let finalStatus = 'unknown';
let finalStatusMessage: string | undefined;
const perfName = getPerfStart();
Expand All @@ -161,6 +178,9 @@ export default class ApexWarper {
// TODO: capture compile errors/failures and report that status
const writePerfName = getPerfStart();
if (!this.config.analyzeOnly) {
if (this.atLeastVerbosity(Verbosity.full)) {
ux.action.start(`Deploying Mutant (${count + 1}/${captures.length})`);
}
this.orgClassIsMutated = true;
// eslint-disable-next-line no-await-in-loop
await this.writeApexClassesToOrg(classUnderTest.className, lines.join('\n'));
Expand All @@ -172,6 +192,9 @@ export default class ApexWarper {
// capture the results against that mutant
const testPerfName = getPerfStart();
if (!this.config.analyzeOnly) {
if (this.atLeastVerbosity(Verbosity.full)) {
ux.action.start(`Executing Tests (${count + 1}/${captures.length})`);
}
// eslint-disable-next-line no-await-in-loop
testResults = await executeTests(this.conn, classUnderTest.testClasses, this.config.timeoutMs);
}
Expand Down Expand Up @@ -236,8 +259,9 @@ export default class ApexWarper {
}

if (this.atLeastVerbosity(Verbosity.minimal)) {
console.log(
`\nKilled ${mutantsKilled}/${count} (${(
ux.action.start('\n');
ux.action.stop(
`\rKilled ${mutantsKilled}/${count} (${(
(mutantsKilled / count) *
100
).toFixed()}%) in ${getPerfDurationHumanReadable(totalExecutePerfName)}`,
Expand Down Expand Up @@ -331,7 +355,7 @@ function reportMutant(capture: QueryCapture, oldText: Lines, newLineParts: strin
// probably a smarter way to do this out there...
const [start, middle, end] = getTextParts(oldText, capture.node);
console.log(
`Start Line ${capture.node.startPosition.row} | ${capture.name}\n`,
`\nStart Line ${capture.node.startPosition.row} | ${capture.name}\n`,
`- ${start}\x1b[32m${middle}\x1b[0m${end}`,
'\n',
`+ ${newLineParts[0]}\x1b[31m${newLineParts[1]}\x1b[0m${newLineParts[2]}`,
Expand Down
2 changes: 2 additions & 0 deletions src/lib/mutations.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable @typescript-eslint/no-unsafe-enum-comparison */
// eslint-disable-next-line import/no-extraneous-dependencies
import { QueryCapture } from 'web-tree-sitter';
import { getTextParts, Lines } from './ts_tools';

Expand Down
1 change: 1 addition & 0 deletions src/lib/sf.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Connection } from '@salesforce/core';
// eslint-disable-next-line import/no-extraneous-dependencies
import { Record } from 'jsforce';
import { pollForResult } from './polling';

Expand Down
1 change: 1 addition & 0 deletions src/lib/ts_tools.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { getApexParser } from 'web-tree-sitter-sfapex';
// eslint-disable-next-line import/no-extraneous-dependencies
import { SyntaxNode } from 'web-tree-sitter';
export interface Lines {
[key: number]: string;
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "@salesforce/dev-config/tsconfig",
"extends": "@salesforce/dev-config/tsconfig-esm",
"compilerOptions": {
"outDir": "lib",
"rootDir": "src",
Expand Down
Loading

0 comments on commit c3fd000

Please sign in to comment.