Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Enable coverage for tests #408

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 20 additions & 11 deletions config/babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,28 @@
*/

module.exports = api => {
const isProd = process.env.NODE_ENV === 'production';

const plugins = [
'@babel/plugin-proposal-class-properties',
'@babel/plugin-transform-destructuring',
'@babel/plugin-transform-modules-commonjs',
'@babel/plugin-transform-parameters',
'@babel/plugin-transform-spread',
'@babel/plugin-proposal-object-rest-spread',
'@babel/plugin-proposal-optional-chaining',
'@babel/plugin-proposal-nullish-coalescing-operator',
'@babel/plugin-transform-classes',
];

if (!isProd) {
// plugins.push('istanbul');
}

api.cache(true);

return {
presets: ['@babel/preset-react', '@babel/preset-typescript'],
plugins: [
'@babel/plugin-proposal-class-properties',
'@babel/plugin-transform-destructuring',
'@babel/plugin-transform-modules-commonjs',
'@babel/plugin-transform-parameters',
'@babel/plugin-transform-spread',
'@babel/plugin-proposal-object-rest-spread',
'@babel/plugin-proposal-optional-chaining',
'@babel/plugin-proposal-nullish-coalescing-operator',
'@babel/plugin-transform-classes',
],
plugins,
};
};
1 change: 1 addition & 0 deletions config/eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

const fs = require('fs');

// TODO: go through directories recursively and look for gitignore inside
const entriesInGitignore = fs
.readFileSync('.gitignore', 'utf8')
.split('\n')
Expand Down
6 changes: 6 additions & 0 deletions config/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ module.exports = (disabledMocks = []) => ({
...(disabledMocks.includes('serialport')
? {}
: { serialport: `${mockDir}/emptyMock.ts` }),
// Force module uuid to resolve with the CJS entry point, because Jest does not support package.json.exports. See https://github.com/uuidjs/uuid/issues/451
uuid: require.resolve('uuid'),
},
transform: {
'^.+\\.[jt]sx?$': [
Expand All @@ -41,4 +43,8 @@ module.exports = (disabledMocks = []) => ({
transformIgnorePatterns: ['node_modules/(?!(pc-nrfconnect-shared)/)'],
setupFilesAfterEnv: [`${__dirname}/../test/setupTests.ts`],
snapshotSerializers: ['enzyme-to-json/serializer'],

coverageDirectory: 'coverage/jest-coverage',
collectCoverage: true,
coverageReporters: ['json', 'text'],
});
20 changes: 20 additions & 0 deletions config/nyc.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright (c) 2022 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-Nordic-4-Clause
*/

module.exports = {
all: true,
'check-coverage': true,
'temp-dir': 'coverage/playwright/.nyc_output',
'report-dir': 'coverage/playwright-coverage',
reporter: 'json',
// must be overwritten by projects that do not have src dir
include: '/src',
exclude: ['test-e2e'],
branches: 30,
lines: 30,
functions: 20,
statements: 30,
};
3 changes: 3 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,9 @@ interface Window {
appDir: string;
appDataDir: string;
appLogDir: string;

collectIstanbulCoverage?: (str: string) => void;
__coverage__?: string;
}

// Let typescript compiler in `npm run lint` resolve css modules
Expand Down
Loading