Skip to content

Commit d4febd8

Browse files
committed
fix(merge-reports): ability to merge reports locally
1 parent 211761f commit d4febd8

File tree

16 files changed

+331
-82
lines changed

16 files changed

+331
-82
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ hot
55
/lib/static/*.min.js
66
/lib/static/data.js
77
/lib/static/sql-wasm.js
8+
/@
89
/test/func/**/report
910
/test/func/**/report-backup
1011
/test/func/**/reports

lib/adapters/event-handling/testplane/snapshots.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,13 @@ interface CreateSnapshotFilePathParams {
3333
attempt: number;
3434
hash: string;
3535
browserId: string;
36+
timestamp: number;
3637
}
3738

38-
export function createSnapshotFilePath({attempt: attemptInput, hash, browserId}: CreateSnapshotFilePathParams): string {
39+
export function createSnapshotFilePath({attempt: attemptInput, hash, browserId, timestamp}: CreateSnapshotFilePathParams): string {
3940
const attempt: number = attemptInput || 0;
40-
const imageDir = _.compact([SNAPSHOTS_PATH, hash]);
41-
const components = imageDir.concat(`${browserId}_${attempt}.zip`);
41+
const snapshotDir = _.compact([SNAPSHOTS_PATH, hash]);
42+
const components = snapshotDir.concat(`${browserId}_${timestamp}_${attempt}.zip`);
4243

4344
return path.join(...components);
4445
}
@@ -141,7 +142,8 @@ export const finalizeSnapshotsForTest = async ({testResult, attempt, reportPath,
141142
const zipFilePath = createSnapshotFilePath({
142143
attempt,
143144
hash: testResult.imageDir,
144-
browserId: testResult.browserId
145+
browserId: testResult.browserId,
146+
timestamp: testResult.timestamp
145147
});
146148
const absoluteZipFilePath = path.resolve(reportPath, zipFilePath);
147149
await fsExtra.ensureDir(path.dirname(absoluteZipFilePath));

lib/adapters/test-result/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export interface ReporterTestResult {
2222
readonly status: TestStatus;
2323
readonly testPath: string[];
2424
/** Test start timestamp in ms */
25-
readonly timestamp: number | undefined;
25+
readonly timestamp: number;
2626
readonly url?: string;
2727
/** Test duration in ms */
2828
readonly duration: number;

lib/adapters/test-result/playwright.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ export class PlaywrightTestResultAdapter implements ReporterTestResult {
350350
return this._testCase.titlePath().slice(3);
351351
}
352352

353-
get timestamp(): number | undefined {
353+
get timestamp(): number {
354354
return this._testResult.startTime.getTime();
355355
}
356356

lib/adapters/test-result/reporter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ export class ReporterTestAdapter implements ReporterTestResult {
108108
return this._testResult.testPath;
109109
}
110110

111-
get timestamp(): number | undefined {
111+
get timestamp(): number {
112112
return this._testResult.timestamp;
113113
}
114114

lib/adapters/test-result/sqlite.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ export class SqliteTestResultAdapter implements ReporterTestResult {
144144
return this._parsedTestResult.testPath as string[];
145145
}
146146

147-
get timestamp(): number | undefined {
147+
get timestamp(): number {
148148
return Number(this._testResult[DB_COLUMN_INDEXES.timestamp]);
149149
}
150150

lib/adapters/test-result/testplane.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ export class TestplaneTestResultAdapter implements ReporterTestResult {
258258
return true;
259259
}
260260

261-
get timestamp(): number | undefined {
261+
get timestamp(): number {
262262
return this._timestamp;
263263
}
264264

lib/cli/commands/merge-reports.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,17 @@
33
const {commands} = require('..');
44
const mergeReports = require('../../merge-reports');
55
const {logError} = require('../../server-utils');
6-
const {ToolName} = require('../../constants');
76

87
const {MERGE_REPORTS: commandName} = commands;
98

109
module.exports = (program, toolAdapter) => {
11-
const {toolName} = toolAdapter;
12-
1310
program
1411
.command(`${commandName} [paths...]`)
1512
.allowUnknownOption()
1613
.description('merge reports')
1714
.option('-d, --destination <destination>', 'path to directory with merged report', toolAdapter.reporterConfig.path)
1815
.option('-h, --header <header>', 'http header for databaseUrls.json files from source paths', collect, [])
1916
.action(async (paths, options) => {
20-
if (toolName !== ToolName.Testplane) {
21-
throw new Error(`CLI command "${commandName}" supports only "${ToolName.Testplane}" tool`);
22-
}
23-
2417
try {
2518
const {destination: destPath, header: headers} = options;
2619

lib/constants/database.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,5 @@ export const DB_COLUMN_INDEXES = SUITES_TABLE_COLUMNS.reduce((acc: Record<string
6767
acc[name] = index;
6868
return acc;
6969
}, {}) as unknown as DbColumnIndexes;
70+
71+
export const DB_FILE_EXTENSION = '.db';

lib/db-utils/server.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ import {SqliteClient} from '../sqlite-client';
1818

1919
export * from './common';
2020

21-
export const prepareUrls = (urls: string[], baseUrl: string): string[] => isUrl(baseUrl) ? normalizeUrls(urls, baseUrl) : urls;
21+
export const prepareUrls = (urls: string[], baseUrl: string): string[] => {
22+
return isUrl(baseUrl)
23+
? normalizeUrls(urls, baseUrl)
24+
: urls.map(u => isUrl(u) ? u : path.join(path.parse(baseUrl).dir, u));
25+
};
2226

2327
export async function downloadDatabases(dbJsonUrls: string[], opts: HandleDatabasesOptions): Promise<(string | DbLoadResult)[]> {
2428
const loadDbJsonUrl = async (dbJsonUrl: string): Promise<{data: DbUrlsJsonData | null}> => {

0 commit comments

Comments
 (0)