Skip to content
This repository has been archived by the owner on Jan 31, 2023. It is now read-only.

TypeScript handling assumes all transforms are specified as arrays #56

Labels

Comments

@bauglir
Copy link
Contributor

bauglir commented Jul 9, 2020

  • Operating System: macOS v10.15.5
  • Cypress Version: v4.10.0
  • Browser Version: Electron 80/Chrome 83

Is this a Feature or Bug?

This is a bug.

Current behavior:

When trying to use https://github.com/TheBrainFamily/cypress-cucumber-preprocessor combined with the out-of-the-box TypeScript support, running any type of test results in TypeError: undefined is not a function.

I have tracked this down to be caused by the way the TypeScript transform is added to the transforms that are already present (i.e. this code and specifically lines 120 and 139).

I don't think this bug is specific to the Cucumber preprocessor.

I'm not that familiar with Browserify, but according to its documentation transform can be "an array of transform functions or modules names which will transform the source code before the parsing". The mentioned lines, incorrectly, assume the transform property is always an array of arrays where the first entry in each array is a string specifying the path to a transform. This causes either the destructuring to fail or causes includes being called on undefined, I haven't dug that deep.

Adjusting the offending lines to something along the lines of

const hasTsifyTransform = transform.some(
  (subTransform) => Array.isArray(subTransform) && subTransform[0].includes('tsify')
);

and

browserifyOptions.transform = transform.filter(
  (subTransform) => !Array.isArray(subTransform) || !subTransform[0].includes('babelify')
);

respectively results in the desired behavior. A quick test using a default value for the destructuring (i.e. ([name = ''])) does not appear to solve the issue.

Desired behavior:

Transforms defined directly as functions should work.

How to reproduce:

In a basic Cypress setup:

  • npm install cypress-cucumber-preprocessor
  • Create a cypress/plugins/index.js containing:
const browserify = require('@cypress/browserify-preprocessor');
const cucumberPreprocessor = require('cypress-cucumber-preprocessor');
const resolve = require('resolve');

module.exports = (on, config) => {
  const options = {
    ...browserify.defaultOptions,
    typescript: resolve.sync('typescript', { baseDir: config.projectRoot })
  };

  on('file:preprocessor', cucumberPreprocessor.default(options));
};
  • Implement the Google example from the preprocessors' documentation and execute the feature (or any test).
  • The undesired behavior occurs.
@chrisbreiding
Copy link
Collaborator

🎉 This issue has been resolved in version 3.0.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.