Skip to content

Commit

Permalink
fix: fixed error when running more than one test method from a same t…
Browse files Browse the repository at this point in the history
…est class (#321)

* fix: fixed error when running more than one test method from a same test class

* chore: new fix that includes all the classes

* fix: added same logic for when there is a namespace specified

* chore: test

* chore: revert access and adjust test

* chore: bump @salesforce/core to 3.34.6
  • Loading branch information
CristiCanizales authored Apr 20, 2023
1 parent dd5234b commit 4185599
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 49 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"main": "lib/src/index.js",
"dependencies": {
"@commitlint/config-conventional": "^17.2.0",
"@salesforce/core": "^3.32.12",
"@salesforce/core": "^3.34.6",
"@types/istanbul-reports": "^3.0.1",
"commitlint": "^17.2.0",
"faye": "1.4.0",
Expand Down
40 changes: 29 additions & 11 deletions src/tests/testService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -397,25 +397,35 @@ export class TestService {
): Promise<AsyncTestArrayConfiguration | SyncTestConfiguration> {
const testNameArray = testNames.split(',');
const testItems: TestItem[] = [];
const classes: string[] = [];
let namespaceInfos: NamespaceInfo[];

for (const test of testNameArray) {
if (test.indexOf('.') > 0) {
const testParts = test.split('.');
if (testParts.length === 3) {
testItems.push({
namespace: `${testParts[0]}`,
className: `${testParts[1]}`,
testMethods: [testParts[2]]
});
if (!classes.includes(testParts[1])) {
testItems.push({
namespace: `${testParts[0]}`,
className: `${testParts[1]}`,
testMethods: [testParts[2]]
});
classes.push(testParts[1]);
} else {
testItems.forEach(element => {
if (element.className === `${testParts[1]}`) {
element.namespace = `${testParts[0]}`;
element.testMethods.push(`${testParts[2]}`);
}
});
}
} else {
if (typeof namespaceInfos === 'undefined') {
namespaceInfos = await queryNamespaces(this.connection);
}
const currentNamespace = namespaceInfos.find(
namespaceInfo => namespaceInfo.namespace === testParts[0]
);

// NOTE: Installed packages require the namespace to be specified as part of the className field
// The namespace field should not be used with subscriber orgs
if (currentNamespace) {
Expand All @@ -430,18 +440,26 @@ export class TestService {
});
}
} else {
testItems.push({
className: testParts[0],
testMethods: [testParts[1]]
});
if (!classes.includes(testParts[0])) {
testItems.push({
className: testParts[0],
testMethods: [testParts[1]]
});
classes.push(testParts[0]);
} else {
testItems.forEach(element => {
if (element.className === testParts[0]) {
element.testMethods.push(testParts[1]);
}
});
}
}
}
} else {
const prop = isValidApexClassID(test) ? 'classId' : 'className';
testItems.push({ [prop]: test });
}
}

return {
tests: testItems,
testLevel: TestLevel.RunSpecifiedTests
Expand Down
25 changes: 25 additions & 0 deletions test/tests/testService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,4 +261,29 @@ describe('Apex Test Suites', async () => {
expect(toolingCreateStub.calledTwice).to.be.true;
});
});

describe('Build Test Payload', async () => {
it('should add all the tests specified even when some belong to the same class', async () => {
const testsPayload = {
testLevel: 'RunSpecifiedTests',
tests: [
{
className: 'TestClass1',
testMethods: ['method1']
},
{
className: 'TestClass2',
testMethods: ['method1', 'method2'],
namespace: 'namespace'
}
]
};
const tests =
'TestClass1.method1,namespace.TestClass2.method1,TestClass2.method2';

const testService = new TestService(mockConnection);
const result = await (testService as any).buildTestPayload(tests);
expect(result.tests.toString()).to.equal(testsPayload.tests.toString());
});
});
});
91 changes: 54 additions & 37 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -399,42 +399,42 @@
mv "~2"
safe-json-stringify "~1"

