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

console log not working #2630

Closed
madroneropaulo opened this issue Mar 28, 2017 · 6 comments
Closed

console log not working #2630

madroneropaulo opened this issue Mar 28, 2017 · 6 comments

Comments

@madroneropaulo
Copy link

madroneropaulo commented Mar 28, 2017

Expected behaviour

I expect to be able to console.log() on any spec.

Actual behaviour

Logs are printed only within the "describe" scope, but not within blocks beforeEach, it, etc.
Instead, a TypeError is returned "undefined is not a constructor (evaluating 'console.log()'...)"

describe('Some spec', function() {
    console.log('it works!') // is logged
    it('Should do something',  function () {
        console.log('it does NOT work') // Type error. No logs. Spec is stopped (error thrown)
    })
})

Environment Details

  • Karma version (output of karma --version): 1.5.0
  • Relevant part of your karma.config.js file
{
        basePath: '',

        frameworks: ['jasmine'],

        exclude: [],

        files: ['test_files.js'],

        preprocessors: {
            './test_files.js': ['webpack']
        },

        reporters: ['spec', 'junit'],

        junitReporter: {
            outputDir: './results'
        },

        browserConsoleLogOptions: {
            level: 'log',
            format: '%b %T: %m',
            terminal: true
        },

        webpack: require('./webpack_config.js'),

        specReporter: {
            suppressPassed: true,  // do not print information about passed tests
            suppressSkipped: false,  // do not print information about skipped tests
        },

        port: 9876,

        colors: true,

        browsers: ['PhantomJS'],

        plugins: [
            require('karma-jasmine'),
            require('karma-webpack'),
            require('karma-junit-reporter'),
            require('karma-spec-reporter'),
            require('karma-sourcemap-loader'),
            require('karma-chrome-launcher'),
            require('karma-phantomjs-launcher')
        ]
    }
  • related used packages
    "karma-chrome-launcher": "2.0.0",
    "karma-firefox-launcher": "1.0.1",
    "karma-jasmine": "1.1.0",
    "karma-jenkins-reporter": "0.0.2",
    "karma-junit-reporter": "1.2.0",
    "karma-phantomjs-launcher": "1.0.2",
    "karma-script-launcher": "1.0.0",
    "karma-sourcemap-loader": "0.3.7",
    "karma-spec-reporter": "0.0.30",
    "karma-webpack": "2.0.2",

Steps to reproduce the behaviour

  1. Write some console.logs all over your specs (within describe blocks, it blocks, beforeEach, etc)
  2. Run karma server
  3. look into console
@maksimr
Copy link
Contributor

maksimr commented Mar 28, 2017

@madroneropaulo this

console.log('it doesn't work :( ')

is invalid javascript.

Try this in your test:

console.log('foo');

@madroneropaulo
Copy link
Author

madroneropaulo commented Mar 28, 2017

@maksimr Ok that was a random text comment, I have valid text on my specs. Please reopen. I updated the issue. I don't want to create a new one.

@maksimr
Copy link
Contributor

maksimr commented Mar 28, 2017

@madroneropaulo can you create a stub project which reproduces this error?
Because I see nothing strange in your config.

Thanks

@wbruno
Copy link

wbruno commented Mar 29, 2017

@madroneropaulo see #2582

@leegee
Copy link

leegee commented Jun 27, 2017

Looks like you are missing two things in your config: client.captureConsole = true and logLevel: config.LOG_LOG,. As @wbruno says, take a look at #2582 very carefully.

@EzraBrooks
Copy link
Collaborator

@wbruno and @leegee are correct, your issue should be solved by implementing the config changes described in the last comment on #2582.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants