Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
*/

var es = require('event-stream'),
gutil = require('gulp-util');
PluginError = require('plugin-error');

var stream = function(injectMethod){
return es.map(function (file, cb) {
try {
file.contents = new Buffer( injectMethod( String(file.contents) ));
} catch (err) {
return cb(new gutil.PluginError('gulp-inject-string', err));
return cb(new PluginError('gulp-inject-string', err));
}
cb(null, file);
});
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@
"gulp": "^3.8.6",
"gulp-rename": "^1.2.0",
"istanbul": "^0.4.0",
"mocha": "^2.3.4"
"mocha": "^2.3.4",
"vinyl": "^2.1.0"
},
"dependencies": {
"event-stream": "^3.1.7",
"gulp-util": "^3.0.0"
"plugin-error": "^0.1.2"
}
}
25 changes: 13 additions & 12 deletions tests/test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@

var fs = require('fs'),
path = require('path'),
gutil = require('gulp-util'),
os = require('os'),
Vinyl = require('vinyl'),
mocha = require('mocha'),
expect = require('chai').expect,
inject = require('../');
Expand Down Expand Up @@ -43,7 +44,7 @@ describe('gulp-inject-string', function(){
var fakeFile;

beforeEach(function () {
fakeFile = new gutil.File({
fakeFile = new Vinyl({
base: 'test/fixtures',
cwd: 'test/',
path: 'test/fixtures/index.html',
Expand All @@ -69,7 +70,7 @@ describe('gulp-inject-string', function(){
var fakeFile;

beforeEach(function () {
fakeFile = new gutil.File({
fakeFile = new Vinyl({
base: 'test/fixtures',
cwd: 'test/',
path: 'test/fixtures/index.html',
Expand All @@ -95,7 +96,7 @@ describe('gulp-inject-string', function(){
var fakeFile;

beforeEach(function () {
fakeFile = new gutil.File({
fakeFile = new Vinyl({
base: 'test/fixtures',
cwd: 'test/',
path: 'test/fixtures/index.html',
Expand All @@ -121,7 +122,7 @@ describe('gulp-inject-string', function(){
var fakeFile;

beforeEach(function () {
fakeFile = new gutil.File({
fakeFile = new Vinyl({
base: 'test/fixtures',
cwd: 'test',
path: 'test/fixtures/index.html',
Expand Down Expand Up @@ -161,7 +162,7 @@ describe('gulp-inject-string', function(){
var fakeFile;

beforeEach(function () {
fakeFile = new gutil.File({
fakeFile = new Vinyl({
base: 'test/fixtures',
cwd: 'test',
path: 'test/fixtures/index.html',
Expand Down Expand Up @@ -200,7 +201,7 @@ describe('gulp-inject-string', function(){
var fakeFile;

beforeEach(function () {
fakeFile = new gutil.File({
fakeFile = new Vinyl({
base: 'test/fixtures',
cwd: 'test',
path: 'test/fixtures/index.html',
Expand Down Expand Up @@ -235,7 +236,7 @@ describe('gulp-inject-string', function(){
});

it('should work for a match at the first character in the target', function(done){
var stream = inject.beforeEach('<!doctype', '<!-- this is a poor example but should still work -->\n');
var stream = inject.beforeEach('<!doctype', '<!-- this is a poor example but should still work -->' + os.EOL);
var expectedFile = fs.readFileSync( path.join(__dirname, './expected/beforeEach2.html'));

stream.once('data', function(newFile){
Expand All @@ -253,7 +254,7 @@ describe('gulp-inject-string', function(){
var fakeFile;

beforeEach(function () {
fakeFile = new gutil.File({
fakeFile = new Vinyl({
base: 'test/fixtures',
cwd: 'test',
path: 'test/fixtures/index.html',
Expand Down Expand Up @@ -288,7 +289,7 @@ describe('gulp-inject-string', function(){
});

it('should work for a match at the last character in the target', function(done){
var stream = inject.afterEach('</html>\n', '<!-- this is a poor example but should still work -->\n');
var stream = inject.afterEach('</html>' + os.EOL, '<!-- this is a poor example but should still work -->' + os.EOL);
var expectedFile = fs.readFileSync( path.join(__dirname, './expected/afterEach2.html'));

stream.once('data', function(newFile){
Expand All @@ -305,7 +306,7 @@ describe('gulp-inject-string', function(){
var fakeFile;

beforeEach(function () {
fakeFile = new gutil.File({
fakeFile = new Vinyl({
base: 'test/fixtures',
cwd: 'test',
path: 'test/fixtures/index.html',
Expand Down Expand Up @@ -355,7 +356,7 @@ describe('gulp-inject-string', function(){

describe('_stream', function () {

it('should fail with a gulp-util.PluginError', function(done){
it('should fail with a PluginError', function(done){
var stream = inject._stream(null, { method: 'fail' });

stream.once('error', function(error){
Expand Down