Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

Commit

Permalink
fix: seperate jest into two test runs (#92)
Browse files Browse the repository at this point in the history
- coverage is unreliable when projects use different tsconfig
- split jest into two tests, server + client
- seperate npm runs
- seperate coverage output and github action

Contributes to: #91

Signed-off-by: Nic Townsend <nictownsend@uk.ibm.com>
  • Loading branch information
nictownsend authored Nov 9, 2020
1 parent 1bf97c4 commit 1f62510
Show file tree
Hide file tree
Showing 16 changed files with 4,992 additions and 3,018 deletions.
6 changes: 4 additions & 2 deletions .github/actions/commenter/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ inputs:
description: "Markdown representation of bundle sizes"
OVERALL_BUNDLE_SIZE_CHANGE:
description: "Overall percentage change of bundle sizes between master and current"
TEST_COVERAGE:
description: "Test coverage report from jest tests"
TEST_COVERAGE_CLIENT:
description: "Test coverage report from jest tests for client code"
TEST_COVERAGE_SERVER:
description: "Test coverage report from jest tests for server code"
runs:
using: "docker"
image: "Dockerfile"
5 changes: 3 additions & 2 deletions .github/actions/commenter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,12 @@ async function comment(message) {
async function createComment() {
try {
const bundleReportContent = core.getInput("BUNDLE_REPORT") ? JSON.parse(core.getInput("BUNDLE_REPORT")) : {};
const testCoverage = core.getInput("TEST_COVERAGE");
const testCoverageClient = core.getInput("TEST_COVERAGE_CLIENT");
const testCoverageServer = core.getInput("TEST_COVERAGE_SERVER");

const title = '# PR Report';
const bundleText = `## Bundle Sizes\n${Object.entries(bundleReportContent).reduce((acc, [codeArea, {bundle_report, overall_bundle_size_change}]) => `${acc}<details><summary>View bundle sizes for '${codeArea}'</summary><br>\n\n${bundle_report}\n##### Overall bundle size change: ${overall_bundle_size_change}\n</details>`, '')}`;
const testText = `## Test Coverage\n<details><summary>View test coverage</summary><br>\n\n${testCoverage}\n</details>`;
const testText = `## Test Coverage\n<details><summary>View test coverage</summary><br>\n\n${testCoverageClient}\n\n\n${testCoverageServer}\n</details>`;
const footer = `Triggered by commit: ${github.context.sha}`;

const commentText = [title, bundleText, testText, footer];
Expand Down
6 changes: 4 additions & 2 deletions .github/actions/coverage-report/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
name: "Coverage report"
description: "Report test coverage"
outputs:
test_coverage:
description: "Text for test coverage"
test_coverage_client:
description: "Text for test coverage on client code"
test_coverage_server:
description: "Text for test coverage on server code"
runs:
using: "docker"
image: "Dockerfile"
43 changes: 24 additions & 19 deletions .github/actions/coverage-report/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,36 @@
const core = require("@actions/core");
const fs = require("fs");

async function formatCoverage() {
async function formatCoverage(testType) {
try {
const coverage = JSON.parse(
fs.readFileSync("./coverage/coverage-summary.json")
fs.readFileSync(`./coverage/${testType}/coverage-summary.json`)
);

let coverageText =
"| File | Lines | Statement | Functions | Branches |\n| --- | --- | --- | --- | --- |\n";

const regex = /^(.+)strimzi-ui\/(.+)$/;

coverageText += Object.entries(coverage).reduce((text, [key, value]) => {
console.log(key);

return `${text}| ${key != "total" ? key.match(regex)[2] : "Total"} | ${
value.lines.pct
}% | ${value.statements.pct}% | ${value.functions.pct}% | ${
value.branches.pct
}% |\n`;
}, '');

core.setOutput("test_coverage", coverageText);
core.setOutput(`test_coverage_${testType}`, coverageTable(coverage));
} catch (error) {
core.setFailed(error.message);
}
}

formatCoverage();
const coverageTable = (coverage) => {
let coverageText =
"| File | Lines | Statement | Functions | Branches |\n| --- | --- | --- | --- | --- |\n";

const regex = /^(.+)strimzi-ui\/(.+)$/;

coverageText += Object.entries(coverage).reduce((text, [key, value]) => {
console.log(key);

return `${text}| ${key != "total" ? key.match(regex)[2] : "Total"} | ${
value.lines.pct
}% | ${value.statements.pct}% | ${value.functions.pct}% | ${
value.branches.pct
}% |\n`;
}, '');

return coverageText;
};

return Promise.all([formatCoverage("client"),
formatCoverage("server")]);
9 changes: 6 additions & 3 deletions .github/workflows/node-pr-jobs-secure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ jobs:
with:
CLIENT_MASTER_REPORT: ${{ env.CLIENT_MASTER_REPORT }}
SERVER_MASTER_REPORT: ${{ env.SERVER_MASTER_REPORT }}
- name: Test
run: npm run test:jest -- --forceExit # force exit in case a test does not clean up after failure
- name: Test client code
run: npm run test:jest:client -- --forceExit # force exit in case a test does not clean up after failure
- name: Test server code
run: npm run test:jest:server -- --forceExit # force exit in case a test does not clean up after failure
- name: Coverage report
id: coverage
if: ${{ always() }}
Expand All @@ -56,4 +58,5 @@ jobs:
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BUNDLE_REPORT: ${{ steps.bundle.outputs.bundle_report }}
TEST_COVERAGE: ${{ steps.coverage.outputs.test_coverage }}
TEST_COVERAGE_CLIENT: ${{ steps.coverage.outputs.test_coverage_client }}
TEST_COVERAGE_SERVER: ${{ steps.coverage.outputs.test_coverage_server }}
2 changes: 0 additions & 2 deletions client/Bootstrap/GraphQLClient/GraphQLClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
* License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html).
*/

/* istanbul ignore file */

import { ApolloClient, HttpLink, split, InMemoryCache } from '@apollo/client';
import { WebSocketLink } from '@apollo/client/link/ws';
import { SubscriptionClient } from 'subscriptions-transport-ws';
Expand Down
31 changes: 31 additions & 0 deletions client/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright Strimzi authors.
* License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html).
*/
const merge = require('lodash.merge');
const { pathsToModuleNameMapper } = require('ts-jest/utils');
const { jestModuleMapper } = require('../utils/tooling/aliasHelper');
const { compilerOptions } = require('./tsconfig.json');
const commonConfig = require('../test_common/jest.common.config');

const config = {
setupFilesAfterEnv: ['<rootDir>/../test_common/jest_rtl_setup.ts'],
testMatch: ['**/*.(spec|steps).[jt]s?(x)'],
coverageDirectory: '<rootDir>/../coverage/client',
moduleNameMapper: {
...pathsToModuleNameMapper(compilerOptions.paths),
...jestModuleMapper,
},
testEnvironment: 'jsdom',
collectCoverageFrom: [
'**/*.{js,ts,jsx,tsx}',
'!**/index.{js,ts,jsx,tsx}',
'!**/*.steps.*',
'!**/*.d.ts',
'!jest.config.js',
// Wrapper around graphql - not something we need/wish to test
'!Bootstrap/GraphQLClient/**',
],
};

module.exports = merge({}, commonConfig, config);
Loading

0 comments on commit 1f62510

Please sign in to comment.