"@salesforce/core@^3.32.12":
version "3.32.12"
resolved "https://registry.yarnpkg.com/@salesforce/core/-/core-3.32.12.tgz#853cc5b6a5f95d4896b2d34a40a6042ef9aa6d2c"
integrity sha512-27rqSiQWul7b/OkJs19FYDv2M/S4oI4efiGv+6sR7UWv7D7CG1P+0XpgLS3d9xRYF30h98n6VQr4W2a+BWFRvA==
"@salesforce/core@^3.34.6":
version "3.34.7"
resolved "https://registry.yarnpkg.com/@salesforce/core/-/core-3.34.7.tgz#445efe5c76fbab53e6c891563aa9b0dc5dd24179"
integrity sha512-C4zyXzLAV5ITMChC8dCP+6Kk3t5vloyP2eXpqBOw96OzF5OaCiN5/TayNN8YJl64pvFFny7FgAQPKk7omFXNSA==
dependencies:
"@salesforce/bunyan" "^2.0.0"
"@salesforce/kit" "^1.8.0"
"@salesforce/schemas" "^1.4.0"
"@salesforce/ts-types" "^1.5.21"
"@types/graceful-fs" "^4.1.5"
"@salesforce/kit" "^1.9.2"
"@salesforce/schemas" "^1.5.1"
"@salesforce/ts-types" "^1.7.2"
"@types/graceful-fs" "^4.1.6"
"@types/semver" "^7.3.13"
ajv "^8.11.2"
ajv "^8.12.0"
archiver "^5.3.0"
change-case "^4.1.2"
debug "^3.2.7"
faye "^1.4.0"
form-data "^4.0.0"
graceful-fs "^4.2.9"
graceful-fs "^4.2.11"
js2xmlparser "^4.0.1"
jsforce "^2.0.0-beta.19"
jsforce "^2.0.0-beta.21"
jsonwebtoken "9.0.0"
ts-retry-promise "^0.7.0"

"@salesforce/kit@^1.8.0":
version "1.8.2"
resolved "https://registry.yarnpkg.com/@salesforce/kit/-/kit-1.8.2.tgz#97d652bef37d02a13dffd6e9b68050e779db2bc4"
integrity sha512-UoY1bgWjw198QMyLKYXlF1bdqBqVtffBgtIT1M/cEwBF/Es1Oz3HaF1TwF98CmyC1dr6rL08Hr2SE5zHGijcLw==
"@salesforce/kit@^1.9.2":
version "1.9.2"
resolved "https://registry.yarnpkg.com/@salesforce/kit/-/kit-1.9.2.tgz#d232f135428363cdfe2649cb99a94bc2eb0a12fd"
integrity sha512-kjZvjFNP6njhAiEa/ErdLXSDWZKafHYJyKCKz1wnSFmDM8TOpKHCCVw5cQo87ZQr8OqxqwUDIAlSBLyMzKi4Lg==
dependencies:
"@salesforce/ts-types" "^1.7.1"
"@salesforce/ts-types" "^1.7.3"
shx "^0.3.3"
tslib "^2.2.0"
tslib "^2.5.0"

"@salesforce/schemas@^1.4.0":
version "1.4.0"
resolved "https://registry.yarnpkg.com/@salesforce/schemas/-/schemas-1.4.0.tgz#7dff427c8059895d8108176047aee600703c82d6"
integrity sha512-BJ25uphssN42Zy6kksheFHMTLiR98AAHe/Wxnv0T4dYxtrEbUjSXVAGKZqfewJPFXA4xB5gxC+rQZtfz6xKCFg==
"@salesforce/schemas@^1.5.1":
version "1.5.1"
resolved "https://registry.yarnpkg.com/@salesforce/schemas/-/schemas-1.5.1.tgz#2d1bfdcf593caaa04cd4b3e6fe621097ff7f28fe"
integrity sha512-MRqU+tn8w5IFvZ0Lm9YKLgxYxr2MQMI+fXXsTrwfUnijsps+ybF9IOTu6MOMxxl2vCUkO8XDjA435wXlWSLI6g==

"@salesforce/ts-sinon@^1.4.2":
version "1.4.2"
Expand All @@ -452,13 +452,20 @@
dependencies:
tslib "^1.10.0"

