JavaScript code
JavaScript shares its execution environment with TypeScript: the same engine, the same API, the same built-in library. This page concentrates on what is specific to it — the compatibility layers.
Example
Section titled “Example”// `input` = the value received, `vars` = the run variablesconst utilisateurs = input.data.filter((u) => u.actif);
console.log(`${utilisateurs.length} utilisateurs actifs`);
return _.sortBy(utilisateurs, 'nom');Postman compatibility
Section titled “Postman compatibility”This is what lets the scripts of an imported Postman collection work with no rewriting.
| Surface | Notes |
|---|---|
pm.variables, pm.environment, pm.globals, pm.collectionVariables | All mapped onto the single run-variable space |
pm.iterationData | The iteration data |
pm.request, pm.response | The current request and response |
pm.test(name, fn), pm.test.skip | The tests |
pm.expect | The assertions (chai) |
pm.sendRequest | An extra call |
pm.info | The run metadata |
pm.vault | The vault |
pm.visualizer.set(template, data) | The visualizer |
pm.cookies, pm.cookies.jar() | The cookies |
pm.setNextRequest, pm.execution.setNextRequest, .skipRequest, .location | Flow control |
postman.getResponseHeader | The legacy API |
pm.test('le statut est 200', function () { pm.expect(pm.response.code).to.eql(200);});
pm.environment.set('commandeId', pm.response.json().id);Bruno compatibility
Section titled “Bruno compatibility”For imported Bruno collections: the bru.*
object — including bru.runRequest(name) — as well as the test() function
used bare.
Migrating cleanly
Section titled “Migrating cleanly”These layers exist so that nothing breaks at import time. In the medium term,
prefer the native boxes: an
Assert is more readable than a
pm.test buried in a script, it has its two then / else outputs visible in the
graph, and its message appears directly in the CI log.