mirror of
https://github.com/tenrok/OverlayScrollbars.git
synced 2026-06-21 14:50:37 +03:00
add coverage report to browser tests
This commit is contained in:
@@ -0,0 +1,5 @@
|
|||||||
|
const { globalSetup } = require('jest-playwright-preset');
|
||||||
|
|
||||||
|
module.exports = async (jestConfig) => {
|
||||||
|
await globalSetup(jestConfig);
|
||||||
|
};
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
const fs = require('fs');
|
||||||
|
const path = require('path');
|
||||||
|
const { execSync } = require('child_process');
|
||||||
|
const del = require('del');
|
||||||
|
const { globalTeardown } = require('jest-playwright-preset');
|
||||||
|
|
||||||
|
const coverageTempDir = './.nyc_output';
|
||||||
|
const coverageTempDirFile = 'coverage.json';
|
||||||
|
const reportDir = './.coverage/browser';
|
||||||
|
|
||||||
|
module.exports = async (jestConfig) => {
|
||||||
|
await globalTeardown(jestConfig);
|
||||||
|
|
||||||
|
const { rootDir } = jestConfig;
|
||||||
|
const coverageTempDirPath = path.resolve(rootDir, coverageTempDir);
|
||||||
|
const coverageTempFilePath = path.resolve(coverageTempDirPath, coverageTempDirFile);
|
||||||
|
const reportDirPath = path.resolve(rootDir, reportDir);
|
||||||
|
|
||||||
|
if (fs.existsSync(coverageTempFilePath)) {
|
||||||
|
const coverageReportText = ' COVERAGE ';
|
||||||
|
|
||||||
|
console.log('');
|
||||||
|
console.log(`\x1b[1m\x1b[44m${coverageReportText}\x1b[0m`);
|
||||||
|
console.log(`Reporting from: "${path.relative(rootDir, coverageTempFilePath)}" in "${path.relative(rootDir, reportDirPath)}"`);
|
||||||
|
|
||||||
|
del.sync(reportDirPath);
|
||||||
|
execSync(`npx nyc report --reporter=lcov --report-dir=${reportDir}`, {
|
||||||
|
cwd: rootDir,
|
||||||
|
});
|
||||||
|
|
||||||
|
const [deletedTempDir] = del.sync(coverageTempDirPath);
|
||||||
|
if (deletedTempDir) {
|
||||||
|
console.log('Deleted:', path.relative(rootDir, deletedTempDir));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
+9
-6
@@ -4,16 +4,17 @@ const browserRollupConfig = require('./config/jest-browser.rollup.config.js');
|
|||||||
|
|
||||||
const testServerLoaderPath = path.resolve(__dirname, './config/jest-test-server.loader.js');
|
const testServerLoaderPath = path.resolve(__dirname, './config/jest-test-server.loader.js');
|
||||||
const jsdomSetupFile = path.resolve(__dirname, './config/jest-jsdom.setup.js');
|
const jsdomSetupFile = path.resolve(__dirname, './config/jest-jsdom.setup.js');
|
||||||
|
const browserGlobalSetupPath = path.resolve(__dirname, './config/jest-browser.globalSetup.js');
|
||||||
|
const browserGlobalTeardownPath = path.resolve(__dirname, './config/jest-browser.globalTeardown.js');
|
||||||
const browserTestEnvironmentPath = path.resolve(__dirname, './config/jest-browser.env.js');
|
const browserTestEnvironmentPath = path.resolve(__dirname, './config/jest-browser.env.js');
|
||||||
const browserSetupFile = path.resolve(__dirname, './config/jest-browser.setup.js');
|
const browserSetupAfterEnvFile = path.resolve(__dirname, './config/jest-browser.setupAfterEnv.js');
|
||||||
|
|
||||||
// For a detailed explanation regarding each configuration property, visit:
|
// For a detailed explanation regarding each configuration property, visit:
|
||||||
// https://jestjs.io/docs/en/configuration.html
|
// https://jestjs.io/docs/en/configuration.html
|
||||||
|
|
||||||
const base = {
|
const base = {
|
||||||
clearMocks: true,
|
clearMocks: true,
|
||||||
collectCoverage: true,
|
coverageDirectory: './.coverage/jsdom',
|
||||||
coverageDirectory: './.coverage',
|
|
||||||
moduleDirectories: resolve.directories,
|
moduleDirectories: resolve.directories,
|
||||||
moduleFileExtensions: resolve.extensions.map((ext) => ext.replace(/\./, '')),
|
moduleFileExtensions: resolve.extensions.map((ext) => ext.replace(/\./, '')),
|
||||||
testPathIgnorePatterns: ['\\\\node_modules\\\\'],
|
testPathIgnorePatterns: ['\\\\node_modules\\\\'],
|
||||||
@@ -21,10 +22,13 @@ const base = {
|
|||||||
|
|
||||||
const browserBase = {
|
const browserBase = {
|
||||||
...base,
|
...base,
|
||||||
|
collectCoverage: false,
|
||||||
preset: 'jest-playwright-preset',
|
preset: 'jest-playwright-preset',
|
||||||
setupFilesAfterEnv: [browserSetupFile],
|
globalSetup: browserGlobalSetupPath,
|
||||||
testMatch: ['**/tests/browser/**/*.test.[jt]s?(x)'],
|
globalTeardown: browserGlobalTeardownPath,
|
||||||
testEnvironment: browserTestEnvironmentPath,
|
testEnvironment: browserTestEnvironmentPath,
|
||||||
|
setupFilesAfterEnv: [browserSetupAfterEnvFile],
|
||||||
|
testMatch: ['**/tests/browser/**/*.test.[jt]s?(x)'],
|
||||||
coveragePathIgnorePatterns: ['/node_modules/', `/${browserRollupConfig.build}/`],
|
coveragePathIgnorePatterns: ['/node_modules/', `/${browserRollupConfig.build}/`],
|
||||||
transform: {
|
transform: {
|
||||||
'^.+\\.[jt]sx?$': 'babel-jest',
|
'^.+\\.[jt]sx?$': 'babel-jest',
|
||||||
@@ -54,7 +58,6 @@ module.exports = {
|
|||||||
name: 'browser-dev',
|
name: 'browser-dev',
|
||||||
color: 'white',
|
color: 'white',
|
||||||
},
|
},
|
||||||
collectCoverage: false,
|
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -1,13 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html lang="en">
|
|
||||||
<head>
|
|
||||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
|
||||||
<title>OverlayScrollbars</title>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div id="hi">hi</div>
|
|
||||||
<script type="text/javascript" src="./dist_/overlayscrollbars.js"></script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
@@ -6,8 +6,8 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "jest --coverage --runInBand --detectOpenHandles",
|
"test": "jest --coverage --runInBand --detectOpenHandles",
|
||||||
"test:jsdom": "jest --coverage --runInBand --detectOpenHandles --selectProjects jsdom --testPathPattern",
|
"test:jsdom": "jest --coverage --runInBand --detectOpenHandles --selectProjects jsdom --testPathPattern",
|
||||||
"test:browser": "jest --coverage --runInBand --detectOpenHandles --selectProjects browser --testPathPattern",
|
"test:browser": "jest --runInBand --detectOpenHandles --selectProjects browser --testPathPattern",
|
||||||
"test:browser-dev": "jest --coverage --runInBand --detectOpenHandles --selectProjects browser-dev --testPathPattern",
|
"test:browser-dev": "jest --runInBand --detectOpenHandles --selectProjects browser-dev --testPathPattern",
|
||||||
"build": "rollup -c"
|
"build": "rollup -c"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+63
-19
@@ -1,5 +1,5 @@
|
|||||||
const { nodeResolve: rollupResolve } = require('@rollup/plugin-node-resolve');
|
const { nodeResolve: rollupResolve } = require('@rollup/plugin-node-resolve');
|
||||||
const { babel: rollupBabelPlugin } = require('@rollup/plugin-babel');
|
const { babel: rollupBabelInputPlugin, createBabelInputPluginFactory } = require('@rollup/plugin-babel');
|
||||||
const { terser: rollupTerser } = require('rollup-plugin-terser');
|
const { terser: rollupTerser } = require('rollup-plugin-terser');
|
||||||
const rollupInject = require('@rollup/plugin-inject');
|
const rollupInject = require('@rollup/plugin-inject');
|
||||||
const rollupCommonjs = require('@rollup/plugin-commonjs');
|
const rollupCommonjs = require('@rollup/plugin-commonjs');
|
||||||
@@ -25,10 +25,8 @@ const rollupConfigDefaults = {
|
|||||||
exports: 'auto',
|
exports: 'auto',
|
||||||
pipeline: ['typescript', 'resolve', 'inject', 'commonjs', 'babel'],
|
pipeline: ['typescript', 'resolve', 'inject', 'commonjs', 'babel'],
|
||||||
};
|
};
|
||||||
|
|
||||||
const legacyBabelConfig = {
|
const legacyBabelConfig = {
|
||||||
exclude: isTestEnv ? [/\/core-js\//] : [], // /\/@testing-library\//
|
exclude: isTestEnv ? [/\/core-js\//] : [], // /\/@testing-library\//
|
||||||
plugins: isTestEnv ? ['babel-plugin-istanbul'] : [],
|
|
||||||
presets: [
|
presets: [
|
||||||
[
|
[
|
||||||
'@babel/preset-env',
|
'@babel/preset-env',
|
||||||
@@ -42,7 +40,6 @@ const legacyBabelConfig = {
|
|||||||
],
|
],
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
const esmBabelConfig = {
|
const esmBabelConfig = {
|
||||||
presets: [
|
presets: [
|
||||||
[
|
[
|
||||||
@@ -58,14 +55,43 @@ const esmBabelConfig = {
|
|||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// workaround for https://github.com/rollup/plugins/issues/774
|
||||||
|
const rollupBabelIstanbulSourceMaps = {};
|
||||||
|
const rollupBabelIstanbulGenerateKey = (filename) => (filename ? filename.replace(/[\\/]+/g, '') : '');
|
||||||
|
const rollupBabelPlugin = isTestEnv
|
||||||
|
? createBabelInputPluginFactory(() => {
|
||||||
|
return {
|
||||||
|
config(cfg) {
|
||||||
|
const { options } = cfg;
|
||||||
|
const { filename, plugins } = options;
|
||||||
|
const istanbulSourceMap = rollupBabelIstanbulSourceMaps[rollupBabelIstanbulGenerateKey(filename)];
|
||||||
|
|
||||||
|
if (istanbulSourceMap) {
|
||||||
|
return {
|
||||||
|
...options,
|
||||||
|
plugins: [
|
||||||
|
...(plugins || []),
|
||||||
|
[
|
||||||
|
'babel-plugin-istanbul',
|
||||||
|
{
|
||||||
|
useInlineSourceMaps: false,
|
||||||
|
inputSourceMap: istanbulSourceMap,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
],
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return options;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
||||||
|
})
|
||||||
|
: rollupBabelInputPlugin;
|
||||||
|
|
||||||
const normalizePath = (pathName) => (pathName ? pathName.split(path.sep).join(path.posix.sep) : pathName);
|
const normalizePath = (pathName) => (pathName ? pathName.split(path.sep).join(path.posix.sep) : pathName);
|
||||||
|
|
||||||
const appendExtension = (file) => {
|
const appendExtension = (file) =>
|
||||||
if (path.extname(file) === '') {
|
path.extname(file) === '' ? file + resolve.extensions.find((ext) => fs.existsSync(path.resolve(`${file}${ext}`))) : file;
|
||||||
return file + resolve.extensions.find((ext) => fs.existsSync(path.resolve(`${file}${ext}`)));
|
|
||||||
}
|
|
||||||
return file;
|
|
||||||
};
|
|
||||||
|
|
||||||
const resolvePath = (basePath, pathToResolve, appendExt) => {
|
const resolvePath = (basePath, pathToResolve, appendExt) => {
|
||||||
const result = pathToResolve ? (path.isAbsolute(pathToResolve) ? pathToResolve : path.resolve(basePath, pathToResolve)) : null;
|
const result = pathToResolve ? (path.isAbsolute(pathToResolve) ? pathToResolve : path.resolve(basePath, pathToResolve)) : null;
|
||||||
@@ -185,14 +211,28 @@ const rollupConfig = (config = {}, { project = process.cwd(), overwrite = {}, si
|
|||||||
sourceMap: sourcemap,
|
sourceMap: sourcemap,
|
||||||
extensions: resolve.extensions,
|
extensions: resolve.extensions,
|
||||||
}),
|
}),
|
||||||
babel: rollupBabelPlugin({
|
babel: [
|
||||||
...(esm ? esmBabelConfig : legacyBabelConfig),
|
isTestEnv
|
||||||
babelHelpers: 'runtime',
|
? {
|
||||||
extensions: resolve.extensions,
|
name: 'collect-bable-plugin-istanbul-input-source-maps',
|
||||||
caller: {
|
transform(code, filename) {
|
||||||
name: 'babel-rollup-build',
|
rollupBabelIstanbulSourceMaps[rollupBabelIstanbulGenerateKey(filename)] = { ...this.getCombinedSourcemap() };
|
||||||
},
|
return {
|
||||||
}),
|
code,
|
||||||
|
map: null,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
}
|
||||||
|
: {},
|
||||||
|
rollupBabelPlugin({
|
||||||
|
...(esm ? esmBabelConfig : legacyBabelConfig),
|
||||||
|
babelHelpers: 'runtime',
|
||||||
|
extensions: resolve.extensions,
|
||||||
|
caller: {
|
||||||
|
name: 'babel-rollup-build',
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
const output = genOutputConfig(esm);
|
const output = genOutputConfig(esm);
|
||||||
@@ -222,7 +262,11 @@ const rollupConfig = (config = {}, { project = process.cwd(), overwrite = {}, si
|
|||||||
: []
|
: []
|
||||||
),
|
),
|
||||||
external: [...Object.keys(devDependencies), ...Object.keys(peerDependencies), ...((Array.isArray(external) && external) || [])],
|
external: [...Object.keys(devDependencies), ...Object.keys(peerDependencies), ...((Array.isArray(external) && external) || [])],
|
||||||
plugins: pipeline.map((item) => (typeof item === 'string' ? pipelineMap[item] : item)),
|
plugins: pipeline.reduce((arr, item) => {
|
||||||
|
const plugin = typeof item === 'string' ? pipelineMap[item] : item;
|
||||||
|
arr.push(...(Array.isArray(plugin) ? plugin : [plugin]));
|
||||||
|
return arr;
|
||||||
|
}, []),
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user