forked from peterbe/minimalcss
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathe2e.js
More file actions
executable file
·72 lines (65 loc) · 2.05 KB
/
e2e.js
File metadata and controls
executable file
·72 lines (65 loc) · 2.05 KB
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
#!/usr/bin/env node
const fs = require('fs');
const spawn = require('child_process').spawnSync;
const inCI = process.env.CI || false;
function assert(truth, failure) {
if (!truth) {
throw new Error(failure);
}
}
function assertStatus(spawned) {
if (spawned.status !== 0) {
console.error('STDOUT', spawned.stdout.toString());
console.error('STDERR', spawned.stderr.toString());
process.exit(spawned.status);
}
}
const version = spawn('./bin/minimalcss.js', ['--version']);
assertStatus(version);
const versionNumber = version.stdout.toString();
assert(!/[^\d\.]/.test(versionNumber.trim()), 'Not a version number');
const versionNumber2 = spawn('./bin/minimalcss.js', ['-v']).stdout.toString();
assert(versionNumber2 === versionNumber, 'alias not working');
function openUrl(url, ...options) {
console.log(`Opening ${url} ...`);
if (inCI) {
options.push('--nosandbox');
}
options.push(url);
const t0 = new Date();
const opened = spawn('./bin/minimalcss.js', options);
assertStatus(opened);
const t1 = new Date();
const t = (t1 - t0) / 1000;
console.log(`Took ${t.toFixed(2)}s`);
return Promise.resolve(opened);
}
// Simplest form of opening
openUrl('https://minimalcss.app/').then((spawned) => {
const css = spawned.stdout.toString();
assert(
css.length > 7000 && css.length < 10000,
'Expect CSS to be between 7,000...10,000'
);
});
// Open with -o
openUrl('https://developer.mozilla.org/', '-o', '/tmp/mdn.css').then(
(spawned) => {
const stdout = spawned.stdout.toString();
assert(!stdout.trim(), 'Output should be empty');
const css = fs.readFileSync('/tmp/mdn.css').toString();
assert(
css.length > 60000 && css.length < 70000,
'Expect CSS to be between 10K...30K'
);
}
);
// With verbose output
openUrl('https://developer.mozilla.org/', '--verbose').then((spawned) => {
const css = spawned.stdout.toString();
assert(/\/\*\nGenerated /.test(css), 'Expected verbose leading comment');
assert(
css.length > 60000 && css.length < 70000,
'Expect CSS to be between 10K...30K'
);
});