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

args.findIndex is not a function #5

Open
sir-dunxalot opened this issue May 25, 2020 · 11 comments
Open

args.findIndex is not a function #5

sir-dunxalot opened this issue May 25, 2020 · 11 comments

Comments

@sir-dunxalot
Copy link

sir-dunxalot commented May 25, 2020

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
Copy link
Author

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;
  });
};

@evandavis
Copy link

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.

@Strajk
Copy link

Strajk commented Jul 23, 2020

@sir-dunxalot @evandavis fixed here #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",

@hitmands
Copy link

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

@hitmands
Copy link

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;
  });

@Pithikos
Copy link

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

@hitmands
Copy link

@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...

@ViRuSTriNiTy
Copy link

ViRuSTriNiTy commented Oct 29, 2020

@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.

@hitmands
Copy link

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.

@pietrofxq
Copy link

pietrofxq commented Feb 11, 2021

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
    }
  })

@ViRuSTriNiTy
Copy link

@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

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

7 participants