Test Helper for running Cypress E2E Tests on Dashboard 2.0
This flow provides two API endpoints:
- The first at
GET /context/flowreturns the fullglobal.msgvalue from the Node-RED context store - The second at
POST /context/resetempty theglobal.msgobject
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":[]}]