#request #http-request #requests #workbook #supporting #scenario

apicize_lib

Library supporting Apicize request dispatch, testing and serialization

17 releases (6 breaking)

0.14.1 Nov 27, 2024
0.14.0 Nov 27, 2024
0.13.3 Nov 25, 2024
0.12.0 Nov 13, 2024
0.8.4 Oct 31, 2024

#262 in Testing

Download history 149/week @ 2024-10-26 667/week @ 2024-11-02 336/week @ 2024-11-09 376/week @ 2024-11-16 628/week @ 2024-11-23 51/week @ 2024-11-30 26/week @ 2024-12-07

1,091 downloads per month

MIT license

485KB
4.5K SLoC

Apicize Rust Library

This is a Rust library supporting Apicize serilization, request dispatching (via Reqwest) and test running (via V8).

Serialization

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.

Opening a Workspace from a Workbook

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.

Saving a Workspace to a Workbook

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.

Executing Tests in a Workspace

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.

JavaScript Testing

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

Buliding JavaScript Dependencies

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.

Dependencies

~96MB
~2M SLoC