forked from jamesshore/lets_code_javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfile_task.js
More file actions
108 lines (95 loc) · 3.49 KB
/
file_task.js
File metadata and controls
108 lines (95 loc) · 3.49 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
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
101
102
103
104
105
106
107
var assert = require('assert')
, fs = require('fs')
, path = require('path')
, exec = require('child_process').exec
, h = require('./helpers');
var cleanUpAndNext = function (callback) {
exec('rm -fr ./foo', function (err, stdout, stderr) {
if (err) { throw err }
if (stderr || stdout) {
console.log (stderr || stdout);
}
callback();
});
};
var tests = {
'before': function () {
process.chdir('./tests');
}
, 'after': function () {
process.chdir('../');
}
, 'test concating two files': function (next) {
h.exec('../bin/cli.js fileTest:foo/concat.txt', function (out) {
var data;
assert.equal('fileTest:foo/src1.txt task\ndefault task\nfileTest:foo/src2.txt task\n' +
'fileTest:foo/concat.txt task', out);
// Check to see the two files got concat'd
data = fs.readFileSync(process.cwd() + '/foo/concat.txt');
assert.equal('src1src2', data.toString());
cleanUpAndNext(next);
});
}
, 'test where a file-task prereq does not change': function (next) {
h.exec('../bin/cli.js fileTest:foo/from-src1.txt', function (out) {
assert.equal('fileTest:foo/src1.txt task\nfileTest:foo/from-src1.txt task', out);
h.exec('../bin/cli.js fileTest:foo/from-src1.txt', function (out) {
// Second time should be a no-op
assert.equal('', out);
cleanUpAndNext(next);
});
});
}
, 'test where a file-task prereq does not change with --always-make': function (next) {
h.exec('../bin/cli.js fileTest:foo/from-src1.txt', function (out) {
assert.equal('fileTest:foo/src1.txt task\nfileTest:foo/from-src1.txt task',
out);
h.exec('../bin/cli.js -B fileTest:foo/from-src1.txt', function (out) {
assert.equal('fileTest:foo/src1.txt task\nfileTest:foo/from-src1.txt task',
out);
cleanUpAndNext(next);
});
});
}
, 'test a preexisting file': function (next) {
var prereqData = 'howdy';
h.exec('mkdir -p foo', function (out) {
fs.writeFileSync('foo/prereq.txt', prereqData);
h.exec('../bin/cli.js fileTest:foo/from-prereq.txt', function (out) {
var data;
assert.equal('fileTest:foo/from-prereq.txt task', out);
data = fs.readFileSync(process.cwd() + '/foo/from-prereq.txt');
assert.equal(prereqData, data.toString());
h.exec('../bin/cli.js fileTest:foo/from-prereq.txt', function (out) {
// Second time should be a no-op
assert.equal('', out);
cleanUpAndNext(next);
});
});
});
}
, 'test a preexisting file with --always-make flag': function (next) {
var prereqData = 'howdy';
h.exec('mkdir -p foo', function (out) {
fs.writeFileSync('foo/prereq.txt', prereqData);
h.exec('../bin/cli.js fileTest:foo/from-prereq.txt', function (out) {
var data;
assert.equal('fileTest:foo/from-prereq.txt task', out);
data = fs.readFileSync(process.cwd() + '/foo/from-prereq.txt');
assert.equal(prereqData, data.toString());
h.exec('../bin/cli.js -B fileTest:foo/from-prereq.txt', function (out) {
assert.equal('fileTest:foo/from-prereq.txt task', out);
cleanUpAndNext(next);
});
});
});
}
, 'test nested directory-task': function (next) {
h.exec('../bin/cli.js fileTest:foo/bar/baz/bamf.txt', function (out) {
data = fs.readFileSync(process.cwd() + '/foo/bar/baz/bamf.txt');
assert.equal('w00t', data);
cleanUpAndNext(next);
});
}
};
module.exports = tests;