Skip to content

Commit

Permalink
chore: update test runner
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeed committed Feb 18, 2021
1 parent 06a3b68 commit 56b9c4f
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 22 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
node_modules
.DS_Store
*-lock.*
*.lock
*.log

Expand Down
9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
},
"scripts": {
"build": "bundt",
"pretest": "npm run build",
"test": "tape test/*.js | tap-spec"
"test": "uvu -r esm test"
},
"files": [
"dist"
Expand All @@ -37,8 +36,8 @@
"serialize"
],
"devDependencies": {
"bundt": "^0.1.1",
"tap-spec": "^4.1.1",
"tape": "^4.6.3"
"bundt": "1.1.2",
"esm": "3.2.25",
"uvu": "0.5.1"
}
}
87 changes: 70 additions & 17 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,75 @@
const test = require('tape');
const fn = require('../dist/obj-str');
import { suite } from 'uvu';
import * as assert from 'uvu/assert';
import objstr from '../src';

const one = true;
const two = true;
const bad = false;
const key = 'abc';
function is(input, expect) {
assert.is(objstr(input), expect);
}

test('obj-str', t => {
t.equal(typeof fn, 'function', 'exports a function');
const API = suite('exports');

t.equal(fn(), '', 'returns empty string by default');
t.equal(fn({}), '', `{} --> ''`);
t.equal(fn({foo: true}), 'foo', `{ foo:true } --> foo`);
t.equal(fn({foo: true, bar: false}), 'foo', `{ foo:true, bar:false } --> foo`);
t.equal(fn({foo: 1 === 1, bar: 1 !== 1, baz: 1 !== 2}), 'foo baz', `{ foo:1===1, bar:1!==1, baz:1!==2 } --> foo baz`);
t.equal(fn({one, two, bad}), 'one two', `{ one, two, bad } --> one two`);
t.equal(fn({'-foo': true}), '-foo', `{ '-foo':true } --> -foo`);
t.equal(fn({[key]: true}), 'abc', `{ [key]:true } --> abc`);
API('should export a function', () => {
assert.type(objstr, 'function');
});

API.run();

// ---

const usage = suite('usage');

usage('true -> ""', () => {
is(true, '');
});

usage('false -> ""', () => {
is(false, '');
});

usage('undefined -> ""', () => {
is(undefined, '');
});

usage('null -> ""', () => {
is(null, '');
});

usage('{} -> ""', () => {
is({}, '');
});

t.end();
usage('[] -> ""', () => {
is([], '');
});

usage('{ foo } -> "foo"', () => {
is({ foo: true }, 'foo');
is({ foo: 1 }, 'foo');
});

usage('{ foo, bar } -> "foo"', () => {
is({ foo: true, bar: false }, 'foo');
is({ foo: 1, bar: 0 }, 'foo');
});

usage('{ foo, bar, baz } -> "foo baz"', () => {
is({ foo: 1 === 1, bar: 1 !== 1, baz: 1 !== 2 }, 'foo baz');
is({ foo: assert, bar: null, baz: Date }, 'foo baz');
});

usage('{ one, two, bad } -> "one two"', () => {
let one=true, two=true, bad=false;
is({ one, two, bad }, 'one two');
});

usage('{ "-foo": x } -> "-foo"', () => {
is({ '-foo': true }, '-foo');
is({ '-foo': 0, '-foo': 1 }, '-foo');
});

usage('{ [key]: x } -> key', () => {
let key = 'abc';
is({ [key]: true }, 'abc');
});

usage.run();

0 comments on commit 56b9c4f

Please sign in to comment.