replace-in-file
Advanced tools
Comparing version 1.0.1 to 1.0.2
{ | ||
"name": "replace-in-file", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "A simple utility to quickly replace text in one or more files.", | ||
@@ -27,16 +27,20 @@ "homepage": "https://github.com/adambuczynski/replace-in-file#readme", | ||
"scripts": { | ||
"lint": "npm run lint:jshint --silent && npm run lint:jscs --silent", | ||
"lint": "npm run lint:jshint -s && npm run lint:jscs -s", | ||
"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", | ||
"preversion": "npm run test", | ||
"postversion": "git push && git push --tags && npm publish" | ||
"pretest": "npm run lint -s", | ||
"istanbul": "babel-node ./node_modules/istanbul/lib/cli cover ./node_modules/mocha/bin/_mocha test/**/*.spec.js", | ||
"test": "npm run istanbul -s", | ||
"preversion": "npm run test -s", | ||
"postversion": "git push && git push --tags && npm publish", | ||
"coverage": "open -a \"Google Chrome\" ./coverage/lcov-report/index.html" | ||
}, | ||
"devDependencies": { | ||
"babel-cli": "^6.5.1", | ||
"babel-preset-es2015": "^6.5.0", | ||
"babel-register": "^6.5.2", | ||
"bluebird": "^3.3.1", | ||
"chai": "^3.5.0", | ||
"chai-as-promised": "^5.2.0", | ||
"dirty-chai": "^1.2.2", | ||
"istanbul": "^1.0.0-alpha.2", | ||
"jscs": "^2.9.0", | ||
@@ -43,0 +47,0 @@ "jscs-stylish": "^0.3.1", |
@@ -5,3 +5,4 @@ # Replace in file | ||
[![node dependencies](https://david-dm.org/adambuczynski/replace-in-file.svg)](https://david-dm.org/adambuczynski/replace-in-file) | ||
[![Build Status](https://travis-ci.org/adambuczynski/replace-in-file.svg?branch=master)](https://travis-ci.org/adambuczynski/replace-in-file) | ||
[![build status](https://travis-ci.org/adambuczynski/replace-in-file.svg?branch=master)](https://travis-ci.org/adambuczynski/replace-in-file) | ||
[![coverage status](https://coveralls.io/repos/github/adambuczynski/replace-in-file/badge.svg?branch=master)](https://coveralls.io/github/adambuczynski/replace-in-file?branch=master) | ||
[![github issues](https://img.shields.io/github/issues/adambuczynski/replace-in-file.svg)](https://github.com/adambuczynski/replace-in-file/issues) | ||
@@ -50,2 +51,2 @@ | ||
Copyright 2015, [Adam Buczynski](http://adambuczynski.com) | ||
Copyright 2015-2016, [Adam Buczynski](http://adambuczynski.com) |
'use strict'; | ||
//Load dependencies | ||
let Promise = require('bluebird'); | ||
let chai = require('chai'); | ||
let dirtyChai = require('dirty-chai'); | ||
let chaiAsPromised = require('chai-as-promised'); | ||
//Enable should assertion style for usage with chai-as-promised | ||
chai.should(); | ||
//Extend chai | ||
chai.use(dirtyChai); | ||
chai.use(chaiAsPromised); | ||
//Expose globals | ||
global.Promise = Promise; | ||
global.expect = chai.expect; | ||
global.assert = chai.assert; |
@@ -24,3 +24,4 @@ 'use strict'; | ||
writeFile('test1', testData, 'utf8'), | ||
writeFile('test2', testData, 'utf8') | ||
writeFile('test2', testData, 'utf8'), | ||
writeFile('test3', 'nope', 'utf8') | ||
])); | ||
@@ -33,9 +34,10 @@ | ||
deleteFile('test1'), | ||
deleteFile('test2') | ||
deleteFile('test2'), | ||
deleteFile('test3') | ||
])); | ||
/** | ||
* Replace in one file | ||
* Tests | ||
*/ | ||
it('should replace contents in a single file', function(done) { | ||
it('should replace contents in a single file with regex', function(done) { | ||
replace({ | ||
@@ -54,5 +56,14 @@ files: 'test1', | ||
/** | ||
* Replace in multiple 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(); | ||
}); | ||
}); | ||
it('should replace contents in a an array of files', function(done) { | ||
@@ -72,16 +83,70 @@ replace({ | ||
/** | ||
* Replace in one file | ||
*/ | ||
it('should replace contents with a string replacement', function(done) { | ||
it('should not return an error on success', function(done) { | ||
replace({ | ||
files: 'test1', | ||
replace: 're place', | ||
replace: /re\splace/g, | ||
with: 'b' | ||
}, () => { | ||
let test1 = fs.readFileSync('test1', 'utf8'); | ||
expect(test1).to.equal('a b c'); | ||
}, (error) => { | ||
expect(error).to.equal(null); | ||
done(); | ||
}); | ||
}); | ||
it('should return an error on failure', function(done) { | ||
replace({ | ||
files: 'nope', | ||
replace: /re\splace/g, | ||
with: 'b' | ||
}, (error) => { | ||
expect(error).not.to.equal(null); | ||
done(); | ||
}); | ||
}); | ||
it('should return a changed files array', function(done) { | ||
replace({ | ||
files: 'test1', | ||
replace: /re\splace/g, | ||
with: 'b' | ||
}, (error, changedFiles) => { | ||
expect(changedFiles).to.be.instanceof(Array); | ||
done(); | ||
}); | ||
}); | ||
it('should return in changed files if something was replaced', function(done) { | ||
replace({ | ||
files: 'test1', | ||
replace: /re\splace/g, | ||
with: 'b' | ||
}, (error, changedFiles) => { | ||
expect(changedFiles).to.have.length(1); | ||
expect(changedFiles[0]).to.equal('test1'); | ||
done(); | ||
}); | ||
}); | ||
it('should not return in changed files if nothing replaced', function(done) { | ||
replace({ | ||
files: 'test1', | ||
replace: 'nope', | ||
with: 'b' | ||
}, (error, changedFiles) => { | ||
expect(changedFiles).to.have.length(0); | ||
done(); | ||
}); | ||
}); | ||
it('should return changed files for multiple files', function(done) { | ||
replace({ | ||
files: ['test1', 'test2', 'test3'], | ||
replace: /re\splace/g, | ||
with: 'b' | ||
}, (error, changedFiles) => { | ||
expect(changedFiles).to.have.length(2); | ||
expect(changedFiles).to.contain('test1'); | ||
expect(changedFiles).to.contain('test2'); | ||
done(); | ||
}); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
10378
206
51
0
12