Commit 63c6fc5f by Ryan McKinley Committed by GitHub

Toolkit: add junit reporting and jest.config.js to plugin build (#22450)

parent 62d86c95
import * as jestCLI from 'jest-cli'; import * as jestCLI from 'jest-cli';
import { useSpinner } from '../../utils/useSpinner'; import { useSpinner } from '../../utils/useSpinner';
import { jestConfig } from '../../../config/jest.plugin.config'; import { loadJestPluginConfig } from '../../../config/jest.plugin.config';
export interface PluginTestOptions { export interface PluginTestOptions {
updateSnapshot: boolean; updateSnapshot: boolean;
...@@ -13,7 +13,7 @@ export interface PluginTestOptions { ...@@ -13,7 +13,7 @@ export interface PluginTestOptions {
export const testPlugin = useSpinner<PluginTestOptions>( export const testPlugin = useSpinner<PluginTestOptions>(
'Running tests', 'Running tests',
async ({ updateSnapshot, coverage, watch, testPathPattern, testNamePattern }) => { async ({ updateSnapshot, coverage, watch, testPathPattern, testNamePattern }) => {
const testConfig = jestConfig(); const testConfig = loadJestPluginConfig();
const cliConfig = { const cliConfig = {
config: JSON.stringify(testConfig), config: JSON.stringify(testConfig),
......
...@@ -60,6 +60,7 @@ const copyFiles = () => { ...@@ -60,6 +60,7 @@ const copyFiles = () => {
'src/config/tsconfig.plugin.local.json', 'src/config/tsconfig.plugin.local.json',
'src/config/eslint.plugin.json', 'src/config/eslint.plugin.json',
'src/config/styles.mock.js', 'src/config/styles.mock.js',
'src/config/jest.plugin.config.local.js',
// plugin test file // plugin test file
'src/plugins/e2e/commonPluginTests.ts', 'src/plugins/e2e/commonPluginTests.ts',
......
// This file is needed because it is used by vscode and other tools that
// call `jest` directly. However, unless you are doing anything special
// do not edit this file
const standard = require('@grafana/toolkit/src/config/jest.plugin.config');
// This process will use the same config that `yarn test` is using
module.exports = standard.jestConfig();
...@@ -57,9 +57,23 @@ export const jestConfig = (baseDir: string = process.cwd()) => { ...@@ -57,9 +57,23 @@ export const jestConfig = (baseDir: string = process.cwd()) => {
moduleDirectories: ['node_modules', 'src'], moduleDirectories: ['node_modules', 'src'],
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json'], moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json'],
setupFiles, setupFiles,
globals: { 'ts-jest': { isolatedModules: true } }, globals: {
'ts-jest': {
isolatedModules: true,
tsConfig: path.resolve(baseDir, 'tsconfig.json'),
},
},
coverageReporters: ['json-summary', 'text', 'lcov'], coverageReporters: ['json-summary', 'text', 'lcov'],
collectCoverageFrom: ['src/**/*.{ts,tsx}', '!**/node_modules/**', '!**/vendor/**'], collectCoverageFrom: ['src/**/*.{ts,tsx}', '!**/node_modules/**', '!**/vendor/**'],
reporters: [
'default',
[
'jest-junit',
{
outputDirectory: 'coverage',
},
],
],
testMatch: [ testMatch: [
'<rootDir>/src/**/__tests__/**/*.{js,jsx,ts,tsx}', '<rootDir>/src/**/__tests__/**/*.{js,jsx,ts,tsx}',
'<rootDir>/src/**/*.{spec,test,jest}.{js,jsx,ts,tsx}', '<rootDir>/src/**/*.{spec,test,jest}.{js,jsx,ts,tsx}',
...@@ -80,3 +94,16 @@ export const jestConfig = (baseDir: string = process.cwd()) => { ...@@ -80,3 +94,16 @@ export const jestConfig = (baseDir: string = process.cwd()) => {
...otherOverrides, ...otherOverrides,
}; };
}; };
/**
* This will load the existing just setup, or use the default if it exists
*/
export const loadJestPluginConfig = (baseDir: string = process.cwd()) => {
const cfgpath = path.resolve(baseDir, 'jest.config.js');
if (!fs.existsSync(cfgpath)) {
const src = path.resolve(baseDir, 'node_modules/@grafana/toolkit/src/config/jest.plugin.config.local.js');
fs.copyFileSync(src, cfgpath);
console.log('Using standard jest plugin config', src);
}
return require(cfgpath);
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment