Skip to content

Commit

Permalink
chore: tape -> uvu tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeed committed Jul 2, 2022
1 parent bc4f827 commit 1c36d10
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 120 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
nodejs: [6, 8, 10, 12, 14, 16]
nodejs: [8, 10, 12, 14, 16]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
Expand All @@ -28,6 +28,9 @@ jobs:
if: matrix.nodejs >= 16
run: npm install -g nyc

- name: Build
run: npm run build

- name: Test
run: npm test
if: matrix.nodejs < 16
Expand Down
6 changes: 2 additions & 4 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 -r esm test/*.js | tap-spec"
"test": "uvu -r esm test"
},
"files": [
"*.d.ts",
Expand All @@ -33,7 +32,6 @@
"devDependencies": {
"bundt": "1.0.1",
"esm": "3.2.25",
"tap-spec": "5.0.0",
"tape": "4.9.1"
"uvu": "0.5.4"
}
}
90 changes: 39 additions & 51 deletions test/classnames.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,84 +2,71 @@
* Ported from `classnames` for compatibility checks.
*/

import test from 'tape';
import fn from '../src';
import { test } from 'uvu';
import * as assert from 'uvu/assert';
import clsx from '../src';

test('(compat) keeps object keys with truthy values', t => {
const out = fn({ a:true, b:false, c:0, d:null, e:undefined, f:1 });
t.is(out, 'a f');
t.end();
test('(compat) keeps object keys with truthy values', () => {
const out = clsx({ a:true, b:false, c:0, d:null, e:undefined, f:1 });
assert.is(out, 'a f');
});

test('(compat) joins arrays of class names and ignore falsy values', t => {
const out = fn('a', 0, null, undefined, true, 1, 'b');
t.is(out, 'a 1 b');
t.end();
test('(compat) joins arrays of class names and ignore falsy values', () => {
const out = clsx('a', 0, null, undefined, true, 1, 'b');
assert.is(out, 'a 1 b');
});

test('(compat) supports heterogenous arguments', t => {
t.is(fn({ a:true }, 'b', 0), 'a b');
t.end();
test('(compat) supports heterogenous arguments', () => {
assert.is(clsx({ a:true }, 'b', 0), 'a b');
});

test('(compat) should be trimmed', t => {
t.is(fn('', 'b', {}, ''), 'b');
t.end();
test('(compat) should be trimmed', () => {
assert.is(clsx('', 'b', {}, ''), 'b');
});

test('(compat) returns an empty string for an empty configuration', t => {
t.is(fn({}), '');
t.end();
test('(compat) returns an empty string for an empty configuration', () => {
assert.is(clsx({}), '');
});

test('(compat) supports an array of class names', t => {
t.is(fn(['a', 'b']), 'a b');
t.end();
test('(compat) supports an array of class names', () => {
assert.is(clsx(['a', 'b']), 'a b');
});

test('(compat) joins array arguments with string arguments', t => {
t.is(fn(['a', 'b'], 'c'), 'a b c');
t.is(fn('c', ['a', 'b']), 'c a b');
t.end();
test('(compat) joins array arguments with string arguments', () => {
assert.is(clsx(['a', 'b'], 'c'), 'a b c');
assert.is(clsx('c', ['a', 'b']), 'c a b');
});

test('(compat) handles multiple array arguments', t => {
t.is(fn(['a', 'b'], ['c', 'd']), 'a b c d');
t.end();
test('(compat) handles multiple array arguments', () => {
assert.is(clsx(['a', 'b'], ['c', 'd']), 'a b c d');
});

test('(compat) handles arrays that include falsy and true values', t => {
t.is(fn(['a', 0, null, undefined, false, true, 'b']), 'a b');
t.end();
test('(compat) handles arrays that include falsy and true values', () => {
assert.is(clsx(['a', 0, null, undefined, false, true, 'b']), 'a b');
});

test('(compat) handles arrays that include arrays', t => {
t.is(fn(['a', ['b', 'c']]), 'a b c');
t.end();
test('(compat) handles arrays that include arrays', () => {
assert.is(clsx(['a', ['b', 'c']]), 'a b c');
});

test('(compat) handles arrays that include objects', t => {
t.is(fn(['a', { b:true, c:false }]), 'a b');
t.end();
test('(compat) handles arrays that include objects', () => {
assert.is(clsx(['a', { b:true, c:false }]), 'a b');
});

test('(compat) handles deep array recursion', t => {
t.is(fn(['a', ['b', ['c', { d:true }]]]), 'a b c d');
t.end();
test('(compat) handles deep array recursion', () => {
assert.is(clsx(['a', ['b', ['c', { d:true }]]]), 'a b c d');
});

test('(compat) handles arrays that are empty', t => {
t.is(fn('a', []), 'a');
t.end();
test('(compat) handles arrays that are empty', () => {
assert.is(clsx('a', []), 'a');
});

test('(compat) handles nested arrays that have empty nested arrays', t => {
t.is(fn('a', [[]]), 'a');
t.end();
test('(compat) handles nested arrays that have empty nested arrays', () => {
assert.is(clsx('a', [[]]), 'a');
});

test('(compat) handles all types of truthy and falsy property values as expected', t => {
const out = fn({
test('(compat) handles all types of truthy and falsy property values as expected', () => {
const out = clsx({
// falsy:
null: null,
emptyString: '',
Expand All @@ -100,6 +87,7 @@ test('(compat) handles all types of truthy and falsy property values as expected
greaterZero: 1
});

t.is(out, 'nonEmptyString whitespace function emptyObject nonEmptyObject emptyList nonEmptyList greaterZero');
t.end();
assert.is(out, 'nonEmptyString whitespace function emptyObject nonEmptyObject emptyList nonEmptyList greaterZero');
});

test.run();
121 changes: 57 additions & 64 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -1,88 +1,81 @@
import test from 'tape';
// @ts-check
import { test } from 'uvu';
import * as assert from 'uvu/assert';
import * as mod from '../src';

const fn = mod.default;

test('exports', t => {
t.is(typeof mod.default, 'function', 'exports default function');
t.is(typeof mod.clsx, 'function', 'exports named function');
t.ok(mod.default === mod.clsx, 'exports are equal');

t.is(typeof mod.default(), 'string', '~> returns string output');
t.is(typeof mod.clsx(), 'string', '~> returns string output');

t.end();
test('exports', () => {
assert.type(mod.default, 'function', 'exports default function');
assert.type(mod.clsx, 'function', 'exports named function');
assert.is(mod.default, mod.clsx, 'exports are equal');

assert.type(mod.default(), 'string', '~> returns string output');
assert.type(mod.clsx(), 'string', '~> returns string output');
});

test('strings', t => {
t.is(fn(''), '');
t.is(fn('foo'), 'foo');
t.is(fn(true && 'foo'), 'foo');
t.is(fn(false && 'foo'), '');
t.end();
test('strings', () => {
assert.is(fn(''), '');
assert.is(fn('foo'), 'foo');
assert.is(fn(true && 'foo'), 'foo');
assert.is(fn(false && 'foo'), '');
});

test('strings (variadic)', t => {
t.is(fn(''), '');
t.is(fn('foo', 'bar'), 'foo bar');
t.is(fn(true && 'foo', false && 'bar', 'baz'), 'foo baz');
t.is(fn(false && 'foo', 'bar', 'baz', ''), 'bar baz');
t.end();
test('strings (variadic)', () => {
assert.is(fn(''), '');
assert.is(fn('foo', 'bar'), 'foo bar');
assert.is(fn(true && 'foo', false && 'bar', 'baz'), 'foo baz');
assert.is(fn(false && 'foo', 'bar', 'baz', ''), 'bar baz');
});

test('objects', t => {
t.is(fn({}), '');
t.is(fn({ foo:true }), 'foo');
t.is(fn({ foo:true, bar:false }), 'foo');
t.is(fn({ foo:'hiya', bar:1 }), 'foo bar');
t.is(fn({ foo:1, bar:0, baz:1 }), 'foo baz');
t.is(fn({ '-foo':1, '--bar':1 }), '-foo --bar');
t.end();
test('objects', () => {
assert.is(fn({}), '');
assert.is(fn({ foo:true }), 'foo');
assert.is(fn({ foo:true, bar:false }), 'foo');
assert.is(fn({ foo:'hiya', bar:1 }), 'foo bar');
assert.is(fn({ foo:1, bar:0, baz:1 }), 'foo baz');
assert.is(fn({ '-foo':1, '--bar':1 }), '-foo --bar');
});

test('objects (variadic)', t => {
t.is(fn({}, {}), '');
t.is(fn({ foo:1 }, { bar:2 }), 'foo bar');
t.is(fn({ foo:1 }, null, { baz:1, bat:0 }), 'foo baz');
t.is(fn({ foo:1 }, {}, {}, { bar:'a' }, { baz:null, bat:Infinity }), 'foo bar bat');
t.end();
test('objects (variadic)', () => {
assert.is(fn({}, {}), '');
assert.is(fn({ foo:1 }, { bar:2 }), 'foo bar');
assert.is(fn({ foo:1 }, null, { baz:1, bat:0 }), 'foo baz');
assert.is(fn({ foo:1 }, {}, {}, { bar:'a' }, { baz:null, bat:Infinity }), 'foo bar bat');
});

test('arrays', t => {
t.is(fn([]), '');
t.is(fn(['foo']), 'foo');
t.is(fn(['foo', 'bar']), 'foo bar');
t.is(fn(['foo', 0 && 'bar', 1 && 'baz']), 'foo baz');
t.end();
test('arrays', () => {
assert.is(fn([]), '');
assert.is(fn(['foo']), 'foo');
assert.is(fn(['foo', 'bar']), 'foo bar');
assert.is(fn(['foo', 0 && 'bar', 1 && 'baz']), 'foo baz');
});

test('arrays (nested)', t => {
t.is(fn([[[]]]), '');
t.is(fn([[['foo']]]), 'foo');
t.is(fn([true, [['foo']]]), 'foo');;
t.is(fn(['foo', ['bar', ['', [['baz']]]]]), 'foo bar baz');
t.end();
test('arrays (nested)', () => {
assert.is(fn([[[]]]), '');
assert.is(fn([[['foo']]]), 'foo');
assert.is(fn([true, [['foo']]]), 'foo');;
assert.is(fn(['foo', ['bar', ['', [['baz']]]]]), 'foo bar baz');
});

test('arrays (variadic)', t => {
t.is(fn([], []), '');
t.is(fn(['foo'], ['bar']), 'foo bar');
t.is(fn(['foo'], null, ['baz', ''], true, '', []), 'foo baz');
t.end();
test('arrays (variadic)', () => {
assert.is(fn([], []), '');
assert.is(fn(['foo'], ['bar']), 'foo bar');
assert.is(fn(['foo'], null, ['baz', ''], true, '', []), 'foo baz');
});

test('arrays (no `push` escape)', t => {
t.is(fn({ push:1 }), 'push');
t.is(fn({ pop:true }), 'pop');
t.is(fn({ push:true }), 'push');
t.is(fn('hello', { world:1, push:true }), 'hello world push');
t.end();
test('arrays (no `push` escape)', () => {
assert.is(fn({ push:1 }), 'push');
assert.is(fn({ pop:true }), 'pop');
assert.is(fn({ push:true }), 'push');
assert.is(fn('hello', { world:1, push:true }), 'hello world push');
});

test('functions', t => {
test('functions', () => {
const foo = () => {};
t.is(fn(foo, 'hello'), 'hello');
t.is(fn(foo, 'hello', fn), 'hello');
t.is(fn(foo, 'hello', [[fn], 'world']), 'hello world');
t.end();
assert.is(fn(foo, 'hello'), 'hello');
assert.is(fn(foo, 'hello', fn), 'hello');
assert.is(fn(foo, 'hello', [[fn], 'world']), 'hello world');
});

test.run();

0 comments on commit 1c36d10

Please sign in to comment.