mirror of
https://github.com/usebruno/bruno.git
synced 2024-11-21 23:43:15 +01:00
feat: revert await keyword for test (#2933)
feat: revert await keyword for test
This commit is contained in:
parent
f6c6a3b2bf
commit
b121afe7bb
@ -15,7 +15,7 @@ const BrunoRequest = require('../bruno-request');
|
||||
const BrunoResponse = require('../bruno-response');
|
||||
const Test = require('../test');
|
||||
const TestResults = require('../test-results');
|
||||
const { cleanJson, appendAwaitToTestFunc } = require('../utils');
|
||||
const { cleanJson } = require('../utils');
|
||||
|
||||
// Inbuilt Library Support
|
||||
const ajv = require('ajv');
|
||||
@ -84,8 +84,6 @@ class TestRuntime {
|
||||
};
|
||||
}
|
||||
|
||||
// add 'await' prefix to the test function calls
|
||||
testsFile = appendAwaitToTestFunc(testsFile);
|
||||
|
||||
const context = {
|
||||
test,
|
||||
|
@ -142,15 +142,10 @@ const cleanJson = (data) => {
|
||||
}
|
||||
};
|
||||
|
||||
const appendAwaitToTestFunc = (str) => {
|
||||
return str.replace(/(?<!\.\s*)(?<!await\s)(test\()/g, 'await $1');
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
evaluateJsExpression,
|
||||
evaluateJsTemplateLiteral,
|
||||
createResponseParser,
|
||||
internalExpressionCache,
|
||||
cleanJson,
|
||||
appendAwaitToTestFunc
|
||||
cleanJson
|
||||
};
|
||||
|
@ -1,10 +1,5 @@
|
||||
const { describe, it, expect } = require('@jest/globals');
|
||||
const {
|
||||
evaluateJsExpression,
|
||||
internalExpressionCache: cache,
|
||||
createResponseParser,
|
||||
appendAwaitToTestFunc
|
||||
} = require('../src/utils');
|
||||
const { evaluateJsExpression, internalExpressionCache: cache, createResponseParser } = require('../src/utils');
|
||||
|
||||
describe('utils', () => {
|
||||
describe('expression evaluation', () => {
|
||||
@ -142,70 +137,4 @@ describe('utils', () => {
|
||||
expect(value).toBe(20);
|
||||
});
|
||||
});
|
||||
|
||||
describe('appendAwaitToTestFunc function', () => {
|
||||
it('example 1', () => {
|
||||
const inputTestsString = `
|
||||
test("should return json", function() {
|
||||
const data = res.getBody();
|
||||
expect(res.getBody()).to.eql({
|
||||
"hello": "bruno"
|
||||
});
|
||||
});
|
||||
`;
|
||||
const ouutputTestsString = appendAwaitToTestFunc(inputTestsString);
|
||||
expect(ouutputTestsString).toBe(`
|
||||
await test("should return json", function() {
|
||||
const data = res.getBody();
|
||||
expect(res.getBody()).to.eql({
|
||||
"hello": "bruno"
|
||||
});
|
||||
});
|
||||
`);
|
||||
});
|
||||
|
||||
it('example 2', () => {
|
||||
const inputTestsString = `
|
||||
await test("should return json", function() {
|
||||
const data = res.getBody();
|
||||
expect(res.getBody()).to.eql({
|
||||
"hello": "bruno"
|
||||
});
|
||||
});
|
||||
test("should return json", function() {
|
||||
const data = res.getBody();
|
||||
expect(res.getBody()).to.eql({
|
||||
"hello": "bruno"
|
||||
});
|
||||
});
|
||||
test("should return json", function() {
|
||||
const data = res.getBody();
|
||||
expect(res.getBody()).to.eql({
|
||||
"hello": "bruno"
|
||||
});
|
||||
});
|
||||
`;
|
||||
const ouutputTestsString = appendAwaitToTestFunc(inputTestsString);
|
||||
expect(ouutputTestsString).toBe(`
|
||||
await test("should return json", function() {
|
||||
const data = res.getBody();
|
||||
expect(res.getBody()).to.eql({
|
||||
"hello": "bruno"
|
||||
});
|
||||
});
|
||||
await test("should return json", function() {
|
||||
const data = res.getBody();
|
||||
expect(res.getBody()).to.eql({
|
||||
"hello": "bruno"
|
||||
});
|
||||
});
|
||||
await test("should return json", function() {
|
||||
const data = res.getBody();
|
||||
expect(res.getBody()).to.eql({
|
||||
"hello": "bruno"
|
||||
});
|
||||
});
|
||||
`);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user