mirror of
https://github.com/usebruno/bruno.git
synced 2025-01-03 12:39:34 +01:00
Adds some simple unit tests around printRunSummary
This commit is contained in:
parent
9bcf56d689
commit
5f32924ddb
42
.github/workflows/unit-tests.yml
vendored
42
.github/workflows/unit-tests.yml
vendored
@ -1,29 +1,31 @@
|
|||||||
name: Unit Tests
|
name: Unit Tests
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [ main ]
|
branches: [main]
|
||||||
pull_request:
|
pull_request:
|
||||||
branches: [ main ]
|
branches: [main]
|
||||||
jobs:
|
jobs:
|
||||||
test:
|
test:
|
||||||
timeout-minutes: 60
|
timeout-minutes: 60
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
- uses: actions/setup-node@v3
|
- uses: actions/setup-node@v3
|
||||||
with:
|
with:
|
||||||
node-version: 16
|
node-version: 16
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: npm i --legacy-peer-deps
|
run: npm i --legacy-peer-deps
|
||||||
- name: Test Package bruno-query
|
- name: Test Package bruno-query
|
||||||
run: npm run test --workspace=packages/bruno-query
|
run: npm run test --workspace=packages/bruno-query
|
||||||
- name: Build Package bruno-query
|
- name: Build Package bruno-query
|
||||||
run: npm run build --workspace=packages/bruno-query
|
run: npm run build --workspace=packages/bruno-query
|
||||||
- name: Test Package bruno-lang
|
- name: Test Package bruno-lang
|
||||||
run: npm run test --workspace=packages/bruno-lang
|
run: npm run test --workspace=packages/bruno-lang
|
||||||
- name: Test Package bruno-schema
|
- name: Test Package bruno-schema
|
||||||
run: npm run test --workspace=packages/bruno-schema
|
run: npm run test --workspace=packages/bruno-schema
|
||||||
- name: Test Package bruno-app
|
- name: Test Package bruno-app
|
||||||
run: npm run test --workspace=packages/bruno-app
|
run: npm run test --workspace=packages/bruno-app
|
||||||
- name: Test Package bruno-js
|
- name: Test Package bruno-js
|
||||||
run: npm run test --workspace=packages/bruno-js
|
run: npm run test --workspace=packages/bruno-js
|
||||||
|
- name: Test Package bruno-cli
|
||||||
|
run: npm run test --workspace=packages/bruno-cli
|
||||||
|
@ -13,6 +13,9 @@
|
|||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "git+https://github.com/usebruno/bruno.git"
|
"url": "git+https://github.com/usebruno/bruno.git"
|
||||||
},
|
},
|
||||||
|
"scripts": {
|
||||||
|
"test": "jest"
|
||||||
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"src",
|
"src",
|
||||||
"bin",
|
"bin",
|
||||||
|
@ -389,5 +389,6 @@ module.exports = {
|
|||||||
command,
|
command,
|
||||||
desc,
|
desc,
|
||||||
builder,
|
builder,
|
||||||
handler
|
handler,
|
||||||
|
printRunSummary
|
||||||
};
|
};
|
||||||
|
67
packages/bruno-cli/src/commands/run.test.js
Normal file
67
packages/bruno-cli/src/commands/run.test.js
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
const { describe, it, expect } = require('@jest/globals');
|
||||||
|
|
||||||
|
const { printRunSummary } = require('./run');
|
||||||
|
|
||||||
|
describe('printRunSummary', () => {
|
||||||
|
// Suppress console.log output
|
||||||
|
jest.spyOn(console, 'log').mockImplementation(() => {});
|
||||||
|
|
||||||
|
it('should produce the correct summary for a successful run', () => {
|
||||||
|
const results = [
|
||||||
|
{
|
||||||
|
testResults: [{ status: 'pass' }, { status: 'pass' }, { status: 'pass' }],
|
||||||
|
assertionResults: [{ status: 'pass' }, { status: 'pass' }],
|
||||||
|
error: null
|
||||||
|
},
|
||||||
|
{
|
||||||
|
testResults: [{ status: 'pass' }, { status: 'pass' }],
|
||||||
|
assertionResults: [{ status: 'pass' }, { status: 'pass' }, { status: 'pass' }],
|
||||||
|
error: null
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
const summary = printRunSummary(results);
|
||||||
|
|
||||||
|
expect(summary.totalRequests).toBe(2);
|
||||||
|
expect(summary.passedRequests).toBe(2);
|
||||||
|
expect(summary.failedRequests).toBe(0);
|
||||||
|
expect(summary.totalAssertions).toBe(5);
|
||||||
|
expect(summary.passedAssertions).toBe(5);
|
||||||
|
expect(summary.failedAssertions).toBe(0);
|
||||||
|
expect(summary.totalTests).toBe(5);
|
||||||
|
expect(summary.passedTests).toBe(5);
|
||||||
|
expect(summary.failedTests).toBe(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should produce the correct summary for a failed run', () => {
|
||||||
|
const results = [
|
||||||
|
{
|
||||||
|
testResults: [{ status: 'fail' }, { status: 'pass' }, { status: 'pass' }],
|
||||||
|
assertionResults: [{ status: 'pass' }, { status: 'fail' }],
|
||||||
|
error: null
|
||||||
|
},
|
||||||
|
{
|
||||||
|
testResults: [{ status: 'pass' }, { status: 'fail' }],
|
||||||
|
assertionResults: [{ status: 'pass' }, { status: 'fail' }, { status: 'fail' }],
|
||||||
|
error: null
|
||||||
|
},
|
||||||
|
{
|
||||||
|
testResults: [],
|
||||||
|
assertionResults: [],
|
||||||
|
error: new Error('Request failed')
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
const summary = printRunSummary(results);
|
||||||
|
|
||||||
|
expect(summary.totalRequests).toBe(3);
|
||||||
|
expect(summary.passedRequests).toBe(2);
|
||||||
|
expect(summary.failedRequests).toBe(1);
|
||||||
|
expect(summary.totalAssertions).toBe(5);
|
||||||
|
expect(summary.passedAssertions).toBe(2);
|
||||||
|
expect(summary.failedAssertions).toBe(3);
|
||||||
|
expect(summary.totalTests).toBe(5);
|
||||||
|
expect(summary.passedTests).toBe(3);
|
||||||
|
expect(summary.failedTests).toBe(2);
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in New Issue
Block a user