mirror of
https://github.com/usebruno/bruno.git
synced 2025-08-15 08:22:53 +02:00
feat: allow test to be asynchrone
This commit is contained in:
53
packages/bruno-js/tests/runtime.spec.js
Normal file
53
packages/bruno-js/tests/runtime.spec.js
Normal file
@ -0,0 +1,53 @@
|
||||
const { describe, it, expect } = require('@jest/globals');
|
||||
const TestRuntime = require('../src/runtime/test-runtime');
|
||||
|
||||
describe('runtime', () => {
|
||||
describe('test-runtime', () => {
|
||||
const baseRequest = {
|
||||
method: 'GET',
|
||||
url: 'http://localhost:3000/',
|
||||
headers: {},
|
||||
data: undefined
|
||||
};
|
||||
const baseResponse = {
|
||||
status: 200,
|
||||
statusText: 'OK',
|
||||
data: [
|
||||
{
|
||||
id: 1
|
||||
},
|
||||
{
|
||||
id: 2
|
||||
},
|
||||
{
|
||||
id: 3
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
it('should wait async tests', async () => {
|
||||
const testFile = `
|
||||
await test('async test', ()=> {
|
||||
return new Promise((resolve)=> {
|
||||
setTimeout(()=> {resolve()},200)
|
||||
})
|
||||
})
|
||||
`;
|
||||
|
||||
const runtime = new TestRuntime();
|
||||
const result = await runtime.runTests(
|
||||
testFile,
|
||||
{ ...baseRequest },
|
||||
{ ...baseResponse },
|
||||
{},
|
||||
{},
|
||||
'.',
|
||||
null,
|
||||
process.env
|
||||
);
|
||||
expect(result.results.map((el) => ({ description: el.description, status: el.status }))).toEqual([
|
||||
{ description: 'async test', status: 'pass' }
|
||||
]);
|
||||
});
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user