diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..4282322 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +# Set the default behavior, in case people don't have core.autocrlf set. +* text eol=lf diff --git a/.gitignore b/.gitignore index f49712c..37e0121 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ .DS_Store -Thumbs.db -node_modules/ -npm-debug.log +node_modules +*.log diff --git a/.jscsrc b/.jscsrc index ee83f5b..5261305 100644 --- a/.jscsrc +++ b/.jscsrc @@ -2,17 +2,17 @@ "preset": "google", "fileExtensions": [".js"], "maxErrors": 100, - "verbose": true, + "verbose": false, "excludeFiles": [ - "public/**", - "node_modules/**", - "client/vendor/**" + "node_modules/**" ], - "requireParenthesesAroundIIFE": true, + "requireCamelCaseOrUpperCaseIdentifiers": "ignoreProperties", "maximumLineLength": 100, "validateLineBreaks": "LF", "validateIndentation": 2, + "disallowTrailingComma": true, + "disallowMultipleSpaces": true, "disallowMultipleVarDecl": "exceptUndefined", "disallowKeywordsOnNewLine": null, "disallowSpacesInsideObjectBrackets": null, diff --git a/.jshintignore b/.jshintignore index c2658d7..3c3629e 100644 --- a/.jshintignore +++ b/.jshintignore @@ -1 +1 @@ -node_modules/ +node_modules diff --git a/.jshintrc b/.jshintrc index 14128db..46b3abe 100644 --- a/.jshintrc +++ b/.jshintrc @@ -8,7 +8,6 @@ "funcscope": true, "futurehostile": true, "globals": { - "angular": false, "define": false, "require": false, "exports": false, @@ -20,15 +19,16 @@ "afterEach": false, "it": false, "inject": false, - "expect": false + "expect": false, + "Promise": true }, - "latedef": true, + "latedef": "nofunc", "noarg": true, "nonew": true, "notypeof": true, "strict": false, "undef": true, - "unused": false, - "browser": true, + "unused": true, + "browser": false, "node": true } diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..6091171 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,18 @@ +language: node_js +node_js: + - "0.10" + - "0.11" + - "0.12" + - "4" + - "5" + - "iojs" +branches: + only: + - master +before_install: + - "npm install -g istanbul" +script: + - "npm run test-ci" +after_script: + - "npm install -g coveralls" + - "cat ./coverage/lcov.info | coveralls" diff --git a/package.json b/package.json index d8d2c87..94c648c 100644 --- a/package.json +++ b/package.json @@ -24,17 +24,20 @@ ], "main": "index.js", "scripts": { - "jshint": "./node_modules/jshint/bin/jshint --reporter=node_modules/jshint-stylish . || true", - "jscs": "./node_modules/jscs/bin/jscs . || true", - "pretest": "npm run jscs & npm run jshint", - "test": "node test.js" + "lint": "npm run lint:jshint --silent && npm run lint:jscs --silent", + "lint:jshint": "jshint . --reporter=node_modules/jshint-stylish", + "lint:jscs": "jscs . --reporter=node_modules/jscs-stylish", + "pretest": "npm run lint", + "test": "mocha test/**/*.spec.js", + "test-ci": "npm run lint && istanbul cover ./node_modules/mocha/bin/_mocha" }, "devDependencies": { - "jasmine": "^2.3.2", - "jasmine-spec-reporter": "^2.4.0", - "jscs": "^2.5.1", - "jshint": "^2.8.0", + "bluebird": "^3.3.1", + "chai": "^3.5.0", + "jscs": "^2.9.0", + "jscs-stylish": "^0.3.1", + "jshint": "^2.9.1", "jshint-stylish": "^2.1.0", - "jsonfile": "^2.2.3" + "mocha": "^2.4.5" } } diff --git a/test.js b/test.js deleted file mode 100644 index 3721bc3..0000000 --- a/test.js +++ /dev/null @@ -1,32 +0,0 @@ -/* global jasmine */ -/* jscs:disable requireCamelCaseOrUpperCaseIdentifiers */ - -/** - * Module dependencies - */ -var Jasmine = require('jasmine'); -var SpecReporter = require('jasmine-spec-reporter'); -var noop = function() {}; - -//Initialize jasmine -var jrunner = new Jasmine(); - -//Set reporters -jrunner.configureDefaultReporter({ - print: noop -}); -jasmine.getEnv().addReporter(new SpecReporter()); - -//Configure -jrunner.loadConfig({ - spec_dir: 'tests', - spec_files: [ - '**/*.spec.js' - ], - helpers: [ - 'helpers/**/*.js' - ] -}); - -//Run tests -jrunner.execute(); diff --git a/test/helpers/setup.js b/test/helpers/setup.js new file mode 100644 index 0000000..70961e9 --- /dev/null +++ b/test/helpers/setup.js @@ -0,0 +1,8 @@ +'use strict'; + +let Promise = require('bluebird'); +let chai = require('chai'); + +global.Promise = Promise; +global.expect = chai.expect; +global.assert = chai.assert; diff --git a/test/mocha.opts b/test/mocha.opts new file mode 100644 index 0000000..c261c3b --- /dev/null +++ b/test/mocha.opts @@ -0,0 +1 @@ +--require test/helpers/setup diff --git a/test/replaceInFile.spec.js b/test/replaceInFile.spec.js new file mode 100644 index 0000000..38986e8 --- /dev/null +++ b/test/replaceInFile.spec.js @@ -0,0 +1,83 @@ +'use strict'; + +/** + * Dependencies + */ +let replace = require('../lib/replaceInFile'); +let fs = require('fs'); +let writeFile = Promise.promisify(fs.writeFile); +let deleteFile = Promise.promisify(fs.unlink); + +/** + * Specifications + */ +describe('Replace in file', () => { + + //Test JSON + let testData = 'a re place c'; + + /** + * Prepare test files + */ + beforeEach(() => Promise.all([ + writeFile('test1', testData, 'utf8'), + writeFile('test2', testData, 'utf8') + ])); + + /** + * Clean up test files + */ + afterEach(() => Promise.all([ + deleteFile('test1'), + deleteFile('test2') + ])); + + /** + * Replace in one file + */ + it('should replace contents in a single file', function(done) { + replace({ + files: 'test1', + replace: /re\splace/g, + with: 'b' + }, () => { + let test1 = fs.readFileSync('test1', 'utf8'); + let test2 = fs.readFileSync('test2', 'utf8'); + expect(test1).to.equal('a b c'); + expect(test2).to.equal(testData); + done(); + }); + }); + + /** + * Replace in multiple file + */ + it('should replace contents in a an array of files', function(done) { + replace({ + files: ['test1', 'test2'], + replace: /re\splace/g, + with: 'b' + }, () => { + let test1 = fs.readFileSync('test1', 'utf8'); + let test2 = fs.readFileSync('test2', 'utf8'); + expect(test1).to.equal('a b c'); + expect(test2).to.equal('a b c'); + done(); + }); + }); + + /** + * Replace in one file + */ + it('should replace contents with a string replacement', function(done) { + replace({ + files: 'test1', + replace: 're place', + with: 'b' + }, () => { + let test1 = fs.readFileSync('test1', 'utf8'); + expect(test1).to.equal('a b c'); + done(); + }); + }); +}); diff --git a/tests/replaceInFile.spec.js b/tests/replaceInFile.spec.js deleted file mode 100644 index 7d315d3..0000000 --- a/tests/replaceInFile.spec.js +++ /dev/null @@ -1,84 +0,0 @@ -'use strict'; - -/** - * Specifications - */ -describe('Replace in file', function() { - - //Get modules - var replace = require('../lib/replaceInFile'); - var jf = require('jsonfile'); - var fs = require('fs'); - - //Test JSON - var testJson = { - test: 'a re place c' - }; - - /** - * Prepare test files - */ - beforeEach(function(done) { - Promise.all([ - jf.writeFileSync('test1.json', testJson), - jf.writeFileSync('test2.json', testJson) - ]).then(done); - }); - - /** - * Clean up test files - */ - afterEach(function(done) { - Promise.all([ - fs.unlink('test1.json'), - fs.unlink('test2.json') - ]).then(done); - }); - - /** - * Replace in one file - */ - it('should replace contents in a single file', function(done) { - replace({ - files: 'test1.json', - replace: /re\splace/g, - with: 'b' - }, function(error) { - var test1 = jf.readFileSync('test1.json'); - expect(test1.test).toBe('a b c'); - done(); - }); - }); - - /** - * Replace in multiple file - */ - it('should replace contents in a an array of files', function(done) { - replace({ - files: ['test1.json', 'test2.json'], - replace: /re\splace/g, - with: 'b' - }, function(error) { - var test1 = jf.readFileSync('test1.json'); - var test2 = jf.readFileSync('test2.json'); - expect(test1.test).toBe('a b c'); - expect(test2.test).toBe('a b c'); - done(); - }); - }); - - /** - * Replace in one file - */ - it('should replace contents with a string replacement', function(done) { - replace({ - files: 'test1.json', - replace: 're place', - with: 'b' - }, function(error) { - var test1 = jf.readFileSync('test1.json'); - expect(test1.test).toBe('a b c'); - done(); - }); - }); -});