Add test coverage.

This commit is contained in:
David Braun 2017-12-06 14:30:53 -05:00
parent 9da406e58f
commit 4315a28f0c
4 changed files with 37 additions and 7 deletions

1
.gitignore vendored
View file

@ -1,3 +1,4 @@
.nyc_output
.vscode .vscode
coverage coverage
node_modules node_modules

View file

@ -223,7 +223,9 @@ const Channel = function(length = 0) {
slice: (start, end = Infinity) => { slice: (start, end = Infinity) => {
const output = Channel(); const output = Channel();
(async () => { (async () => {
// Consume values before the starting point.
for (let index = 0; index < start; index++) { for (let index = 0; index < start; index++) {
const value = await readOnly.shift(); const value = await readOnly.shift();

View file

@ -13,14 +13,11 @@
"dependencies": {}, "dependencies": {},
"devDependencies": { "devDependencies": {
"@nodeguy/assert": "0.1.4", "@nodeguy/assert": "0.1.4",
"mocha": "4.0.1" "mocha": "4.0.1",
"nyc": "11.3.0"
}, },
"homepage": "https://github.com/NodeGuy/channel", "homepage": "https://github.com/NodeGuy/channel",
"keywords": [ "keywords": ["CSP", "channel", "concurrency"],
"CSP",
"channel",
"concurrency"
],
"license": "Apache-2.0", "license": "Apache-2.0",
"main": "lib/index.js", "main": "lib/index.js",
"repository": { "repository": {
@ -28,6 +25,14 @@
"url": "git+https://github.com/NodeGuy/channel.git" "url": "git+https://github.com/NodeGuy/channel.git"
}, },
"scripts": { "scripts": {
"test": "mocha --recursive" "test": "nyc mocha --recursive"
},
"nyc": {
"check-coverage": true,
"branches": 100,
"functions": 100,
"lines": 100,
"statements": 100,
"reporter": ["html", "text-summary"]
} }
} }

View file

@ -136,6 +136,7 @@ describe(`Channel`, function() {
const channel = Channel(); const channel = Channel();
Channel.select([channel.push(`cancelled`)]).cancel(); Channel.select([channel.push(`cancelled`)]).cancel();
const closed = Channel.of(); const closed = Channel.of();
assert.equal( assert.equal(
await Channel.select([channel.shift(), closed.shift()]), await Channel.select([channel.shift(), closed.shift()]),
closed closed
@ -211,6 +212,18 @@ describe(`Channel object`, function() {
channel.close(); channel.close();
assert.strictEqual(await channel.shift(), undefined); assert.strictEqual(await channel.shift(), undefined);
}); });
it(`Don't set 'lastValue' to 'undefined' when closing a channel with a cancelled shift.`, async function() {
const channel = Channel();
// Set lastValue to 0.
channel.push(0);
await channel.shift();
channel.shift().cancel();
channel.close();
assert.strictEqual(channel.value(), 0);
});
}); });
it(`concat`, async function() { it(`concat`, async function() {
@ -386,6 +399,15 @@ describe(`Channel object`, function() {
[1, 2, 3] [1, 2, 3]
); );
}); });
it(`start after end of channel`, async function() {
assert.deepEqual(
await Channel.of(0, 1, 2)
.slice(10)
.values(),
[]
);
});
}); });
it(`some`, async function() { it(`some`, async function() {