Skip to content

Commit 28964e9

Browse files
author
benholloway
committed
converted release and test tasks to new format, ensured BDD-like descriptions
1 parent 75749fc commit 28964e9

File tree

6 files changed

+224
-129
lines changed

6 files changed

+224
-129
lines changed

test/helpers/angularity-test.js

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
'use strict';
33

44
var Q = require('q'),
5+
fs = require('fs'),
56
path = require('path'),
67
isArray = require('lodash.isarray'),
78
gulp = require('gulp'),
@@ -202,6 +203,44 @@ function getConcatenation() {
202203
};
203204
}
204205

206+
/**
207+
* A utility equivalent to performing <code>String.replace()</code> using the contents of each <code>add()</code>
208+
* statement
209+
* @returns {{add: function, commit: function}}
210+
*/
211+
function replacer() {
212+
var list = [];
213+
var self = {
214+
add: function(before, after) {
215+
list.push({
216+
before: before,
217+
after : after
218+
});
219+
return self;
220+
},
221+
commit: function() {
222+
return function(pathElements) {
223+
var filePath = path.resolve.apply(path, [].concat(pathElements));
224+
var text = fs.existsSync(filePath) && fs.readFileSync(filePath).toString();
225+
function replaceSingle(item) {
226+
if (text) {
227+
if (typeof item.before === 'string') {
228+
while (text.indexOf(item.before) >= 0) {
229+
text = text.replace(item.before, item.after);
230+
}
231+
} else if ((typeof item.before === 'object') && ('test' in item.before)) {
232+
text = text.replace(item.before, item.after);
233+
}
234+
}
235+
return text;
236+
}
237+
list.forEach(replaceSingle);
238+
return text;
239+
};
240+
}
241+
};
242+
return self;
243+
}
205244

