directories-test.js
2.01 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
/*
* directories-test.js: Tests for working with directories in broadway.
*
* (C) 2011, Nodejitsu Inc.
* MIT LICENSE
*
*/
var assert = require('assert'),
fs = require('fs'),
path = require('path'),
vows = require('vows'),
broadway = require('../../lib/broadway');
var fixturesDir = path.join(__dirname, '..', 'fixtures'),
emptyAppDir = path.join(fixturesDir, 'empty-app'),
emptyAppFile = path.join(fixturesDir, 'sample-app.json'),
appConfig = JSON.parse(fs.readFileSync(emptyAppFile, 'utf8')),
directories = appConfig.directories;
vows.describe('broadway/common/directories').addBatch({
"When using broadway.common.directories": {
"it should have the correct methods defined": function () {
assert.isObject(broadway.common.directories);
assert.isFunction(broadway.common.directories.create);
assert.isFunction(broadway.common.directories.remove);
},
"the normalize() method should correctly modify a set of directories": function () {
directories = broadway.common.directories.normalize({'#ROOT': emptyAppDir}, directories);
Object.keys(directories).forEach(function (key) {
assert.isTrue(directories[key].indexOf(emptyAppDir) !== -1);
});
},
"the create() method": {
topic: function () {
broadway.common.directories.create(directories, this.callback);
},
"should create the specified directories": function (err, dirs) {
assert.isTrue(!err);
dirs.forEach(function (dir) {
assert.isTrue((fs.existsSync || path.existsSync)(dir));
});
},
"the destroy() method": {
topic: function () {
broadway.common.directories.remove(directories, this.callback);
},
"should remove the specified directories": function (err, dirs) {
assert.isTrue(!err);
dirs.forEach(function (dir) {
assert.isFalse((fs.existsSync || path.existsSync)(dir));
});
}
}
}
}
}).export(module);