Skip to content

Commit

Permalink
Add test should queue clear
Browse files Browse the repository at this point in the history
  • Loading branch information
timursevimli committed Jan 13, 2024
1 parent 8993793 commit 7cc1a71
Showing 1 changed file with 26 additions and 7 deletions.
33 changes: 26 additions & 7 deletions test/unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
const { test, plan } = require('tap');
const Queue = require('../queue.js');

plan(16);
plan(17);

const items = new Array(10).fill('test').map((e, i) => e + i);

test('Done handling', (t) => {
let doneCalled = false;
Expand Down Expand Up @@ -218,7 +220,6 @@ test('Drain handling', (t) => {
});

test('Should task handling: async', (t) => {
const items = new Array(100).fill('item').map((e, i) => e + i);
const results = [];

const queue = new Queue(1)
Expand Down Expand Up @@ -248,7 +249,6 @@ test('Should task handling: async', (t) => {
});

test('Should task handling: callback', (t) => {
const items = new Array(100).fill('item').map((e, i) => e + i);
const results = [];

const queue = new Queue(1)
Expand All @@ -274,7 +274,6 @@ test('Should task handling: callback', (t) => {
});

test('Should task handling: promise', (t) => {
const items = new Array(100).fill('item').map((e, i) => e + i);
const results = [];

const queue = new Queue(1)
Expand Down Expand Up @@ -302,7 +301,6 @@ test('Should task handling: promise', (t) => {
});

test('Should task handling: multiple', (t) => {
const items = new Array(100).fill('item').map((e, i) => e + i);
const results = [];

const queue = new Queue(1)
Expand Down Expand Up @@ -396,8 +394,6 @@ test('Should add task without process', (t) => {
});

test('Queue pipe handling', (t) => {
const items = new Array(100).fill('item').map((e, i) => e + i);

const dest1 = new Queue(1)
.process((item, callback) => {
setTimeout(() => {
Expand Down Expand Up @@ -439,3 +435,26 @@ test('Queue pipe handling', (t) => {
queue.add(item);
}
});

test('Should queue clear', (t) => {
const queue = new Queue(1).pause();

const dest = new Queue(1);

queue.pipe(dest);

t.plan(5);

queue.add('test1');
queue.add('test2');
queue.add('test3');

t.equal(queue.waiting.length, 3);
t.equal(queue.destination, dest);

queue.clear();

t.equal(queue.waiting.length, 0);
t.equal(queue.count, 0);
t.equal(queue.destination, null);
});

0 comments on commit 7cc1a71

Please sign in to comment.