forked from sindresorhus/pageres-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
65 lines (49 loc) · 1.83 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
import fs from 'fs';
import {spawn} from 'child_process';
import execa from 'execa';
import test from 'ava';
import {version as pkgVersion} from '../package';
test('generate screenshot', async t => {
await execa('./cli.js', ['https://sindresorhus.com', '320x240']);
t.true(fs.existsSync('sindresorhus.com-320x240.png'));
fs.unlinkSync('sindresorhus.com-320x240.png');
});
test.cb('remove temporary files on cancel', t => {
t.plan(1);
const subprocess = spawn('./cli.js', ['https://sindresorhus.com', '320x240']);
subprocess.on('exit', () => {
t.false(fs.existsSync('sindresorhus.com-320x240.png'));
t.end();
});
setTimeout(() => {
subprocess.kill('SIGINT');
}, 500);
});
test('show error if no url is specified', async t => {
await t.throwsAsync(execa('./cli.js', ['320x240']), /Specify a url/);
});
test('use 1366x768 as default resolution', async t => {
await execa('./cli.js', ['https://sindresorhus.com']);
t.true(fs.existsSync('sindresorhus.com-1366x768.png'));
fs.unlinkSync('sindresorhus.com-1366x768.png');
});
test('generate screenshots using keywords', async t => {
await execa('./cli.js', ['https://sindresorhus.com', 'iphone5s']);
t.true(fs.existsSync('sindresorhus.com-320x568.png'));
fs.unlinkSync('sindresorhus.com-320x568.png');
});
test('generate screenshots with multiple filename', async t => {
await execa.command('./cli.js [ https://google.com --filename=google ] [ https://sindresorhus.com --filename=sindre ]');
t.true(fs.existsSync('google.png'));
fs.unlinkSync('google.png');
t.true(fs.existsSync('sindre.png'));
fs.unlinkSync('sindre.png');
});
test('show help screen', async t => {
const {stdout} = await execa('./cli.js', ['--help']);
t.regex(stdout, /pageres <url>/);
});
test('show version', async t => {
const {stdout} = await execa('./cli.js', ['--version']);
t.is(stdout, pkgVersion);
});