specmatic / specmatic/specmatic-node
Error import Specmatic in Cypress tests
Open
@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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.