Skip to content

Commit

Permalink
Improve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bokub committed Sep 19, 2018
1 parent 27ccc2e commit 415263d
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 45 deletions.
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
[![Version][version-src]][version-href]
[![Codecov][codecov-src]][codecov-href]
[![Downloads][downloads-src]][downloads-href]
[![Publish size][publish-src]][publish-href]
[![XO code style][xo-src]][xo-href]
[![Mentioned in Awesome Node.js][awesome-src]][awesome-href]

Expand Down Expand Up @@ -184,15 +183,13 @@ MIT © [Boris K](https://github.com/bokub)
[build-src]: https://flat.badgen.net/travis/bokub/gradient-string
[version-src]: https://runkit.io/bokub/npm-version/branches/master/gradient-string?style=flat
[codecov-src]: https://flat.badgen.net/codecov/c/github/bokub/gradient-string
[downloads-src]: https://flat.badgen.net/npm/dm/gradient-string?color=pink
[publish-src]: https://flat.badgen.net/packagephobia/publish/gradient-string
[downloads-src]: https://flat.badgen.net/npm/dm/gradient-string?color=FF9800
[xo-src]: https://flat.badgen.net/badge/code%20style/XO/5ed9c7
[awesome-src]: https://awesome.re/mentioned-badge-flat.svg

[build-href]: https://travis-ci.org/bokub/gradient-string
[version-href]: https://www.npmjs.com/package/gradient-string
[codecov-href]: https://codecov.io/gh/bokub/gradient-string
[downloads-href]: https://www.npmjs.com/package/gradient-string
[publish-href]: https://packagephobia.now.sh/result?p=gradient-string
[xo-href]: https://github.com/sindresorhus/xo
[awesome-href]: https://github.com/sindresorhus/awesome-nodejs
2 changes: 2 additions & 0 deletions examples/built-in.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env node

// Run with npm run built-in
const gradient = require('..');

Expand Down
2 changes: 2 additions & 0 deletions examples/demo.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env node

// Run with npm run demo
const gradient = require('..');

Expand Down
57 changes: 34 additions & 23 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"devDependencies": {
"ava": "^0.25.0",
"codecov": "^3.1.0",
"cross-env": "^5.2.0",
"nyc": "^13.1.0",
"xo": "^0.23.0"
},
Expand Down Expand Up @@ -47,6 +48,6 @@
"coverage": "nyc report --reporter=text-lcov > coverage.lcov && codecov",
"demo": "node examples/demo.js",
"fix": "xo --fix",
"test": "xo && nyc ava"
"test": "xo && nyc cross-env FORCE_COLOR=1 ava"
}
}
21 changes: 4 additions & 17 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,14 @@ test('throw error if hsvSpin is not a string, but only if interpolation is HSV',

/* eslint-disable unicorn/escape-case */
test('works fine', t => {
assertEqualOne(t, g('blue', 'white', 'red')('abc'), [
'\u001b[94ma\u001b[39m\u001b[97mb\u001b[39m\u001b[91mc\u001b[39m',
'\u001b[38;2;0;0;255ma\u001b[39m\u001b[38;2;255;255;255mb\u001b[39m\u001b[38;2;255;0;0mc\u001b[39m'
]);
t.not(g('blue', 'white', 'red')('abc'), 'abc');

// Red -> yellow -> green (short arc)
assertEqualOne(t, g('red', 'green')('abc', {interpolation: 'hsv'}), [
'\u001b[91ma\u001b[39m\u001b[33mb\u001b[39m\u001b[32mc\u001b[39m',
'\u001b[38;2;255;0;0ma\u001b[39m\u001b[38;2;191;191;0mb\u001b[39m\u001b[38;2;0;128;0mc\u001b[39m'
]);
t.not(g('red', 'green')('abc'), g('red', 'green')('abc', {interpolation: 'hsv'}));

// Red -> blue -> green (long arc)
assertEqualOne(t, g('red', 'green')('abc', {interpolation: 'hsv', hsvSpin: 'long'}), [
'\u001b[91ma\u001b[39m\u001b[34mb\u001b[39m\u001b[32mc\u001b[39m',
'\u001b[38;2;255;0;0ma\u001b[39m\u001b[38;2;0;0;191mb\u001b[39m\u001b[38;2;0;128;0mc\u001b[39m'
]);
t.not(g('red', 'green')('abc'), g('red', 'green')('abc', {interpolation: 'hsv', hsvSpin: 'long'}));
t.not(g('red', 'green')('abc', {interpolation: 'hsv'}), g('red', 'green')('abc', {interpolation: 'hsv', hsvSpin: 'long'}));
});

test('varargs syntax equal to array syntax', t => {
Expand All @@ -67,8 +59,3 @@ test('multiline option works fine', t => {
test('case insensitive options', t => {
t.is(g('red', 'green')('abc', {interpolation: 'hsv', hsvSpin: 'long'}), g('red', 'green')('abc', {interpolation: 'HSV', hsvSpin: 'Long'}));
});

// Asset that actual is equal to at least one element of expected
function assertEqualOne(t, actual, expected) {
t.true(expected.indexOf(actual) > -1);
}

0 comments on commit 415263d

Please sign in to comment.