mirror of
https://github.com/usebruno/bruno.git
synced 2026-06-23 20:55:41 +00:00
feat: support tv4 as a inbuilt lib (#4589)
This commit is contained in:
@@ -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"
|
||||
},
|
||||
|
||||
@@ -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 {
|
||||
@@ -151,6 +152,7 @@ class ScriptRuntime {
|
||||
'crypto-js': CryptoJS,
|
||||
'xml2js': xml2js,
|
||||
cheerio,
|
||||
tv4,
|
||||
...whitelistedModules,
|
||||
fs: allowScriptFilesystemAccess ? fs : undefined,
|
||||
'node-vault': NodeVault
|
||||
@@ -285,6 +287,7 @@ class ScriptRuntime {
|
||||
'crypto-js': CryptoJS,
|
||||
'xml2js': xml2js,
|
||||
cheerio,
|
||||
tv4,
|
||||
...whitelistedModules,
|
||||
fs: allowScriptFilesystemAccess ? fs : undefined,
|
||||
'node-vault': NodeVault
|
||||
|
||||
@@ -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) => {
|
||||
@@ -209,6 +210,7 @@ class TestRuntime {
|
||||
'crypto-js': CryptoJS,
|
||||
'xml2js': xml2js,
|
||||
cheerio,
|
||||
tv4,
|
||||
...whitelistedModules,
|
||||
fs: allowScriptFilesystemAccess ? fs : undefined,
|
||||
'node-vault': NodeVault
|
||||
|
||||
@@ -12,6 +12,7 @@ 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;
|
||||
@@ -19,6 +20,7 @@ const bundleLibraries = async () => {
|
||||
globalThis.atob = atob;
|
||||
globalThis.Buffer = Buffer;
|
||||
globalThis.CryptoJS = CryptoJS;
|
||||
globalThis.tv4 = tv4;
|
||||
globalThis.requireObject = {
|
||||
...(globalThis.requireObject || {}),
|
||||
'chai': { expect, assert },
|
||||
@@ -26,7 +28,8 @@ const bundleLibraries = async () => {
|
||||
'buffer': { Buffer },
|
||||
'btoa': btoa,
|
||||
'atob': atob,
|
||||
'crypto-js': CryptoJS
|
||||
'crypto-js': CryptoJS,
|
||||
'tv4': tv4
|
||||
};
|
||||
`;
|
||||
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
meta {
|
||||
name: tv4
|
||||
}
|
||||
@@ -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;
|
||||
});
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user