Skip to content

Commit

Permalink
Include traceur runtime into transpiled distribution file + test
Browse files Browse the repository at this point in the history
  • Loading branch information
lkrnac committed Oct 14, 2014
1 parent 2ca8242 commit 85560e6
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 10 deletions.
23 changes: 23 additions & 0 deletions gulpfile-es5.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'use strict';

var gulp = require('gulp');
var mocha = require('gulp-mocha');

var exec = require('child_process').exec;

//This task build in separate process to ensure that
//Traceur runtime is undefined for upcoming ES5 test
gulp.task('build', function (cb) {
exec('gulp build', function (err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
cb(err);
});
});

gulp.task('default', ['build'], function(){
return gulp.src('test/es5Spec.js')
.pipe(mocha({
reporter: 'spec'
}));
});
4 changes: 4 additions & 0 deletions lib/jasstor.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
*/
'use strict';

//Traceur is included here only to provide runtime in transpiled ES5 code
// jshint -W098
var traceur = require('gulp-traceur');

var fs = require('fs');
var bcrypt = require('bcrypt');

Expand Down
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,10 @@
"gulp-traceur": "^0.13.0",
"gulp-watch": "^0.7.0",
"jshint-stylish": "^0.4.0",
"should": "^4.0.4",
"traceur": "0.0.58"
"should": "^4.0.4"
},
"scripts": {
"test": "gulp coverage",
"test": "gulp --gulpfile gulpfile-es5.js && gulp coverage",
"build": "gulp build"
},
"dependencies": {
Expand Down
31 changes: 31 additions & 0 deletions test/es5Spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
'use strict';

// jshint -W098
var should = require('should');
var fs = require('fs');

var Jasstor = require('../dist/jasstor');
var checkError = require('./testUtils').checkError;

var credentialsFile = 'testCredentials.txt';

describe('Transpiled Jasstor library', function () {
var jasstor = new Jasstor(credentialsFile);
beforeEach(function (done) {
//ignore error when testing file didn't exist before deletion
fs.unlink(credentialsFile, function (err) {
jasstor.saveCredentials('user', 'password', function (err) {
done(err);
});
});
});
it('should work when included into ES5 module', function(done) {
fs.readFile(credentialsFile, function (err, data) {
checkError(err, done);
var jsonData = JSON.parse(data);
jsonData.user.should.be.ok;
jsonData.user.should.not.equal('password');
done();
});
});
});
8 changes: 1 addition & 7 deletions test/jasstorSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,11 @@ var fs = Bluebird.promisifyAll(require('fs'));
// jshint -W098
var should = require('should');

var checkError = require('../test/testUtils').checkError;
import Jasstor from '../dist/jasstor.js';

var credentialsFile = 'testCredentials.txt';

var checkError = (err, done) => {
if (err) {
done(err);
}
};

var readFilePromise = function (credentialsFile, userName) {
return fs.readFileAsync(credentialsFile)
.then(JSON.parse)
Expand Down Expand Up @@ -94,5 +89,4 @@ describe('jasstor', () => {
});
});
});

});
7 changes: 7 additions & 0 deletions test/testUtils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict';

module.exports.checkError = function(err, done) {
if (err) {
done(err);
}
};

0 comments on commit 85560e6

Please sign in to comment.