Skip to content

Commit 07638e6

Browse files
committed
Replace Ava with Vitest
1 parent 674bb17 commit 07638e6

File tree

4 files changed

+2780
-4220
lines changed

4 files changed

+2780
-4220
lines changed

.github/workflows/run.yml

+16-20
Original file line numberDiff line numberDiff line change
@@ -10,32 +10,27 @@ jobs:
1010
name: Lint
1111
runs-on: ubuntu-latest
1212
steps:
13-
- uses: actions/checkout@v3
14-
- uses: actions/setup-node@v3
13+
- uses: actions/checkout@v4
14+
- uses: actions/setup-node@v4
1515
with:
16-
node-version: 16
16+
node-version: 18
1717
- run: npm ci
1818
- run: npm run lint
1919

2020
test:
2121
name: Test (Node v${{ matrix.node }})
2222
runs-on: ubuntu-latest
23-
strategy:
24-
matrix:
25-
node: [ 10, 16 ]
2623
steps:
27-
- uses: actions/checkout@v3
28-
- uses: actions/setup-node@v3
24+
- uses: actions/checkout@v4
25+
- uses: actions/setup-node@v4
2926
with:
30-
node-version: ${{ matrix.node }}
27+
node-version: 18
3128
- run: npm ci
32-
- run: npm test
3329
- run: npm run coverage
34-
- uses: codecov/codecov-action@v3
35-
if: matrix.node == 16
30+
- name: Update code coverage
31+
uses: codecov/codecov-action@v4
3632
with:
37-
files: ./coverage.lcov
38-
33+
token: ${{ secrets.CODECOV_TOKEN }}
3934
publish:
4035
name: Publish on npm
4136
runs-on: ubuntu-latest
@@ -44,12 +39,13 @@ jobs:
4439
- lint
4540
- test
4641
steps:
47-
- uses: actions/checkout@v3
48-
- uses: actions/setup-node@v3
42+
- uses: actions/checkout@v4
43+
- uses: actions/setup-node@v4
4944
with:
50-
node-version: 16
45+
node-version: 18
46+
registry-url: https://registry.npmjs.org/
5147
- run: npm ci
5248
- name: Publish on npm
53-
uses: JS-DevTools/npm-publish@v1
54-
with:
55-
token: ${{ secrets.NPM_TOKEN }}
49+
run: npm publish
50+
env:
51+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

index.spec.js

+59-57
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,62 @@
1-
import test from 'ava';
1+
import {describe, it, expect} from 'vitest';
22
import g from '.';
33

