@usebruno/js
Advanced tools
Comparing version 0.6.0 to 0.7.0
{ | ||
"name": "@usebruno/js", | ||
"version": "0.6.0", | ||
"version": "0.7.0", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -5,6 +5,7 @@ const Handlebars = require('handlebars'); | ||
class Bru { | ||
constructor(envVariables, collectionVariables, processEnvVars) { | ||
constructor(envVariables, collectionVariables, processEnvVars, collectionPath) { | ||
this.envVariables = envVariables; | ||
this.collectionVariables = collectionVariables; | ||
this.processEnvVars = cloneDeep(processEnvVars || {}); | ||
this.collectionPath = collectionPath; | ||
} | ||
@@ -28,2 +29,6 @@ | ||
cwd() { | ||
return this.collectionPath; | ||
} | ||
getEnvName() { | ||
@@ -30,0 +35,0 @@ return this.envVariables.__name__; |
@@ -10,2 +10,3 @@ const { NodeVM } = require('vm2'); | ||
const punycode = require('punycode'); | ||
const fs = require('fs'); | ||
const Bru = require('../bru'); | ||
@@ -31,2 +32,4 @@ const BrunoRequest = require('../bruno-request'); | ||
// This approach is getting out of hand | ||
// Need to refactor this to use a single arg (object) instead of 7 | ||
async runRequestScript( | ||
@@ -39,5 +42,6 @@ script, | ||
onConsoleLog, | ||
processEnvVars | ||
processEnvVars, | ||
allowScriptFilesystemAccess | ||
) { | ||
const bru = new Bru(envVariables, collectionVariables, processEnvVars); | ||
const bru = new Bru(envVariables, collectionVariables, processEnvVars, collectionPath); | ||
const req = new BrunoRequest(request); | ||
@@ -90,3 +94,4 @@ | ||
'node-fetch': fetch, | ||
'crypto-js': CryptoJS | ||
'crypto-js': CryptoJS, | ||
fs: allowScriptFilesystemAccess ? fs : undefined | ||
} | ||
@@ -112,5 +117,6 @@ } | ||
onConsoleLog, | ||
processEnvVars | ||
processEnvVars, | ||
allowScriptFilesystemAccess | ||
) { | ||
const bru = new Bru(envVariables, collectionVariables, processEnvVars); | ||
const bru = new Bru(envVariables, collectionVariables, processEnvVars, collectionPath); | ||
const req = new BrunoRequest(request); | ||
@@ -146,2 +152,12 @@ const res = new BrunoResponse(response); | ||
mock: { | ||
// node libs | ||
path, | ||
stream, | ||
util, | ||
url, | ||
http, | ||
https, | ||
punycode, | ||
zlib, | ||
// 3rd party libs | ||
atob, | ||
@@ -155,3 +171,4 @@ btoa, | ||
'node-fetch': fetch, | ||
'crypto-js': CryptoJS | ||
'crypto-js': CryptoJS, | ||
fs: allowScriptFilesystemAccess ? fs : undefined | ||
} | ||
@@ -158,0 +175,0 @@ } |
const { NodeVM } = require('vm2'); | ||
const chai = require('chai'); | ||
const path = require('path'); | ||
const http = require('http'); | ||
const https = require('https'); | ||
const stream = require('stream'); | ||
const util = require('util'); | ||
const zlib = require('zlib'); | ||
const url = require('url'); | ||
const punycode = require('punycode'); | ||
const fs = require('fs'); | ||
const Bru = require('../bru'); | ||
@@ -13,2 +21,3 @@ const BrunoRequest = require('../bruno-request'); | ||
const atob = require('atob'); | ||
const axios = require('axios'); | ||
const btoa = require('btoa'); | ||
@@ -24,3 +33,3 @@ const lodash = require('lodash'); | ||
runTests( | ||
async runTests( | ||
testsFile, | ||
@@ -33,5 +42,6 @@ request, | ||
onConsoleLog, | ||
processEnvVars | ||
processEnvVars, | ||
allowScriptFilesystemAccess | ||
) { | ||
const bru = new Bru(envVariables, collectionVariables, processEnvVars); | ||
const bru = new Bru(envVariables, collectionVariables, processEnvVars, collectionPath); | ||
const req = new BrunoRequest(request); | ||
@@ -83,3 +93,14 @@ const res = new BrunoResponse(response); | ||
mock: { | ||
// node libs | ||
path, | ||
stream, | ||
util, | ||
url, | ||
http, | ||
https, | ||
punycode, | ||
zlib, | ||
// 3rd party libs | ||
atob, | ||
axios, | ||
btoa, | ||
@@ -91,3 +112,4 @@ lodash, | ||
chai, | ||
'crypto-js': CryptoJS | ||
'crypto-js': CryptoJS, | ||
fs: allowScriptFilesystemAccess ? fs : undefined | ||
} | ||
@@ -97,3 +119,4 @@ } | ||
vm.run(testsFile, path.join(collectionPath, 'vm.js')); | ||
const asyncVM = vm.run(`module.exports = async () => { ${testsFile}}`, path.join(collectionPath, 'vm.js')); | ||
await asyncVM(); | ||
@@ -100,0 +123,0 @@ return { |
@@ -1,4 +0,4 @@ | ||
const Test = (__brunoTestResults, chai) => (description, callback) => { | ||
const Test = (__brunoTestResults, chai) => async (description, callback) => { | ||
try { | ||
callback(); | ||
await callback(); | ||
__brunoTestResults.addResult({ description, status: 'pass' }); | ||
@@ -5,0 +5,0 @@ } catch (error) { |
@@ -14,3 +14,3 @@ const jsonQuery = require('json-query'); | ||
/** | ||
* Creates a function from a Javascript expression | ||
* Creates a function from a JavaScript expression | ||
* | ||
@@ -123,3 +123,3 @@ * When the function is called, the variables used in this expression are picked up from the context | ||
/** | ||
* Objects that are created inside vm2 execution context result in an serilaization error when sent to the renderer process | ||
* Objects that are created inside vm2 execution context result in an serialization error when sent to the renderer process | ||
* Error sending from webFrameMain: Error: Failed to serialize arguments | ||
@@ -126,0 +126,0 @@ * at s.send (node:electron/js2c/browser_init:169:631) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
27451
934
5
7