Giter VIP home page Giter VIP logo

Comments (9)

javierbrea avatar javierbrea commented on June 12, 2024 2

Hi @mbruggenwirth , no, unfortunately I had not as much time for the project as I'd like. I hope to release the TypeScript migration soon, and then I'll be able to work on this feature. But I can't say when it will be ready 😞 I will notify it on this issue as soon as I start working on it.

from main.

javierbrea avatar javierbrea commented on June 12, 2024 1

@mbruggenwirth , I hope it will be available sometime in the next 3 months. I'm currently finishing the migration of the whole project to TypeScript, and improving the architecture to make easier to expose the next big feature to the API, which in fact is to support spying routes.

from main.

javierbrea avatar javierbrea commented on June 12, 2024

Hi @mbruggenwirth ,
First of all, thanks for the feedback 😃 . I have planned to add support for spying routes, and, when that feature is implemented, it would be possible to add new cypress commands allowing to write assertions about them.

from main.

mbruggenwirth avatar mbruggenwirth commented on June 12, 2024

@javierbrea awesome! Any idea when this will be on the schedule.
It will help me with my internal mock-server pitch.

from main.

mbruggenwirth avatar mbruggenwirth commented on June 12, 2024

@javierbrea any update about this enhancement?

from main.

mbruggenwirth avatar mbruggenwirth commented on June 12, 2024

@javierbrea any update about this enhancement?

from main.

mbruggenwirth avatar mbruggenwirth commented on June 12, 2024

Is there any progress on this issue?

from main.

javierbrea avatar javierbrea commented on June 12, 2024

Not for the moment @mbruggenwirth 😞 . Anyway, let me think about how to implement it by using a plugin, so you may implement it by yourself until it is added to the core features. I hope to answer soon with a proposal 😃

from main.

SimeonC avatar SimeonC commented on June 12, 2024

I thought I'd share my workaround as I couldn't manage to figure out how to get plugins to do this. Basically I changed to run an express proxy in front of mocks-server so I could catch the responses.

const path = require('path');

const express = require('express');
const { createServer } = require('@mocks-server/main');
// this just gets the root of my repository folder
const { workspaceRoot } = require('nx/src/utils/workspace-root.js');
const {
  createProxyMiddleware,
  fixRequestBody,
} = require('http-proxy-middleware');

const core = createServer({
  server: {
    port: 3101,
  },
  plugins: {
    inquirerCli: {
      enabled: typeof process.env.CI === 'undefined',
    },
  },
  files: {
    enabled: true,
    path: path.join(workspaceRoot, 'apps/mock-server/mocks'),
    babelRegister: {
      enabled: true,
      options: {
        presets: ['@babel/env', '@babel/preset-typescript'],
      },
    },
  },
});

core.start();

const app = express();

let requests = [];

app.use(express.json());
app.delete('/test-requests', (req, res) => {
  requests = [];
  res.status(200).end();
});

app.get('/test-requests', (req, res) => {
  res.json(requests);
});

const proxy = express();
proxy.use(express.json());
proxy.use(
  createProxyMiddleware({
    target: 'http://localhost:3101',
    changeOrigin: true,
    onProxyReq: (proxyReq, req, res, options) => {
      requests.push({
        url: req.url,
        method: req.method,
        headers: req.headers,
        body: req.body,
        params: req.params,
      });
      return fixRequestBody(proxyReq, req, res, options);
    },
  }),
);

app.listen(3102);
proxy.listen(3100);

Then in cypress I do;

beforeEach(() => {
  cy.request('DELETE', 'http://localhost:3102/test-requests');
});

Cypress.Commands.add('getApiSubmits', () =>
  cy
    .request<
      (Record<string, string> & { body: object })[]
    >('GET', 'http://localhost:3102/test-requests')
    .then((res) =>
      res.body
        .filter((r) => r.method === 'PUT' && r.url.startsWith('/responses/'))
        .map((r) => r.body),
    ),
);

from main.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.