This is a Rust library supporting Apicize serilization, request dispatching (via Reqwest) and test running (via V8).
Broadly speaking, Workbooks and associated structures are how Apicize testing information is persisted in JSON format.
Workspaces contain indexed views of Workbook structures like requests, scenarios, etc. which make it more efficient
to traverse hierarchical and ordered information.
The function Workspace::open_from_file
will populate a workspace from a a workbook file, its private parameters file, and global
parameters file (if specified). Entities are indexed and warnings are generated if a workbook contains any references to parameters
that are not found in the private or globals file.
The function Workspace::save
persists workspace information to workbook, private parameters and global parameters files. Private parameters
are saved to a file with the same name as the workbook but with an .apicize-priv
extension. Global parameters are saved to the
user's OS configuration directory under apicize/globals.json
.
Tests are executed via the test_runner::run
function, which accepts an Arc to the workspace being tested, an optional list of request IDs to execute (defaults to all), an optional
cancellation token, and an Arc to instant that testing was started.
This library leverages V8 to execute tests to validate requests. This sandboxed envioronment does not include NodeJS or Browser functionality, primarily to prevent arbitrary test code in a Workbook from doing anything harmful.
The following variables and functions are available in the testing sandbox:
- request: A variable containing the submitted HTTP request
- response: A variable containing the HTTP response
- variables: A variable containing key-value pairs originally sourced from the assigned Scenario parameter, but can be updated to pass values to subsequent and child requests in a group
- assert: An exported function of Chai's Node assertion style
- expect / should: Exported functions of Chai's BDD assertion style
- jsonpath: An exported function of JSONPath Plus
- xpath: An exported function of XPath
- dom: An exported function of xmldom
The build.rs file triggers a copy of the file test-framework/dist/framework.min.js
file, which is used in the test runner.
If you change test-framework/index.js
or dependencies, you will need to rebuild framework.min.js
To do, run yarn build
from the test-framework
directory.