ocassio / testcafe-reporter-custom

TestCafe reporter that allows you to provide your own logic

Home Page:https://www.npmjs.com/package/testcafe-reporter-custom

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

testcafe-reporter-custom

This is the custom reporter plugin for TestCafe.

Install

npm install testcafe-reporter-custom

Usage

When you run tests from the command line, specify the reporter name by using the --reporter option:

testcafe chrome 'path/to/test/file.js' --reporter custom

When you use API, pass the reporter name to the reporter() method:

testCafe
    .createRunner()
    .src('path/to/test/file.js')
    .browsers('chrome')
    .reporter('custom') // <-
    .run();

After that you can define your custom logic in reporter/index.js file.
It can be defined as an object or factory function.

For example:

module.exports = function () {
    return {
        async reportTaskStart(/* startTime, userAgents, testCount */) {
            throw new Error('Not implemented');
        },

        async reportFixtureStart(/* name, path, meta */) {
            throw new Error('Not implemented');
        },

        async reportTestStart(/* name, meta */) {
            // NOTE: This method is optional.
        },

        async reportTestDone(/* name, testRunInfo, meta */) {
            throw new Error('Not implemented');
        },

        async reportTaskDone(/* endTime, passed, warnings, result */) {
            throw new Error('Not implemented');
        }
    };
}

API is completely the same as for regular reporter.

Configuration

Reporter can be configured using reporter.config.js file, which should be placed in a project root folder.

module.exports = {
    path: 'reporter/main.js'
};

Possible options are presented in the table below.

Option Default Value Description
path 'reporter/index.js' Path to your reporter.
moduleType 'commonjs' Whether your reporter uses CommonJS or ES Modules. Possible values are commonjs and module.
tsNodePath 'node_modules/ts-node' Path to your ts-node installation (only used for *.ts files).
tsOptions undefined ts-node options (only used for *.ts files).

TypeScript Usage

In order to use TypeScript with this reporter, at least ts-node and typescript packages should be installed.

npm install --save-dev ts-node typescript

After that you need to create reporter.config.ts file and specify path to your reporter.

module.exports = {
    path: 'reporter/index.ts'
};

As testcafe-reporter-custom use ts-node in order to execute TypeScript files, all it's rules are applied.

If you want to provide additional ts-node options, you can use tsOptions in the reporter configuration file.
For example, you can specify custom tsconfig file using the following configuration:

module.exports = {
    path: 'reporter/index.ts',
    tsOptions: {
        project: 'tsconfig.reporter.json'
    }
};

Usage Examples

There is a couple of usage examples available in this repository:

About

TestCafe reporter that allows you to provide your own logic

https://www.npmjs.com/package/testcafe-reporter-custom

License:MIT License


Languages

Language:JavaScript 100.0%