Skip to content

Commit

Permalink
Adding tests for log lines
Browse files Browse the repository at this point in the history
  • Loading branch information
rishigupta1599 committed Nov 24, 2023
1 parent 65394eb commit 9d48829
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions packages/core/test/unit/queue.test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { AbortController, generatePromise, waitForTimeout } from '../../src/utils.js';
import Queue from '../../src/queue.js';
import { logger, setupTest } from '../helpers/index.js';

describe('Unit / Tasks Queue', () => {
let q;

beforeEach(() => {
beforeEach(async () => {
q = new Queue('test');
await setupTest();
});

it('has a customizable concurrency', () => {
Expand Down Expand Up @@ -238,10 +240,10 @@ describe('Unit / Tasks Queue', () => {
let p1 = q.push('item #1');
let p2 = q.push('item #2');
expect(q.size).toBe(2);

q.log.loglevel('debug');
q.close(true);
expect(logger.stderr).toEqual(jasmine.arrayContaining(['[percy:core:queue] Clearing test queue, queued state: 2, pending state: 0']));
expect(q.size).toBe(0);

await expectAsync(p1)
.toBeRejectedWithError('This operation was aborted');
await expectAsync(p2)
Expand Down Expand Up @@ -403,13 +405,15 @@ describe('Unit / Tasks Queue', () => {

it('flushing queued task', async () => {
q.set({ concurrency: 1 });
q.log.loglevel('debug');
await q.start();
let resolve, deferred = new Promise(r => (resolve = r));
q.readyState = 2;
q.push('item_1');
let p1 = q.push(deferred);
expect(q.size).toBe(2);
let promise = generatePromise(q.flush());
expect(logger.stderr).toEqual(jasmine.arrayContaining(['[percy:core:queue] Flushing test queue, queued state: 1, pending state: 1']));
await expectAsync(promise).toBePending();
await expectAsync(p1).toBePending();
q.process(deferred);
Expand All @@ -421,10 +425,12 @@ describe('Unit / Tasks Queue', () => {

it('empty flush', async () => {
q.set({ concurrency: 1 });
q.log.loglevel('debug');
await q.start();
q.readyState = 2;
expect(q.size).toBe(0);
let promise = generatePromise(q.flush());
expect(logger.stderr).toEqual(jasmine.arrayContaining(['[percy:core:queue] Flushing test queue, queued state: 0, pending state: 0']));
await expectAsync(promise).toBePending();
await expectAsync(promise).toBeResolved();
});
Expand Down

0 comments on commit 9d48829

Please sign in to comment.