mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Toolkit: add junit reporting and jest.config.js to plugin build (#22450)
This commit is contained in:
parent
62d86c956f
commit
63c6fc5f4e
@ -1,6 +1,6 @@
|
||||
import * as jestCLI from 'jest-cli';
|
||||
import { useSpinner } from '../../utils/useSpinner';
|
||||
import { jestConfig } from '../../../config/jest.plugin.config';
|
||||
import { loadJestPluginConfig } from '../../../config/jest.plugin.config';
|
||||
|
||||
export interface PluginTestOptions {
|
||||
updateSnapshot: boolean;
|
||||
@ -13,7 +13,7 @@ export interface PluginTestOptions {
|
||||
export const testPlugin = useSpinner<PluginTestOptions>(
|
||||
'Running tests',
|
||||
async ({ updateSnapshot, coverage, watch, testPathPattern, testNamePattern }) => {
|
||||
const testConfig = jestConfig();
|
||||
const testConfig = loadJestPluginConfig();
|
||||
|
||||
const cliConfig = {
|
||||
config: JSON.stringify(testConfig),
|
||||
|
@ -60,6 +60,7 @@ const copyFiles = () => {
|
||||
'src/config/tsconfig.plugin.local.json',
|
||||
'src/config/eslint.plugin.json',
|
||||
'src/config/styles.mock.js',
|
||||
'src/config/jest.plugin.config.local.js',
|
||||
|
||||
// plugin test file
|
||||
'src/plugins/e2e/commonPluginTests.ts',
|
||||
|
@ -0,0 +1,8 @@
|
||||
// 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()) => {
|
||||
moduleDirectories: ['node_modules', 'src'],
|
||||
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json'],
|
||||
setupFiles,
|
||||
globals: { 'ts-jest': { isolatedModules: true } },
|
||||
globals: {
|
||||
'ts-jest': {
|
||||
isolatedModules: true,
|
||||
tsConfig: path.resolve(baseDir, 'tsconfig.json'),
|
||||
},
|
||||
},
|
||||
coverageReporters: ['json-summary', 'text', 'lcov'],
|
||||
collectCoverageFrom: ['src/**/*.{ts,tsx}', '!**/node_modules/**', '!**/vendor/**'],
|
||||
reporters: [
|
||||
'default',
|
||||
[
|
||||
'jest-junit',
|
||||
{
|
||||
outputDirectory: 'coverage',
|
||||
},
|
||||
],
|
||||
],
|
||||
testMatch: [
|
||||
'<rootDir>/src/**/__tests__/**/*.{js,jsx,ts,tsx}',
|
||||
'<rootDir>/src/**/*.{spec,test,jest}.{js,jsx,ts,tsx}',
|
||||
@ -80,3 +94,16 @@ export const jestConfig = (baseDir: string = process.cwd()) => {
|
||||
...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);
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user