feat(karma-junit-reporter): type definition for JUnit reporter (#42334)

- new type definition covering v2 of `karma-junit-reporter`
- tests based on documented api

Thanks!
This commit is contained in:
Piotr Błażejewicz (Peter Blazejewicz) 2020-02-14 02:30:39 +01:00 committed by GitHub
parent fe9175e589
commit bfe90392a0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 94 additions and 0 deletions

34
types/karma-junit-reporter/index.d.ts vendored Normal file
View File

@ -0,0 +1,34 @@
// Type definitions for karma-junit-reporter 2.0
// Project: https://github.com/karma-runner/karma-junit-reporter#readme
// Definitions by: Piotr Błażejewicz (Peter Blazejewicz) <https://github.com/peterblazejewicz>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 3.2
import 'karma';
declare module 'karma' {
interface ConfigOptions {
junitReporter?: JUnitReporterConfiguration;
}
interface JUnitReporterConfiguration {
/** results will be saved as $outputDir/$browserName.xml */
outputDir?: string;
/** if included, results will be saved as $outputDir/$browserName/$outputFile */
outputFile?: string;
/** suite will become the package name attribute in xml testsuite element */
suite?: string;
/** add browser name to report and classes names */
useBrowserName?: boolean;
/** function (browser, result) to customize the name attribute in xml testcase element */
nameFormatter?: (browser: any, result: any) => string;
/** function (browser, result) to customize the classname attribute in xml testcase element */
classNameFormatter?: (browser: any, result: any) => string;
/** key value pair of properties to add to the <properties> section of the report */
properties?: {
[key: string]: any;
};
/** use '1' if reporting to be per SonarQube 6.2 XML format */
xmlVersion?: number | null;
}
}

View File

@ -0,0 +1,36 @@
import karma = require('karma');
// See https://github.com/karma-runner/karma-coverage/blob/v1.1.2/README.md#basic
module.exports = (config: karma.Config) => {
config.set({
files: ['src/**/*.js', 'test/**/*.js'],
// coverage reporter generates the coverage
reporters: ['progress', 'coverage', 'junit'],
preprocessors: {
// source files, that you wanna generate coverage for
// do not include tests or libraries
// (these files will be instrumented by Istanbul)
'src/**/*.js': ['coverage'],
},
// the default configuration
junitReporter: {
outputDir: 'junit',
outputFile: 'test-resutls.xml',
suite: 'tests',
useBrowserName: true,
nameFormatter: (browser, result) => {
return browser.id + '-browser';
},
classNameFormatter: (browser, result) => {
return browser.name + '-class';
},
properties: {
isValid: true,
},
xmlVersion: 1,
},
});
};

View File

@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"karma-junit-reporter-tests.ts"
]
}

View File

@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }