Skip to content

Commit

Permalink
clean up dest tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Contra committed Jan 16, 2014
1 parent 6996e80 commit 9e803f9
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 87 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# gulp changelog

# 3.4

- added `--tasks` that prints out the tree of tasks + deps
- global cli + local install mismatch is no longer fatal
- remove tests for fs stuff
- switch core src, dest, and watch to vinyl-fs

## 3.3.4

- `--base` is now `--cwd`
Expand Down
1 change: 0 additions & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
'use strict';

var gulp = require('./');
var gutil = require('gulp-util');

var mocha = require('gulp-mocha');
var jshint = require('gulp-jshint');
Expand Down
160 changes: 74 additions & 86 deletions test/dest.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@ var fs = require('graceful-fs');

require('mocha');

var outpath = join(__dirname, "./out-fixtures");

describe('gulp output stream', function() {
describe('dest()', function() {
beforeEach(rimraf.bind(null, outpath));
afterEach(rimraf.bind(null, outpath));

it('should return a stream', function(done) {
var stream = gulp.dest(join(__dirname, "./fixtures/"));
Expand All @@ -21,81 +25,69 @@ describe('gulp output stream', function() {
});

it('should return a output stream that writes files', function(done) {
var outpath = join(__dirname, "./out-fixtures");
rimraf(outpath, function(err){
should.not.exist(err);
var instream = gulp.src(join(__dirname, "./fixtures/**/*.txt"));
var outstream = gulp.dest(outpath);
instream.pipe(outstream);

outstream.on('error', done);
outstream.on('data', function(file) {
// data should be re-emitted right
should.exist(file);
should.exist(file.path);
should.exist(file.contents);
join(file.path,'').should.equal(join(__dirname, "./fixtures/copy/example.txt"));
String(file.contents).should.equal("this is a test");
});
outstream.on('end', function() {
fs.readFile(join(outpath, "copy", "example.txt"), function(err, contents){
should.not.exist(err);
should.exist(contents);
String(contents).should.equal("this is a test");
done();
});
var instream = gulp.src(join(__dirname, "./fixtures/**/*.txt"));
var outstream = gulp.dest(outpath);
instream.pipe(outstream);

outstream.on('error', done);
outstream.on('data', function(file) {
// data should be re-emitted right
should.exist(file);
should.exist(file.path);
should.exist(file.contents);
join(file.path,'').should.equal(join(__dirname, "./fixtures/copy/example.txt"));
String(file.contents).should.equal("this is a test");
});
outstream.on('end', function() {
fs.readFile(join(outpath, "copy", "example.txt"), function(err, contents){
should.not.exist(err);
should.exist(contents);
String(contents).should.equal("this is a test");
done();
});
});
});

it('should return a output stream that does not write non-read files', function(done) {
var outpath = join(__dirname, "./out-fixtures");
rimraf(outpath, function(err){
should.not.exist(err);
var instream = gulp.src(join(__dirname, "./fixtures/**/*.txt"), {read:false});
var outstream = gulp.dest(outpath);
instream.pipe(outstream);

outstream.on('error', done);
outstream.on('data', function(file) {
// data should be re-emitted right
should.exist(file);
should.exist(file.path);
should.not.exist(file.contents);
join(file.path,'').should.equal(join(__dirname, "./fixtures/copy/example.txt"));
});
outstream.on('end', function() {
fs.readFile(join(outpath, "copy", "example.txt"), function(err, contents){
should.exist(err);
should.not.exist(contents);
done();
});
var instream = gulp.src(join(__dirname, "./fixtures/**/*.txt"), {read:false});
var outstream = gulp.dest(outpath);
instream.pipe(outstream);

outstream.on('error', done);
outstream.on('data', function(file) {
// data should be re-emitted right
should.exist(file);
should.exist(file.path);
should.not.exist(file.contents);
join(file.path,'').should.equal(join(__dirname, "./fixtures/copy/example.txt"));
});
outstream.on('end', function() {
fs.readFile(join(outpath, "copy", "example.txt"), function(err, contents){
should.exist(err);
should.not.exist(contents);
done();
});
});
});

it('should return a output stream that writes streaming files', function(done) {
var outpath = join(__dirname, "./out-fixtures");
rimraf(outpath, function(err){
should.not.exist(err);
var instream = gulp.src(join(__dirname, "./fixtures/**/*.txt"), {buffer:false});
var outstream = instream.pipe(gulp.dest(outpath));

outstream.on('error', done);
outstream.on('data', function(file) {
// data should be re-emitted right
should.exist(file);
should.exist(file.path);
should.exist(file.contents);
join(file.path,'').should.equal(join(__dirname, "./fixtures/copy/example.txt"));
});
outstream.on('end', function() {
fs.readFile(join(outpath, "copy", "example.txt"), function(err, contents){
should.not.exist(err);
should.exist(contents);
String(contents).should.equal("this is a test");
done();
});
var instream = gulp.src(join(__dirname, "./fixtures/**/*.txt"), {buffer:false});
var outstream = instream.pipe(gulp.dest(outpath));

outstream.on('error', done);
outstream.on('data', function(file) {
// data should be re-emitted right
should.exist(file);
should.exist(file.path);
should.exist(file.contents);
join(file.path,'').should.equal(join(__dirname, "./fixtures/copy/example.txt"));
});
outstream.on('end', function() {
fs.readFile(join(outpath, "copy", "example.txt"), function(err, contents){
should.not.exist(err);
should.exist(contents);
String(contents).should.equal("this is a test");
done();
});
});
});
Expand All @@ -117,27 +109,23 @@ describe('gulp output stream', function() {
});

function testWriteDir(srcOptions, done) {
var outpath = join(__dirname, "./out-fixtures");
rimraf(outpath, function(err){
should.not.exist(err);
var instream = gulp.src(join(__dirname, "./fixtures/stuff"), srcOptions);
var outstream = instream.pipe(gulp.dest(outpath));

outstream.on('error', done);
outstream.on('data', function(file) {
// data should be re-emitted right
should.exist(file);
should.exist(file.path);
join(file.path,'').should.equal(join(__dirname, "./fixtures/stuff"));
});
outstream.on('end', function() {
fs.exists(join(outpath, "stuff"), function(exists) {
/* stinks that ok is an expression instead of a function call */
/* jshint expr: true */
should(exists).be.ok;
/* jshint expr: false */
done();
});
var instream = gulp.src(join(__dirname, "./fixtures/stuff"), srcOptions);
var outstream = instream.pipe(gulp.dest(outpath));

outstream.on('error', done);
outstream.on('data', function(file) {
// data should be re-emitted right
should.exist(file);
should.exist(file.path);
join(file.path,'').should.equal(join(__dirname, "./fixtures/stuff"));
});
outstream.on('end', function() {
fs.exists(join(outpath, "stuff"), function(exists) {
/* stinks that ok is an expression instead of a function call */
/* jshint expr: true */
should(exists).be.ok;
/* jshint expr: false */
done();
});
});
}
Expand Down

0 comments on commit 9e803f9

Please sign in to comment.