Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: normalize urls while merging reports #503

Merged
merged 1 commit into from
Sep 13, 2023
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
3 changes: 2 additions & 1 deletion lib/db-utils/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import {SqliteAdapter} from '../sqlite-adapter';

export * from './common';

export const prepareUrls = (urls: string[], baseUrl: string): string[] => isUrl(baseUrl) ? normalizeUrls(urls, baseUrl) : urls;

export async function downloadDatabases(dbJsonUrls: string[], opts: HandleDatabasesOptions): Promise<(string | DbLoadResult)[]> {
const loadDbJsonUrl = async (dbJsonUrl: string): Promise<{data: DbUrlsJsonData | null}> => {
if (isUrl(dbJsonUrl)) {
Expand All @@ -28,7 +30,6 @@ export async function downloadDatabases(dbJsonUrls: string[], opts: HandleDataba
return {data};
};

const prepareUrls = (urls: string[], baseUrl: string): string[] => isUrl(baseUrl) ? normalizeUrls(urls, baseUrl) : urls;
const loadDbUrl = (dbUrl: string, opts: HandleDatabasesOptions): Promise<string> => downloadSingleDatabase(dbUrl, opts);

return commonSqliteUtils.handleDatabases(dbJsonUrls, {...opts, loadDbJsonUrl, prepareUrls, loadDbUrl});
Expand Down
8 changes: 6 additions & 2 deletions lib/merge-reports/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const axios = require('axios');
const _ = require('lodash');
const serverUtils = require('../server-utils');
const dbServerUtils = require('../db-utils/server');

module.exports = async (pluginConfig, hermione, srcPaths, {destination: destPath}) => {
validateOpts(srcPaths, destPath);
Expand Down Expand Up @@ -50,9 +51,12 @@ async function tryResolveUrl(url) {
const currentDbUrls = _.get(data, 'dbUrls', []);
const currentJsonUrls = _.get(data, 'jsonUrls', []);

const responses = await Promise.all(currentJsonUrls.map(tryResolveUrl));
const preparedDbUrls = dbServerUtils.prepareUrls(currentDbUrls, url);
const preparedJsonUrls = dbServerUtils.prepareUrls(currentJsonUrls, url);

dbUrls.push(...currentDbUrls);
const responses = await Promise.all(preparedJsonUrls.map(tryResolveUrl));

dbUrls.push(...preparedDbUrls);

responses.forEach(response => {
dbUrls.push(...response.dbUrls);
Expand Down
14 changes: 14 additions & 0 deletions test/unit/lib/merge-reports/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,20 @@ describe('lib/merge-reports', () => {
assert.calledOnceWith(serverUtils.writeDatabaseUrlsFile, destination, ['path-1.db', 'path-2.db', 'path-3.db', 'path-4.db']);
});

it('should normalize urls while merging reports', async () => {
const pluginConfig = stubConfig();
const hermione = stubTool(pluginConfig, {}, {}, htmlReporter);
const paths = ['src-report/path-1.json'];
const destination = 'dest-report/path';

axiosStub.get.withArgs('src-report/path-1.json').resolves({data: {jsonUrls: ['https://foo.bar/path-2.json']}});
axiosStub.get.withArgs('https://foo.bar/path-2.json').resolves({data: {jsonUrls: [], dbUrls: ['sqlite.db']}});

await execMergeReports_({pluginConfig, hermione, paths, opts: {destination}});

assert.calledOnceWith(serverUtils.writeDatabaseUrlsFile, destination, ['https://foo.bar/sqlite.db']);
});

it('should fallback to json url while merging reports', async () => {
const pluginConfig = stubConfig();
const hermione = stubTool(pluginConfig, {}, {}, htmlReporter);
Expand Down
Loading