Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions schemas/apex-run-test.json
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,66 @@
"additionalProperties": false
}
},
"setup": {
"type": "array",
"items": {
"type": "object",
"properties": {
"Id": {
"type": "string"
},
"StackTrace": {
"type": ["string", "null"]
},
"Message": {
"type": ["string", "null"]
},
"AsyncApexJobId": {
"type": "string"
},
"MethodName": {
"type": "string"
},
"ApexLogId": {
"type": ["string", "null"]
},
"ApexClass": {
"type": "object",
"properties": {
"Id": {
"type": "string"
},
"Name": {
"type": "string"
},
"NamespacePrefix": {
"type": "string"
}
},
"required": ["Id", "Name", "NamespacePrefix"],
"additionalProperties": false
},
"TestSetupTime": {
"type": "number"
},
"FullName": {
"type": "string"
}
},
"required": [
"Id",
"StackTrace",
"Message",
"AsyncApexJobId",
"MethodName",
"ApexLogId",
"ApexClass",
"TestSetupTime",
"FullName"
],
"additionalProperties": false
}
},
"coverage": {
"type": "object",
"properties": {
Expand Down
60 changes: 60 additions & 0 deletions schemas/logic-get-test.json
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,66 @@
"additionalProperties": false
}
},
"setup": {
"type": "array",
"items": {
"type": "object",
"properties": {
"Id": {
"type": "string"
},
"StackTrace": {
"type": ["string", "null"]
},
"Message": {
"type": ["string", "null"]
},
"AsyncApexJobId": {
"type": "string"
},
"MethodName": {
"type": "string"
},
"ApexLogId": {
"type": ["string", "null"]
},
"ApexClass": {
"type": "object",
"properties": {
"Id": {
"type": "string"
},
"Name": {
"type": "string"
},
"NamespacePrefix": {
"type": "string"
}
},
"required": ["Id", "Name", "NamespacePrefix"],
"additionalProperties": false
},
"TestSetupTime": {
"type": "number"
},
"FullName": {
"type": "string"
}
},
"required": [
"Id",
"StackTrace",
"Message",
"AsyncApexJobId",
"MethodName",
"ApexLogId",
"ApexClass",
"TestSetupTime",
"FullName"
],
"additionalProperties": false
}
},
"coverage": {
"type": "object",
"properties": {
Expand Down
60 changes: 60 additions & 0 deletions schemas/logic-run-test.json
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,66 @@
"additionalProperties": false
}
},
"setup": {
"type": "array",
"items": {
"type": "object",
"properties": {
"Id": {
"type": "string"
},
"StackTrace": {
"type": ["string", "null"]
},
"Message": {
"type": ["string", "null"]
},
"AsyncApexJobId": {
"type": "string"
},
"MethodName": {
"type": "string"
},
"ApexLogId": {
"type": ["string", "null"]
},
"ApexClass": {
"type": "object",
"properties": {
"Id": {
"type": "string"
},
"Name": {
"type": "string"
},
"NamespacePrefix": {
"type": "string"
}
},
"required": ["Id", "Name", "NamespacePrefix"],
"additionalProperties": false
},
"TestSetupTime": {
"type": "number"
},
"FullName": {
"type": "string"
}
},
"required": [
"Id",
"StackTrace",
"Message",
"AsyncApexJobId",
"MethodName",
"ApexLogId",
"ApexClass",
"TestSetupTime",
"FullName"
],
"additionalProperties": false
}
},
"coverage": {
"type": "object",
"properties": {
Expand Down
32 changes: 32 additions & 0 deletions src/reporters/jsonReporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { ApexTestRunResultStatus } from '@salesforce/apex-node/lib/src/tests/typ
export type RunResult = {
summary: Summary;
tests: CliTestResult[];
setup?: CliTestSetupResult[];
coverage?: CliCoverageResult;
};

Expand Down Expand Up @@ -82,6 +83,18 @@ type PerClassCoverage = {
NumLinesUncovered: number;
};

type CliTestSetupResult = {
Id: string;
StackTrace: string | null;
Message: string | null;
AsyncApexJobId: string;
MethodName: string;
ApexLogId: string | null;
ApexClass: { Id: string; Name: string; NamespacePrefix: string };
TestSetupTime: number;
FullName: string;
};

type CliCoverageResult = {
coverage: ClassCoverage[];
records: PerClassCoverage[];
Expand Down Expand Up @@ -132,6 +145,25 @@ export class JsonReporter {
FullName: test.fullName,
...(includeCategory ? { Category: test.category } : {}),
})),
...(result.setup?.length
? {
setup: result.setup.map((s) => ({
Id: s.id,
StackTrace: s.stackTrace,
Message: s.message,
AsyncApexJobId: s.asyncApexJobId,
MethodName: s.methodName,
ApexLogId: s.apexLogId,
ApexClass: {
Id: s.apexClass.id,
Name: s.apexClass.name,
NamespacePrefix: s.apexClass.namespacePrefix,
},
TestSetupTime: s.testSetupTime,
FullName: s.fullName,
})),
}
: {}),
...(result.codecoverage
? {
coverage: this.formatCoverage(result),
Expand Down
9 changes: 5 additions & 4 deletions test/commands/logic/testHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,11 @@ export async function setupUnifiedFrameworkProject(): Promise<TestSession> {
const sfdxProjectPath = path.join(session.project.dir, 'sfdx-project.json');

// We need to update the sourceApiVersion to 65.0 because the changes in the api are not supported in 64.0
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const sfdxProject = JSON.parse(fs.readFileSync(sfdxProjectPath, 'utf8'));
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-argument
sfdxProject.sourceApiVersion = parseInt(sfdxProject.sourceApiVersion, 10) < 65 ? '65.0' : sfdxProject.sourceApiVersion;
const sfdxProject = JSON.parse(fs.readFileSync(sfdxProjectPath, 'utf8')) as {
sourceApiVersion: string;
};
sfdxProject.sourceApiVersion =
parseInt(sfdxProject.sourceApiVersion, 10) < 65 ? '65.0' : sfdxProject.sourceApiVersion;
fs.writeFileSync(sfdxProjectPath, JSON.stringify(sfdxProject, null, 2));

execCmd('project:deploy:start --source-dir force-app', { ensureExitCode: 0, cli: 'sf' });
Expand Down
36 changes: 18 additions & 18 deletions test/nuts/unifiedFrameworkProject/config/project-scratch-def.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
{
"orgName": "Easy Spaces",
"edition": "Developer",
"hasSampleData": false,
"features": ["Walkthroughs", "EnableSetPasswordInApi"],
"settings": {
"lightningExperienceSettings": {
"enableS1DesktopEnabled": true
},
"mobileSettings": {
"enableS1EncryptedStoragePref2": false
},
"pathAssistantSettings": {
"pathAssistantEnabled": true
},
"userEngagementSettings": {
"enableOrchestrationInSandbox": true,
"enableShowSalesforceUserAssist": false
}
"orgName": "Easy Spaces",
"edition": "Developer",
"hasSampleData": false,
"features": ["Walkthroughs", "EnableSetPasswordInApi"],
"settings": {
"lightningExperienceSettings": {
"enableS1DesktopEnabled": true
},
"mobileSettings": {
"enableS1EncryptedStoragePref2": false
},
"pathAssistantSettings": {
"pathAssistantEnabled": true
},
"userEngagementSettings": {
"enableOrchestrationInSandbox": true,
"enableShowSalesforceUserAssist": false
}
}
}
8 changes: 8 additions & 0 deletions test/reporters/jsonReporter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import {
failureResult,
runWithMixed,
mixedResult,
runWithSetup,
jsonWithSetup,
} from '../testData.js';

describe('JSON Test Reporter', () => {
Expand All @@ -50,4 +52,10 @@ describe('JSON Test Reporter', () => {
const formatted = reporter.format(runWithMixed);
expect(formatted).to.deep.equal(mixedResult);
});

it('should include @testSetup methods in setup array', () => {
const reporter = new JsonReporter();
const formatted = reporter.format(runWithSetup);
expect(formatted).to.deep.equal(jsonWithSetup);
});
});
18 changes: 9 additions & 9 deletions test/shared/TestRunService.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ describe('Common TestRunService behavior', () => {

// Spy on buildSyncPayload to verify the testCategory parameter
const buildSyncPayloadSpy = sandbox.spy(TestService.prototype, 'buildSyncPayload');

// Stub runTestSynchronous to avoid actual execution
sandbox.stub(TestService.prototype, 'runTestSynchronous').resolves({
summary: {
outcome: 'Passed',
summary: {
outcome: 'Passed',
testsRan: 1,
failRate: '0%',
orgId: '00D4xx00000FH4IEAW',
Expand All @@ -77,9 +77,9 @@ describe('Common TestRunService behavior', () => {
username: 'test@example.com',
hostname: 'https://na139.salesforce.com',
commandTime: '60 ms',
testExecutionTime: '53 ms'
testExecutionTime: '53 ms',
},
tests: []
tests: [],
});

await TestRunService.runTestCommand(context);
Expand Down Expand Up @@ -113,7 +113,7 @@ describe('Common TestRunService behavior', () => {

// Spy on buildAsyncPayload to verify the testCategory parameter (RunLocalTests uses async by default)
const buildAsyncPayloadSpy = sandbox.spy(TestService.prototype, 'buildAsyncPayload');

// Stub runTestAsynchronous to avoid actual execution
sandbox.stub(TestService.prototype, 'runTestAsynchronous').resolves({
testRunId: '707xx0000AUS2gH',
Expand Down Expand Up @@ -152,7 +152,7 @@ describe('Common TestRunService behavior', () => {

// Spy on buildAsyncPayload to verify the testCategory parameter (logic uses async by default)
const buildAsyncPayloadSpy = sandbox.spy(TestService.prototype, 'buildAsyncPayload');

// Stub runTestAsynchronous to avoid actual execution
sandbox.stub(TestService.prototype, 'runTestAsynchronous').resolves({
testRunId: '707xx0000AUS2gH',
Expand Down Expand Up @@ -190,7 +190,7 @@ describe('Common TestRunService behavior', () => {

// Spy on buildAsyncPayload to verify the testCategory parameter (logic uses async by default)
const buildAsyncPayloadSpy = sandbox.spy(TestService.prototype, 'buildAsyncPayload');

// Stub runTestAsynchronous to avoid actual execution
sandbox.stub(TestService.prototype, 'runTestAsynchronous').resolves({
testRunId: '707xx0000AUS2gH',
Expand All @@ -203,4 +203,4 @@ describe('Common TestRunService behavior', () => {
expect(buildAsyncPayloadSpy.firstCall.args[4]).to.equal('Flow,Apex');
});
});
});
});
Loading
Loading