Skip to content

Commit fce129c

Browse files
committed
Preconditions implemented with tests
1 parent 06b3cfa commit fce129c

File tree

9 files changed

+426
-75
lines changed

9 files changed

+426
-75
lines changed

.gitignore

+2-7
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,9 @@ coverage
2121

2222
# Compiled binary addons (http://nodejs.org/api/addons.html)
2323
build/Release
24-
dist
2524

2625
# Dependency directory
2726
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
2827
node_modules
29-
30-
# Coverage
31-
.coverrun
32-
.coverdata
33-
reports
34-
debug
28+
target/
29+
dist/

LICENSE

+1-2
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@
186186
same "printed page" as the copyright notice for easier
187187
identification within third-party archives.
188188

189-
Copyright {yyyy} {name of copyright owner}
189+
Copyright 2016 Wave Software
190190

191191
Licensed under the Apache License, Version 2.0 (the "License");
192192
you may not use this file except in compliance with the License.
@@ -199,4 +199,3 @@
199199
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200200
See the License for the specific language governing permissions and
201201
limitations under the License.
202-

gulpfile.js

+79-13
Original file line numberDiff line numberDiff line change
@@ -14,36 +14,67 @@ var gutil = require('gulp-util');
1414
var through = require('through2');
1515
var globby = require('globby');
1616

17-
var sources = ['./lib/**/*.js'];
18-
var testSources = ['./test/**/*.js'];
17+
var sources = ['lib/**/*.js'];
18+
var testSources = ['test/**/*.js'];
1919

2020
gulp.task('lint', function () {
2121
return gulp.src(sources)
2222
.pipe(eslint({
2323
extends: 'eslint:recommended',
24-
ecmaFeatures: {
25-
'modules': true
26-
}
24+
rules: {
25+
strict: 2
26+
},
27+
env: {
28+
node: true
29+
}
2730
}))
2831
.pipe(eslint.format())
2932
.pipe(eslint.failAfterError());
3033
});
3134

