-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.mjs
93 lines (82 loc) · 2.64 KB
/
test.mjs
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
91
92
93
import assert from 'assert';
import cp from 'child_process';
import fs from 'fs';
import dateFormat, { masks } from 'dateformat';
function file(date) {
return dateFormat(date, 'ddd-yyyy-mm-dd".pdf"').toLowerCase();
}
function iso(date) {
return dateFormat(date, masks.isoDate);
}
teardown(() => {
cp.execSync('rm -f *.pdf');
});
suite('nyt-crossword', function () {
this.timeout(0);
this.slow(7000);
test('No arg', () => {
let f = file(new Date());
let o = cp.execSync('npx nyt-crossword').toString();
let d = new Date();
assert.strictEqual(o, `${iso(d)}... \x1B[32m${file(d)}\x1B[0m\n`);
assert.ok(fs.existsSync(f));
});
test('1 date', () => {
let f = file(new Date('2022-10-24'));
let o = cp.execSync('npx nyt-crossword 2022-10-24').toString();
assert.strictEqual(
o,
'2022-10-24... \x1B[32mmon-2022-10-24.pdf\x1B[0m\n'
);
assert.ok(fs.existsSync(f));
});
test('2 dates', () => {
let a = file(new Date('2022-10-23'));
let b = file(new Date('2022-10-24'));
let o = cp
.execSync('npx nyt-crossword 2022-10-23 2022-10-24')
.toString();
assert.strictEqual(
o,
[
'2022-10-23... \x1B[32msun-2022-10-23.pdf\x1B[0m\n',
'2022-10-24... \x1B[32mmon-2022-10-24.pdf\x1B[0m\n'
].join('')
);
assert.ok(fs.existsSync(a));
assert.ok(fs.existsSync(b));
});
test('2 dates, --day', () => {
let a = file(new Date('2022-10-23'));
let b = file(new Date('2022-10-24'));
let o = cp
.execSync('npx nyt-crossword --day sun 2022-10-23 2022-10-24')
.toString();
assert.strictEqual(
o,
'2022-10-23... \x1B[32msun-2022-10-23.pdf\x1B[0m\n'
);
assert.ok(fs.existsSync(a));
assert.ok(!fs.existsSync(b));
});
test('1 date, --latex', () => {
let f = file(new Date('2022-10-24'));
let o = cp.execSync('npx nyt-crossword 2022-10-24 --latex').toString();
assert.strictEqual(
o,
'2022-10-24... \x1B[32mmon-2022-10-24.pdf\x1B[0m\n'
);
assert.ok(fs.existsSync(f));
});
test('Future date', () => {
assert.doesNotThrow(() => {
let o = cp.execSync('npx nyt-crossword 2050-01-01').toString();
assert.ok(
[
'2050-01-01... \x1B[31mError: 401\x1B[0m\n',
'2050-01-01... \x1B[31mError: 500\x1B[0m\n'
].includes(o)
);
});
});
});