Skip to content

Commit

Permalink
Initial tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Dec 1, 2019
1 parent 46a5a81 commit 73bdefe
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 2 deletions.
8 changes: 8 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: ~> 1.0
language: node_js
os:
- linux
import:
- ljharb/travis-ci:node/all.yml
- ljharb/travis-ci:node/pretest.yml
- ljharb/travis-ci:node/posttest.yml
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
"scripts": {
"lint": "eslint .",
"pretest": "npm run lint",
"test": "echo \"Error: no test specified\" && exit 1"
"tests-only": "node test",
"test": "npm run tests-only",
"posttest": "npx aud"
},
"repository": {
"type": "git",
Expand All @@ -30,6 +32,7 @@
"homepage": "https://github.com/ljharb/side-channel#readme",
"devDependencies": {
"@ljharb/eslint-config": "^15.0.2",
"eslint": "^6.7.2"
"eslint": "^6.7.2",
"tape": "^4.11.0"
}
}
69 changes: 69 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
'use strict';

var test = require('tape');

var getSideChannel = require('../');

test('export', function (t) {
t.equal(typeof getSideChannel, 'function', 'is a function');
t.equal(getSideChannel.length, 0, 'takes no arguments');

var channel = getSideChannel();
t.ok(channel, 'is truthy');
t.equal(typeof channel, 'object', 'is an object');

t.end();
});

test('assert', function (t) {
var channel = getSideChannel();
t['throws'](
function () { channel.assert({}); },
TypeError,
'nonexistent value throws'
);

var o = {};
channel.set(o, 'data');
t.doesNotThrow(function () { channel.assert(o); }, 'existent value noops');

t.end();
});

test('has', function (t) {
var channel = getSideChannel();
var o = [];

t.equal(channel.has(o), false, 'nonexistent value yields false');

channel.set(o, 'foo');
t.equal(channel.has(o), true, 'existent value yields true');

t.end();
});

test('get', function (t) {
var channel = getSideChannel();
var o = {};
t.equal(channel.get(o), undefined, 'nonexistent value yields undefined');

var data = {};
channel.set(o, data);
t.equal(channel.get(o), data, '"get" yields data set by "set"');

t.end();
});

test('set', function (t) {
var channel = getSideChannel();
var o = function () {};
t.equal(channel.get(o), undefined, 'value not set');

channel.set(o, 42);
t.equal(channel.get(o), 42, 'value was set');

channel.set(o, Infinity);
t.equal(channel.get(o), Infinity, 'value was set again');

t.end();
});

0 comments on commit 73bdefe

Please sign in to comment.