Skip to content

Commit

Permalink
chore: coverage summary
Browse files Browse the repository at this point in the history
  • Loading branch information
mistic100 committed Nov 10, 2024
1 parent 6e58872 commit d8e7b36
Show file tree
Hide file tree
Showing 32 changed files with 127 additions and 44 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,8 @@ jobs:
path: 'cypress/reports/html/.jsons/*.json'
reporter: mochawesome-json

- name: move lcov report
if: ${{ !cancelled() }}
run: mv cypress/reports/lcov-viewer cypress/reports/html/coverage
- name: coverage summary
run: node ./build/generate-coverage-summary.mjs >> $GITHUB_STEP_SUMMARY

- name: report artifact
uses: actions/upload-artifact@v4
Expand Down
20 changes: 9 additions & 11 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
node_modules
yarn-error.log
.nyc_output
.tmp
.turbo
docs/.vitepress/cache
docs/.vitepress/.temp
.typedoc
!docs/.typedoc
dist
/public
reports
cypress/screenshots
cypress/snapshots/diff
.tmp
.nyc_output
dist
docs/.vitepress/.temp
docs/.vitepress/cache
node_modules
public
reports
yarn-error.log
57 changes: 57 additions & 0 deletions build/generate-coverage-summary.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/**
* Generates a markdown summary from the coverage report
*/

import vm from 'node:vm';
import { readFileSync } from 'node:fs';

const TOTAL = '_total_';

const script = new vm.Script(readFileSync('cypress/reports/lcov-viewer/report-data.js'));
const context = vm.createContext({ window: {} });
script.runInContext(context);

const values = Object.values(context.window.COVERAGE_DATA)
.reduce((result, { metrics, path }) => {
const module = path.split('/').shift();
[TOTAL, module].forEach(key => {
const moduleMetrics = result[key] ?? {
branches: { total: 0, covered: 0 },
functions: { total: 0, covered: 0 },
lines: { total: 0, covered: 0 },
};

moduleMetrics.branches.total += metrics.branches.total;
moduleMetrics.branches.covered += metrics.branches.covered;
moduleMetrics.functions.total += metrics.functions.total;
moduleMetrics.functions.covered += metrics.functions.covered;
moduleMetrics.lines.total += metrics.lines.total;
moduleMetrics.lines.covered += metrics.lines.covered;

result[key] = moduleMetrics;
});
return result;
}, {});

function percentWithColor({ covered, total }) {
const percent = Math.round(covered / total * 10000) / 100;
const color = percent >= 80 ? '#248f29' : percent >= 60 ? '#d3b334' : '#d3343c';
return `\${\\textsf{\\color{${color}}${percent.toFixed(1)}\\\\%}}$`;
}

const summary = `
# ${percentWithColor(values[TOTAL].lines)} lines, ${percentWithColor(values[TOTAL].functions)} functions, ${percentWithColor(values[TOTAL].branches)} branches
| Package | Lines | Line Coverage | Functions | Function Coverage | Branches | Branch Coverage |
| ------- | -----:| ------------- | ---------:| ----------------- | --------:| ----------------|
${Object.entries(values)
.filter(([name]) => name !== TOTAL)
.map(([name, { lines, functions, branches }]) => {
const entry = ({ covered, total }) => `${covered}/${total} | ${percentWithColor({ covered, total })}`;
return `| **${name}** | ${entry(lines)} | ${entry(functions)} | ${entry(branches)} |`;
})
.join('\n')
}
`;

console.log(summary);
2 changes: 1 addition & 1 deletion build/generate-typedoc-readme.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { mkdir, readFile, writeFile } from 'fs/promises';
const PACKAGES_DIR = 'packages';
const PKG_FILE = 'package.json';
const TYPEDOC_FILE = 'typedoc.json';
const DIST_DIR = '.typedoc';
const DIST_DIR = '.tmp/typedoc';
const DIST_FILE = 'README.md';

