https://cypress.io logo
Join Discord
Powered by
# e2e-testing
  • f

    famous-restaurant-30435

    07/13/2022, 9:50 PM
    If you have a file like that in your repo, I think you could just execute it with node.
    node mocks/index.js
  • a

    able-monkey-72947

    07/13/2022, 9:52 PM
    Oh, duh. Sorry... I've been looking at this way too long today and my brain is pretty fried...
  • f

    famous-restaurant-30435

    07/13/2022, 9:53 PM
    Thats how you would handle it server side in the build. Then you would still have to start the client side mocks.
  • f

    famous-restaurant-30435

    07/13/2022, 9:54 PM
    This is what I have used in the past to start client side mocks when Cypress is executed
  • f

    famous-restaurant-30435

    07/13/2022, 9:54 PM
    Cypress.on("test:before:run:async", async () => { await worker.start(); });
  • f

    famous-restaurant-30435

    07/13/2022, 9:54 PM
    Copy code
    Cypress.on("test:before:run:async", async () => {
      await worker.start();
    });
  • a

    able-monkey-72947

    07/13/2022, 9:56 PM
    clientside mocks we have a whole apparatus for already, it does use msw
  • f

    famous-restaurant-30435

    07/13/2022, 9:56 PM
    Ah ok
  • a

    able-monkey-72947

    07/13/2022, 9:56 PM
    bleh, hitting an `import`/`require` headache trying to
    node
    that script.
  • f

    famous-restaurant-30435

    07/13/2022, 9:57 PM
    Oh lame, might have to break the server start one out into its own file so it can be executed in node and the client side mocks are executed elsewhere
  • a

    able-monkey-72947

    07/13/2022, 10:00 PM
    I just swapped everything over to require and it looks like it worked. Any idea where this is running now?
  • f

    famous-restaurant-30435

    07/13/2022, 10:01 PM
    Im not sure I understand the question
  • a

    able-monkey-72947

    07/13/2022, 10:02 PM
    So my test app is fetching
    cat-facts.com/api
    or whatever, what's the mechanism to make the app hit MSW during build time instead of getting actual cat facts?
  • a

    able-monkey-72947

    07/13/2022, 10:02 PM
    Like its not running on a localhost port somewhere as far as I can tell?
  • f

    famous-restaurant-30435

    07/13/2022, 10:05 PM
    Actually I think my approach might be the wrong one to take here. I need to look into this more.
  • a

    able-monkey-72947

    07/13/2022, 10:06 PM
    Never mind, another melting-brain moment.
    Copy code
    if (process.env.NODE_ENV === 'test') {
      require('../../mocks')
    }
    high up in the nextjs app and it'll pick it up during the build process.
  • a

    able-monkey-72947

    07/13/2022, 10:06 PM
    I think.
  • f

    famous-restaurant-30435

    07/13/2022, 10:07 PM
    It will but it would also need to call the
    server.listen()
    function
  • f

    famous-restaurant-30435

    07/13/2022, 10:07 PM
    Otherwise the mock server wont be listening for the requests during the build
  • f

    famous-restaurant-30435

    07/13/2022, 10:09 PM
    Well actually I think im wrong there.
  • f

    famous-restaurant-30435

    07/13/2022, 10:09 PM
    https://github.com/vercel/next.js/tree/canary/examples/with-msw
  • f

    famous-restaurant-30435

    07/13/2022, 10:09 PM
    Based on the Next.js example there, you dont have to execute that file manually.
  • a

    able-monkey-72947

    07/13/2022, 10:10 PM
    Yeah, I think what you said is on the right track but I don't think you have to node run that file, just import it into the app.
  • a

    able-monkey-72947

    07/13/2022, 10:38 PM
    huzzah.
  • a

    able-monkey-72947

    07/13/2022, 10:38 PM
    I have a few more things I want to explore in this repo then I'll post the link, hopefully this can help someone else.
  • g

    green-book-63455

    07/14/2022, 7:27 AM
    I am having a problem using request to authorise. looking at what is coming back after the request, body is empty. I think this may be due to the setup I have so hopefully someone can tell me. I have a frontend svelte app with a login screen. This calls the login rest api for a backend server and receives a token if the username / password is successful. Now when I login manually via the browser - success. When I use cypress to complete the screen - success. When I use cypress to call the login rest api directly - success. But if use request of the login page, then it doesn't work. So with the configuration above, is request just not going to work?
  • h

    hallowed-noon-70189

    07/14/2022, 10:26 AM
    @gray-kilobyte-89541 please share how to handle websocket using cypress in angular app
  • g

    gray-kilobyte-89541

    07/14/2022, 11:52 AM
    I am not sure what difference it makes, but find my websocket advice by searching https://cypress.tips/search
  • a

    able-monkey-72947

    07/14/2022, 2:59 PM
    I feel pretty dense here, but how do I turn on
    experimentalInteractiveRunEvents
    ? I have tried both
    Copy code
    module.exports = defineConfig({
      e2e: {
        ...
      },
      experiments: { experimentalInteractiveRunEvents: true }
    })
    and
    Copy code
    module.exports = defineConfig({
      e2e: {
        ...,
        experiments: { experimentalInteractiveRunEvents: true }
      },
    })
    in my
    cypress.config.js
    file and I'm not see any logging output from either event.
  • a

    able-monkey-72947

    07/14/2022, 3:01 PM
    Sorry, these are for the
    before:spec
    and
    after:spec
    event, I'm just trying to
    console.log(spec)
    .
1...686970...192Latest