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

[Feature Request] Allow for an install of Vue.js Devtools #1742

Closed
nothingismagick opened this issue May 18, 2018 · 10 comments
Closed

[Feature Request] Allow for an install of Vue.js Devtools #1742

nothingismagick opened this issue May 18, 2018 · 10 comments

Comments

@nothingismagick
Copy link

Current behavior:

Vue tools is not active

I am running Cypress that is testing a site served by a live dev-server created with the Quasar-Framework. If I just visit the page as served in a normal browser that has VueJS Devtools installed, I can see a lot of information about vue state etc. It is invaluable for vuex etc. I installed the VueJS extension into the Cypress chrome browser, but it remains inactive.

screen shot 2018-05-18 at 22 26 22

Desired behavior:

I would also like to know exactly what the Vue state is while testing, because even though I can address it within a spec it would still be really nice to have.

Steps to reproduce:

start a development server at localhost:8080 with $ quasar dev
npm run cypress opena properly rigged Vue.spec.js test with const getStore = () => cy.window().its('app.$store')
Install the Vue Js Devtools as an extension in the Chrome browser started by cypress
https://github.com/vuejs/vue-devtools
See that the browser does not detect vue. :(

Versions

Cypress package version: 2.1.0
MacOS v10.12.6
Chrome 65

@brian-mann
Copy link
Member

React dev tools has a hook that enables you to point to the correct window. We use it in our own Cypress tests. Likely Vue has this same thing, but if not, could borrow from the same concept as react dev tools.

Vue isn't finding it because it's looking at window.top which is Cypress -> not your App. Instead you can just use your app itself (or cypress code) to point vue to window.top so that the extension finds it. It may be as simple as window.top.vue = window.vue but I'd have to dig in.

Whatever it is, I don't think you need anything in Cypress core to facilitate this. You have native access to everything in Cypress so you just have to look at how the vue dev tools works and then connect whatever it is from your app to the extension.

@nothingismagick
Copy link
Author

Ok, thanks. I'll ask over at vue-devtools - maybe you could leave this issue open for tracking until I resolve it? I will report in.

@nothingismagick
Copy link
Author

nothingismagick commented May 24, 2018

Issue cross-linking - for the refs.

vuejs/devtools-v6#353

@jennifer-shehane jennifer-shehane added the stage: awaiting external fix A 3rd party bug in Cypress - awaiting release label May 25, 2018
@nothingismagick
Copy link
Author

This has been resolved.

Add <script src="http://localhost:8098"></script> to the <head> of your index.html

$ npm install -g @vue/devtools
$ vue-devtools
$ cypress open

vuejs/devtools-v6#353 (comment)

@jennifer-shehane jennifer-shehane removed the stage: awaiting external fix A 3rd party bug in Cypress - awaiting release label May 31, 2018
@brian-mann
Copy link
Member

brian-mann commented May 31, 2018

Instead of adding this to your index.html you can do the whole thing from inside of Cypress itself (so that its separated out from your app code. For instance... you could automatically do this on every visit or on every page load...

cy.visit('...', {
  onBeforeLoad: (win) => {
    const script = win.document.createElement('script')
    script.src = '...'
    win.document.body.appendChild(script)
  }
})

// or ...

Cypress.on('window:before:load', (win) => {
  // same thing here
})

P.S. I haven't tried what I wrote above, but with the window:before:load hooks you can tap into your document before it loads and inject javascript or do whatever it is you want. You don't even need to insert the <script> you could just implement exactly what the script itself does.

@nothingismagick
Copy link
Author

Thanks, I will look into this very soon and report back. It sounds like the right thing to do, however there would need to be a guarantee that the electron app from Vuetools is running before cypress enters the load loop.

@brian-mann
Copy link
Member

I believe Chromium guarantees that the extensions are loaded prior to content.

@TheJoeSchr
Copy link

Instead of adding this to your index.html you can do the whole thing from inside of Cypress itself (so that its separated out from your app code. For instance... you could automatically do this on every visit or on every page load...

cy.visit('...', {
  onBeforeLoad: (win) => {
    const script = win.document.createElement('script')
    script.src = '...'
    win.document.body.appendChild(script)
  }
})

// or ...

Cypress.on('window:before:load', (win) => {
  // same thing here
})

P.S. I haven't tried what I wrote above, but with the window:before:load hooks you can tap into your document before it loads and inject javascript or do whatever it is you want. You don't even need to insert the <script> you could just implement exactly what the script itself does.

This doesn't work, it seems win.document.body is null at this stage.

@jennifer-shehane
Copy link
Member

@JoeSchr True, you should be able to inject it into the window.document.head.

Cypress.on('window:before:load', (win) => {
  const script = win.document.createElement('script')
  script.src = '...'
  win.document.head.appendChild(script)
})

// or...

cy.visit('...', {
  onBeforeLoad: (win) => {
    const script = win.document.createElement('script')
    script.src = '...'
    win.document.head.appendChild(script)
  }
})

@TheJoeSchr
Copy link

TheJoeSchr commented Apr 27, 2020

Thx, while this works regarding adding the script tag to head and is awesome because it doesn't block the site until the link is called, vue-devtools is still "waiting for connection" even though I see the script gets fetched in the network inspector.

so far, for me, the only way to make vue-devtools connect is to put this into a layout component:

export default defineComponent({
  setup(props, ctx: SetupContext) {
  ...
  }
  head() {
    return {
      // inject vue-devtool connection
      script:
        process.env.NODE_ENV !== "production"
          ? [{ src: "http://localhost:8098" }] // vue-devtool
          : [],
    };
  },
});

Problem with this approach, it blocks until this script loads and is executed, so if vue-devtools is not running it "freezes" for a few seconds, which can quite add up if you run e.g. all tests at once

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

4 participants