4-
test('throw error if wrong gradient arguments', t => {
5-
t.throws(() => g()('abc'));
6-
t.throws(() => g('red')('abc'));
7-
});
8-
9-
test('do not throw error if nothing to color', t => {
10-
t.is(g('gold', 'silver')(), '');
11-
t.is(g('gold', 'silver')(null), '');
12-
});
13-
14-
test('throw error if options is not an object', t => {
15-
t.throws(() => g('blue', 'red')('abc', false), null, 'Expected `options` to be an `object`, got `boolean`');
16-
});
17-
18-
test('throw error if interpolation is not a string', t => {
19-
t.throws(() => g('blue', 'red')('abc', {interpolation: 1000}), null, 'Expected `options.interpolation` to be a `string`, got `number`');
20-
});
21-
22-
test('throw error if hsvSpin is not a string, but only if interpolation is HSV', t => {
23-
t.notThrows(() => g('blue', 'red')('abc', {hsvSpin: 42}));
24-
t.throws(() => g('blue', 'red')('abc', {interpolation: 'hsv', hsvSpin: 42}), null, 'Expected `options.hsvSpin` to be a `string`, got `number`');
25-
});
26-
27-
test('works fine', t => {
28-
t.not(g('blue', 'white', 'red')('abc'), 'abc');
29-
30-
// Red -> yellow -> green (short arc)
31-
t.not(g('red', 'green')('abc'), g('red', 'green')('abc', {interpolation: 'hsv'}));
32-
33-
// Red -> blue -> green (long arc)
34-
t.not(g('red', 'green')('abc'), g('red', 'green')('abc', {interpolation: 'hsv', hsvSpin: 'long'}));
35-
t.not(g('red', 'green')('abc', {interpolation: 'hsv'}), g('red', 'green')('abc', {interpolation: 'hsv', hsvSpin: 'long'}));
36-
});
37-
38-
test('varargs syntax equal to array syntax', t => {
39-
t.is(g('yellow', 'green')('abc'), g(['yellow', 'green'])('abc'));
40-
});
41-
42-
test('supports aliases', t => {
43-
t.is(g.cristal('Hello world'), g('#bdfff3', '#4ac29a')('Hello world'));
44-
t.is(g.pastel('Hello world'), g('#74ebd5', '#74ecd5')('Hello world', {interpolation: 'hsv', hsvSpin: 'long'}));
45-
});
46-
47-
test('multiline option works the same way on one line strings', t => {
48-
t.is(g('blue', 'white', 'red').multiline('abc'), g('blue', 'white', 'red')('abc'));
49-
t.is(g('red', 'green').multiline('abc', {interpolation: 'hsv'}), g('red', 'green')('abc', {interpolation: 'hsv'}));
50-
});
51-
52-
test('multiline option works fine', t => {
53-
t.is(g('orange', 'purple').multiline('hello\nworld'), g('orange', 'purple')('hello') + '\n' + g('orange', 'purple')('world'));
54-
t.is(g.atlas.multiline('abc\n\ndef'), g.atlas('abc') + '\n\n' + g.atlas('def'));
55-
t.not(g.rainbow.multiline('hi\nworld'), g.rainbow('hi') + '\n' + g.rainbow('world'));
56-
});
57-
58-
test('case insensitive options', t => {
59-
t.is(g('red', 'green')('abc', {interpolation: 'hsv', hsvSpin: 'long'}), g('red', 'green')('abc', {interpolation: 'HSV', hsvSpin: 'Long'}));
4+
describe('Gradient Tests', () => {
5+
it('should throw an error if wrong gradient arguments are passed', () => {
6+
expect(() => g()('abc')).toThrow();
7+
expect(() => g('red')('abc')).toThrow();
8+
});
9+
10+
it('should not throw an error if there is nothing to color', () => {
11+
expect(g('gold', 'silver')()).toBe('');
12+
expect(g('gold', 'silver')(null)).toBe('');
13+
});
14+
15+
it('should throw an error if options is not an object', () => {
16+
expect(() => g('blue', 'red')('abc', false)).toThrowError('Expected `options` to be an `object`, got `boolean`');
17+
});
18+
19+
it('should throw an error if interpolation is not a string', () => {
20+
expect(() => g('blue', 'red')('abc', {interpolation: 1000})).toThrowError('Expected `options.interpolation` to be a `string`, got `number`');
21+
});
22+
23+
it('should throw an error if hsvSpin is not a string, but only if interpolation is HSV', () => {
24+
expect(() => g('blue', 'red')('abc', {hsvSpin: 42})).not.toThrow();
25+
expect(() => g('blue', 'red')('abc', {interpolation: 'hsv', hsvSpin: 42})).toThrowError('Expected `options.hsvSpin` to be a `string`, got `number`');
26+
});
27+
28+
it('should work correctly with different gradient and interpolation options', () => {
29+
expect(g('blue', 'white', 'red')('abc')).not.toBe('abc');
30+
31+
// Red -> yellow -> green (short arc)
32+
expect(g('red', 'green')('abc')).not.toBe(g('red', 'green')('abc', {interpolation: 'hsv'}));
33+
34+
// Red -> blue -> green (long arc)
35+
expect(g('red', 'green')('abc')).not.toBe(g('red', 'green')('abc', {interpolation: 'hsv', hsvSpin: 'long'}));
36+
expect(g('red', 'green')('abc', {interpolation: 'hsv'})).not.toBe(g('red', 'green')('abc', {interpolation: 'hsv', hsvSpin: 'long'}));
37+
});
38+
39+
it('should support varargs syntax equal to array syntax', () => {
40+
expect(g('yellow', 'green')('abc')).toBe(g(['yellow', 'green'])('abc'));
41+
});
42+
43+
it('should support aliases', () => {
44+
expect(g.cristal('Hello world')).toBe(g('#bdfff3', '#4ac29a')('Hello world'));
45+
expect(g.pastel('Hello world')).toBe(g('#74ebd5', '#74ecd5')('Hello world', {interpolation: 'hsv', hsvSpin: 'long'}));
46+
});
47+
48+
it('multiline option should work the same way on one-line strings', () => {
49+
expect(g('blue', 'white', 'red').multiline('abc')).toBe(g('blue', 'white', 'red')('abc'));
50+
expect(g('red', 'green').multiline('abc', {interpolation: 'hsv'})).toBe(g('red', 'green')('abc', {interpolation: 'hsv'}));
51+
});
52+
53+
it('multiline option should work correctly', () => {
54+
expect(g('orange', 'purple').multiline('hello\nworld')).toBe(g('orange', 'purple')('hello') + '\n' + g('orange', 'purple')('world'));
55+
expect(g.atlas.multiline('abc\n\ndef')).toBe(g.atlas('abc') + '\n\n' + g.atlas('def'));
56+
expect(g.rainbow.multiline('hi\nworld')).not.toBe(g.rainbow('hi') + '\n' + g.rainbow('world'));
57+
});
58+
59+
it('case-insensitive options should work correctly', () => {
60+
expect(g('red', 'green')('abc', {interpolation: 'hsv', hsvSpin: 'long'})).toBe(g('red', 'green')('abc', {interpolation: 'HSV', hsvSpin: 'Long'}));
61+
});
6062
});

0 commit comments

Comments
 (0)