Skip to content

feat: support tv4 as a inbuilt lib #4589

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/bruno-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"node-vault": "^0.10.2",
"path": "^0.12.7",
"quickjs-emscripten": "^0.29.2",
"tv4": "^1.3.0",
"uuid": "^9.0.0",
"xml2js": "^0.6.2"
},
Expand Down
3 changes: 3 additions & 0 deletions packages/bruno-js/src/runtime/script-runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const CryptoJS = require('crypto-js');
const NodeVault = require('node-vault');
const xml2js = require('xml2js');
const cheerio = require('cheerio');
const tv4 = require('tv4');
const { executeQuickJsVmAsync } = require('../sandbox/quickjs');

class ScriptRuntime {
Expand Down Expand Up @@ -151,6 +152,7 @@ class ScriptRuntime {
'crypto-js': CryptoJS,
'xml2js': xml2js,
cheerio,
tv4,
...whitelistedModules,
fs: allowScriptFilesystemAccess ? fs : undefined,
'node-vault': NodeVault
Expand Down Expand Up @@ -285,6 +287,7 @@ class ScriptRuntime {
'crypto-js': CryptoJS,
'xml2js': xml2js,
cheerio,
tv4,
...whitelistedModules,
fs: allowScriptFilesystemAccess ? fs : undefined,
'node-vault': NodeVault
Expand Down
2 changes: 2 additions & 0 deletions packages/bruno-js/src/runtime/test-runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const CryptoJS = require('crypto-js');
const NodeVault = require('node-vault');
const xml2js = require('xml2js');
const cheerio = require('cheerio');
const tv4 = require('tv4');
const { executeQuickJsVmAsync } = require('../sandbox/quickjs');

const getResultsSummary = (results) => {
Expand Down Expand Up @@ -209,6 +210,7 @@ class TestRuntime {
'crypto-js': CryptoJS,
'xml2js': xml2js,
cheerio,
tv4,
...whitelistedModules,
fs: allowScriptFilesystemAccess ? fs : undefined,
'node-vault': NodeVault
Expand Down
5 changes: 4 additions & 1 deletion packages/bruno-js/src/sandbox/bundle-libraries.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,24 @@ const bundleLibraries = async () => {
import btoa from "btoa";
import atob from "atob";
import * as CryptoJS from "@usebruno/crypto-js";
import tv4 from "tv4";
globalThis.expect = expect;
globalThis.assert = assert;
globalThis.moment = moment;
globalThis.btoa = btoa;
globalThis.atob = atob;
globalThis.Buffer = Buffer;
globalThis.CryptoJS = CryptoJS;
globalThis.tv4 = tv4;
globalThis.requireObject = {
...(globalThis.requireObject || {}),
'chai': { expect, assert },
'moment': moment,
'buffer': { Buffer },
'btoa': btoa,
'atob': atob,
'crypto-js': CryptoJS
'crypto-js': CryptoJS,
'tv4': tv4
};
`;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
meta {
name: tv4
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
meta {
name: tv4
type: http
seq: 1
}

post {
url: {{host}}/api/echo/json
body: json
auth: inherit
}

body:json {
{
"name": "John",
"age": 30
}
}

tests {
const tv4 = require("tv4")

const schema = {
type: 'object',
properties: {
name: { type: 'string' },
age: { type: 'number' }
}
};

let responseData = res.getBody();

let isValid = tv4.validate(responseData, schema);

test("Response body matches expected schema", function () {
expect(isValid, tv4.error ? tv4.error.message : "").to.be.true;
});

}