question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cypress 3.3.1 does not load plugins/index.js on Linux

See original GitHub issue

Current behavior:

I tried adding the cypress-cucumber-preprocessor plugin so I can use feature files. Cypress loads the preprocessor on Windows but not if I run the same config on Linux.

I have a cypress/plugins/index.js file that is not loaded. On Windows 10, my .feature file is run successfully. On Linux (Ubuntu 19.04) I see:

Module parse failed: Unexpected token (1:12)
You may need an appropriate loader to handle this file type.
> Feature: It runs
| 
|   I want to see the startup page

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

  cypress/integration/smoke.feature

The error was:

./cypress/integration/smoke.feature 1:12
Module parse failed: Unexpected token (1:12)
You may need an appropriate loader to handle this file type.
> Feature: It runs
| 
|   I want to see the startup page

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.

If I run with DEBUG=cypress:* then on Windows I see a log statement I put in my cypress/plugins/index.js in the log:

const cucumber = require('cypress-cucumber-preprocessor').default
module.exports = (on, config) => {
  console.log('CUCUMBER', config);
  on('file:preprocessor', cucumber());
}

Note the lines following CUCUMBER { animationDistanceThreshold: 5, below.

2019-06-25T09:38:26.607Z cypress:server:plugins:child require pluginsFile
2019-06-25T09:38:28.534Z cypress:server:plugins:child run plugins function
2019-06-25T09:38:28.534Z cypress:server:plugins:child register event _get:task:body with id 0
2019-06-25T09:38:28.534Z cypress:server:plugins:child register event _get:task:keys with id 1
CUCUMBER { animationDistanceThreshold: 5,
  fileServerFolder: 'C:\\Users\\user\\project',
  baseUrl: null,
  fixturesFolder: 'C:\\Users\\user\\project\\cypress\\fixtures',
  chromeWebSecurity: false,
  modifyObstructiveCode: false,
  integrationFolder: 'C:\\Users\\user\\project\\cypress\\integration',
  env: 
   { http_proxy: '<my proxy>',
     https_proxy: '<my proxy>',
     no_proxy: 'localhost' },
  pluginsFile: 'C:\\Users\\user\\project\\cypress\\plugins\\index.js',
  hosts: null,
  screenshotsFolder: 'C:\\Users\\user\\project\\cypress\\screenshots',
  numTestsKeptInMemory: 0,
  supportFile: 'C:\\Users\\user\\project\\cypress\\support\\index.js',
  port: null,
  supportFolder: 'C:\\Users\\user\\project\\cypress\\support',
  reporter: 'spec',
  videosFolder: 'C:\\Users\\user\\project\\cypress\\videos',
  reporterOptions: null,
  testFiles: '**/*.*',
  defaultCommandTimeout: 4000,
  trashAssetsBeforeRuns: true,
  execTimeout: 60000,
  blacklistHosts: null,
  pageLoadTimeout: 60000,
  userAgent: null,
  requestTimeout: 5000,
  viewportWidth: 1000,
  responseTimeout: 30000,
  viewportHeight: 800,
  taskTimeout: 60000,
  video: true,
  videoCompression: 32,
  videoUploadOnPasses: true,
  watchForFileChanges: false,
  waitForAnimations: true }
2019-06-25T09:38:28.546Z cypress:server:plugins:child register event file:preprocessor with id 2
2019-06-25T09:38:28.552Z cypress:server:plugins register plugins process event _get:task:body with id 0
2019-06-25T09:38:28.552Z cypress:server:plugins register event '_get:task:body'
2019-06-25T09:38:28.552Z cypress:server:plugins register plugins process event _get:task:keys with id 1
2019-06-25T09:38:28.552Z cypress:server:plugins register event '_get:task:keys'

The log from Linux does not show the console.log being run:

2019-06-24T16:34:28.959Z cypress:server:plugins:child require pluginsFile
2019-06-24T16:34:29.609Z cypress:webpack user options: { webpackOptions: { resolve: { extensions: [Array] }, module: { rules: [Array] } } }
2019-06-24T16:34:29.613Z cypress:server:plugins:child run plugins function
2019-06-24T16:34:29.613Z cypress:server:plugins:child register event _get:task:body with id 0
2019-06-24T16:34:29.614Z cypress:server:plugins:child register event _get:task:keys with id 1
2019-06-24T16:34:29.614Z cypress:server:plugins:child register event file:preprocessor with id 2
2019-06-24T16:34:29.618Z cypress:server:plugins register plugins process event _get:task:body with id 0
2019-06-24T16:34:29.618Z cypress:server:plugins register event '_get:task:body'
2019-06-24T16:34:29.619Z cypress:server:plugins register plugins process event _get:task:keys with id 1
2019-06-24T16:34:29.619Z cypress:server:plugins register event '_get:task:keys'

Desired behavior:

It should preprocess .feature files on Windows and Linux.

Steps to reproduce: (app code and test code)

Add "cypress-cucumber-preprocessor": "^1.12.0" to your package.json file and run npm install

Add the following to cypress/plugins/index.js:

const cucumber = require('cypress-cucumber-preprocessor').default
module.exports = (on, config) => {
  console.log('CUCUMBER', config);
  on('file:preprocessor', cucumber());
}

Create a file cypress/integration/test.feature file with these contents: Note the console.log.

Feature: It runs

  I want to see the startup page

  @smoke
  Scenario: Open the app
    Given I open the app
    Then I see something

Create a file cypress/integration/test/test.js with these contents:

import { Given } from "cypress-cucumber-preprocessor/steps";
import { Then } from 'cypress-cucumber-preprocessor/steps';

const url = 'http://localhost:4200';
Given('I open the app', () => {
  cy.visit(url)
})

Then(`I see something`, () => {
  cy.title().should('exist')
})

Versions

Cypress 3.3.1 and 3.1.0 cypress-cucumber-preprocessor 1.12.0 Windows 10 and Ubuntu 19.04 Electron (whatever version is installed by cypress)

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
malixsyscommented, Nov 16, 2019

@edoloughlin : Stupid question but, is your pluginsFile set to false?

0reactions
jennifer-shehanecommented, Jan 20, 2021

Right now there doesn’t seem to be enough information to reproduce the problem on our end. We’ll have to close this issue until we can reproduce it. This does not mean that your issue is not happening - it just means that we do not have a path to move forward.

Please comment in this issue with a reproducible example and we will consider reopening the issue. Here are some tips for providing a Short, Self Contained, Correct, Example and our own Troubleshooting Cypress guide.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshooting | Cypress Documentation
Open Cypress via cypress open · Go to Developer Tools -> View App Data · This will take you to the directory in...
Read more >
cypress-io/cypress - Gitter
Hello everyone, I was wondering if anyone has any issues relating to "Unexpected token < in JSON at position 0 at JSON.parse" errors...
Read more >
cypress-terminal-report - npm
Using cypress-fail-fast and logging to files does not work out of the box. ... Register the output plugin in cypress/plugins/index.js.
Read more >
Installing Cypress - w3resource
In this tutorial we will show you how to install Cypress via npm, yarn. We will also show you how to install Cypress...
Read more >
cypress/code-coverage v3.10.0 - npm.io
npm install -D @cypress/code-coverage ... Register tasks in your cypress/plugins/index.js file ... This plugin DOES NOT instrument your code.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found