Skip to content

Commit

Permalink
merge test coverages
Browse files Browse the repository at this point in the history
  • Loading branch information
SteffenDE committed Feb 10, 2024
1 parent e07a58e commit a3f6273
Show file tree
Hide file tree
Showing 18 changed files with 1,199 additions and 33 deletions.
89 changes: 84 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,14 @@ jobs:
MIX_ENV: test

- name: Run tests
run: mix test
run: mix test --cover --export-coverage default

- uses: actions/upload-artifact@v3
if: always()
with:
name: mix-test-coverage-${{ matrix.otp }}-${{ matrix.elixir }}
path: cover/default.coverdata
retention-days: 7

npm_test:
name: npm test
Expand Down Expand Up @@ -122,10 +129,14 @@ jobs:
${{ runner.os }}-node-
- name: npm install and test
run: |
cd assets
npm install
npm test
run: npm run js:test

- uses: actions/upload-artifact@v3
if: always()
with:
name: js-unit-coverage
path: assets/coverage/
retention-days: 7

e2e_test:
name: e2e test
Expand Down Expand Up @@ -193,3 +204,71 @@ jobs:
name: playwright-report
path: playwright-report/
retention-days: 7

- uses: actions/upload-artifact@v3
if: always()
with:
name: e2e-test-results
path: test/e2e/test-results/
retention-days: 7

- uses: actions/upload-artifact@v3
if: always()
with:
name: mix-e2e-coverage
path: cover/e2e.coverdata
retention-days: 7

coverage_report:
name: coverage report

runs-on: ubuntu-latest
needs: [mix_test, npm_test, e2e_test]

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Set up Elixir
uses: erlef/setup-beam@v1
with:
elixir-version: 1.16.1
otp-version: 26.2

- name: Download mix unit coverage
uses: actions/download-artifact@v3
with:
name: mix-test-coverage-26.0-1.15.5

- name: Download mix e2e coverage
uses: actions/download-artifact@v3
with:
name: mix-e2e-coverage

- name: Generate mix coverage report
run: mix test.coverage

- name: Download js-unit-coverage artifact
uses: actions/download-artifact@v3
with:
name: js-unit-coverage

- name: Download e2e-test-results artifact
uses: actions/download-artifact@v3
with:
name: e2e-test-results

- name: Set up Node.js 18.x
uses: actions/setup-node@v1
with:
node-version: 18.x

- name: Merge coverage reports
run: node cover:merge

- name: Upload coverage report
uses: actions/upload-artifact@v3
with:
name: overall-coverage
path: cover/
retention-days: 7
28 changes: 19 additions & 9 deletions assets/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,30 @@ module.exports = {
// coverageDirectory: undefined,

// An array of regexp pattern strings used to skip coverage collection
// coveragePathIgnorePatterns: [
// "/node_modules/"
// ],
coveragePathIgnorePatterns: [
"/node_modules/",
"/test/"
],

collectCoverage: true,

// Indicates which provider should be used to instrument code for coverage
coverageProvider: "v8",

// A list of reporter names that Jest uses when writing coverage reports
// coverageReporters: [
// "json",
// "text",
// "lcov",
// "clover"
// ],
coverageReporters: ["none"],

reporters: [
["jest-monocart-coverage", {
name: "Phoenix LiveView JS Unit Coverage",
reports: [
["raw", {outputDir: "./raw"}],
["v8"],
["console-summary"]
],
outputDir: "./coverage"
}]
],

// An object that configures minimum threshold enforcement for coverage results
// coverageThreshold: undefined,
Expand Down
128 changes: 128 additions & 0 deletions assets/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions assets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"eslint-plugin-jest": "27.6.3",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"jest-monocart-coverage": "^1.0.2",
"phoenix": "1.7.10"
}
}
23 changes: 23 additions & 0 deletions js-coverage.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import fs from "fs";
import { CoverageReport } from "monocart-coverage-reports";

const coverageOptions = {
name: "Phoenix LiveView JS Coverage",
inputDir: [
"./assets/coverage/raw",
"./test/e2e/test-results/coverage/raw"
],
outputDir: "./cover/merged-js",
reports: [
["v8"],
["console-summary"]
],
sourcePath: (filePath) => {
if (!filePath.startsWith("assets")) {
return "assets/js/phoenix_live_view/" + filePath;
} else {
return filePath;
}
},
};
await new CoverageReport(coverageOptions).generate();
Loading

0 comments on commit a3f6273

Please sign in to comment.