/
test.js
100 lines (86 loc) · 2.89 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
91
92
93
94
95
96
97
98
99
100
'use strict';
/* eslint-env mocha */
const {strict: assert} = require('assert');
const fs = require('fs');
const path = require('path');
const {exec} = require('child_process');
const pathExists = require('path-exists');
const spawn = require('cross-spawn');
describe('concurrent', () => {
it('runs grunt tasks successfully', () => {
assert(pathExists.sync(path.join(__dirname, 'tmp/1')));
assert(pathExists.sync(path.join(__dirname, 'tmp/2')));
assert(pathExists.sync(path.join(__dirname, 'tmp/3')));
});
it('runs grunt task sequence successfully', () => {
const file5 = fs.statSync(path.join(__dirname, 'tmp/5'));
const file6 = fs.statSync(path.join(__dirname, 'tmp/6'));
assert.ok(Date.parse(file5.ctime) < Date.parse(file6.ctime));
});
it('forwards CLI args to grunt sub-processes', done => {
const expected = '--arg1=test,--arg2';
exec('grunt concurrent:testargs ' + expected, () => {
const args1 = fs.readFileSync(path.join(__dirname, 'tmp/args1'), 'utf8');
const args2 = fs.readFileSync(path.join(__dirname, 'tmp/args2'), 'utf8');
assert.ok(args1.includes(expected));
assert.ok(args2.includes(expected));
done();
});
});
describe('`logConcurrentOutput` option', () => {
let logOutput = '';
before(done => {
let isDoneCalled = false;
const subprocess = spawn('grunt', ['concurrent:log']);
subprocess.stdout.setEncoding('utf8');
subprocess.stdout.on('data', data => {
logOutput += data;
subprocess.kill();
if (!isDoneCalled) {
isDoneCalled = true;
done();
}
});
});
it('outputs concurrent logging', () => {
const expected = 'Running "concurrent:log" (concurrent) task';
assert(logOutput.includes(expected));
});
});
describe('works with supports-color lib', () => {
it('ensures that colors are supported by default', done => {
exec('grunt concurrent:colors', () => {
assert.equal(fs.readFileSync(path.join(__dirname, 'tmp/colors'), 'utf8'), 'true');
done();
});
});
it('doesn\'t support colors with --no-color option', done => {
exec('grunt concurrent:colors --no-color', () => {
assert.equal(fs.readFileSync(path.join(__dirname, 'tmp/colors'), 'utf8'), 'false');
done();
});
});
});
describe('`indent` option', () => {
const testOutput = 'indent test output';
const indentedTestOutput = ' ' + testOutput;
it('indents output when true', done => {
exec('grunt concurrent:indentTrue', (error, stdout) => {
assert.ok(stdout.split('\n').includes(indentedTestOutput));
done();
});
});
it('does not indent output when false', done => {
exec('grunt concurrent:indentFalse', (error, stdout) => {
assert.ok(stdout.split('\n').includes(testOutput));
done();
});
});
it('indents output by default', done => {
exec('grunt concurrent:indentDefault', (error, stdout) => {
assert.ok(stdout.split('\n').includes(indentedTestOutput));
done();
});
});
});
});