Skip to content

Commit

Permalink
chore: add e2e coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
mistic100 committed Nov 10, 2024
1 parent 6b8b69d commit da147e3
Show file tree
Hide file tree
Showing 59 changed files with 975 additions and 154 deletions.
63 changes: 59 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,46 @@ on:
- '*'
paths-ignore:
- 'examples/**'
- 'docs/**'
pull_request:
branches:
- main
paths-ignore:
- 'examples/**'
- 'docs/**'
workflow_dispatch: {}

jobs:
changes:
runs-on: ubuntu-latest

permissions:
pull-requests: read

outputs:
build: ${{ steps.filter.outputs.build }}
src: ${{ steps.filter.outputs.src }}
e2e: ${{ steps.filter.outputs.e2e }}
docs: ${{ steps.filter.outputs.docs }}

steps:
- uses: dorny/paths-filter@v3
id: filter
with:
filters: |
build:
- '*'
- 'build/**'
src:
- 'packages/**'
e2e:
- 'cypress/**'
docs:
- 'docs/**'
build:
needs: changes

if: ${{ needs.changes.outputs.build == 'true' || needs.changes.outputs.src == 'true' }}

runs-on: ubuntu-latest

steps:
Expand All @@ -38,16 +67,20 @@ jobs:
reporter: mocha-json

e2e:
if: ${{ !startsWith(github.head_ref, 'dependabot') }}
needs: [changes, build]

if: ${{ startsWith(github.head_ref, 'dependabot') && (needs.changes.outputs.build == 'true' || needs.changes.outputs.e2e == 'true') }}

runs-on: ubuntu-latest
needs: build

steps:
- uses: actions/checkout@v4

- name: setup
uses: ./.github/workflows/shared/setup
with:
cache-readonly: true
turbo-cache: false

- name: e2e
run: yarn ci:e2e
Expand All @@ -61,6 +94,9 @@ jobs:
path: 'cypress/reports/html/.jsons/*.json'
reporter: mochawesome-json

- name: coverage summary
run: node ./build/generate-coverage-summary.mjs >> $GITHUB_STEP_SUMMARY

- name: report artifact
uses: actions/upload-artifact@v4
if: ${{ !cancelled() }}
Expand All @@ -79,3 +115,22 @@ jobs:
excludes: .jsons
auth-token: ${{ secrets.NETLIFY_AUTH_TOKEN }}
site-id: ${{ secrets.NETLIFY_REPORTS_SITE_ID }}

docs:
needs: [changes, build]

if: ${{ startsWith(github.head_ref, 'dependabot') && (needs.changes.outputs.build == 'true' || needs.changes.outputs.docs == 'true') }}

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: setup
uses: ./.github/workflows/shared/setup
with:
cache-readonly: true
turbo-cache: false

- name: build
run: yarn doc:build
31 changes: 0 additions & 31 deletions .github/workflows/documentation.yml

This file was deleted.

10 changes: 6 additions & 4 deletions .github/workflows/shared/setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ name: setup
inputs:
turbo-cache:
default: true
cache-readonly:
default: false

runs:
using: composite
Expand All @@ -21,21 +23,21 @@ runs:
- name: yarn cache
uses: actions/cache@v4
if: ${{ !startsWith(github.ref_name, 'dependabot') }}
if: ${{ !inputs.cache-readonly && !startsWith(github.ref_name, 'dependabot') }}
with:
key: yarn-${{ hashFiles('yarn.lock') }}
path: ${{ env.YARN_CACHE_DIR }}

- name: yarn cache ro
uses: actions/cache/restore@v4
if: ${{ startsWith(github.ref_name, 'dependabot') }}
if: ${{ inputs.cache-readonly || startsWith(github.ref_name, 'dependabot') }}
with:
key: yarn-${{ hashFiles('yarn.lock') }}
path: ${{ env.YARN_CACHE_DIR }}