"@salesforce/ts-types@^1.5.21", "@salesforce/ts-types@^1.7.1":
"@salesforce/ts-types@^1.7.1":
version "1.7.1"
resolved "https://registry.yarnpkg.com/@salesforce/ts-types/-/ts-types-1.7.1.tgz#86b0d0c3bfd5c9b1752662a019a3d2f3bc8ff118"
integrity sha512-jwZb8fYxbOmEckoJTxG2+5ZEJNJOFxmRJ/FioPnSu4IMFzpK3QbyujfqpHwLfPKHq0xlKRMx+F8QAVVKI/PA4w==
dependencies:
tslib "^2.4.1"

"@salesforce/ts-types@^1.7.2", "@salesforce/ts-types@^1.7.3":
version "1.7.3"
resolved "https://registry.yarnpkg.com/@salesforce/ts-types/-/ts-types-1.7.3.tgz#89b79ff0aaa55fea9f2de0afa8e515be3e17d0d8"
integrity sha512-jpmekGqZ7tpHRJwf1rF0yBJ/IMC5mOrryNi4HZkKuNQn8RF97WpynmL8Om04mLTCESvCiif3y7NWfIcxtID2Gw==
dependencies:
tslib "^2.5.0"

"@sinonjs/commons@^1", "@sinonjs/commons@^1.3.0", "@sinonjs/commons@^1.4.0", "@sinonjs/commons@^1.7.0":
version "1.8.3"
resolved "https://registry.npmjs.org/@sinonjs/commons/-/commons-1.8.3.tgz"
Expand Down Expand Up @@ -528,10 +535,10 @@
"@types/minimatch" "*"
"@types/node" "*"

"@types/graceful-fs@^4.1.5":
version "4.1.5"
resolved "https://registry.npmjs.org/@types/graceful-fs/-/graceful-fs-4.1.5.tgz"
integrity sha512-anKkLmZZ+xm4p8JWBf4hElkM4XR+EZeA2M9BAkkTldmcyDY4mbdIJnRghDJH3Ov5ooY7/UAoENtmdMSkaAd7Cw==
"@types/graceful-fs@^4.1.6":
version "4.1.6"
resolved "https://registry.yarnpkg.com/@types/graceful-fs/-/graceful-fs-4.1.6.tgz#e14b2576a1c25026b7f02ede1de3b84c3a1efeae"
integrity sha512-Sig0SNORX9fdW+bQuTEovKj3uHcUL6LQKbCrrqb1X7J6/ReAbhCXRAhc+SMejhLELFj2QcyuxmUooZ4bt5ReSw==
dependencies:
"@types/node" "*"

Expand Down Expand Up @@ -757,7 +764,7 @@ ajv@^8.0.1, ajv@^8.11.0:
require-from-string "^2.0.2"
uri-js "^4.2.2"

ajv@^8.11.2:
ajv@^8.12.0:
version "8.12.0"
resolved "https://registry.yarnpkg.com/ajv/-/ajv-8.12.0.tgz#d1a0527323e22f53562c567c00991577dfbe19d1"
integrity sha512-sRu1kpcO9yLtYxBKvqfTeh9KzZEwO3STyX1HT+4CaDzC6HpTGYhIhPIzj9XuKU7KYDwnaeh5hcOwjy1QuJzBPA==
Expand Down Expand Up @@ -2278,11 +2285,16 @@ globby@^11.1.0:
merge2 "^1.4.1"
slash "^3.0.0"

graceful-fs@^4.1.11, graceful-fs@^4.1.15, graceful-fs@^4.1.2, graceful-fs@^4.1.6, graceful-fs@^4.2.0, graceful-fs@^4.2.9:
graceful-fs@^4.1.11, graceful-fs@^4.1.15, graceful-fs@^4.1.2, graceful-fs@^4.1.6, graceful-fs@^4.2.0:
version "4.2.10"
resolved "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.10.tgz"
integrity sha512-9ByhssR2fPVsNZj478qUUbKfmL0+t5BDVyjShtyZZLiK7ZDAArFFfopyOTj0M05wE2tJPisA4iTnnXl2YoPvOA==

graceful-fs@^4.2.11:
version "4.2.11"
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.11.tgz#4183e4e8bf08bb6e05bbb2f7d2e0c8f712ca40e3"
integrity sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==

