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.

Create a Plugins / Extensions API

See original GitHub issue

The idea behind this

As it stands - while users can create custom commands in the driver, we do not expose any real way to alter, modify or change Cypress’s behavior BEHIND the driver (in the node server code).

Currently all we expose is a simple cypress.json to change the way Cypress works. This is heavily limiting.

What we need to do is expose a public interface so users can write node code to modify and alter the internals.

The use cases we’re specifically trying to support are:

Custom Preprocessors

Swapping out the default preprocessor for custom ones. This is the thing that processes the spec files and ultimately serves them to the browser.

Customizing the preprocess would enable users to write typescript, coffeescript 2.0, clojurescript, use webpack, customize babel options, use newer ES7 features, etc, etc. Big win.

Browser Configuration

Users would have access to the browser processes and launch configuration. This would enable them to change the flags used to launch browsers.

You could also use this to load in browser extensions.

Browser Finding

Changes / modifies the logic we use to find browsers on the system.

Custom Configuration

Having just a single cypress.json is limiting. Users have expressed a desire to have more programatic control over things like environment variables.

Backend Messaging

While we currently expose cy.exec and cy.request, there is still a desire to message / talk directly to your backend.

Exposing this API would enable you to do things like call your application code directly to do things like setup / seed / create / update database records.

Screenshot Diffing

As we continue to expand the features of Cypress we would expand these API’s to do things like letting you swap out the screenshot diffing algorithm.

The Cypress Ecosystem

Going down this route will enable us to develop a Cypress Ecosystem consisting of official extensions (created by us) as well as user submitted extensions.

We’ll also need to create an “index” of extensions that enable users to search, browse, and submit new extensions.

Things to consider

  • How will we / users handle versioning for plugins? We may need to set a process.versions.cypress
  • How will we differentiate official plugins from regular ones? We could publish them under our @cypress npm namespace.
  • How will we make modifying the default plugin that Cypress uses by default. Users may want to swap out entire implementations (like the preprocessor) or perhaps just modify the configuration for the default one.
  • We should likely seed a commented out cypress/plugins/index.js with all of the API’s that we support.
  • We should enable users to easily debug their node code by passing a flag to Cypress which spawns the internal chrome inspector.
  • Users code will run in the builtin node environment that comes with Cypress.

Examples of how we could do this

// cypress/plugins/index.js

module.exports = ((register, config, utils, defaults) => {
  register('on:spec:file:preprocessor', (filePath, options) => {
    // do your own custom preprocessing on the spec
  })

  register('on:before:browser:launch', (browserName, flags) => {
    // do your own custom bits on launching the browser
    // such as loading in an extension or modifying the flags
    // used to launch the browser
  })

  register('on:find:all:browsers', (browsersFound) => {
    // add or modify the browsers we found
  })

  register('on:config', (config) => {
    // read in your own yaml files to change some
    // environment variables
    return fs.readFile("./some/yaml", "utf8")
    .then((str) => {
      const yaml = jsYaml.parse(str)

      config.env.yml = yaml

      return config
    })
  })

  register('on:driver:message', (msg, options) => {
    const db = require('./lib/db') // your db

    const request = require('request') // 3rd party request module

    // pass custom messages and do your own thing here loading
    // your own application files
    switch (msg) {
      case 'create:user':
        return db.seed(options)
      case 'reset:db':
        return db.reset()
      case 'make:request':
        return Promise.all(options.urls, request)
    }
  })
})

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:12
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
bahmutovcommented, Oct 18, 2017
2reactions
laurentpayotcommented, Jun 27, 2018

@brian-mann I made the switch to Cypress 3.0.1 yesterday. I had some minor CoffeeScript file related issues (#2046) but making firebase-related tasks work was a pain because firebase use grpc and grpc and electron do not live together well. I encountered the following issue https://github.com/grpc/grpc/issues/6138 that I fixed by a postinstall of the electron runtime of grpc, plus I had to create symbolic links to it because Firebase (or Cypress?) was still looking for the node version of grpc.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Chrome Extensions getting started guides
These tutorials not only teach you how to build real-world extensions but also strive to share development tips and best practices. In addition, ......
Read more >
Your First Extension - Visual Studio Code
Create your first Visual Studio Code extension (plug-in) with a simple ... In this topic, we'll teach you the fundamental concepts for building...
Read more >
Managing plugins and extensions through the API - Elastic
Managing plugins and extensions through the APIedit · Option 1: Stream the file from a publicly-accessible download URL · Option 2: Upload the...
Read more >
Build an API Plugin Guide | Mailchimp Developer
To build our custom plugin, we'll first navigate to where we created our API project (called myapiserver in the Quick Start Guide). From...
Read more >
Plugins extension - Strapi Developer Docs
# Extending a plugin's content-types · (optional) Create the ./src/extensions folder at the root of the app, if the folder does not already...
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