- name: turbo cache
uses: actions/cache@v4
if: ${{ inputs.turbo-cache && !startsWith(github.ref_name, 'dependabot') }}
if: ${{ inputs.turbo-cache && !inputs.cache-readonly && !startsWith(github.ref_name, 'dependabot') }}
with:
path: .turbo
key: turbo-${{ github.sha }}
Expand All @@ -44,7 +46,7 @@ runs:
- name: turbo cache ro
uses: actions/cache/restore@v4
if: ${{ inputs.turbo-cache && startsWith(github.ref_name, 'dependabot') }}
if: ${{ inputs.turbo-cache && (inputs.cache-readonly || startsWith(github.ref_name, 'dependabot')) }}
with:
path: .turbo
key: turbo-${{ github.sha }}
Expand Down
19 changes: 9 additions & 10 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,13 +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
dist
docs/.vitepress/.temp
docs/.vitepress/cache
node_modules
public
reports
yarn-error.log
6 changes: 6 additions & 0 deletions .nycrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"report-dir": "./cypress/reports",
"reporter": ["@lcov-viewer/istanbul-report"],
"exclude": ["icons/**"],
"excludeAfterRemap": true
}
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
3 changes: 2 additions & 1 deletion build/plugins/esbuild-plugin-map-fix.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Plugin } from 'esbuild';
import { basename } from 'path';

/**
* Alters the paths in maps
Expand All @@ -14,7 +15,7 @@ export function mapFixPlugin(): Plugin {
return;
}

console.log('MAP', `Fix ${mapFile.path}`);
console.log('MAP', `Fix ${basename(mapFile.path)}`);

const content = JSON.parse(mapFile.text);
content.sources = content.sources.map((src: string) => {
Expand Down
76 changes: 41 additions & 35 deletions build/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import type { Plugin } from 'esbuild';
import { sassPlugin } from 'esbuild-sass-plugin';
import { defineConfig } from 'tsup';
import { assetsPlugin } from './plugins/esbuild-plugin-assets';
import { budgetPlugin } from './plugins/esbuild-plugin-budget';
// import { istanbulPlugin } from './plugins/esbuild-plugin-istanbul';
import { mapFixPlugin } from './plugins/esbuild-plugin-map-fix';
import { scssBundlePlugin } from './plugins/esbuild-plugin-scss-bundle';
import { budgetPlugin } from './plugins/esbuild-plugin-budget';
import { license } from './templates/license';
import { npmrc } from './templates/npmrc';
import { packageJson } from './templates/package';
Expand All @@ -19,53 +21,57 @@ ${
*/`;

return defineConfig((options) => {
const dev = options.watch || options.define?.['config'] === 'dev';
const dts = !dev && options.define?.['dts'] !== 'off';
const e2e = options.env?.E2E;
const dev = e2e || options.watch;

const plugins: Plugin[] = [
sassPlugin(),
];

if (!e2e) {
plugins.push(
mapFixPlugin()
);
}

if (!dev) {
plugins.push(
budgetPlugin(pkg.psv.budget),
scssBundlePlugin(),
assetsPlugin({
'LICENSE': license(),
'.npmrc': npmrc(),
'README.md': readme(pkg),
'package.json': packageJson(pkg),
})
);
}

return {
entryPoints: [pkg.main],
outDir: 'dist',
clean: true,
format: dev ? ['esm'] : ['esm', 'cjs'],
outExtension({ format }) {
return {
js: { cjs: '.cjs', esm: '.module.js', iife: '.js' }[format],
};
},
dts: dts,
outExtension: ({ format }) => ({
js: { cjs: '.cjs', esm: '.module.js', iife: '.js' }[format],
}),
dts: !dev,
sourcemap: true,
external: ['three'],
noExternal: [/three\/examples\/.*/],
target: 'es2021',
define: {
PKG_VERSION: `'${pkg.version}'`,
},
esbuildPlugins: [
sassPlugin(),
mapFixPlugin(),
budgetPlugin(pkg.psv.budget),
...(dev
? []
: [
scssBundlePlugin(),
assetsPlugin({
'LICENSE': license(),
'.npmrc': npmrc(),
'README.md': readme(pkg),
'package.json': packageJson(pkg),
}),
]),
],
esbuildOptions(options) {
options.banner = {
js: banner,
css: banner,
};
options.loader = {
'.svg': 'text',
'.glsl': 'text',
};
loader: {
'.svg': 'text',
'.glsl': 'text',
},
clean: true,
banner: {
js: banner,
css: banner,
},
esbuildPlugins: plugins,
};
});
}
Loading

0 comments on commit da147e3

Please sign in to comment.