From cc09dc7d9bcc5ac0b1c6fa76cb57d12009c813b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20B=C5=82a=C5=BCejewicz=20=28Peter=20Blazejewicz=29?= Date: Mon, 2 Mar 2020 19:50:51 +0100 Subject: [PATCH] feat(karma-json-to-file-reporter): add type definition (#42735) - type definitions - tests https://www.npmjs.com/package/karma-json-to-file-reporter#config Thanks! --- types/karma-json-to-file-reporter/index.d.ts | 42 +++++++++++++++++++ .../karma-json-to-file-reporter-tests.ts | 16 +++++++ .../karma-json-to-file-reporter/tsconfig.json | 23 ++++++++++ types/karma-json-to-file-reporter/tslint.json | 1 + 4 files changed, 82 insertions(+) create mode 100644 types/karma-json-to-file-reporter/index.d.ts create mode 100644 types/karma-json-to-file-reporter/karma-json-to-file-reporter-tests.ts create mode 100644 types/karma-json-to-file-reporter/tsconfig.json create mode 100644 types/karma-json-to-file-reporter/tslint.json diff --git a/types/karma-json-to-file-reporter/index.d.ts b/types/karma-json-to-file-reporter/index.d.ts new file mode 100644 index 0000000000..16aeb25082 --- /dev/null +++ b/types/karma-json-to-file-reporter/index.d.ts @@ -0,0 +1,42 @@ +// Type definitions for karma-json-to-file-reporter 1.0 +// Project: https://github.com/HarryBurns/karma-json-to-file-reporter#readme +// Definitions by: Piotr Błażejewicz (Peter Blazejewicz) +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 3.2 + +import 'karma'; + +declare module 'karma' { + interface ConfigOptions { + /** + * see {@link https://www.npmjs.com/package/karma-json-to-file-reporter#config} + */ + jsonToFileReporter?: JsonToFileReporterOptions; + } + + /** + * JSON messages logged via console.log(_) will be filtered + * and saved to local json file you specified in config. + */ + interface JsonToFileReporterOptions { + /** Path for your json output file. By default it will save your files in the root of your project. */ + outputPath?: string; + /** + * File name pattern. You can use wildcards: + * `*timestamp*` - for current karma run timestamp. + * `*index*` - for log entry index: 1, 2, 3, etc. + * @default 'logFile_start-timestamp.json' + */ + fileName?: string; + /** + * Set it true to overwrite files if it already exists. If false, log entries will be added to the end + */ + overwrite?: boolean; + /** + * Filter for json objects. This option can be: + * - string - filter JSONs by field on the root level + * - predicate function + */ + filter?: string | ((obj: object) => boolean); + } +} diff --git a/types/karma-json-to-file-reporter/karma-json-to-file-reporter-tests.ts b/types/karma-json-to-file-reporter/karma-json-to-file-reporter-tests.ts new file mode 100644 index 0000000000..654dfda5fd --- /dev/null +++ b/types/karma-json-to-file-reporter/karma-json-to-file-reporter-tests.ts @@ -0,0 +1,16 @@ +import karma = require('karma'); + +// Mocha reporter options tests +const mochaReporter: karma.JsonToFileReporterOptions = { + outputPath: 'tests/out/', +}; + +module.exports = (config: karma.Config) => { + config.set({ + jsonToFileReporter: { + outputPath: 'tests/out/', + }, + plugins: ['karma-json-to-file-reporter'], + reporters: ['json-to-file'], + }); +}; diff --git a/types/karma-json-to-file-reporter/tsconfig.json b/types/karma-json-to-file-reporter/tsconfig.json new file mode 100644 index 0000000000..4b8742ff83 --- /dev/null +++ b/types/karma-json-to-file-reporter/tsconfig.json @@ -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-json-to-file-reporter-tests.ts" + ] +} diff --git a/types/karma-json-to-file-reporter/tslint.json b/types/karma-json-to-file-reporter/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/karma-json-to-file-reporter/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }