2

I have simple test to test mochawesome-report when I run it in terminal I have "undefined" multiple times during tests. How to remove it?

undefined

  Sample test
    √ Passed
    1) Failing
undefined
undefined
  1 passing (4s)
  1 failing
undefined
  1) Sample test
       Failing:

My tests:

context('Sample test', () => {
    it('Passed', () => {
        cy.document().title().should('not.contain', 'unicorns')
    })
    it('Failing', () => {
        cy.document().title().should('contain', 'unicorns')
    })
  })

and

context('Second sample test', () => {
    it('A passing test', () => {
        cy.document().title().should('not.contain', 'unicorns')
    })
  })
  • Are U sure your code not log something into console.log ??? – SkorpEN Jan 29 at 13:56
1

I tried to pin down the source of "undefined" on both your example and my own tests.

After playing around with it for a while, "undefined" seems to be coming from Cypress, not Mocha reporter since I've tried running the tests without it and "undefined" is still in console.

So, my config was just sth. like:

{
    "projectId": "<my_project_id>",
    "baseUrl": "<url>", 
    "integrationFolder": "cypress/integration/",
    "testFiles": "test*.js"
}

I ran the tests with a command like this: .\node_modules\.bin\cypress run --config-file test.json

The tests were as simple as:

describe('Sample test', function() {
    it('Passed', function() {
        cy.visit('/');      
    });
});

And the output in console was the following one:

====================================================================================================

  (Run Starting)

  ┌────────────────────────────────────────────────────────────────────────────────────────────────┐
  │ Cypress:    3.8.3                                                                              │
  │ Browser:    Electron 78 (headless)                                                             │
  │ Specs:      1 found (accessSitesForRegisteredUserOnly.js)                                      │
  └────────────────────────────────────────────────────────────────────────────────────────────────┘


────────────────────────────────────────────────────────────────────────────────────────────────────

  Running:  accessSitesForRegisteredUserOnly.js                                             (1 of 1)
undefined
...
...
(and more undefined later on)

If I run the same tests in the Cypress Test Runner, there's no problem with the tests and no "undefined" anywhere.

I've tried all this on Windows 10 with Cypress 3.8.3.

You can also have a look on Cypress open issues on Github and if you can't find an answer there, you might choose to fill in a new issue, it might be a bug.

EDIT:

A bit more information. The problem will be platform specific, most likely related to Windows console and some e.g. colors. If I run the same examples on a Linux system, there are no "undefined" in console:

$ ./node_modules/.bin/cypress run --config-file test.json
====================================================================================================

  (Run Starting)

  ┌────────────────────────────────────────────────────────────────────────────────────────────────┐
  │ Cypress:    3.8.2                                                                              │
  │ Browser:    Electron 78 (headless)                                                             │
  │ Specs:      1 found (test.js)                                                                  │
  └────────────────────────────────────────────────────────────────────────────────────────────────┘


────────────────────────────────────────────────────────────────────────────────────────────────────

  Running:  test.js                                                                         (1 of 1)


  Sample test
    ✓ Passed (7690ms)


  1 passing (8s)


  (Results)

  ┌────────────────────────────────────────────────────────────────────────────────────────────────┐
  │ Tests:        1                                                                                │
  │ Passing:      1                                                                                │
  │ Failing:      0                                                                                │
  │ Pending:      0                                                                                │
  │ Skipped:      0                                                                                │
  │ Screenshots:  0                                                                                │
  │ Video:        true                                                                             │
  │ Duration:     7 seconds                                                                        │
  │ Spec Ran:     test.js                                                                          │
  └────────────────────────────────────────────────────────────────────────────────────────────────┘


  (Video)

  -  Started processing:  Compressing to 32 CRF                                                     
  -  Finished processing: /home/pavel/testing/alpine/AlpinePro.Tests.Cypress/cypress/     (1 second)
                          videos/test.js.mp4                                                        


====================================================================================================

  (Run Finished)


       Spec                                              Tests  Passing  Failing  Pending  Skipped  
  ┌────────────────────────────────────────────────────────────────────────────────────────────────┐
  │ ✔  test.js                                  00:07        1        1        -        -        - │
  └────────────────────────────────────────────────────────────────────────────────────────────────┘
    ✔  All specs passed!                        00:07        1        1        -        -        -  

Ran the tests even with Mocha:

{
    "projectId": "",
    "baseUrl": "<url>",
    "screenshotsFolder": "cypress/results/screenshots",
    "videosFolder": "cypress/results/videos",
    "viewportHeight": 1080,
    "viewportWidth": 1920,
    "video": true,
    "fixturesFolder": "cypress/fixtures_dev",
    "reporter": "cypress-multi-reporters",
    "reporterOptions": {
        "configFile": "reporterOptions.json"
    },
    "integrationFolder": "cypress/integration",
    "testFiles": "test*.js"
}

The (highly subjective) takeaways are clear: use a proper operating system :)

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.