Skip to content

Commit

Permalink
Update test-list results
Browse files Browse the repository at this point in the history
  • Loading branch information
projkov committed Sep 8, 2024
1 parent 87f0cca commit a6ddb66
Show file tree
Hide file tree
Showing 4 changed files with 176 additions and 7 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,6 @@ tests_run:

tests_down:
$(compose) $(tests_env) $(tests_profile) down -v

develop_down:
$(compose) $(dev_env) $(dev_profile) down -v
11 changes: 4 additions & 7 deletions src/modules/test_runs/testRun.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { runCLI } from '@jest/core';
import { TestRunService } from './testRun.service';
import { SessionService } from '../sessions/session.service';
import { TestRun } from './testRun.entity';
import { createTestListObject } from 'src/utils/data';

const testOptions = {
globalSetup: './src/utils/setup/jest.setup.ts',
Expand All @@ -23,7 +24,7 @@ export class TestRunController {
constructor(
private readonly testRunService: TestRunService,
private readonly sessionService: SessionService,
) { }
) {}

@Post()
@ApiOperation({ summary: 'Create a new test session' })
Expand Down Expand Up @@ -69,12 +70,8 @@ export class TestRunController {
};

try {
const { results } = await runCLI(options as any, [process.cwd()]);
const suites = results.testResults.map((results) => ({
file: results.testFilePath,
tests: results.testResults.map((test) => test.fullName),
}));
res.status(200).json({ suites });
const results = await runCLI(options as any, [process.cwd()]);
res.status(200).json({ suites: createTestListObject(results) });
} catch (error) {
res.status(500).json({ message: 'Internal server error', error: error.message });
}
Expand Down
139 changes: 139 additions & 0 deletions src/utils/data.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
import { createTestListObject } from './data';

describe('Data utilities', () => {
it('Should return correct test list from test result object', async () => {
const testRunResult = {
results: {
numFailedTestSuites: 0,
numFailedTests: 0,
numPassedTestSuites: 1,
numPassedTests: 4,
numPendingTestSuites: 0,
numPendingTests: 0,
numRuntimeErrorTestSuites: 0,
numTodoTests: 0,
numTotalTestSuites: 1,
numTotalTests: 4,
openHandles: [],
snapshot: {
added: 0,
didUpdate: false,
failure: false,
filesAdded: 0,
filesRemoved: 0,
filesRemovedList: [],
filesUnmatched: 0,
filesUpdated: 0,
matched: 0,
total: 0,
unchecked: 0,
uncheckedKeysByFile: [],
unmatched: 0,
updated: 0,
},
startTime: 1725776846607,
success: true,
testResults: [
{
leaks: false,
numFailingTests: 0,
numPassingTests: 4,
numPendingTests: 0,
numTodoTests: 0,
openHandles: [],
perfStats: {
end: 1725776847159,
runtime: 524,
slow: false,
start: 1725776846635,
},
skipped: false,
snapshot: {
added: 0,
fileDeleted: false,
matched: 0,
unchecked: 0,
uncheckedKeys: [],
unmatched: 0,
updated: 0,
},
testFilePath: '/app/src/suites/1.0.0-ballot/Patient/patients.spec.ts',
testResults: [
{
ancestorTitles: ['Patients test'],
duration: 3,
failureDetails: [],
failureMessages: [],
fullName: 'Patients test Should only have available interactions',
invocations: 1,
location: null,
numPassingAsserts: 1,
retryReasons: [],
status: 'passed',
title: 'Should only have available interactions',
},
{
ancestorTitles: ['Patients test'],
duration: 1,
failureDetails: [],
failureMessages: [],
fullName: 'Patients test Should only have available search params',
invocations: 1,
location: null,
numPassingAsserts: 1,
retryReasons: [],
status: 'passed',
title: 'Should only have available search params',
},
{
ancestorTitles: ['Patients test'],
duration: 1,
failureDetails: [],
failureMessages: [],
fullName: 'Patients test Should only have available combo search params',
invocations: 1,
location: null,
numPassingAsserts: 1,
retryReasons: [],
status: 'passed',
title: 'Should only have available combo search params',
},
{
ancestorTitles: ['Patients test'],
duration: 0,
failureDetails: [],
failureMessages: [],
fullName: 'Patients test Should only have valid resources in CREATE action',
invocations: 1,
location: null,
numPassingAsserts: 1,
retryReasons: [],
status: 'passed',
title: 'Should only have valid resources in CREATE action',
},
],
failureMessage: null,
},
],
wasInterrupted: false,
},
};

expect(createTestListObject(testRunResult)).toEqual([
{
suiteId: '1.0.0-ballot',
groups: [
{
groupName: 'Patients test',
tests: [
'Patients test Should only have available interactions',
'Patients test Should only have available search params',
'Patients test Should only have available combo search params',
'Patients test Should only have valid resources in CREATE action',
],
},
],
},
]);
});
});
30 changes: 30 additions & 0 deletions src/utils/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,33 @@ export function createRequestObject(
requestBody: req.body,
};
}

export function createTestListObject(testRun: any) {
const { results } = testRun;

const preparedResults = results.testResults.map((resultItem) => {
const testFilePath = resultItem.testFilePath;
const suiteId = testFilePath.split('/')?.[4];
const groupsRaw = resultItem.testResults.map((testItem) => {
return {
groupName: testItem.ancestorTitles[0],
testTitle: testItem.fullName,
};
});

const groupNames = [...new Set(groupsRaw.map((groupItem) => groupItem.groupName))];
const groups = groupNames.map((groupName) => {
return {
groupName: groupName,
tests: groupsRaw.filter((groupItem) => groupItem.groupName === groupName).map((a) => a.testTitle),
};
});

return {
suiteId: suiteId,
groups: groups,
};
});

return preparedResults;
}

0 comments on commit a6ddb66

Please sign in to comment.