Update test process

This commit is contained in:
Adam Buczynski
2016-02-16 15:20:46 +13:00
parent 527852b6b2
commit ec8209b2b0
12 changed files with 137 additions and 139 deletions

2
.gitattributes vendored Normal file
View File

@@ -0,0 +1,2 @@
# Set the default behavior, in case people don't have core.autocrlf set.
* text eol=lf

5
.gitignore vendored
View File

@@ -1,4 +1,3 @@
.DS_Store
Thumbs.db
node_modules/
npm-debug.log
node_modules
*.log

10
.jscsrc
View File

@@ -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,

View File

@@ -1 +1 @@
node_modules/
node_modules

View File

@@ -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
}

18
.travis.yml Normal file
View File

@@ -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"

View File

@@ -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"
}
}

32
test.js
View File

@@ -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();

8
test/helpers/setup.js Normal file
View File

@@ -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;

1
test/mocha.opts Normal file
View File

@@ -0,0 +1 @@
--require test/helpers/setup

View File

@@ -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();
});
});
});

View File

@@ -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();
});
});
});