diff --git a/packages/apex-node/src/reporters/junitReporter.ts b/packages/apex-node/src/reporters/junitReporter.ts index 23394541..af448053 100644 --- a/packages/apex-node/src/reporters/junitReporter.ts +++ b/packages/apex-node/src/reporters/junitReporter.ts @@ -72,17 +72,18 @@ export class JUnitReporter { let junitTests = ''; for (const testCase of tests) { - junitTests += `${tab}${tab}\n`; + const methodName = this.xmlEscape(testCase.methodName); + junitTests += `${tab}${tab}\n`; if ( testCase.outcome === ApexTestResultOutcome.Fail || testCase.outcome === ApexTestResultOutcome.CompileFail ) { - junitTests += `${tab}${tab}${tab}`; + let message = this.isEmpty(testCase.message) ? '' : testCase.message; + message = this.xmlEscape(message); + junitTests += `${tab}${tab}${tab}`; if (testCase.stackTrace) { junitTests += ``; } @@ -94,6 +95,15 @@ export class JUnitReporter { return junitTests; } + private xmlEscape(value: string): string { + return value + .replace(/&/g, '&') + .replace(//g, '>') + .replace(/"/g, '"') + .replace(/'/g, '''); + } + private isEmpty(value: string | number): boolean { if ( value === null || diff --git a/packages/apex-node/test/reporters/tapReporter.test.ts b/packages/apex-node/test/reporters/tapReporter.test.ts index 9175e23b..c8f64a6e 100644 --- a/packages/apex-node/test/reporters/tapReporter.test.ts +++ b/packages/apex-node/test/reporters/tapReporter.test.ts @@ -70,6 +70,7 @@ describe('TAP Reporter Tests', () => { 'Class.AccountProcessorTest.testCountContacts: line 47, column 1' ]); expect(result[12].diagnostics).to.eql([ + 'Weird characters <>&"\'', 'Surrounded by newlines.', 'and whitespace.' ]); diff --git a/packages/apex-node/test/reporters/testResults.ts b/packages/apex-node/test/reporters/testResults.ts index 7d6830e9..d7182844 100644 --- a/packages/apex-node/test/reporters/testResults.ts +++ b/packages/apex-node/test/reporters/testResults.ts @@ -445,7 +445,8 @@ export const testResults: TestResult = { id: '07M3t000003bQwREAU', queueItemId: '7093t000000c0eiAAA', stackTrace: null, - message: '\r\n\r\nSurrounded by newlines.\r\n and whitespace.\r\n\r\n', + message: + 'Weird characters <>&"\'\r\n\r\nSurrounded by newlines.\r\n and whitespace.\r\n\r\n', asyncApexJobId: '7073t000061uwZIAAY', methodName: 'testGetCallout', outcome: ApexTestResultOutcome.Fail, @@ -568,7 +569,7 @@ export const junitResult = ` - \n \n diff --git a/packages/plugin-apex/package.json b/packages/plugin-apex/package.json index cda476ed..350f8784 100644 --- a/packages/plugin-apex/package.json +++ b/packages/plugin-apex/package.json @@ -6,7 +6,7 @@ "bugs": "https://github.com/forcedotcom/salesforcedx-apex/issues", "main": "lib/index.js", "dependencies": { - "@oclif/core": "^1.5.2", + "@oclif/core": "^1.16.4", "@salesforce/apex-node": "1.2.0", "@salesforce/command": "^5.1.0", "@salesforce/core": "^3.23.3", @@ -16,7 +16,7 @@ "devDependencies": { "@oclif/plugin-command-snapshot": "^3", "@oclif/plugin-help": "^5", - "@oclif/test": "^2", + "@oclif/test": "^2.2.2", "@salesforce/dev-config": "3.0.1", "@salesforce/plugin-command-reference": "^1.3.16", "@salesforce/ts-sinon": "^1.1.2", diff --git a/packages/plugin-apex/yarn.lock b/packages/plugin-apex/yarn.lock index f78a9456..30f974fb 100644 --- a/packages/plugin-apex/yarn.lock +++ b/packages/plugin-apex/yarn.lock @@ -383,7 +383,7 @@ is-wsl "^2.1.1" tslib "^2.3.1" -"@oclif/core@^1.0.8", "@oclif/core@^1.2.1", "@oclif/core@^1.3.1", "@oclif/core@^1.3.4", "@oclif/core@^1.3.6", "@oclif/core@^1.5.2", "@oclif/core@^1.6.4", "@oclif/core@^1.7.0": +"@oclif/core@^1.0.8", "@oclif/core@^1.2.1", "@oclif/core@^1.3.4", "@oclif/core@^1.3.6", "@oclif/core@^1.6.4", "@oclif/core@^1.7.0": version "1.8.2" resolved "https://registry.yarnpkg.com/@oclif/core/-/core-1.8.2.tgz#a29bce3e555614be7a17962dd4743d8da21d6b27" integrity sha512-0fP+mY/APCRoVuaf4YqOlSar6xe5rsnKq1oApoknMVDE4jCTN/eVqOkE5/lGOEcS+EB2MNM+HFz/8lcR6+gY3Q== @@ -418,6 +418,40 @@ widest-line "^3.1.0" wrap-ansi "^7.0.0" +"@oclif/core@^1.16.4": + version "1.16.4" + resolved "https://registry.yarnpkg.com/@oclif/core/-/core-1.16.4.tgz#fafa338ada0624d7f1adac036302b05a37cd96d0" + integrity sha512-l+xHtVMteJWeTZZ+f2yLyNjf69X0mhAH8GILXnmoAGAemXbc1DVstvloxOouarvm9xyHHhquzO1Qg5l6xa1VIw== + dependencies: + "@oclif/linewrap" "^1.0.0" + "@oclif/screen" "^3.0.2" + ansi-escapes "^4.3.2" + ansi-styles "^4.3.0" + cardinal "^2.1.1" + chalk "^4.1.2" + clean-stack "^3.0.1" + cli-progress "^3.10.0" + debug "^4.3.4" + ejs "^3.1.6" + fs-extra "^9.1.0" + get-package-type "^0.1.0" + globby "^11.1.0" + hyperlinker "^1.0.0" + indent-string "^4.0.0" + is-wsl "^2.2.0" + js-yaml "^3.14.1" + natural-orderby "^2.0.3" + object-treeify "^1.1.33" + password-prompt "^1.1.2" + semver "^7.3.7" + string-width "^4.2.3" + strip-ansi "^6.0.1" + supports-color "^8.1.1" + supports-hyperlinks "^2.2.0" + tslib "^2.3.1" + widest-line "^3.1.0" + wrap-ansi "^7.0.0" + "@oclif/errors@1.3.5", "@oclif/errors@^1.2.2", "@oclif/errors@^1.3.3", "@oclif/errors@^1.3.5": version "1.3.5" resolved "https://registry.yarnpkg.com/@oclif/errors/-/errors-1.3.5.tgz#a1e9694dbeccab10fe2fe15acb7113991bed636c" @@ -543,13 +577,13 @@ dependencies: fancy-test "^1.4.10" -"@oclif/test@^2": - version "2.1.0" - resolved "https://registry.yarnpkg.com/@oclif/test/-/test-2.1.0.tgz#e5a0ba619c890770782e48c82d18f5921e2d2b9f" - integrity sha512-o+JTv3k28aMUxywJUlJY1/DORLqumoZFRII492phOmtXM16rD6Luy3z1qinT4BvEtPj2BzOPd2whr/VdYszaYw== +"@oclif/test@^2.2.2": + version "2.2.2" + resolved "https://registry.yarnpkg.com/@oclif/test/-/test-2.2.2.tgz#1dc0992b85b6e6bf8f463758f410994866a572fa" + integrity sha512-gzVB+sstU45NHHjaMws3+/VjQmmO4VbDr1AcUg+/IzjMIwEvM6ssYD/d1kNPup0OjIgQqRQgGyVxKJX/vqHMtg== dependencies: - "@oclif/core" "^1.3.1" - fancy-test "^2.0.0" + "@oclif/core" "^1.16.4" + fancy-test "^2.0.4" "@octokit/auth-token@^2.4.4": version "2.5.0" @@ -2504,10 +2538,10 @@ fancy-test@^1.4.10: nock "^13.0.0" stdout-stderr "^0.1.9" -fancy-test@^2.0.0: - version "2.0.0" - resolved "https://registry.yarnpkg.com/fancy-test/-/fancy-test-2.0.0.tgz#f1477ae4190820318816914aabe273c0a0dbd597" - integrity sha512-SFb2D/VX9SV+wNYXO1IIh1wyxUC1GS0mYCFJOWD1ia7MPj9yE2G8jaPkw4t/pg0Sj7/YJP56OzMY4nAuJSOugQ== +fancy-test@^2.0.4: + version "2.0.4" + resolved "https://registry.yarnpkg.com/fancy-test/-/fancy-test-2.0.4.tgz#b7650e13598e5ad2a27f0d89ad07813bfb09d53e" + integrity sha512-jZbiHiJY1phazdfQkVhdBEY5aZXEydiZzFxK9VqCfrMmRw/kHPgQ6i88+nyqQwpFV3yL2mUbMe/NEfMaSfO7+g== dependencies: "@types/chai" "*" "@types/lodash" "*"