Skip to content

Error import Specmatic in Cypress tests #139

@tkrisztian95

Description

@tkrisztian95

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?

Metadata

Metadata

Labels

questionFurther information is requested

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions