Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Error: TypeError: Cannot read property 'println' of undefined" when adding 'new ConsoleReporter() in config #413

Closed
testifyqa opened this issue Jan 25, 2020 · 1 comment
Labels
enhancement

Comments

@testifyqa
Copy link
Contributor

@testifyqa testifyqa commented Jan 25, 2020

When I try to run npm test with new ConsoleReporter() in my serenity config block, I get the error "Error: TypeError: Cannot read property 'println' of undefined"

If I remove it, I do not.

I am aware that if I instead call a function of ConsoleReporter like ConsoleReporter.forDarkTerminals() then I do not get the error.

Bit confused though as according to comments on #350 , you should be able to just do new ConsoleReporter() ??

my protractor.conf.js file looks like below...

const
    { Photographer, TakePhotosOfFailures } = require('@serenity-js/protractor'),
    { SerenityBDDReporter } = require('@serenity-js/serenity-bdd'),
    { ConsoleReporter } = require('@serenity-js/console-reporter');

exports.config = { 
    directConnect: true,
    allScriptsTimeout: 120000,
    capabilities: {
        browserName: 'chrome'
    },
    specs: ['./features/*.feature'],
    framework: 'custom',
    frameworkPath: require.resolve('@serenity-js/protractor/adapter'), 
    onPrepare: () => {
        require('ts-node').register({ 
            project: './tsconfig.json'
        });
    },
    serenity: {
        runner: 'cucumber',
        crew: [
            Photographer.whoWill(TakePhotosOfFailures),
            new SerenityBDDReporter(),
            new ConsoleReporter() // removing this line gets rid of error
        ]
    },
    cucumberOpts: {
        require: ['./features/**/*.ts'],
        compiler: 'ts:ts-node/register'
    },
};

Error in console is below...

[18:40:03] E/launcher - Error: TypeError: Cannot read property 'println' of undefined
    at MatchesObjectsWithCommonPrototype.transformation (/Users/t.knee/Documents/DevProjects/JavascriptProjects/TestifyQA/serenity-js-framework/node_modules/@serenity-js/console-reporter/src/stage/crew/console-reporter/ConsoleReporter.ts:193:30)
    at MatchesObjectsWithCommonPrototype.MatcherRule.execute (/Users/t.knee/Documents/DevProjects/JavascriptProjects/TestifyQA/serenity-js-framework/node_modules/tiny-types/src/pattern-matching/rules/MatcherRule.ts:13:21)
    at ObjectMatcher.PatternMatcher.else (/Users/t.knee/Documents/DevProjects/JavascriptProjects/TestifyQA/serenity-js-framework/node_modules/tiny-types/src/pattern-matching/PatternMatcher.ts:17:71)
    at ConsoleReporter.notifyOf (/Users/t.knee/Documents/DevProjects/JavascriptProjects/TestifyQA/serenity-js-framework/node_modules/@serenity-js/console-reporter/src/stage/crew/console-reporter/ConsoleReporter.ts:325:18)
    at /Users/t.knee/Documents/DevProjects/JavascriptProjects/TestifyQA/serenity-js-framework/node_modules/@serenity-js/core/src/stage/StageManager.ts:33:59
    at Array.forEach (<anonymous>)
    at StageManager.notifyOf (/Users/t.knee/Documents/DevProjects/JavascriptProjects/TestifyQA/serenity-js-framework/node_modules/@serenity-js/core/src/stage/StageManager.ts:33:26)
    at Stage.announce (/Users/t.knee/Documents/DevProjects/JavascriptProjects/TestifyQA/serenity-js-framework/node_modules/@serenity-js/core/src/stage/Stage.ts:111:22)
    at Serenity.announce (/Users/t.knee/Documents/DevProjects/JavascriptProjects/TestifyQA/serenity-js-framework/node_modules/@serenity-js/core/src/Serenity.ts:30:20)
    at /Users/t.knee/Documents/DevProjects/JavascriptProjects/TestifyQA/serenity-js-framework/node_modules/@serenity-js/cucumber/src/notifier/Notifier.ts:138:47
    at Array.forEach (<anonymous>)
    at Notifier.emit (/Users/t.knee/Documents/DevProjects/JavascriptProjects/TestifyQA/serenity-js-framework/node_modules/@serenity-js/cucumber/src/notifier/Notifier.ts:138:16)
    at Notifier.scenarioStarts (/Users/t.knee/Documents/DevProjects/JavascriptProjects/TestifyQA/serenity-js-framework/node_modules/@serenity-js/cucumber/src/notifier/Notifier.ts:55:18)
    at EventEmitter.<anonymous> (/Users/t.knee/Documents/DevProjects/JavascriptProjects/TestifyQA/serenity-js-framework/node_modules/@serenity-js/cucumber/src/listeners/CucumberEventProtocolAdapter.ts:110:26)
    at EventEmitter.emit (events.js:215:7)
[18:40:03] E/launcher - Process exited with error code 100
npm ERR! Test failed.  See above for more details.
➜  serenity-js-framework git:(develop/help-jan-find-bugs) ✗ 

Thanks

@jan-molak
Copy link
Member

@jan-molak jan-molak commented Jan 25, 2020

Hi @testifyqa!

The ConsoleReporter has gone through several implementations since its original inception, so the different tickets are referring to two different versions.

Originally, the ConsoleReporter did not support colour output and did not have any dependencies. That's why it could be called as per the older ticket - new ConsoleReporter().

However, now that the class supports colour output, it also requires other classes that have now taken over the responsibility for the printing.

Those classes such as the Printer and TerminalTheme are instantiated for you when you call the factory methods like ConsoleReporter.withDefaultColourSupport(), ConsoleReporter.forDarkTerminals() and so on.

When the ConsoleReporter constructor is used directly, however, the developer is expected to provide those dependencies themselves.

Having said that, it might be good to add a check in the constructor to avoid those "null pointer errors" at runtime.

Good catch!

@jan-molak jan-molak added the enhancement label Jan 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement
Projects
None yet
Development

No branches or pull requests

2 participants