Skip to content
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

fix(#263): Implement script- & test-runtime in node:vm #1565

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
5 changes: 1 addition & 4 deletions docs/contributing/contributing_fr.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ Vous aurez besoin de [Node v18.x ou la dernière version LTS](https://nodejs.org

Bruno est développé comme une application _client lourd_. Vous devrez charger l'application en démarrant nextjs dans un premier terminal, puis démarre l'application Electron dans un second.


### Dépendances

- NodeJS v18
Expand Down Expand Up @@ -68,7 +67,6 @@ done
find . -type f -name "package-lock.json" -delete
```


### Tests

```bash
Expand All @@ -79,12 +77,11 @@ npm test --workspace=packages/bruno-schema
npm test --workspace=packages/bruno-lang
```


### Ouvrir une Pull Request

- Merci de conserver les PR minimes et focalisées sur un seul objectif
- Merci de suivre le format de nom des branches :
- feature/[feature name]: Cette branche doit contenir une fonctionnalité spécifique
- Exemple : feature/dark-mode
- bugfix/[bug name]: Cette branche doit contenir seulement une solution pour un bug spécifique
- Exemple : bugfix/bug-1
- Exemple : bugfix/bug-1
10 changes: 4 additions & 6 deletions docs/readme/readme_cn.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<br />
<img src="../../assets/images/logo-transparent.png" width="80"/>

### Bruno - 开源IDE,用于探索和测试API
### Bruno - 开源 IDE,用于探索和测试 API

[![GitHub version](https://badge.fury.io/gh/usebruno%2Fbruno.svg)](https://badge.fury.io/gh/usebruno%bruno)
[![CI](https://github.com/usebruno/bruno/actions/workflows/unit-tests.yml/badge.svg?branch=main)](https://github.com/usebruno/bruno/workflows/unit-tests.yml)
Expand All @@ -12,16 +12,14 @@

[English](../../readme.md) | [Українська](./readme_ua.md) | [Русский](./readme_ru.md) | [Türkçe](./readme_tr.md) | [Deutsch](./readme_de.md) | [Français](./readme_fr.md) | [Português (BR)](./readme_pt_br.md) | [한국어](./readme_kr.md) | [বাংলা](./readme_bn.md) | [Español](./readme_es.md) | [Italiano](./readme_it.md) | [Română](./readme_ro.md) | [Polski](./readme_pl.md) | [简体中文](./readme_cn.md)


Bruno 是一款全新且创新的 API 客户端,旨在颠覆 Postman 和其他类似工具。

Bruno 直接在您的电脑文件夹中存储您的 API 信息。我们使用纯文本标记语言 Bru 来保存有关 API 的信息。

您可以使用 Git 或您选择的任何版本控制系统来对您的API信息进行版本控制和协作
您可以使用 Git 或您选择的任何版本控制系统来对您的 API 信息进行版本控制和协作

Bruno 仅限离线使用。我们计划永不向 Bruno 添加云同步功能。我们重视您的数据隐私,并认为它应该留在您的设备上。阅读我们的长期愿景 [点击查看](https://github.com/usebruno/bruno/discussions/269)


📢 观看我们在印度 FOSS 3.0 会议上的最新演讲 [点击查看](https://www.youtube.com/watch?v=7bSMFpbcPiY)

![bruno](../../assets/images/landing-2.png) <br /><br />
Expand Down Expand Up @@ -97,9 +95,9 @@ sudo apt install bruno

### 贡献 👩‍💻🧑‍💻

我很高兴您希望改进bruno。请查看 [贡献指南](../../contributing.md)。
我很高兴您希望改进 bruno。请查看 [贡献指南](../../contributing.md)。

即使您无法通过代码做出贡献,我们仍然欢迎您提出BUG和新的功能需求
即使您无法通过代码做出贡献,我们仍然欢迎您提出 BUG 和新的功能需求

### 作者

Expand Down
7 changes: 2 additions & 5 deletions docs/readme/readme_fr.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
[![Website](https://img.shields.io/badge/Website-Visit-blue)](https://www.usebruno.com)
[![Download](https://img.shields.io/badge/Download-Latest-brightgreen)](https://www.usebruno.com/downloads)


[English](/readme.md) | [Українська](docs/readme/readme_ua.md) | [Русский](docs/readme/readme_ru.md) | [Türkçe](docs/readme/readme_tr.md) | [Deutsch](docs/readme/readme_de.md) | **Français** | [Português (BR)](docs/readme/readme_pt_br.md) | [한국어](docs/readme/readme_kr.md) | [বাংলা](docs/readme/readme_bn.md) | [Español](docs/readme/readme_es.md) | [Italiano](docs/readme/readme_it.md) | [Română](docs/readme/readme_ro.md) | [Polski](docs/readme/readme_pl.md)

Bruno est un nouveau client API, innovant, qui a pour but de révolutionner le _statu quo_ que représente Postman et les autres outils.
Expand All @@ -21,17 +20,15 @@ Vous pouvez utiliser git ou tout autre gestionnaire de version pour travailler d

Bruno ne fonctionne qu'en mode déconnecté. Il n'y a pas d'abonnement ou de synchronisation avec le cloud Bruno, il n'y en aura jamais. Nous sommes conscients de la confidentialité de vos données et nous sommes convaincus qu'elles doivent rester sur vos appareils. Vous pouvez lire notre vision à long terme [ici (en anglais)](https://github.com/usebruno/bruno/discussions/269).


📢 Regarder notre présentation récente lors de la conférence India FOSS 3.0 (en anglais) [ici](https://www.youtube.com/watch?v=7bSMFpbcPiY)

📢 Regarder notre présentation récente lors de la conférence India FOSS 3.0 (en anglais) [ici](https://www.youtube.com/watch?v=7bSMFpbcPiY)

![bruno](/assets/images/landing-2.png) <br /><br />

### Installation

Bruno est disponible au téléchargement [sur notre site web](https://www.usebruno.com/downloads), pour Mac, Windows et Linux.

Vous pouvez aussi installer Bruno via un gestionnaire de paquets, comme Homebrew, Chocolatey, Scoop, Snap et Apt.
Vous pouvez aussi installer Bruno via un gestionnaire de paquets, comme Homebrew, Chocolatey, Scoop, Snap et Apt.

```sh
# Mac via Homebrew
Expand Down
8 changes: 0 additions & 8 deletions package-lock.json

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

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
"test:prettier:web": "npm run test:prettier --workspace=packages/bruno-app",
"prepare": "husky install"
},

"overrides": {
"rollup": "3.2.5"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ const QueryResult = ({ item, collection, data, dataBuffer, width, disableRunEven
</div>
{error ? (
<div>
<div className="text-red-500">{error}</div>
<pre className="text-red-500 whitespace-pre-wrap">{error}</pre>

{error && typeof error === 'string' && error.toLowerCase().includes('self signed certificate') ? (
<div className="mt-6 muted text-xs">
Expand Down
1 change: 1 addition & 0 deletions packages/bruno-cli/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ Thank you for using Bruno CLI!
## Changelog

<!-- An absolute link is used here because npm treats links differently -->

See [https://github.com/usebruno/bruno/releases](https://github.com/usebruno/bruno/releases)

## License
Expand Down
109 changes: 84 additions & 25 deletions packages/bruno-cli/src/runner/run-single-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const FormData = require('form-data');
const prepareRequest = require('./prepare-request');
const interpolateVars = require('./interpolate-vars');
const { interpolateString } = require('./interpolate-string');
const { ScriptRuntime, TestRuntime, VarsRuntime, AssertRuntime } = require('@usebruno/js');
const { ScriptRuntime, TestRuntime, VarsRuntime, AssertRuntime, runScript } = require('@usebruno/js');
const { stripExtension } = require('../utils/filesystem');
const { getOptions } = require('../utils/bru');
const https = require('https');
Expand Down Expand Up @@ -72,21 +72,41 @@ const runSingleRequest = async function (
get(collectionRoot, 'request.script.req'),
get(bruJson, 'request.script.req')
]).join(os.EOL);
if (requestScriptFile?.length) {
const scriptRuntime = new ScriptRuntime();
const result = await scriptRuntime.runRequestScript(
if (scriptingConfig?.runtime === 'node') {
const result = await runScript(
decomment(requestScriptFile),
request,
envVariables,
collectionVariables,
collectionPath,
null,
processEnvVars,
scriptingConfig
{
envVariables,
collectionVariables,
processEnvVars
},
false,
collectionPath,
scriptingConfig,
null
);
if (result?.nextRequestName !== undefined) {
nextRequestName = result.nextRequestName;
}
} else {
if (requestScriptFile?.length) {
const scriptRuntime = new ScriptRuntime();
const result = await scriptRuntime.runRequestScript(
decomment(requestScriptFile),
request,
envVariables,
collectionVariables,
collectionPath,
null,
processEnvVars,
scriptingConfig
);
if (result?.nextRequestName !== undefined) {
nextRequestName = result.nextRequestName;
}
}
}

// interpolate variables inside request
Expand Down Expand Up @@ -276,22 +296,42 @@ const runSingleRequest = async function (
get(collectionRoot, 'request.script.res'),
get(bruJson, 'request.script.res')
]).join(os.EOL);
if (responseScriptFile?.length) {
const scriptRuntime = new ScriptRuntime();
const result = await scriptRuntime.runResponseScript(
if (scriptingConfig?.runtime === 'node') {
const result = await runScript(
decomment(responseScriptFile),
request,
response,
envVariables,
collectionVariables,
{
envVariables,
collectionVariables,
processEnvVars
},
false,
collectionPath,
null,
processEnvVars,
scriptingConfig
scriptingConfig,
null
);
if (result?.nextRequestName !== undefined) {
nextRequestName = result.nextRequestName;
}
} else {
if (responseScriptFile?.length) {
const scriptRuntime = new ScriptRuntime();
const result = await scriptRuntime.runResponseScript(
decomment(responseScriptFile),
request,
response,
envVariables,
collectionVariables,
collectionPath,
null,
processEnvVars,
scriptingConfig
);
if (result?.nextRequestName !== undefined) {
nextRequestName = result.nextRequestName;
}
}
}

// run assertions
Expand Down Expand Up @@ -321,20 +361,39 @@ const runSingleRequest = async function (
// run tests
let testResults = [];
const testFile = compact([get(collectionRoot, 'request.tests'), get(bruJson, 'request.tests')]).join(os.EOL);
if (typeof testFile === 'string') {
const testRuntime = new TestRuntime();
const result = await testRuntime.runTests(

if (scriptingConfig?.runtime === 'node') {
const result = await runScript(
decomment(testFile),
request,
response,
envVariables,
collectionVariables,
{
envVariables,
collectionVariables,
processEnvVars
},
true,
collectionPath,
null,
processEnvVars,
scriptingConfig
scriptingConfig,
null
);
testResults = get(result, 'results', []);
} else {
if (typeof testFile === 'string') {
const testRuntime = new TestRuntime();
const result = await testRuntime.runTests(
decomment(testFile),
request,
response,
envVariables,
collectionVariables,
collectionPath,
null,
processEnvVars,
scriptingConfig
);
testResults = get(result, 'results', []);
}
}

if (testResults?.length) {
Expand Down
Loading