(async () => {
Expand Down
25 changes: 24 additions & 1 deletion cypress.config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@

import fs from 'fs';
// @ts-ignore
import cypressOnFix from 'cypress-on-fix';
import { defineConfig } from 'cypress';
import { configureVisualRegression } from 'cypress-visual-regression';
import registerCodeCoverageTasks from '@cypress/code-coverage/task';
Expand All @@ -15,10 +19,13 @@ export default defineConfig({
visualRegressionType: 'regression',
},
setupNodeEvents(on, config) {
on = cypressOnFix(on);

registerCodeCoverageTasks(on, config);
configureVisualRegression(on);
cypressMochawesomeReporterPlugin(on);

// define browser size for screenshots (headless mode)
on('before:browser:launch', (browser, launchOptions) => {
// should be bigger than the largest viewport used + browser UI elements
const width = 1600;
Expand All @@ -42,6 +49,22 @@ export default defineConfig({
return launchOptions
});

// move lcov html report
on('after:run', () => {
const ROOT_DIR = 'cypress/reports/';

console.log(`Move ${ROOT_DIR}lcov-viewer to ${ROOT_DIR}html/coverage`);

fs.mkdirSync(ROOT_DIR + 'html/coverage', { recursive: true });
fs.copyFileSync(ROOT_DIR + 'lcov-viewer/report-data.js', ROOT_DIR + 'html/coverage/report-data.js');

const index = fs.readFileSync(ROOT_DIR + 'lcov-viewer/index.html', 'utf-8')
.replace('src="app.js"', 'src="https://cdn.jsdelivr.net/npm/@lcov-viewer/istanbul-report@1/lib/assets/app.js"')
.replace(/<title>.*<\/title>/, '<title>Photo Sphere Viewer - E2E coverage</title>');

fs.writeFileSync(ROOT_DIR + 'html/coverage/index.html', index, 'utf-8');
});

return config;
},
},
Expand All @@ -61,7 +84,7 @@ export default defineConfig({
removeJsonsFolderAfterMerge: false,
cdn: true,
charts: true,
reportPageTitle: 'Photo Sphere Viewer',
reportTitle: 'Photo Sphere Viewer',
reportPageTitle: 'Photo Sphere Viewer - E2E results',
},
});
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"alive-server": "^1.3.0",
"cypress": "^13.15.0",
"cypress-mochawesome-reporter": "^3.8.2",
"cypress-on-fix": "^1.0.3",
"cypress-visual-regression": "^5.2.2",
"esbuild-sass-plugin": "^3.3.0",
"eslint": "^8.57.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/autorotate-plugin/typedoc.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
"entryPoints": ["src/index.ts"],
"entryPointStrategy": "resolve",
"name": "AutorotatePlugin",
"readme": "./.typedoc/README.md"
"readme": "./.tmp/typedoc/README.md"
}
2 changes: 1 addition & 1 deletion packages/compass-plugin/typedoc.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
"entryPoints": ["src/index.ts"],
"entryPointStrategy": "resolve",
"name": "CompassPlugin",
"readme": "./.typedoc/README.md"
"readme": "./.tmp/typedoc/README.md"
}
2 changes: 1 addition & 1 deletion packages/core/typedoc.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
"entryPoints": ["src/index.ts"],
"entryPointStrategy": "resolve",
"name": "Core",
"readme": "./.typedoc/README.md"
"readme": "./.tmp/typedoc/README.md"
}
2 changes: 1 addition & 1 deletion packages/cubemap-adapter/typedoc.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
"entryPoints": ["src/index.ts"],
"entryPointStrategy": "resolve",
"name": "CubemapAdapter",
"readme": "./.typedoc/README.md"
"readme": "./.tmp/typedoc/README.md"
}
2 changes: 1 addition & 1 deletion packages/cubemap-tiles-adapter/typedoc.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
"entryPoints": ["src/index.ts"],
"entryPointStrategy": "resolve",
"name": "CubemapTilesAdapter",
"readme": "./.typedoc/README.md"
"readme": "./.tmp/typedoc/README.md"
}
2 changes: 1 addition & 1 deletion packages/cubemap-video-adapter/typedoc.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
"entryPoints": ["src/index.ts"],
"entryPointStrategy": "resolve",
"name": "CubemapVideoAdapter",
"readme": "./.typedoc/README.md"
"readme": "./.tmp/typedoc/README.md"
}
2 changes: 1 addition & 1 deletion packages/equirectangular-tiles-adapter/typedoc.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
"entryPoints": ["src/index.ts"],
"entryPointStrategy": "resolve",
"name": "EquirectangularTilesAdapter",
"readme": "./.typedoc/README.md"
"readme": "./.tmp/typedoc/README.md"
}
2 changes: 1 addition & 1 deletion packages/equirectangular-video-adapter/typedoc.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
"entryPoints": ["src/index.ts"],
"entryPointStrategy": "resolve",
"name": "EquirectangularVideoAdapter",
"readme": "./.typedoc/README.md"
"readme": "./.tmp/typedoc/README.md"
}
2 changes: 1 addition & 1 deletion packages/gallery-plugin/typedoc.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
"entryPoints": ["src/index.ts"],
"entryPointStrategy": "resolve",
"name": "GalleryPlugin",
"readme": "./.typedoc/README.md"
"readme": "./.tmp/typedoc/README.md"
}
2 changes: 1 addition & 1 deletion packages/gyroscope-plugin/typedoc.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
"entryPoints": ["src/index.ts"],
"entryPointStrategy": "resolve",
"name": "GyroscopePlugin",
"readme": "./.typedoc/README.md"
"readme": "./.tmp/typedoc/README.md"
}
2 changes: 1 addition & 1 deletion packages/map-plugin/typedoc.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
"entryPoints": ["src/index.ts"],
"entryPointStrategy": "resolve",
"name": "MapPlugin",
"readme": "./.typedoc/README.md"
"readme": "./.tmp/typedoc/README.md"
}
2 changes: 1 addition & 1 deletion packages/markers-plugin/typedoc.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
"entryPoints": ["src/index.ts"],
"entryPointStrategy": "resolve",
"name": "MarkersPlugin",
"readme": "./.typedoc/README.md"
"readme": "./.tmp/typedoc/README.md"
}
2 changes: 1 addition & 1 deletion packages/overlays-plugin/typedoc.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
"entryPoints": ["src/index.ts"],
"entryPointStrategy": "resolve",
"name": "OverlaysPlugin",
"readme": "./.typedoc/README.md"
"readme": "./.tmp/typedoc/README.md"
}
2 changes: 1 addition & 1 deletion packages/plan-plugin/typedoc.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
"entryPoints": ["src/index.ts"],
"entryPointStrategy": "resolve",
"name": "PlanPlugin",
"readme": "./.typedoc/README.md"
"readme": "./.tmp/typedoc/README.md"
}
2 changes: 1 addition & 1 deletion packages/resolution-plugin/typedoc.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
"entryPoints": ["src/index.ts"],
"entryPointStrategy": "resolve",
"name": "ResolutionPlugin",
"readme": "./.typedoc/README.md"
"readme": "./.tmp/typedoc/README.md"
}
2 changes: 1 addition & 1 deletion packages/settings-plugin/typedoc.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
"entryPoints": ["src/index.ts"],
"entryPointStrategy": "resolve",
"name": "SettingsPlugin",
"readme": "./.typedoc/README.md"
"readme": "./.tmp/typedoc/README.md"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"name": "Core",
"readme": "./.typedoc/README.md"
"readme": "./.tmp/typedoc/README.md"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"name": "TestAdapter",
"readme": "./.typedoc/README.md"
"readme": "./.tmp/typedoc/README.md"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"name": "TestPlugin",
"readme": "./.typedoc/README.md"
"readme": "./.tmp/typedoc/README.md"
}
8 changes: 4 additions & 4 deletions packages/shared/tests/generate-typedoc-readme.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('generate-typedoc-readme', () => {
execSync(`node ${path.join(__dirname, '../../../build/generate-typedoc-readme.mjs')}`, { cwd: testDir });

const cases = {
'.typedoc/README.md': `
'.tmp/typedoc/README.md': `
# Core
- [Viewer](classes/Core.Viewer.html)
Expand All @@ -29,17 +29,17 @@ describe('generate-typedoc-readme', () => {
- [TestAdapter](modules/TestAdapter.html)`,

'packages/core/.typedoc/README.md': `
'packages/core/.tmp/typedoc/README.md': `
NPM package : [@photo-sphere-viewer/core](https://www.npmjs.com/package/@photo-sphere-viewer/core)
Documentation : https://photo-sphere-viewer.js.org`,

'packages/test-adapter/.typedoc/README.md': `
'packages/test-adapter/.tmp/typedoc/README.md': `
NPM package : [@photo-sphere-viewer/test-adapter](https://www.npmjs.com/package/@photo-sphere-viewer/test-adapter)
Documentation : https://photo-sphere-viewer.js.org/adapters/test.html`,

'packages/test-plugin/.typedoc/README.md': `
'packages/test-plugin/.tmp/typedoc/README.md': `
NPM package : [@photo-sphere-viewer/test-plugin](https://www.npmjs.com/package/@photo-sphere-viewer/test-plugin)
Documentation : https://photo-sphere-viewer.js.org/plugins/test.html`,
Expand Down
2 changes: 1 addition & 1 deletion packages/stereo-plugin/typedoc.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
"entryPoints": ["src/index.ts"],
"entryPointStrategy": "resolve",
"name": "StereoPlugin",
"readme": "./.typedoc/README.md"
"readme": "./.tmp/typedoc/README.md"
}
2 changes: 1 addition & 1 deletion packages/video-plugin/typedoc.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
"entryPoints": ["src/index.ts"],
"entryPointStrategy": "resolve",
"name": "VideoPlugin",
"readme": "./.typedoc/README.md"
"readme": "./.tmp/typedoc/README.md"
}
2 changes: 1 addition & 1 deletion packages/virtual-tour-plugin/typedoc.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
"entryPoints": ["src/index.ts"],
"entryPointStrategy": "resolve",
"name": "VirtualTourPlugin",
"readme": "./.typedoc/README.md"
"readme": "./.tmp/typedoc/README.md"
}
2 changes: 1 addition & 1 deletion packages/visible-range-plugin/typedoc.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
"entryPoints": ["src/index.ts"],
"entryPointStrategy": "resolve",
"name": "VisibleRangePlugin",
"readme": "./.typedoc/README.md"
"readme": "./.tmp/typedoc/README.md"
}
2 changes: 1 addition & 1 deletion typedoc.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"cleanOutputDir": false,
"excludePrivate": true,
"entryPointStrategy": "packages",
"readme": ".typedoc/README.md",
"readme": ".tmp/typedoc/README.md",
"entryPoints": ["packages/*"],
"exclude": ["packages/shared"],
"validation": {
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2390,6 +2390,11 @@ cypress-mochawesome-reporter@^3.8.2:
mochawesome-merge "^4.2.1"
mochawesome-report-generator "^6.2.0"

cypress-on-fix@^1.0.3:
version "1.0.3"
resolved "https://registry.yarnpkg.com/cypress-on-fix/-/cypress-on-fix-1.0.3.tgz#7a98c2d7c863a3690a6400c7488441071a0b1a30"
integrity sha512-iC+LSKKZM0ppOoSGHK6FOxspHG+K6RaJFWlxUjrjjI5fyzmtgR5xBxEP4dsnoNthS1Lq4v70AN1PRZtJrYgNRw==

cypress-visual-regression@^5.2.2:
version "5.2.2"
resolved "https://registry.yarnpkg.com/cypress-visual-regression/-/cypress-visual-regression-5.2.2.tgz#4dc3e7e223683ffa3419025f397f50dba91ac8e0"
Expand Down

0 comments on commit d8e7b36

Please sign in to comment.