206245
module.exports = {
207246
runner : runner,
@@ -211,5 +250,6 @@ module.exports = {
211250
getFileDelete : getFileDelete,
212251
randomFlags : randomFlags,
213252
getTimeoutSwitch: getTimeoutSwitch,
214-
getConcatenation: getConcatenation
253+
getConcatenation: getConcatenation,
254+
replacer : replacer
215255
};

test/specs/cli.spec.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ describe('The Angularity cli interface', function () {
1717

1818
afterEach(helper.cleanUp);
1919

20-
describe('with no other arguments', function (done) {
20+
describe('should exit cleanly where there are no other arguments', function (done) {
2121
helper.runner.create()
2222
.addInvocation()
2323
.forEach(fastIt(expectations))
@@ -30,31 +30,31 @@ describe('The Angularity cli interface', function () {
3030
}
3131
});
3232

33-
describe('with version switch', function (done) {
33+
describe('should display help where requested', function (done) {
3434
helper.runner.create()
35-
.addInvocation('--version')
36-
.addInvocation('-v')
35+
.addInvocation('--help')
36+
.addInvocation('-h')
37+
// .addInvocation('-?') // TODO @bholloway process cannot be spawned on windows when it has -? flag
3738
.forEach(fastIt(expectations))
3839
.finally(done);
3940

4041
function expectations(testCase) {
41-
var version = require(path.resolve('package.json')).version;
42-
expect(testCase.stdout).toMatch(new RegExp('^angularity\\:\\s*' + version));
42+
// test the help message begins with the description from the package.json
43+
var description = require(path.resolve('package.json')).description;
44+
expect(testCase.stderr).toMatch(new RegExp('^\\s*' + description));
4345
}
4446
});
4547

46-
describe('with help switch', function (done) {
48+
describe('should display version where requested', function (done) {
4749
helper.runner.create()
48-
.addInvocation('--help')
49-
.addInvocation('-h')
50-
// .addInvocation('-?') // TODO @bholloway process cannot be spawned on windows when it has -? flag
50+
.addInvocation('--version')
51+
.addInvocation('-v')
5152
.forEach(fastIt(expectations))
5253
.finally(done);
5354

5455
function expectations(testCase) {
55-
// test the help message begins with the description from the package.json
56-
var description = require(path.resolve('package.json')).description;
57-
expect(testCase.stderr).toMatch(new RegExp('^\\s*' + description));
56+
var version = require(path.resolve('package.json')).version;
57+
expect(testCase.stdout).toMatch(new RegExp('^angularity\\:\\s*' + version));
5858
}
5959
});
6060
});

test/specs/tasks/build.spec.js

Lines changed: 11 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
'use strict';
22

3-
var fs = require('fs'),
4-
path = require('path');
5-
6-
var jasmineDiffMatchers = require('jasmine-diff-matchers');
3+
var diffMatchers = require('jasmine-diff-matchers');
74

85
var helper = require('../../helpers/angularity-test'),
96
matchers = require('../../helpers/jasmine-matchers');
@@ -33,7 +30,7 @@ describe('The Angularity build task', function () {
3330

3431
afterEach(helper.cleanUp);
3532

36-
describe('with help switch', function (done) {
33+
describe('should display help when requested', function (done) {
3734
helper.runner.create()
3835
.addInvocation('build --help')
3936
.addInvocation('build -h')
@@ -47,7 +44,7 @@ describe('The Angularity build task', function () {
4744
}
4845
});
4946

50-
describe('with the minimal-es5 project', function(done) {
47+
describe('should operate minified (by default)', function(done) {
5148
helper.runner.create()
5249
.addSource('minimal-es5')
5350
.addInvocation('build')
@@ -57,7 +54,7 @@ describe('The Angularity build task', function () {
5754
.finally(done);
5855
});
5956

60-
describe('with the minimal-es5 project unminified', function(done) {
57+
describe('should operate unminified', function(done) {
6158
helper.runner.create()
6259
.addSource('minimal-es5-unminified')
6360
.addInvocation('build --unminified')
@@ -80,13 +77,14 @@ function expectations(testCase) {
8077
expect(testCase.cwd).toHaveExpectedItemsExcept();
8178

8279
// build output
80+
expect(workingBuildFile('index.html')).diffFilePatch(sourceBuildFile('index.html'));
8381
expect(workingBuildFile('index.js')).diffFilePatch(sourceBuildFile('index.js'));
8482
expect(workingBuildFile('index.css')).diffFilePatch(sourceBuildFile('index.css'));
8583
// expect(workingBuildFile('index.js.map' )).diffFilePatch(sourceBuildFile('index.js.map')); // TODO @bholloway solve repeatability of .map files
8684
// expect(workingBuildFile('index.css.map')).diffFilePatch(sourceBuildFile('index.css.map')); // TODO @bholloway solve repeatability of .map files
8785

88-
// must remove basePath to allow karam.conf.js to be correctly diff'd
89-
var replace = replacer()
86+
// must remove basePath to allow karma.conf.js to be correctly diff'd
87+
var replace = helper.replacer()
9088
.add(/^\s*basePath:.*$/gm, '')
9189
.add(/\\{2}/g, '/')
9290
.commit();
@@ -95,11 +93,10 @@ function expectations(testCase) {
9593
expect(replace(workingTestFile('karma.conf.js'))).diffPatch(replace(sourceTestFile('karma.conf.js')));
9694
expect(workingTestFile('index.js')).diffFilePatch(sourceTestFile('index.js'));
9795
// expect(workingTestFile('index.js.map')).diffFilePatch(sourceTestFile('index.js.map')); // TODO @bholloway solve repeatability of .map files
98-
9996
}
10097

10198
function customMatchers() {
102-
jasmine.addMatchers(jasmineDiffMatchers.diffPatch);
99+
jasmine.addMatchers(diffMatchers.diffPatch);
103100
jasmine.addMatchers({
104101
toBeHelpWithError : matchers
105102
.getHelpMatcher(/^\s*The "build" task/),
@@ -114,36 +111,6 @@ function customMatchers() {
114111
});
115112
}
116113

117-
function replacer() {
118-
var list = [];
119-
var self = {
120-
add: function(before, after) {
121-
list.push({
122-
before: before,
123-
after : after
124-
});
125-
return self;
126-
},
127-
commit: function() {
128-
return function(pathElements) {
129-
var filePath = path.resolve.apply(path, [].concat(pathElements));
130-
var text = fs.existsSync(filePath) && fs.readFileSync(filePath).toString();
131-
function replaceSingle(item) {
132-
if (text) {
133-
if (typeof item.before === 'string') {
134-
while (text.indexOf(item.before) >= 0) {
135-
text = text.replace(item.before, item.after);
136-
}
137-
} else if ((typeof item.before === 'object') && ('test' in item.before)) {
138-
text = text.replace(item.before, item.after);
139-
}
140-
}
141-
return text;
142-
}
143-
list.forEach(replaceSingle);
144-
return text;
145-
};
146-
}
147-
};
148-
return self;
149-
}
114+
module.exports = {
115+
expectations: expectations
116+
};

test/specs/tasks/init.spec.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ describe('The Angularity init task', function () {
4040

4141
afterEach(helper.cleanUp);
4242

43-
describe('with help switch', function (done) {
43+
describe('should display help when requested', function (done) {
4444
helper.runner.create()
4545
.addInvocation('init --help')
4646
.addInvocation('init -h')
@@ -54,8 +54,8 @@ describe('The Angularity init task', function () {
5454
}
5555
});
5656

57-
describe('directory creation', function () {
58-
it('should rerun in any directory with package.json', function(done) {
57+
describe('should rerun in any directory with package.json', function () {
58+
it('init', function(done) {
5959
helper.runner.create()
6060
.addInvocation('init')
6161
.run()

0 commit comments

Comments
 (0)