32-
gulp.task('test', [], function (done) {
33-
return gulp.src(testSources, { read: false })
35+
gulp.task('test', ['lint'], function (done) {
36+
var prependToAll = function(path, globs) {
37+
var ret = [];
38+
for (var v of globs) {
39+
ret.push(path + '/' + v);
40+
}
41+
return ret;
42+
};
43+
var fs = require('fs');
44+
var target = 'target';
45+
if (!fs.existsSync(target)) {
46+
fs.mkdirSync(target);
47+
}
48+
var pwd = process.cwd();
49+
process.chdir(target);
50+
var testSrc = prependToAll('..', testSources);
51+
var src = prependToAll('..', sources);
52+
return gulp.src(testSrc, { read: false })
3453
.pipe(cover.instrument({
35-
pattern: sources,
36-
debugDirectory: 'debug'
54+
pattern: src,
55+
debugDirectory: 'debug'
3756
}))
3857
.pipe(mocha())
3958
.pipe(cover.gather())
40-
.pipe(cover.format())
41-
.pipe(gulp.dest('reports'));
59+
.pipe(cover.enforce({
60+
statements: 98,
61+
blocks: 98,
62+
lines: 98,
63+
}))
64+
.pipe(cover.format([
65+
{ reporter: 'html', outFile: 'coverage.html' },
66+
{ reporter: 'json', outFile: 'coverage.json' },
67+
{ reporter: 'lcov', outFile: 'coverage.lcov' },
68+
]))
69+
.pipe(gulp.dest('reports'))
70+
.on('end', function() {
71+
process.chdir(pwd);
72+
});
4273
});
4374
gulp.task('watch', function() {
4475
gulp.watch(sources.concat(testSources), ['test']);
4576
});
46-
gulp.task('build', function() {
77+
gulp.task('build-browser', ['test'], function() {
4778
// gulp expects tasks to return a stream, so we create one here.
4879
var bundledStream = through();
4980

@@ -53,13 +84,47 @@ gulp.task('build', function() {
5384
.pipe(source('eid.js'))
5485
// the rest of the gulp task, as you would normally write it.
5586
// here we're copying from the Browserify + Uglify2 recipe.
87+
.pipe(buffer())
88+
.on('error', gutil.log)
89+
.pipe(gulp.dest('dist/browser/js/'));
90+
91+
// "globby" replaces the normal "gulp.src" as Browserify
92+
// creates it's own readable stream.
93+
globby(['./lib/**/*.js']).then(function(entries) {
94+
// create the Browserify instance.
95+
var b = browserify({
96+
entries: entries,
97+
debug: true
98+
});
99+
100+
// pipe the Browserify stream into the stream we created earlier
101+
// this starts our gulp pipeline.
102+
b.bundle().pipe(bundledStream);
103+
}).catch(function(err) {
104+
// ensure any errors from globby are handled
105+
bundledStream.emit('error', err);
106+
});
107+
108+
// finally, we return the stream, so gulp knows when this task is done.
109+
return bundledStream;
110+
});
111+
gulp.task('build-minified', ['test'], function() {
112+
// gulp expects tasks to return a stream, so we create one here.
113+
var bundledStream = through();
114+
115+
bundledStream
116+
// turns the output bundle stream into a stream containing
117+
// the normal attributes gulp plugins expect.
118+
.pipe(source('eid.min.js'))
119+
// the rest of the gulp task, as you would normally write it.
120+
// here we're copying from the Browserify + Uglify2 recipe.
56121
.pipe(buffer())
57122
.pipe(sourcemaps.init({loadMaps: true}))
58123
// Add gulp plugins to the pipeline here.
59124
.pipe(uglify())
60125
.on('error', gutil.log)
61126
.pipe(sourcemaps.write('./'))
62-
.pipe(gulp.dest('./dist/js/'));
127+
.pipe(gulp.dest('dist/browser/js/'));
63128

64129
// "globby" replaces the normal "gulp.src" as Browserify
65130
// creates it's own readable stream.
@@ -81,4 +146,5 @@ gulp.task('build', function() {
81146
// finally, we return the stream, so gulp knows when this task is done.
82147
return bundledStream;
83148
});
149+
gulp.task('build', ['build-minified', 'build-browser']);
84150
gulp.task('default', ['lint', 'test', 'build']);

lib/eid.js

+19-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
1-
'use strict';
1+
/*
2+
* Copyright 2016 Wave Software
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
216

3-
var Eid = (function() {
17+
(function(module) {
18+
'use strict';
419

520
function JFormatter(format) {
621
this.format = function(arr) {
@@ -235,7 +250,6 @@ Eid.getMessageFormat = function() {
235250
return EidInternal.messageFormat;
236251
};
237252

238-
return Eid;
239-
})();
240-
241253
module.exports = Eid;
254+
255+
})(module);

lib/eid/exceptions.js

+36-31
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,31 @@
1-
'use strict';
1+
/*
2+
* Copyright 2016 Wave Software
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
216

3-
var Eid = require('../eid');
4-
var commonExConstructor = function(eid, message) {
5-
if (!(eid instanceof Eid)) {
6-
eid = new Eid(eid.toString());
17+
(function(exports) {
18+
'use strict';
19+
20+
var Eid = require('../eid');
21+
var commonExConstructor = function(eid, message) {
22+
if (!(eid instanceof Eid)) {
23+
eid = new Eid(eid.toString());
24+
}
25+
this.message = message !== undefined ? (eid + " " + message) : eid;
26+
this.eid = eid;
727
}
8-
this.message = message !== undefined ? (eid + " " + message) : eid;
9-
this.eid = eid;
10-
}
11-
var EidRuntimeException = (function() {
28+
1229
/**
1330
* <strong>This class shouldn't be used in any public API or library.</strong> It is designed to be used for in-house development
1431
* of end user applications which will report Bugs in standardized error pages or post them to issue tracker.
@@ -32,10 +49,7 @@ var EidRuntimeException = (function() {
3249
commonExConstructor.apply(this, [eid, message]);
3350
}
3451
EidRuntimeException.prototype = new Error();
35-
return EidRuntimeException;
36-
})();
3752

38-
var EidNullPointerException = (function() {
3953
/**
4054
* <strong>This class shouldn't be used in any public API or library.</strong> It is designed to be used for in-house development
4155
* of end user applications which will report Bugs in standardized error pages or post them to issue tracker.
@@ -54,10 +68,7 @@ var EidNullPointerException = (function() {
5468
commonExConstructor.apply(this, [eid, message]);
5569
}
5670
EidNullPointerException.prototype = EidRuntimeException.prototype;
57-
return EidNullPointerException;
58-
})();
5971

60-
var EidIllegalArgumentException = (function() {
6172
/**
6273
* <strong>This class shouldn't be used in any public API or library.</strong> It is designed to be used for in-house development
6374
* of end user applications which will report Bugs in standardized error pages or post them to issue tracker.
@@ -76,10 +87,7 @@ var EidIllegalArgumentException = (function() {
7687
commonExConstructor.apply(this, [eid, message]);
7788
}
7889
EidIllegalArgumentException.prototype = EidRuntimeException.prototype;
79-
return EidIllegalArgumentException;
80-
})();
8190

82-
var EidIllegalStateException = (function() {
8391
/**
8492
* <strong>This class shouldn't be used in any public API or library.</strong> It is designed to be used for in-house development
8593
* of end user applications which will report Bugs in standardized error pages or post them to issue tracker.
@@ -98,10 +106,7 @@ var EidIllegalStateException = (function() {
98106
commonExConstructor.apply(this, [eid, message]);
99107
}
100108
EidIllegalStateException.prototype = EidRuntimeException.prototype;
101-
return EidIllegalStateException;
102-
})();
103109

104-
var EidIndexOfOfBoundsException = (function() {
105110
/**
106111
* <strong>This class shouldn't be used in any public API or library.</strong> It is designed to be used for in-house development
107112
* of end user applications which will report Bugs in standardized error pages or post them to issue tracker.
@@ -115,16 +120,16 @@ var EidIndexOfOfBoundsException = (function() {
115120
* @see EidRuntimeException
116121
* @author Krzysztof Suszyński <[email protected]>
117122
*/
118-
function EidIndexOfOfBoundsException(eid, message) {
119-
this.name = 'EidIndexOfOfBoundsException';
123+
function EidIndexOutOfBoundsException(eid, message) {
124+
this.name = 'EidIndexOutOfBoundsException';
120125
commonExConstructor.apply(this, [eid, message]);
121126
}
122-
EidIndexOfOfBoundsException.prototype = EidRuntimeException.prototype;
123-
return EidIndexOfOfBoundsException;
124-
})();
127+
EidIndexOutOfBoundsException.prototype = EidRuntimeException.prototype;
128+
129+
exports.EidRuntimeException = EidRuntimeException;
130+
exports.EidNullPointerException = EidNullPointerException;
131+
exports.EidIllegalArgumentException = EidIllegalArgumentException;
132+
exports.EidIllegalStateException = EidIllegalStateException;
133+
exports.EidIndexOutOfBoundsException = EidIndexOutOfBoundsException;
125134

126-
exports.EidRuntimeException = EidRuntimeException;
127-
exports.EidNullPointerException = EidNullPointerException;
128-
exports.EidIllegalArgumentException = EidIllegalArgumentException;
129-
exports.EidIllegalStateException = EidIllegalStateException;
130-
exports.EidIndexOfOfBoundsException = EidIndexOfOfBoundsException;
135+
})(exports);

0 commit comments

Comments
 (0)