Skip to content

Commit

Permalink
ci: improve each module coverage (#219)
Browse files Browse the repository at this point in the history
* Increments coverage adding each service unit tests

* Removes comments
  • Loading branch information
robertolemesp authored Apr 29, 2024
1 parent 529a1f9 commit d61b519
Show file tree
Hide file tree
Showing 2 changed files with 176 additions and 0 deletions.
86 changes: 86 additions & 0 deletions test/unit/each-promise.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import {
describe,
assert,
beforeEach,
afterEach,
test,
} from '../../src/index.js';

describe('Asynchronous Before and After Each Suite', {
background: false,
icon: '🔬',
});

let counter = 0;

const asyncPreIncrement = async () =>
await new Promise((resolve) => resolve(++counter));

const beforeEachHelper = beforeEach(asyncPreIncrement, { immediate: true });

const afterEachHelper = afterEach(asyncPreIncrement, {});

test(() => {
assert.equal(
counter,
2,
'value incremented by 1 from beforeEach with immediate option should be 2'
);
});

test(() => {
assert.equal(
counter,
4,
'value incremented by 1 from beforeEach with immediate option and by 1 from previous test with afterEach should be 4'
);
});

afterEachHelper.pause();
beforeEachHelper.pause();

test(() => {
assert.equal(
counter,
5,
'value should still 5 by pausing both beforeEach and afterEach, considering the abscence of beforeEach effect'
);
});

test(() => {
assert.equal(
counter,
5,
'value should still 5 by pausing both beforeEach and afterEach, considering the the abscence of beforeEach and afterEach (from previous test) effects'
);
});

afterEachHelper.continue();
beforeEachHelper.continue();

test(() => {
assert.equal(
counter,
6,
'value incremented by 1 from unpausing beforeEach should be 6'
);
});

test(() => {
assert.equal(
counter,
8,
'value incremented by 1 from beforeEach and 1 by previous test with afterEach should be 8'
);
});

beforeEachHelper.reset();
afterEachHelper.reset();

test(() => {
assert.equal(
counter,
9,
'value should still 9 by reseting both beforeEach and afterEach'
);
});
90 changes: 90 additions & 0 deletions test/unit/each.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import {
describe,
assert,
beforeEach,
afterEach,
test,
} from '../../src/index.js';

describe('Before and After Each Suite', {
background: false,
icon: '🔬',
});

let counter = 0;

const beforeEachHelper = beforeEach(
() => {
++counter;
},
{ immediate: true }
);

const afterEachHelper = afterEach(() => {
++counter;
}, {});

test(() => {
assert.equal(
counter,
2,
'value incremented by 1 from beforeEach with immediate option should be 2'
);
});

test(() => {
assert.equal(
counter,
4,
'value incremented by 1 from beforeEach with immediate option and by 1 from previous test with afterEach should be 4'
);
});

afterEachHelper.pause();
beforeEachHelper.pause();

test(() => {
assert.equal(
counter,
5,
'value should still 5 by pausing both beforeEach and afterEach, considering the abscence of beforeEach effect'
);
});

test(() => {
assert.equal(
counter,
5,
'value should still 5 by pausing both beforeEach and afterEach, considering the the abscence of beforeEach and afterEach (from previous test) effects'
);
});

afterEachHelper.continue();
beforeEachHelper.continue();

test(() => {
assert.equal(
counter,
6,
'value incremented by 1 from unpausing beforeEach should be 6'
);
});

test(() => {
assert.equal(
counter,
8,
'value incremented by 1 from beforeEach and 1 by previous test with afterEach should be 8'
);
});

beforeEachHelper.reset();
afterEachHelper.reset();

test(() => {
assert.equal(
counter,
9,
'value should still 9 by reseting both beforeEach and afterEach'
);
});

0 comments on commit d61b519

Please sign in to comment.