-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathcmd.spec.js
97 lines (77 loc) · 2.31 KB
/
cmd.spec.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
91
92
93
94
95
96
97
'use strict';
var exec = require('child_process').exec;
var fs = require('fs');
var expect = require('chai').expect;
describe('cmd.spec.js', function () {
['browser', 'es2015', 'browserify'].forEach(function (style) {
it('should generate files using ' + style + ' style', function (done) {
var cmdArgs = [
'-f "test-it/**html"',
'-s ' +style,
'--htmlmin-minifyCSS',
'--htmlmin-minifyJS',
'--htmlmin-collapseWhitespace'
].join(' ');
exec('bin/cmd.js ' + cmdArgs, function(err, stdout) {
expect(stdout).to.eql(fs.readFileSync('test-it/expected/' + style + '.js').toString());
done();
});
});
});
it('should load all files passed as extra args', function(done) {
var cmdArgs = [
'-s browser',
'--htmlmin-minifyCSS',
'--htmlmin-minifyJS',
'--htmlmin-collapseWhitespace',
'--',
'test-it/first.html',
'test-it/second.html'
].join(' ');
exec('bin/cmd.js ' + cmdArgs, function(err, stdout) {
expect(stdout).to.eql(fs.readFileSync('test-it/expected/browser.js').toString());
done();
});
});
it('should load all html files from current folder if no glob pattern nor file list provided', function (done) {
var cmdArgs = [
'-s browser',
'--htmlmin-minifyCSS',
'--htmlmin-minifyJS',
'--htmlmin-collapseWhitespace'
].join(' ');
exec('(cd test-it && ../bin/cmd.js ' + cmdArgs + ')', function(err, stdout) {
var expectedFileContent = fs.readFileSync('test-it/expected/browser.js')
.toString()
.replace(new RegExp('test-it/', 'g'), '');
expect(stdout).to.eq(expectedFileContent);
done();
});
});
it('should ignore missing files', function (done) {
var cmdArgs = [
'--ignore-missing',
'-s browser',
'--',
'non-existing.file.html'
].join(' ');
exec('bin/cmd.js ' + cmdArgs, function (err, stdout) {
expect(err).to.be.null;
expect(stdout).to.eql(fs.readFileSync('test-it/expected/browser.empty.js').toString());
done();
});
});
it('should fail on missing files', function (done) {
var cmdArgs = [
'--',
'non-existing.file.html'
].join(' ');
exec('bin/cmd.js ' + cmdArgs, function (err, stdout, stderr) {
expect(stdout).to.eql('');
expect(stderr).to.contain('ENOENT');
expect(stderr).to.contain('open \'non-existing.file.html\'');
expect(err.code).to.eql(1);
done();
});
});
});