-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathtest.js
90 lines (76 loc) · 2.35 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import test from 'ava';
import a from './index.js';
const effects = Object.keys(a);
// eslint-disable-next-line no-promise-executor-return
const sleep = ms => new Promise(r => setTimeout(r, ms));
for (const effect of effects) {
test(`throw error if invalid speed (${effect})`, t => {
t.throws(() => a[effect]('abc', ''), {message: 'Expected `speed` to be an number greater than 0'});
});
test(`animations are starting automatically (${effect})`, async t => {
const an = a[effect]('Lorem ipsum\ndolor sit amet');
for (let i = 0; i < 150; i++) {
// eslint-disable-next-line no-await-in-loop
await sleep(10);
if (an.f > 2) {
t.pass();
return; // Exit the test right when there is a result
}
}
t.fail();
});
test(`console.log stops the animation (${effect})`, async t => {
const an = a[effect]('Lorem ipsum\ndolor sit amet');
await sleep(20);
t.is(an.stopped, false);
console.log('This log should stop the animation');
t.is(an.stopped, true);
});
test(`start and stop are working (${effect})`, t => {
const an = a[effect]('Lorem ipsum\ndolor sit amet');
t.is(an.stopped, false);
an.stop();
t.is(an.stopped, true);
an.start();
t.is(an.stopped, false);
});
test(`manual render is working (${effect})`, t => {
const an = a[effect]('Lorem ipsum\ndolor sit amet').stop();
t.is(an.f, 0);
an.render();
t.is(an.f, 1);
an.render();
t.is(an.f, 2);
});
test(`text can be replaced (${effect})`, t => {
if (['radar'].indexOf(effect) > -1) {
return t.pass(); // Ignore some animations
}
const an = a[effect]('Y Y Y').stop();
const f1 = an.frame();
an.replace('Z Z Z');
const f2 = an.frame();
t.true(f1.indexOf('Y') > -1);
t.false(f1.indexOf('Z') > -1);
t.false(f2.indexOf('Y') > -1);
t.true(f2.indexOf('Z') > -1);
});
test(`multiline is well supported (${effect})`, t => {
const an = a[effect]('Lorem\nipsum\ndolor\nsit\namet').stop();
const frame = an.frame();
t.is(an.lines, 5);
t.is(frame.split('\n').length, 5);
});
test(`forced start is not a problem (${effect})`, async t => {
await t.notThrowsAsync(async () => {
a[effect]('Lorem ipsum\ndolor sit amet', 10).start();
await sleep(20);
});
});
test(`test lots of frames (${effect})`, t => {
const an = a[effect]('Lorem ipsum\ndolor sit amet').stop();
for (let i = 0; i < 5000; i++) {
t.notThrows(() => an.frame());
}
});
}