Skip to content

Plainwire 0.13.0: JavaScript scripts

Choose a tag to compare

@janwan2003 janwan2003 released this 20 Nov 17:08
· 11 commits to main since this release
  • JavaScript in .http files, in the JetBrains HTTP Client format. < {% … %} above the request line runs before the request (request.variables.set('sig', …) for this request only; request.environment.get, request.url.tryGetSubstituted(), headers and body). > {% … %} after the request runs on the response: client.test('name', () => client.assert(response.status === 200, '…')), client.global.set('token', response.body.token), client.log, client.exit(); response.status, response.body (parsed JSON or text), response.headers.valueOf(name), response.contentType. < ./sign.js / > ./check.js load the code from a file. Helpers: crypto (MD5/SHA-1/SHA-2 and HMAC, hex or Base64), $random, jsonPath, btoa/atob, console.log. For server-sent events and WebSocket, response.body.onEachMessage(…) replays the received messages. Before, these blocks were kept in the file but never run. REST Client has no scripting (#521); in Thunder Client it is a paid feature.
  • client.global values work as {{name}} in later requests (after request, file and environment variables), are kept per workspace, and are listed and cleared with Plainwire: Show / Clear Script Variables (client.global)…. A request that uses a variable only a handler sets says which request to send first.
  • client.test results appear with the # @assert checks: in the Tests tab, Run all, and the CLI reports (JUnit, JSON, Markdown, GitHub annotations). An error in a handler is a failed check; an error in a pre-request script stops the request ("Not sent: …").
  • Request editor: a Scripts tab to edit both scripts; the response's Tests tab shows the script log.
  • Scripts run in a separate Node vm context with a 5 second limit, only in trusted workspaces (Plainwire does not run in Restricted Mode). Setting plainwire.runScripts (default on) skips them.
  • Postman import keeps scripts that run. Test scripts that are plain checks still become # @assert lines; any other test script (setting variables, conditions, loops) and every pre-request script is kept whole as a > {% %} / < {% %} block and runs with a Postman-compatible pm API: pm.test, pm.expect (the common chain), pm.response (code, json(), text(), headers, to.have.status/header/body/jsonBody, to.be.ok/json), pm.environment / collectionVariables / globals / variables, and the older tests["…"], postman.setEnvironmentVariable, responseBody. pm.sendRequest, require() and pm.visualizer are not supported (the import warns). Folder- and collection-level scripts are still skipped with a warning.
  • CLI: plainwire run --no-scripts; -v prints every script's log, and a failed request prints its log.