hard-rejection@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/hard-rejection/-/hard-rejection-2.1.0.tgz#1c6eda5c1685c63942766d79bb40ae773cecd883"
Expand Down Expand Up @@ -2749,10 +2761,10 @@ jsesc@^2.5.1:
resolved "https://registry.npmjs.org/jsesc/-/jsesc-2.5.2.tgz"
integrity sha512-OYu7XEzjkCQ3C5Ps3QIZsQfNpqoJyZZA99wd9aWd05NCtC5pWOkShK2mkL6HXQR6/Cy2lbNdPlZBpuQHXE63gA==

jsforce@^2.0.0-beta.19:
version "2.0.0-beta.19"
resolved "https://registry.yarnpkg.com/jsforce/-/jsforce-2.0.0-beta.19.tgz#4a136b88d6a9f6668714c4ccbb0acd55e46ea493"
integrity sha512-WdF6hs7kukXNGvp/VRhu2DngldgiBBorsc2WA5us08oJGbEIPwn/itqYJWKJ+rfPXepz5JbkWQd48XHGjqmPpw==
jsforce@^2.0.0-beta.21:
version "2.0.0-beta.21"
resolved "https://registry.yarnpkg.com/jsforce/-/jsforce-2.0.0-beta.21.tgz#04c94d762d2536bf1af3062d5cca206656f5b12b"
integrity sha512-74GUF/96vYBNZo3SUccXtt4CmfvZ0iqTSc0Z3OB940Ec7oU6coOAGhlCZ+XprXaHOMMhXMXrZQ1PCd16yjIA7A==
dependencies:
"@babel/runtime" "^7.12.5"
"@babel/runtime-corejs3" "^7.12.5"
Expand All @@ -2773,7 +2785,7 @@ jsforce@^2.0.0-beta.19:
open "^7.0.0"
regenerator-runtime "^0.13.3"
strip-ansi "^6.0.0"
xml2js "^0.4.22"
xml2js "^0.5.0"

json-parse-better-errors@^1.0.1:
version "1.0.2"
Expand Down Expand Up @@ -4475,6 +4487,11 @@ tslib@^2.4.1:
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.4.1.tgz#0d0bfbaac2880b91e22df0768e55be9753a5b17e"
integrity sha512-tGyy4dAjRIEwI7BzsB0lynWgOpfqjUdq91XXAlIWD2OwKBH7oCl/GZG/HT4BOHrTlPMOASlMQ7veyTqpmRcrNA==

tslib@^2.5.0:
version "2.5.0"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.5.0.tgz#42bfed86f5787aeb41d031866c8f402429e0fddf"
integrity sha512-336iVw3rtn2BUK7ORdIAHTyxHGRIHVReokCR3XjbckJMK7ms8FysBfhLR8IXnAgy7T0PTPNBWKiH514FOW/WSg==

tsutils@^3.21.0:
version "3.21.0"
resolved "https://registry.npmjs.org/tsutils/-/tsutils-3.21.0.tgz"
Expand Down Expand Up @@ -4699,10 +4716,10 @@ write-file-atomic@^2.4.2:
imurmurhash "^0.1.4"
signal-exit "^3.0.2"

xml2js@^0.4.22:
version "0.4.23"
resolved "https://registry.npmjs.org/xml2js/-/xml2js-0.4.23.tgz"
integrity sha512-ySPiMjM0+pLDftHgXY4By0uswI3SPKLDw/i3UXbnO8M/p28zqexCUoPmQFrYD+/1BzhGJSs2i1ERWKJAtiLrug==
xml2js@^0.5.0:
version "0.5.0"
resolved "https://registry.yarnpkg.com/xml2js/-/xml2js-0.5.0.tgz#d9440631fbb2ed800203fad106f2724f62c493b7"
integrity sha512-drPFnkQJik/O+uPKpqSgr22mpuFHqKdbS835iAQrUC73L2F5WkboIRd63ai/2Yg6I1jzifPFKH2NTK+cfglkIA==
dependencies:
sax ">=0.6.0"
xmlbuilder "~11.0.0"
Expand Down

0 comments on commit 4185599

Please sign in to comment.