gulpjs / vinyl

Virtual file format.
MIT License
1.28k stars 105 forks source link

Accept a "data" property as additional metadata #23

Closed colynb closed 10 years ago

colynb commented 10 years ago

I'm developing a standard methodology for passing meta data to plugins using a separate plugin called gulp-data (see https://www.npmjs.org/package/gulp-data). It all works fine without this change, but when writing gulp plugin unit tests by instantiating a File object with the data property attached, the tests fail. It looks like setting a default value here fixes that. Now I can write tests on adhoc files:

var srcFile = new gutil.File({
  path: "test/fixtures/filepath.txt",
  cwd: "test/",
  base: "test/fixtures",
  contents: new Buffer("Fake data"),
  data: { message: "Some data" }
});
coveralls commented 10 years ago

Coverage Status

Coverage remained the same when pulling 2b56e743c4a8c15842283a2517bab80dced86085 on colynb:master into 83bd747bcce78c3d0e190494b75e852256e7fced on wearefractal:master.

yocontra commented 10 years ago

The entire file object is data though. How is this better than

var srcFile = new gutil.File({
  path: "test/fixtures/filepath.txt",
  cwd: "test/",
  base: "test/fixtures",
  contents: new Buffer("Fake data")
});
srcFile.message = 'some data';

?

colynb commented 10 years ago

I was so focused on trying to attach the prop during instantiation I didn't even think about adding it after the fact. Closing request.

var srcFile = new gutil.File({
  path: "test/fixtures/filepath.txt",
  cwd: "test/",
  base: "test/fixtures",
  contents: new Buffer("Fake data"),
  message1: "Hello"
});
srcFile.message2 = "World";

// srcFile.message1 === undefined
// srcFile.message2 === "World"