cypress-browser-extension-plugin icon indicating copy to clipboard operation
cypress-browser-extension-plugin copied to clipboard

args.findIndex is not a function

Open sir-dunxalot opened this issue 5 years ago • 11 comments

After installing this addon in a new Cypress test suite, I see the following error when opening a test in the browser:

image

Stack trace:

TypeError: args.findIndex is not a function
    at /Users/YYY/Codebases/XXX/node_modules/cypress-browser-extension-plugin/loader.js:155:41
    at processTicksAndRejections (internal/process/task_queues.js:93:5)

This error is caused by the following code:

// app/cypress/support/index.js
const extensionLoader = require('cypress-browser-extension-plugin/loader');

module.exports = (on, config) => {
  on('before:browser:launch', extensionLoader.load({
    source: '/Users/YYY/Codebases/XXX/build',
    skipHooks: false,
    validBrowser: ['chrome'],
    watch: true,
  }));
};

Simplifying the implementation to the example shown in the Regular Usage section of the Readme does not change anything.

// app/cypress/support/index.js
const extensionLoader = require('cypress-browser-extension-plugin/loader');

module.exports = (on, config) => {
  on('before:browser:launch', extensionLoader.load('/Users/YYY/Codebases/XXX/build'));
});

sir-dunxalot avatar May 25 '20 21:05 sir-dunxalot

I should also specify my deps:

"cypress": "^4.6.0",
"cypress-browser-extension-plugin": "^0.1.0",

This is my current workaround (doesn't use this lib):

const path = require('path');

module.exports = (on, config) => {
  on('before:browser:launch', async (browser, launchOptions) => {

    if (browser.family === 'chromium' && browser.name !== 'electron') {
      const extensionPath = path.resolve(__dirname, '../', '../', 'build'); // The folder where I build the unpacked extension

      launchOptions.extensions.push(extensionPath);
    }

    return launchOptions;
  });
};

sir-dunxalot avatar May 25 '20 22:05 sir-dunxalot

I think it's because this package assumes that you have your scripts injected declaratively via content_scripts in the manifest. If your content script is injected programmatically (or if you don't have one) I think this error pops up.

evandavis avatar Jul 15 '20 22:07 evandavis

@sir-dunxalot @evandavis fixed here https://github.com/ejoubaud/cypress-browser-extension-plugin/pull/7

If you need it working now, you can use fixed version in package.json like this:

"cypress-browser-extension-plugin": "Strajk/cypress-browser-extension-plugin#15f14eaad4c0602339ddd67aafd9ec9d9145936b",

Strajk avatar Jul 23 '20 13:07 Strajk

I'd like to get #7 merged if possible.

hitmands avatar Oct 12 '20 13:10 hitmands

This fixes it:

  on('before:browser:launch', async (browser = {}, launchOptions) => {
    const loader = extension.load({
      source: '/path/to/xt'
      alias: 'coolExtension'
    });

    const args = await loader(browser, []);

    launchOptions.args.push(...args);

    return launchOptions;
  });

hitmands avatar Oct 12 '20 20:10 hitmands

@hitmands just a small typo; it's extensionLoader, not extension. But seems to work otherwise :+1:

Pithikos avatar Oct 28 '20 11:10 Pithikos

@Pithikos that was just because I had the import named differently on my codebase, probably the naming would have to be revisited anyway because it feels counter intuitive that extensionLoader.load would return a loader function...

hitmands avatar Oct 29 '20 09:10 hitmands

@hitmands Next time you should not post a solution claiming it's yours when it's not. It is a simple rip of my solution posted months ago in #7 ... and then you included the mentioned typo. Very sad.

ViRuSTriNiTy avatar Oct 29 '20 11:10 ViRuSTriNiTy

Hi @ViRuSTriNiTy , from developer to developer, this definitely isn't the tone one should really use. I don't know whether you're taking this like a challenge, but here we're just trying to get stuff done.

There was (and still is) an open issue around the args.findIndex, and by looking on the internet we found out how to fix it.

Was my snippet elaborated from yours? Yes, it probably was, I don't really remember anymore but it is indeed very likely. Every future developer will feed himself with the work done by the previous generation, this isn't anything but very human.

It wasn't an attack against your own copyrights. I suggest you revisit the tone you use in conversations as github is meant to be welcoming everyone's contributions.

I also hope @ejoubaud will moderate your comment.

hitmands avatar Oct 29 '20 11:10 hitmands

This library is not needed anymore. You can launch a browser extension in the before launch hook like this:

on('before:browser:launch', (browser = {}, launchOptions) => {
    if (browser.name === 'chrome') {
      launchOptions.extensions.push('/path/to/extension')
      return launchOptions
    }
  })

pietrofxq avatar Feb 11 '21 03:02 pietrofxq

@pietrofxq Yes, that is right, there is also an NPM module that implements this approach with additional bells and whistles: https://github.com/ejoubaud/cypress-browser-extension-plugin

ViRuSTriNiTy avatar Feb 11 '21 08:02 ViRuSTriNiTy