Test Helper for running Cypress E2E Tests on Dashboard 2.0

This flow provides two API endpoints:

  • The first at GET /context/flow returns the full global.msg value from the Node-RED context store
  • The second at POST /context/reset empty the global.msg object

These can be used in a Cypress E2E testing environment whereby you connect nodes to a helper function that stores their output into global.msg. This API can then be called by cy.request() in Cypress to (a) reset the context store, and, (b) read the last stored message to ensure messages are passed through a flow correctly.

[{"id":"node-red-tab-helper-api","type":"tab","label":"Helper API","disabled":false,"info":"","env":[]},{"id":"node-red-http-in-store-context","type":"http in","z":"node-red-tab-helper-api","name":"","url":"/context/flow","method":"get","upload":false,"swaggerDoc":"","x":130,"y":50,"wires":[["fcn-store-context"]]},{"id":"fcn-store-context","type":"function","z":"node-red-tab-helper-api","name":"function 1","func":"msg.payload = {\n    msg: global.get('msg')\n}\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":300,"y":50,"wires":[["node-red-http-out-store-context"]]},{"id":"node-red-http-out-store-context","type":"http response","z":"node-red-tab-helper-api","name":"","statusCode":"","headers":{},"x":430,"y":50,"wires":[]},{"id":"node-red-http-in-reset-context","type":"http in","z":"node-red-tab-helper-api","name":"","url":"/context/reset","method":"post","upload":false,"swaggerDoc":"","x":130,"y":100,"wires":[["fcn-reset-context"]]},{"id":"fcn-reset-context","type":"function","z":"node-red-tab-helper-api","name":"function 2","func":"global.set('msg', undefined)\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":300,"y":100,"wires":[["node-red-http-out-reset-context"]]},{"id":"node-red-http-out-reset-context","type":"http response","z":"node-red-tab-helper-api","name":"","statusCode":"","headers":{},"x":430,"y":100,"wires":[]}]

Flow Info

Created 8 months, 3 weeks ago
Rating: not yet rated

Owner

Actions

Rate:

Node Types

Core
  • function (x2)
  • http in (x2)
  • http response (x2)
Other
  • tab (x1)

Tags

  • dashboard-2.0
  • cypress
  • e2e
  • testing
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option