Skip to content

Commit

Permalink
chore: Add integration test for re-assigning a stream to contents (#339)
Browse files Browse the repository at this point in the history
  • Loading branch information
phated authored Jun 11, 2023
1 parent 0baaf36 commit 061d1b3
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions test/integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,22 @@ var testConstants = require('./utils/test-constants');
var describeStreams = require('./utils/suite');

var base = testConstants.outputBase;
var inputPath = testConstants.inputPath;
var inputDirpath = testConstants.inputDirpath;
var outputDirpath = testConstants.outputDirpath;
var symlinkDirpath = testConstants.symlinkDirpath;
var inputBase = path.join(base, './in/');
var inputGlob = path.join(inputBase, './*.txt');
var outputBase = path.join(base, './out/');
var outputPath = path.join(outputBase, './test.txt');
var outputSymlink = path.join(symlinkDirpath, './foo');
var outputDirpathSymlink = path.join(outputDirpath, './foo');
var content = testConstants.contents;

var clean = cleanup(base);

describeStreams('integrations', function (stream) {
var from = stream.Readable.from;
var pipeline = stream.pipeline;

var streamUtils = testStreams(stream);
Expand Down Expand Up @@ -204,4 +207,32 @@ describeStreams('integrations', function (stream) {
done
);
});

it('can re-assign contents to a well-behaving stream as per issue #310', function (done) {
var contents = ['something', ' ', 'else'];

function assert() {
expect(fs.readFileSync(outputPath).toString()).toEqual(contents.join(''));
done();
}

pipeline(
[
vfs.src(inputPath),
new stream.Transform({
objectMode: true,
transform: function (file, enc, cb) {
if (typeof enc === 'function') {
cb = enc;
}

file.contents = from(contents);
cb(null, file);
},
}),
vfs.dest(outputBase),
],
assert
);
});
});

0 comments on commit 061d1b3

Please sign in to comment.