Skip to content

Commit

Permalink
feat(tests): support json schema validation (#6532)
Browse files Browse the repository at this point in the history
* feat(tests): support json schema validation

* add json schema to cli test

---------

Co-authored-by: gatzjames <jamesgatzos@gmail.com>
  • Loading branch information
kobenguyent and gatzjames committed Dec 6, 2023
1 parent 6fa7e5d commit 1d97689
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 1 deletion.
29 changes: 29 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"_id":"ut_babcaf85ec1b481ebed1e1cd1aa61a75","type":"UnitTest","parentId":"uts_b12681ace8eb4e5999b5b51677c4c269","modified":1632964811893,"created":1632962936043,"requestId":"req_f2cd394aad83485c8f7bee1b612165d5","name":"Returns 200","code":"const response1 = await insomnia.send();\nexpect(response1.status).to.equal(200);"}
{"_id":"ut_babcaf85ec1b481ebed1e1cd1aa61a75","type":"UnitTest","parentId":"uts_b12681ace8eb4e5999b5b51677c4c269","modified":1632964811893,"created":1632962936043,"requestId":"req_f2cd394aad83485c8f7bee1b612165d5","name":"Returns 200","code":"const response1 = await insomnia.send();\nexpect(response1.status).to.equal(200);\nconst schema = {\n \"$schema\": \"http://json-schema.org/draft-07/schema#\",\n \"title\": \"Response Schema\",\n \"type\": \"object\",\n \"properties\": {\n \"id\": {\n \"type\": \"string\"\n }\n },\n \"required\": [\n \"id\"\n ]\n}\nexpect(JSON.parse(response1.data)).to.be.jsonSchema(schema)"}
3 changes: 3 additions & 0 deletions packages/insomnia-testing/src/run/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ const runInternal = async <TReturn, TNetworkResponse>(
// This is the only way to add new globals to the Mocha environment as far as I can tell
// @ts-expect-error -- global hack
global.insomnia = new Insomnia(options);

// eslint-disable-next-line @typescript-eslint/no-var-requires
chai.use(require('chai-json-schema'));
// @ts-expect-error -- global hack
global.chai = chai;

Expand Down
1 change: 1 addition & 0 deletions packages/insomnia/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"aws4": "^1.12.0",
"axios": "^1.4.0",
"chai": "^4.3.4",
"chai-json-schema": "1.5.1",
"change-case": "^4.1.2",
"clone": "^2.1.0",
"color": "^3.1.2",
Expand Down

0 comments on commit 1d97689

Please sign in to comment.