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

Not compatible with @cypress/code-coverage #198

Closed
amitguptagwl opened this issue Aug 4, 2019 · 8 comments
Closed

Not compatible with @cypress/code-coverage #198

amitguptagwl opened this issue Aug 4, 2019 · 8 comments

Comments

@amitguptagwl
Copy link

When I add following in cypress/plugins/index.js

module.exports = (on, config) => {
  on('task', require('@cypress/code-coverage/task'))
}

It gives compilation error "ParseError: Unexpected token"

@jcundill
Copy link
Contributor

jcundill commented Aug 9, 2019

I can't reproduce this, it works for me

Screenshot 2019-08-09 at 23 59 01

Maybe you need to add to support as well as plugins see

@jcundill
Copy link
Contributor

jcundill commented Aug 9, 2019

closing for now - please add more details, steps to reproduce, and reopen if appropriate

@jcundill jcundill closed this as completed Aug 9, 2019
@ghost
Copy link

ghost commented Jan 21, 2020

I'm running in to similar issues, a bit more context here:

Oops...we found an error preparing this test file:

  /home/rohdef/git/project/cypress/integration/acceptance-tests/my.feature

The error was:


/home/rohdef/git/project/cypress/integration/acceptance-tests/my.feature:1
#language: da
^
ParseError: Unexpected token

This occurred while Cypress was compiling and bundling your test code. This is usually caused by:

- A missing file or dependency
- A syntax error in the file or one of its dependencies

Fix the error in your code and re-run your tests.

  (Results)

  ┌────────────────────────────────────────────────────────────────────────────────────────────────┐
  │ Tests:        0                                                                                │
  │ Passing:      0                                                                                │
  │ Failing:      1                                                                                │
  │ Pending:      0                                                                                │
  │ Skipped:      0                                                                                │
  │ Screenshots:  0                                                                                │
  │ Video:        false                                                                            │
  │ Duration:     0 seconds                                                                        │
  │ Spec Ran:     acceptance-tests/my.feature                                    │
  └────────────────────────────────────────────────────────────────────────────────────────────────┘

@jcundill seems that I cannot reopen :)

@ghost
Copy link

ghost commented Jan 21, 2020

Seems that it also happens if I create a simple feature in English:

/home/rohdef/git/project/cypress/integration/acceptance-tests/my.feature:1
Feature: As somebody I can do stuff
            ^
ParseError: Unexpected token

This occurred while Cypress was compiling and bundling your test code. This is usually caused by:

- A missing file or dependency
- A syntax error in the file or one of its dependencies

Looks like it's somehow meddling with the parser

@ghost
Copy link

ghost commented Jan 21, 2020

    "cypress-cucumber-preprocessor": {
        "nonGlobalStepDefinitions": true,
        "stepDefinitions": "cypress/integration",
        "cucumberJson": {
            "generate": true,
            "outputFolder": "dist/cypress/cucumber-json",
            "filePrefix": "",
            "fileSuffix": ".cucumber"
        }
    },
    "devDependencies": {
        "cypress": "^3.8.2",
        "cypress-cucumber-preprocessor": "^2.0.1",
    }

the cypress and cypress-cucumber parts of my config (btw. as a side note, is there a way to get the cypress-cucumber-preprocessor config out of package.json?)

@ghost
Copy link

ghost commented Jan 21, 2020

Aaaaaand, I need to find something solid to bang my head against :p Read and followed these instructions without thinking: https://docs.cypress.io/guides/tooling/code-coverage.html#Install-the-plugin so I ended up with:

const cucumber = require('cypress-cucumber-preprocessor').default

module.exports = (on, config) => {
    on('file:preprocessor', cucumber())
}

module.exports = (on, config) => {
    on('task', require('@cypress/code-coverage/task'))
}

instead of something sensible like:

const cucumber = require('cypress-cucumber-preprocessor').default
const coverage = require('@cypress/code-coverage/task')

module.exports = (on, config) => {
    on('file:preprocessor', cucumber())
    on('task', coverage())
}

in my support/index.js. Sorry for the noise.

@liebsterkamerad
Copy link

liebsterkamerad commented Jul 24, 2020

Aaaaaand, I need to find something solid to bang my head against :p Read and followed these instructions without thinking: https://docs.cypress.io/guides/tooling/code-coverage.html#Install-the-plugin so I ended up with:

const cucumber = require('cypress-cucumber-preprocessor').default

module.exports = (on, config) => {
    on('file:preprocessor', cucumber())
}

module.exports = (on, config) => {
    on('task', require('@cypress/code-coverage/task'))
}

instead of something sensible like:

const cucumber = require('cypress-cucumber-preprocessor').default
const coverage = require('@cypress/code-coverage/task')

module.exports = (on, config) => {
    on('file:preprocessor', cucumber())
    on('task', coverage())
}

in my support/index.js. Sorry for the noise.

Nothing to sorry about, I've just run into the same problem and your answer was the only one on the whole internet that helped me to solve this damn problem. I've ended up with the following plugins/index.js and it finally worked:

const cucumber = require('cypress-cucumber-preprocessor').default

// todo check for cucumber problem
module.exports = (on, config) => {
  require('@cypress/code-coverage/task')(on, config)
  on('file:preprocessor', cucumber())
  // include any other plugin code...

  // It's IMPORTANT to return the config object
  // with any changed environment variables
  return config
}

I need to learn Javascript better :/

@edimitchel
Copy link

I've tried with require('cypress-react-unit-test/plugins/load-webpack')(on, config); and it's doesn't work with.
Yes this import is for Unit Testing but it do all the work for adding code coverage that we need.

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

No branches or pull requests

4 participants