@netatwork/mocha-utils
Version:
Utility package for mocha based test setup
29 lines (24 loc) • 1.1 kB
text/typescript
import { FilePattern, ConfigOptions } from 'karma';
class KarmaMochaHtmlReporter {
public static readonly $inject = ['baseReporterDecorator', 'config', 'logger', 'helper', 'formatError'] as const;
public constructor(
// eslint-disable-next-line @typescript-eslint/ban-types
decorator: Function,
config: ConfigOptions,
) {
const MOCHA_CORE_PATTERN = /([\\/]karma-mocha[\\/])/i;
const createPattern: (pattern: string) => FilePattern = (pattern: string) => ({ pattern, included: true, served: true, watched: false });
decorator(this);
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const files = config.files!;
let index = Math.max(
files.findIndex((file) => MOCHA_CORE_PATTERN.test((file as FilePattern).pattern)),
0
);
files.splice(++index, 0, createPattern(__dirname + '/style.css'));
files.splice(++index, 0, createPattern(__dirname + '/reporter.js'));
}
}
module.exports = {
'reporter:kmhtml': ['type', KarmaMochaHtmlReporter]
};