-
Notifications
You must be signed in to change notification settings - Fork 58
/
Copy pathindex-nodetest.js
142 lines (120 loc) · 3.44 KB
/
index-nodetest.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
'use strict';
var assert = require('../helpers/assert');
describe('the index', function() {
var subject, mockUi;
beforeEach(function() {
subject = require('../../index');
mockUi = {
verbose: true,
messages: [],
write: function() { },
writeLine: function(message) {
this.messages.push(message);
}
};
});
it('has a name', function() {
var result = subject.createDeployPlugin({
name: 'test-plugin'
});
assert.equal(result.name, 'test-plugin');
});
it('implements the correct hooks', function() {
var plugin = subject.createDeployPlugin({
name: 'test-plugin'
});
assert.typeOf(plugin.configure, 'function');
assert.typeOf(plugin.prepare, 'function');
});
describe('configure hook', function() {
it('resolves if config is ok', function() {
var plugin = subject.createDeployPlugin({
name: 'revision-data'
});
var context = {
ui: mockUi,
config: {
"revision-data": {
type: 'file-hash',
filePattern: 'eeee'
}
}
};
plugin.beforeHook(context);
plugin.configure(context);
assert.ok(true); // it didn't throw
});
it('warns about missing optional config', function() {
var plugin = subject.createDeployPlugin({
name: 'revision-data'
});
var context = {
ui: mockUi,
config: {
"revision-data": {
}
}
};
plugin.beforeHook(context);
plugin.configure(context);
var messages = mockUi.messages.reduce(function(previous, current) {
if (/- Missing config:\s.*, using default:\s/.test(current)) {
previous.push(current);
}
return previous;
}, []);
assert.equal(messages.length, 6);
});
it('adds default config to the config object', function() {
var plugin = subject.createDeployPlugin({
name: 'revision-data'
});
var context = {
ui: mockUi,
config: {
"revision-data": {
}
}
};
plugin.beforeHook(context);
plugin.configure(context);
assert.isDefined(context.config['revision-data'].type);
assert.isDefined(context.config['revision-data'].filePattern);
assert.isDefined(context.config['revision-data'].scm);
});
});
describe('prepare hook', function() {
it('returns the revisionData', function() {
var plugin = subject.createDeployPlugin({
name: 'revision-data'
});
var context = {
distDir: 'tests/fixtures',
distFiles: ['index.html'],
ui: mockUi,
config: {
"revision-data": {
type: 'file-hash',
filePattern: 'index.html',
scm: function(context) {
return require('../../lib/scm-data-generators')['git'];
},
distDir: function(context) {
return context.distDir;
},
distFiles: function(context) {
return context.distFiles;
}
},
}
};
plugin.beforeHook(context);
return assert.isFulfilled(plugin.prepare(context))
.then(function(result) {
assert.equal(result.revisionData.revisionKey, 'ae1569f72495012cd5e8588e0f2f5d49');
assert.isNotNull(result.revisionData.timestamp);
assert.isNotNull(result.revisionData.scm.email);
});
});
});
});