Skip to content

Commit

Permalink
integrate standalone coverage reports
Browse files Browse the repository at this point in the history
  • Loading branch information
cenfun committed Dec 5, 2023
1 parent 92d6d39 commit 100e737
Show file tree
Hide file tree
Showing 55 changed files with 153 additions and 5,040 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
/node_modules
/packages/**/dist
/package-lock.json
/lib/runtime
/lib/packages
/.env
/scripts/mock/demo/dist/
26 changes: 7 additions & 19 deletions lib/generate-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const Util = require('./utils/util.js');
const { getTickInfo } = require('./utils/system.js');
const Visitor = require('./visitor.js');
const { calculateSummary } = require('./common.js');
const { addGlobalCoverageReport } = require('./plugins/coverage/coverage.js');
const { generateGlobalCoverageReport } = require('./plugins/coverage/coverage.js');
const version = require('../package.json').version;

const getReportName = (options, config, metadata) => {
Expand All @@ -15,27 +15,15 @@ const getReportName = (options, config, metadata) => {
return 'Test Report';
};

const generateGlobalCoverageReport = (dataList, options) => {
const {
name, outputDir, coverage
} = options;
const coverageOptions = {
title: `Coverage Report - ${name}`,
outputDir,
outputName: 'coverage',
... coverage
};
return addGlobalCoverageReport(dataList, coverageOptions);
};

const artifactsHandler = async (visitor, options) => {
const artifactsHandler = async (visitor, reporterOptions) => {
const artifacts = [].concat(visitor.artifacts);

// global artifacts
const { coverage } = visitor.artifactDataMap;
if (coverage) {
const report = await generateGlobalCoverageReport(coverage, options);
artifacts.push(report);
const globalCoverageReport = await generateGlobalCoverageReport(reporterOptions);
if (globalCoverageReport) {
artifacts.push(globalCoverageReport);
}

return artifacts;
};

Expand Down
15 changes: 9 additions & 6 deletions lib/generate-report.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,19 @@ const generateJson = (outputDir, htmlFile, reportData) => {

const generateHtml = async (outputDir, htmlFile, reportData, inline) => {

const jsFiles = [];
jsFiles.push(path.resolve(__dirname, './packages/monocart-common.js'));
jsFiles.push(path.resolve(__dirname, './packages/monocart-reporter.js'));

const options = {
inline,
reportData,
jsFiles: ['monocart-common.js', 'monocart-reporter.js'],
htmlDir: outputDir,
jsFiles,
assetsPath: './assets',
outputDir,
htmlFile,

outputDir,
reportDataFile: 'report-data.js',
assetsRelative: ''
reportDataFile: 'report-data.js'
};

const htmlPath = await Util.saveHtmlReport(options);
Expand Down Expand Up @@ -152,7 +155,7 @@ const generateReport = async (reportData, options) => {
if (artifacts) {
artifacts.forEach((report) => {
const g = report.global ? `${EC.magenta('(global)')}` : '';
Util.logInfo(`${report.name}: ${EC.cyan(report.path)} ${report.title} ${g}`);
Util.logInfo(`${report.type}: ${EC.cyan(report.path)} ${report.name} ${g}`);
// convert path to relative reporter
report.path = Util.relativePath(report.path, outputDir);
});
Expand Down
8 changes: 1 addition & 7 deletions lib/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,9 @@ export type CoverageReportOptions = {

export function addCoverageReport(
v8list: any[],
testInfo: TestInfo,
options?: CoverageReportOptions
testInfo: TestInfo
): Promise<any | void>;

export function addGlobalCoverageReport(
dataList: any[],
options: CoverageReportOptions
): Promise<any>;

export function attachCoverageReport(
coverage: any[] | any,
testInfo: TestInfo,
Expand Down
5 changes: 1 addition & 4 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ const { getTrends } = require('./common.js');

const merge = require('./merge-data.js');
const { attachAuditReport } = require('./plugins/audit/audit.js');
const {
addCoverageReport, addGlobalCoverageReport, attachCoverageReport
} = require('./plugins/coverage/coverage.js');
const { addCoverageReport, attachCoverageReport } = require('./plugins/coverage/coverage.js');
const { attachNetworkReport } = require('./plugins/network/network.js');

const { createStateServer, useState } = require('./plugins/state/state.js');
Expand All @@ -24,7 +22,6 @@ class Reporter {
static attachAuditReport = attachAuditReport;

static addCoverageReport = addCoverageReport;
static addGlobalCoverageReport = addGlobalCoverageReport;
static attachCoverageReport = attachCoverageReport;

static attachNetworkReport = attachNetworkReport;
Expand Down
1 change: 0 additions & 1 deletion lib/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export const merge = MonocartReporter.merge;
export const attachAuditReport = MonocartReporter.attachAuditReport;

export const addCoverageReport = MonocartReporter.addCoverageReport;
export const addGlobalCoverageReport = MonocartReporter.addGlobalCoverageReport;
export const attachCoverageReport = MonocartReporter.attachCoverageReport;

export const attachNetworkReport = MonocartReporter.attachNetworkReport;
Expand Down
5 changes: 0 additions & 5 deletions lib/platform/share.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@ const Util = {
name: 'network',
contentType: 'text/html',
reportFile: 'network-report.json'
},
// artifact will be removed finally
artifact: {
name: 'artifact',
contentType: 'application/json'
}
},

Expand Down
194 changes: 0 additions & 194 deletions lib/plugins/coverage/converter/collect-source-maps.js

This file was deleted.

Loading

0 comments on commit 100e737

Please sign in to comment.