specmatic / specmatic/specmatic-node

Error import Specmatic in Cypress tests

Open
#139 3 comments 0 reactions 1 assignee View on GitHub

@harikrishnan83 is already working on this.

Since Jan 31, 2024.

question
Dominant language
TypeScript
Stars
6
Forks
4
PR merge metrics
No merged PRs in 30d

Description

Describe the bug
I'm trying to import Specmatic in a Cypress test, like

import { setHttpStubExpectations } from "specmatic";

and I'm getting the following error while running the tests by npx cypress run --browser electron:

TypeError: The following error originated from your test code, not from Cypress.   > _fs.default.existsSync is not a function

Desktop:

  • OS: Windows 10
  • Node version: 18.12.
  • Specmatic Version: 1.2.14
  • "cypress": "^13.2.0",

Additional context
I'm trying to achieve that from a Cypress test, using the cy.intercept() and cy.reply() functions, the tests are backed with the Specmatic stub and it returns the example/transient stubs always verified against the API specification.

For example:

    cy.intercept("/api/v1/foo/list", async (req) => {
      // fetch test data from Specmatic stub
      const data = await fetch("http://localhost:35337" + req.url, {
        headers: {
          Accept: "application/json",
          "Content-Type": "application/json",
          Authorization: "Bearer token"
        }
      });
      req.reply(data);
    });

Should this work?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.