pax_global_header00006660000000000000000000000064133131770400014511gustar00rootroot0000000000000052 comment=09c5bf424cca072c2ee63a7d3c68d885923f173c vinyl-2.2.0/000077500000000000000000000000001331317704000126535ustar00rootroot00000000000000vinyl-2.2.0/.editorconfig000066400000000000000000000003261331317704000153310ustar00rootroot00000000000000# http://editorconfig.org root = true [*] indent_style = space indent_size = 2 charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true end_of_line = lf [*.md] trim_trailing_whitespace = false vinyl-2.2.0/.eslintignore000066400000000000000000000000121331317704000153470ustar00rootroot00000000000000coverage/ vinyl-2.2.0/.eslintrc000066400000000000000000000000301331317704000144700ustar00rootroot00000000000000{ "extends": "gulp" } vinyl-2.2.0/.gitattributes000066400000000000000000000000161331317704000155430ustar00rootroot00000000000000* text eol=lf vinyl-2.2.0/.gitignore000066400000000000000000000011461331317704000146450ustar00rootroot00000000000000# Logs logs *.log # Runtime data pids *.pid *.seed # Directory for instrumented libs generated by jscoverage/JSCover lib-cov # Coverage directory used by tools like istanbul coverage # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) .grunt # Compiled binary addons (http://nodejs.org/api/addons.html) build/Release # Dependency directory # Commenting this out is preferred by some people, see # https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git- node_modules # Users Environment Variables .lock-wscript # Garbage files .DS_Store vinyl-2.2.0/.jscsrc000066400000000000000000000000271331317704000141420ustar00rootroot00000000000000{ "preset": "gulp" } vinyl-2.2.0/.travis.yml000066400000000000000000000002021331317704000147560ustar00rootroot00000000000000sudo: false language: node_js node_js: - '10' - '8' - '6' - '4' - '0.12' - '0.10' after_script: - npm run coveralls vinyl-2.2.0/LICENSE000066400000000000000000000022141331317704000136570ustar00rootroot00000000000000The MIT License (MIT) Copyright (c) 2013 Blaine Bublitz , Eric Schoffstall and other contributors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. vinyl-2.2.0/README.md000066400000000000000000000307631331317704000141430ustar00rootroot00000000000000

# vinyl [![NPM version][npm-image]][npm-url] [![Downloads][downloads-image]][npm-url] [![Build Status][travis-image]][travis-url] [![AppVeyor Build Status][appveyor-image]][appveyor-url] [![Coveralls Status][coveralls-image]][coveralls-url] [![Gitter chat][gitter-image]][gitter-url] Virtual file format. ## What is Vinyl? Vinyl is a very simple metadata object that describes a file. When you think of a file, two attributes come to mind: `path` and `contents`. These are the main attributes on a Vinyl object. A file does not necessarily represent something on your computer’s file system. You have files on S3, FTP, Dropbox, Box, CloudThingly.io and other services. Vinyl can be used to describe files from all of these sources. ## What is a Vinyl Adapter? While Vinyl provides a clean way to describe a file, we also need a way to access these files. Each file source needs what I call a "Vinyl adapter". A Vinyl adapter simply exposes a `src(globs)` and a `dest(folder)` method. Each return a stream. The `src` stream produces Vinyl objects, and the `dest` stream consumes Vinyl objects. Vinyl adapters can expose extra methods that might be specific to their input/output medium, such as the `symlink` method [`vinyl-fs`][vinyl-fs] provides. ## Usage ```js var Vinyl = require('vinyl'); var jsFile = new Vinyl({ cwd: '/', base: '/test/', path: '/test/file.js', contents: new Buffer('var x = 123') }); ``` ## API ### `new Vinyl([options])` The constructor is used to create a new instance of `Vinyl`. Each instance represents a separate file, directory or symlink. All internally managed paths (`cwd`, `base`, `path`, `history`) are normalized and have trailing separators removed. See [Normalization and concatenation][normalization] for more information. Options may be passed upon instantiation to create a file with specific properties. #### `options` Options are not mutated by the constructor. ##### `options.cwd` The current working directory of the file. Type: `String` Default: `process.cwd()` ##### `options.base` Used for calculating the `relative` property. This is typically where a glob starts. Type: `String` Default: `options.cwd` ##### `options.path` The full path to the file. Type: `String` Default: `undefined` ##### `options.history` Stores the path history. If `options.path` and `options.history` are both passed, `options.path` is appended to `options.history`. All `options.history` paths are normalized by the `file.path` setter. Type: `Array` Default: `[]` (or `[options.path]` if `options.path` is passed) ##### `options.stat` The result of an `fs.stat` call. This is how you mark the file as a directory or symbolic link. See [isDirectory()][is-directory], [isSymbolic()][is-symbolic] and [fs.Stats][fs-stats] for more information. Type: [`fs.Stats`][fs-stats] Default: `undefined` ##### `options.contents` The contents of the file. If `options.contents` is a [`ReadableStream`][readable-stream], it is wrapped in a [`cloneable-readable`][cloneable-readable] stream. Type: [`ReadableStream`][readable-stream], [`Buffer`][buffer], or `null` Default: `null` ##### `options.{custom}` Any other option properties will be directly assigned to the new Vinyl object. ```js var Vinyl = require('vinyl'); var file = new Vinyl({ foo: 'bar' }); file.foo === 'bar'; // true ``` ### Instance methods Each Vinyl object will have instance methods. Every method will be available but may return differently based on what properties were set upon instantiation or modified since. #### `file.isBuffer()` Returns `true` if the file contents are a [`Buffer`][buffer], otherwise `false`. #### `file.isStream()` Returns `true` if the file contents are a [`Stream`][stream], otherwise `false`. #### `file.isNull()` Returns `true` if the file contents are `null`, otherwise `false`. #### `file.isDirectory()` Returns `true` if the file represents a directory, otherwise `false`. A file is considered a directory when: - `file.isNull()` is `true` - `file.stat` is an object - `file.stat.isDirectory()` returns `true` When constructing a Vinyl object, pass in a valid [`fs.Stats`][fs-stats] object via `options.stat`. If you are mocking the [`fs.Stats`][fs-stats] object, you may need to stub the `isDirectory()` method. #### `file.isSymbolic()` Returns `true` if the file represents a symbolic link, otherwise `false`. A file is considered symbolic when: - `file.isNull()` is `true` - `file.stat` is an object - `file.stat.isSymbolicLink()` returns `true` When constructing a Vinyl object, pass in a valid [`fs.Stats`][fs-stats] object via `options.stat`. If you are mocking the [`fs.Stats`][fs-stats] object, you may need to stub the `isSymbolicLink()` method. #### `file.clone([options])` Returns a new Vinyl object with all attributes cloned. __By default custom attributes are cloned deeply.__ If `options` or `options.deep` is `false`, custom attributes will not be cloned deeply. If `file.contents` is a [`Buffer`][buffer] and `options.contents` is `false`, the [`Buffer`][buffer] reference will be reused instead of copied. #### `file.inspect()` Returns a formatted-string interpretation of the Vinyl object. Automatically called by node's `console.log`. ### Instance properties Each Vinyl object will have instance properties. Some may be unavailable based on what properties were set upon instantiation or modified since. #### `file.contents` Gets and sets the contents of the file. If set to a [`ReadableStream`][readable-stream], it is wrapped in a [`cloneable-readable`][cloneable-readable] stream. Throws when set to any value other than a [`ReadableStream`][readable-stream], a [`Buffer`][buffer] or `null`. Type: [`ReadableStream`][readable-stream], [`Buffer`][buffer], or `null` #### `file.cwd` Gets and sets current working directory. Will always be normalized and have trailing separators removed. Throws when set to any value other than non-empty strings. Type: `String` #### `file.base` Gets and sets base directory. Used for relative pathing (typically where a glob starts). When `null` or `undefined`, it simply proxies the `file.cwd` property. Will always be normalized and have trailing separators removed. Throws when set to any value other than non-empty strings or `null`/`undefined`. Type: `String` #### `file.path` Gets and sets the absolute pathname string or `undefined`. Setting to a different value appends the new path to `file.history`. If set to the same value as the current path, it is ignored. All new values are normalized and have trailing separators removed. Throws when set to any value other than a string. Type: `String` #### `file.history` Array of `file.path` values the Vinyl object has had, from `file.history[0]` (original) through `file.history[file.history.length - 1]` (current). `file.history` and its elements should normally be treated as read-only and only altered indirectly by setting `file.path`. Type: `Array` #### `file.relative` Gets the result of `path.relative(file.base, file.path)`. Throws when set or when `file.path` is not set. Type: `String` Example: ```js var file = new File({ cwd: '/', base: '/test/', path: '/test/file.js' }); console.log(file.relative); // file.js ``` #### `file.dirname` Gets and sets the dirname of `file.path`. Will always be normalized and have trailing separators removed. Throws when `file.path` is not set. Type: `String` Example: ```js var file = new File({ cwd: '/', base: '/test/', path: '/test/file.js' }); console.log(file.dirname); // /test file.dirname = '/specs'; console.log(file.dirname); // /specs console.log(file.path); // /specs/file.js ``` #### `file.basename` Gets and sets the basename of `file.path`. Throws when `file.path` is not set. Type: `String` Example: ```js var file = new File({ cwd: '/', base: '/test/', path: '/test/file.js' }); console.log(file.basename); // file.js file.basename = 'file.txt'; console.log(file.basename); // file.txt console.log(file.path); // /test/file.txt ``` #### `file.stem` Gets and sets stem (filename without suffix) of `file.path`. Throws when `file.path` is not set. Type: `String` Example: ```js var file = new File({ cwd: '/', base: '/test/', path: '/test/file.js' }); console.log(file.stem); // file file.stem = 'foo'; console.log(file.stem); // foo console.log(file.path); // /test/foo.js ``` #### `file.extname` Gets and sets extname of `file.path`. Throws when `file.path` is not set. Type: `String` Example: ```js var file = new File({ cwd: '/', base: '/test/', path: '/test/file.js' }); console.log(file.extname); // .js file.extname = '.txt'; console.log(file.extname); // .txt console.log(file.path); // /test/file.txt ``` #### `file.symlink` Gets and sets the path where the file points to if it's a symbolic link. Will always be normalized and have trailing separators removed. Throws when set to any value other than a string. Type: `String` ### `Vinyl.isVinyl(file)` Static method used for checking if an object is a Vinyl file. Use this method instead of `instanceof`. Takes an object and returns `true` if it is a Vinyl file, otherwise returns `false`. __Note: This method uses an internal flag that some older versions of Vinyl didn't expose.__ Example: ```js var Vinyl = require('vinyl'); var file = new Vinyl(); var notAFile = {}; Vinyl.isVinyl(file); // true Vinyl.isVinyl(notAFile); // false ``` ### `Vinyl.isCustomProp(property)` Static method used by Vinyl when setting values inside the constructor or when copying properties in `file.clone()`. Takes a string `property` and returns `true` if the property is not used internally, otherwise returns `false`. This method is useful for inheritting from the Vinyl constructor. Read more in [Extending Vinyl][extending-vinyl]. Example: ```js var Vinyl = require('vinyl'); Vinyl.isCustomProp('sourceMap'); // true Vinyl.isCustomProp('path'); // false -> internal getter/setter ``` ## Normalization and concatenation Since all properties are normalized in their setters, you can just concatenate with `/`, and normalization takes care of it properly on all platforms. Example: ```js var file = new File(); file.path = '/' + 'test' + '/' + 'foo.bar'; console.log(file.path); // posix => /test/foo.bar // win32 => \\test\\foo.bar ``` But never concatenate with `\`, since that is a valid filename character on posix system. ## Extending Vinyl When extending Vinyl into your own class with extra features, you need to think about a few things. When you have your own properties that are managed internally, you need to extend the static `isCustomProp` method to return `false` when one of these properties is queried. ```js var Vinyl = require('vinyl'); var builtInProps = ['foo', '_foo']; class SuperFile extends Vinyl { constructor(options) { super(options); this._foo = 'example internal read-only value'; } get foo() { return this._foo; } static isCustomProp(name) { return super.isCustomProp(name) && builtInProps.indexOf(name) === -1; } } ``` This makes properties `foo` and `_foo` ignored when cloning, and when passed in options to `constructor(options)` so they don't get assigned to the new object. Same goes for `clone()`. If you have your own internal stuff that needs special handling during cloning, you should extend it to do so. ## License MIT [is-symbolic]: #issymbolic [is-directory]: #isdirectory [normalization]: #normalization-and-concatenation [extending-vinyl]: #extending-vinyl [stream]: https://nodejs.org/api/stream.html#stream_stream [readable-stream]: https://nodejs.org/api/stream.html#stream_readable_streams [buffer]: https://nodejs.org/api/buffer.html#buffer_class_buffer [fs-stats]: http://nodejs.org/api/fs.html#fs_class_fs_stats [vinyl-fs]: https://github.com/gulpjs/vinyl-fs [cloneable-readable]: https://github.com/mcollina/cloneable-readable [downloads-image]: http://img.shields.io/npm/dm/vinyl.svg [npm-url]: https://www.npmjs.com/package/vinyl [npm-image]: http://img.shields.io/npm/v/vinyl.svg [travis-url]: https://travis-ci.org/gulpjs/vinyl [travis-image]: http://img.shields.io/travis/gulpjs/vinyl.svg?label=travis-ci [appveyor-url]: https://ci.appveyor.com/project/gulpjs/vinyl [appveyor-image]: https://img.shields.io/appveyor/ci/gulpjs/vinyl.svg?label=appveyor [coveralls-url]: https://coveralls.io/r/gulpjs/vinyl [coveralls-image]: http://img.shields.io/coveralls/gulpjs/vinyl/master.svg [gitter-url]: https://gitter.im/gulpjs/gulp [gitter-image]: https://badges.gitter.im/gulpjs/gulp.svg vinyl-2.2.0/appveyor.yml000066400000000000000000000007541331317704000152510ustar00rootroot00000000000000# http://www.appveyor.com/docs/appveyor-yml # http://www.appveyor.com/docs/lang/nodejs-iojs environment: matrix: # node.js - nodejs_version: "0.10" - nodejs_version: "0.12" - nodejs_version: "4" - nodejs_version: "6" - nodejs_version: "8" - nodejs_version: "10" install: - ps: Install-Product node $env:nodejs_version - npm install test_script: - node --version - npm --version - cmd: npm test build: off # build version format version: "{build}" vinyl-2.2.0/index.js000066400000000000000000000174671331317704000143370ustar00rootroot00000000000000'use strict'; var path = require('path'); var util = require('util'); var isBuffer = require('buffer').Buffer.isBuffer; var clone = require('clone'); var cloneable = require('cloneable-readable'); var replaceExt = require('replace-ext'); var cloneStats = require('clone-stats'); var cloneBuffer = require('clone-buffer'); var removeTrailingSep = require('remove-trailing-separator'); var isStream = require('./lib/is-stream'); var normalize = require('./lib/normalize'); var inspectStream = require('./lib/inspect-stream'); var builtInFields = [ '_contents', '_symlink', 'contents', 'stat', 'history', 'path', '_base', 'base', '_cwd', 'cwd', ]; function File(file) { var self = this; if (!file) { file = {}; } // Stat = files stats object this.stat = file.stat || null; // Contents = stream, buffer, or null if not read this.contents = file.contents || null; // Replay path history to ensure proper normalization and trailing sep var history = Array.prototype.slice.call(file.history || []); if (file.path) { history.push(file.path); } this.history = []; history.forEach(function(path) { self.path = path; }); this.cwd = file.cwd || process.cwd(); this.base = file.base; this._isVinyl = true; this._symlink = null; // Set custom properties Object.keys(file).forEach(function(key) { if (self.constructor.isCustomProp(key)) { self[key] = file[key]; } }); } File.prototype.isBuffer = function() { return isBuffer(this.contents); }; File.prototype.isStream = function() { return isStream(this.contents); }; File.prototype.isNull = function() { return (this.contents === null); }; File.prototype.isDirectory = function() { if (!this.isNull()) { return false; } if (this.stat && typeof this.stat.isDirectory === 'function') { return this.stat.isDirectory(); } return false; }; File.prototype.isSymbolic = function() { if (!this.isNull()) { return false; } if (this.stat && typeof this.stat.isSymbolicLink === 'function') { return this.stat.isSymbolicLink(); } return false; }; File.prototype.clone = function(opt) { var self = this; if (typeof opt === 'boolean') { opt = { deep: opt, contents: true, }; } else if (!opt) { opt = { deep: true, contents: true, }; } else { opt.deep = opt.deep === true; opt.contents = opt.contents !== false; } // Clone our file contents var contents; if (this.isStream()) { contents = this.contents.clone(); } else if (this.isBuffer()) { contents = opt.contents ? cloneBuffer(this.contents) : this.contents; } var file = new this.constructor({ cwd: this.cwd, base: this.base, stat: (this.stat ? cloneStats(this.stat) : null), history: this.history.slice(), contents: contents, }); // Clone our custom properties Object.keys(this).forEach(function(key) { if (self.constructor.isCustomProp(key)) { file[key] = opt.deep ? clone(self[key], true) : self[key]; } }); return file; }; File.prototype.inspect = function() { var inspect = []; // Use relative path if possible var filePath = this.path ? this.relative : null; if (filePath) { inspect.push('"' + filePath + '"'); } if (this.isBuffer()) { inspect.push(this.contents.inspect()); } if (this.isStream()) { inspect.push(inspectStream(this.contents)); } return ''; }; // Newer Node.js versions use this symbol for custom inspection. if (util.inspect.custom) { File.prototype[util.inspect.custom] = File.prototype.inspect; } File.isCustomProp = function(key) { return builtInFields.indexOf(key) === -1; }; File.isVinyl = function(file) { return (file && file._isVinyl === true) || false; }; // Virtual attributes // Or stuff with extra logic Object.defineProperty(File.prototype, 'contents', { get: function() { return this._contents; }, set: function(val) { if (!isBuffer(val) && !isStream(val) && (val !== null)) { throw new Error('File.contents can only be a Buffer, a Stream, or null.'); } // Ask cloneable if the stream is a already a cloneable // this avoid piping into many streams // reducing the overhead of cloning if (isStream(val) && !cloneable.isCloneable(val)) { val = cloneable(val); } this._contents = val; }, }); Object.defineProperty(File.prototype, 'cwd', { get: function() { return this._cwd; }, set: function(cwd) { if (!cwd || typeof cwd !== 'string') { throw new Error('cwd must be a non-empty string.'); } this._cwd = removeTrailingSep(normalize(cwd)); }, }); Object.defineProperty(File.prototype, 'base', { get: function() { return this._base || this._cwd; }, set: function(base) { if (base == null) { delete this._base; return; } if (typeof base !== 'string' || !base) { throw new Error('base must be a non-empty string, or null/undefined.'); } base = removeTrailingSep(normalize(base)); if (base !== this._cwd) { this._base = base; } else { delete this._base; } }, }); // TODO: Should this be moved to vinyl-fs? Object.defineProperty(File.prototype, 'relative', { get: function() { if (!this.path) { throw new Error('No path specified! Can not get relative.'); } return path.relative(this.base, this.path); }, set: function() { throw new Error('File.relative is generated from the base and path attributes. Do not modify it.'); }, }); Object.defineProperty(File.prototype, 'dirname', { get: function() { if (!this.path) { throw new Error('No path specified! Can not get dirname.'); } return path.dirname(this.path); }, set: function(dirname) { if (!this.path) { throw new Error('No path specified! Can not set dirname.'); } this.path = path.join(dirname, this.basename); }, }); Object.defineProperty(File.prototype, 'basename', { get: function() { if (!this.path) { throw new Error('No path specified! Can not get basename.'); } return path.basename(this.path); }, set: function(basename) { if (!this.path) { throw new Error('No path specified! Can not set basename.'); } this.path = path.join(this.dirname, basename); }, }); // Property for getting/setting stem of the filename. Object.defineProperty(File.prototype, 'stem', { get: function() { if (!this.path) { throw new Error('No path specified! Can not get stem.'); } return path.basename(this.path, this.extname); }, set: function(stem) { if (!this.path) { throw new Error('No path specified! Can not set stem.'); } this.path = path.join(this.dirname, stem + this.extname); }, }); Object.defineProperty(File.prototype, 'extname', { get: function() { if (!this.path) { throw new Error('No path specified! Can not get extname.'); } return path.extname(this.path); }, set: function(extname) { if (!this.path) { throw new Error('No path specified! Can not set extname.'); } this.path = replaceExt(this.path, extname); }, }); Object.defineProperty(File.prototype, 'path', { get: function() { return this.history[this.history.length - 1]; }, set: function(path) { if (typeof path !== 'string') { throw new Error('path should be a string.'); } path = removeTrailingSep(normalize(path)); // Record history only when path changed if (path && path !== this.path) { this.history.push(path); } }, }); Object.defineProperty(File.prototype, 'symlink', { get: function() { return this._symlink; }, set: function(symlink) { // TODO: should this set the mode to symbolic if set? if (typeof symlink !== 'string') { throw new Error('symlink should be a string'); } this._symlink = removeTrailingSep(normalize(symlink)); }, }); module.exports = File; vinyl-2.2.0/lib/000077500000000000000000000000001331317704000134215ustar00rootroot00000000000000vinyl-2.2.0/lib/inspect-stream.js000066400000000000000000000003711331317704000167160ustar00rootroot00000000000000'use strict'; function inspectStream(stream) { var streamType = stream.constructor.name; // Avoid StreamStream if (streamType === 'Stream') { streamType = ''; } return '<' + streamType + 'Stream>'; } module.exports = inspectStream; vinyl-2.2.0/lib/is-stream.js000066400000000000000000000003021331317704000156560ustar00rootroot00000000000000'use strict'; function isStream(stream) { if (!stream) { return false; } if (typeof stream.pipe !== 'function') { return false; } return true; } module.exports = isStream; vinyl-2.2.0/lib/normalize.js000066400000000000000000000002261331317704000157570ustar00rootroot00000000000000'use strict'; var path = require('path'); function normalize(str) { return str === '' ? str : path.normalize(str); } module.exports = normalize; vinyl-2.2.0/package.json000066400000000000000000000024061331317704000151430ustar00rootroot00000000000000{ "name": "vinyl", "version": "2.2.0", "description": "Virtual file format.", "author": "Gulp Team (http://gulpjs.com/)", "contributors": [ "Eric Schoffstall ", "Blaine Bublitz " ], "repository": "gulpjs/vinyl", "license": "MIT", "engines": { "node": ">= 0.10" }, "main": "index.js", "files": [ "LICENSE", "index.js", "lib" ], "scripts": { "lint": "eslint . && jscs index.js lib/ test/", "pretest": "npm run lint", "test": "mocha --async-only", "cover": "istanbul cover _mocha --report lcovonly", "coveralls": "npm run cover && istanbul-coveralls" }, "dependencies": { "clone": "^2.1.1", "clone-buffer": "^1.0.0", "clone-stats": "^1.0.0", "cloneable-readable": "^1.0.0", "remove-trailing-separator": "^1.0.1", "replace-ext": "^1.0.0" }, "devDependencies": { "eslint": "^1.7.3", "eslint-config-gulp": "^2.0.0", "expect": "^1.20.2", "istanbul": "^0.4.3", "istanbul-coveralls": "^1.0.3", "jscs": "^2.3.5", "jscs-preset-gulp": "^1.0.0", "mississippi": "^1.2.0", "mocha": "^2.4.5" }, "keywords": [ "virtual", "filesystem", "file", "directory", "stat", "path" ] } vinyl-2.2.0/test/000077500000000000000000000000001331317704000136325ustar00rootroot00000000000000vinyl-2.2.0/test/.eslintrc000066400000000000000000000000351331317704000154540ustar00rootroot00000000000000{ "extends": "gulp/test" } vinyl-2.2.0/test/file.js000066400000000000000000001230531331317704000151130ustar00rootroot00000000000000'use strict'; var fs = require('fs'); var path = require('path'); var util = require('util'); var expect = require('expect'); var miss = require('mississippi'); var cloneable = require('cloneable-readable'); var File = require('../'); var pipe = miss.pipe; var from = miss.from; var concat = miss.concat; var isCloneable = cloneable.isCloneable; var isWin = (process.platform === 'win32'); describe('File', function() { describe('isVinyl()', function() { it('returns true for a Vinyl object', function(done) { var file = new File(); var result = File.isVinyl(file); expect(result).toEqual(true); done(); }); it('returns false for a normal object', function(done) { var result = File.isVinyl({}); expect(result).toEqual(false); done(); }); it('returns false for null', function(done) { var result = File.isVinyl(null); expect(result).toEqual(false); done(); }); it('returns false for a string', function(done) { var result = File.isVinyl('foobar'); expect(result).toEqual(false); done(); }); it('returns false for a String object', function(done) { var result = File.isVinyl(new String('foobar')); expect(result).toEqual(false); done(); }); it('returns false for a number', function(done) { var result = File.isVinyl(1); expect(result).toEqual(false); done(); }); it('returns false for a Number object', function(done) { var result = File.isVinyl(new Number(1)); expect(result).toEqual(false); done(); }); // This is based on current implementation // A test was added to document and make aware during internal changes // TODO: decide if this should be leak-able it('returns true for a mocked object', function(done) { var result = File.isVinyl({ _isVinyl: true }); expect(result).toEqual(true); done(); }); }); describe('defaults', function() { it('defaults cwd to process.cwd', function(done) { var file = new File(); expect(file.cwd).toEqual(process.cwd()); done(); }); it('defaults base to process.cwd', function(done) { var file = new File(); expect(file.base).toEqual(process.cwd()); done(); }); it('defaults base to cwd property', function(done) { var cwd = path.normalize('/'); var file = new File({ cwd: cwd }); expect(file.base).toEqual(cwd); done(); }); it('defaults path to null', function(done) { var file = new File(); expect(file.path).toNotExist(); expect(file.path).toEqual(null); done(); }); it('defaults history to an empty array', function(done) { var file = new File(); expect(file.history).toEqual([]); done(); }); it('defaults stat to null', function(done) { var file = new File(); expect(file.stat).toNotExist(); expect(file.stat).toEqual(null); done(); }); it('defaults contents to null', function(done) { var file = new File(); expect(file.contents).toNotExist(); expect(file.contents).toEqual(null); done(); }); }); describe('constructor()', function() { it('sets base', function(done) { var val = path.normalize('/'); var file = new File({ base: val }); expect(file.base).toEqual(val); done(); }); it('sets cwd', function(done) { var val = path.normalize('/'); var file = new File({ cwd: val }); expect(file.cwd).toEqual(val); done(); }); it('sets path (and history)', function(done) { var val = path.normalize('/test.coffee'); var file = new File({ path: val }); expect(file.path).toEqual(val); expect(file.history).toEqual([val]); done(); }); it('sets history (and path)', function(done) { var val = path.normalize('/test.coffee'); var file = new File({ history: [val] }); expect(file.path).toEqual(val); expect(file.history).toEqual([val]); done(); }); it('sets stat', function(done) { var val = {}; var file = new File({ stat: val }); expect(file.stat).toEqual(val); done(); }); it('sets contents', function(done) { var val = new Buffer('test'); var file = new File({ contents: val }); expect(file.contents).toEqual(val); done(); }); it('sets custom properties', function(done) { var sourceMap = {}; var file = new File({ sourceMap: sourceMap }); expect(file.sourceMap).toEqual(sourceMap); done(); }); it('normalizes path', function(done) { var val = '/test/foo/../test.coffee'; var expected = path.normalize(val); var file = new File({ path: val }); expect(file.path).toEqual(expected); expect(file.history).toEqual([expected]); done(); }); it('normalizes and removes trailing separator from path', function(done) { var val = '/test/foo/../foo/'; var expected = path.normalize(val.slice(0, -1)); var file = new File({ path: val }); expect(file.path).toEqual(expected); done(); }); it('normalizes history', function(done) { var val = [ '/test/bar/../bar/test.coffee', '/test/foo/../test.coffee', ]; var expected = val.map(function(p) { return path.normalize(p); }); var file = new File({ history: val }); expect(file.path).toEqual(expected[1]); expect(file.history).toEqual(expected); done(); }); it('normalizes and removes trailing separator from history', function(done) { var val = [ '/test/foo/../foo/', '/test/bar/../bar/', ]; var expected = val.map(function(p) { return path.normalize(p.slice(0, -1)); }); var file = new File({ history: val }); expect(file.history).toEqual(expected); done(); }); it('appends path to history if both exist and different from last', function(done) { var val = path.normalize('/test/baz/test.coffee'); var history = [ path.normalize('/test/bar/test.coffee'), path.normalize('/test/foo/test.coffee'), ]; var file = new File({ path: val, history: history }); var expectedHistory = history.concat(val); expect(file.path).toEqual(val); expect(file.history).toEqual(expectedHistory); done(); }); it('does not append path to history if both exist and same as last', function(done) { var val = path.normalize('/test/baz/test.coffee'); var history = [ path.normalize('/test/bar/test.coffee'), path.normalize('/test/foo/test.coffee'), val, ]; var file = new File({ path: val, history: history }); expect(file.path).toEqual(val); expect(file.history).toEqual(history); done(); }); it('does not mutate history array passed in', function(done) { var val = path.normalize('/test/baz/test.coffee'); var history = [ path.normalize('/test/bar/test.coffee'), path.normalize('/test/foo/test.coffee'), ]; var historyCopy = Array.prototype.slice.call(history); var file = new File({ path: val, history: history }); var expectedHistory = history.concat(val); expect(file.path).toEqual(val); expect(file.history).toEqual(expectedHistory); expect(history).toEqual(historyCopy); done(); }); }); describe('isBuffer()', function() { it('returns true when the contents are a Buffer', function(done) { var val = new Buffer('test'); var file = new File({ contents: val }); expect(file.isBuffer()).toEqual(true); done(); }); it('returns false when the contents are a Stream', function(done) { var val = from([]); var file = new File({ contents: val }); expect(file.isBuffer()).toEqual(false); done(); }); it('returns false when the contents are null', function(done) { var file = new File({ contents: null }); expect(file.isBuffer()).toEqual(false); done(); }); }); describe('isStream()', function() { it('returns false when the contents are a Buffer', function(done) { var val = new Buffer('test'); var file = new File({ contents: val }); expect(file.isStream()).toEqual(false); done(); }); it('returns true when the contents are a Stream', function(done) { var val = from([]); var file = new File({ contents: val }); expect(file.isStream()).toEqual(true); done(); }); it('returns false when the contents are null', function(done) { var file = new File({ contents: null }); expect(file.isStream()).toEqual(false); done(); }); }); describe('isNull()', function() { it('returns false when the contents are a Buffer', function(done) { var val = new Buffer('test'); var file = new File({ contents: val }); expect(file.isNull()).toEqual(false); done(); }); it('returns false when the contents are a Stream', function(done) { var val = from([]); var file = new File({ contents: val }); expect(file.isNull()).toEqual(false); done(); }); it('returns true when the contents are null', function(done) { var file = new File({ contents: null }); expect(file.isNull()).toEqual(true); done(); }); }); describe('isDirectory()', function() { var fakeStat = { isDirectory: function() { return true; }, }; it('returns false when the contents are a Buffer', function(done) { var val = new Buffer('test'); var file = new File({ contents: val, stat: fakeStat }); expect(file.isDirectory()).toEqual(false); done(); }); it('returns false when the contents are a Stream', function(done) { var val = from([]); var file = new File({ contents: val, stat: fakeStat }); expect(file.isDirectory()).toEqual(false); done(); }); it('returns true when the contents are null & stat.isDirectory is true', function(done) { var file = new File({ contents: null, stat: fakeStat }); expect(file.isDirectory()).toEqual(true); done(); }); it('returns false when stat exists but does not contain an isDirectory method', function(done) { var file = new File({ contents: null, stat: {} }); expect(file.isDirectory()).toEqual(false); done(); }); it('returns false when stat does not exist', function(done) { var file = new File({ contents: null }); expect(file.isDirectory()).toEqual(false); done(); }); }); describe('isSymbolic()', function() { var fakeStat = { isSymbolicLink: function() { return true; }, }; it('returns false when the contents are a Buffer', function(done) { var val = new Buffer('test'); var file = new File({ contents: val, stat: fakeStat }); expect(file.isSymbolic()).toEqual(false); done(); }); it('returns false when the contents are a Stream', function(done) { var val = from([]); var file = new File({ contents: val, stat: fakeStat }); expect(file.isSymbolic()).toEqual(false); done(); }); it('returns true when the contents are null & stat.isSymbolicLink is true', function(done) { var file = new File({ contents: null, stat: fakeStat }); expect(file.isSymbolic()).toEqual(true); done(); }); it('returns false when stat exists but does not contain an isSymbolicLink method', function(done) { var file = new File({ contents: null, stat: {} }); expect(file.isSymbolic()).toEqual(false); done(); }); it('returns false when stat does not exist', function(done) { var file = new File({ contents: null }); expect(file.isSymbolic()).toEqual(false); done(); }); }); describe('clone()', function() { it('copies all attributes over with Buffer contents', function(done) { var options = { cwd: '/', base: '/test/', path: '/test/test.coffee', contents: new Buffer('test'), }; var file = new File(options); var file2 = file.clone(); expect(file2).toNotBe(file); expect(file2.cwd).toEqual(file.cwd); expect(file2.base).toEqual(file.base); expect(file2.path).toEqual(file.path); expect(file2.contents).toNotBe(file.contents); expect(file2.contents.toString('utf8')).toEqual(file.contents.toString('utf8')); done(); }); it('assigns Buffer content reference when contents option is false', function(done) { var options = { cwd: '/', base: '/test/', path: '/test/test.js', contents: new Buffer('test'), }; var file = new File(options); var copy1 = file.clone({ contents: false }); expect(copy1.contents).toBe(file.contents); var copy2 = file.clone(); expect(copy2.contents).toNotBe(file.contents); var copy3 = file.clone({ contents: 'invalid' }); expect(copy3.contents).toNotBe(file.contents); done(); }); it('copies all attributes over with Stream contents', function(done) { var options = { cwd: '/', base: '/test/', path: '/test/test.coffee', contents: from(['wa', 'dup']), }; var file = new File(options); var file2 = file.clone(); expect(file2).toNotBe(file); expect(file2.cwd).toEqual(file.cwd); expect(file2.base).toEqual(file.base); expect(file2.path).toEqual(file.path); expect(file2.contents).toNotBe(file.contents); var ends = 2; var data = null; var data2 = null; function assert(err) { if (err) { done(err); return; } if (--ends === 0) { expect(data).toNotBe(data2); expect(data.toString('utf8')).toEqual(data2.toString('utf8')); done(); } } pipe([ file.contents, concat(function(d) { data = d; }), ], assert); pipe([ file2.contents, concat(function(d) { data2 = d; }), ], assert); }); it('does not start flowing until all clones flows (data)', function(done) { var options = { cwd: '/', base: '/test/', path: '/test/test.coffee', contents: from(['wa', 'dup']), }; var file = new File(options); var file2 = file.clone(); var ends = 2; var data = ''; var data2 = ''; function assert() { if (--ends === 0) { expect(data).toEqual(data2); done(); } } // Start flowing file2 file2.contents.on('data', function(chunk) { data2 += chunk.toString('utf8'); }); process.nextTick(function() { // Nothing was written yet expect(data).toEqual(''); expect(data2).toEqual(''); // Starts flowing file file.contents.on('data', function(chunk) { data += chunk.toString('utf8'); }); }); file2.contents.on('end', assert); file.contents.on('end', assert); }); it('does not start flowing until all clones flows (readable)', function(done) { var options = { cwd: '/', base: '/test/', path: '/test/test.coffee', contents: from(['wa', 'dup']), }; var file = new File(options); var file2 = file.clone(); var data2 = ''; function assert(data) { expect(data.toString('utf8')).toEqual(data2); } // Start flowing file2 file2.contents.on('readable', function() { var chunk; while ((chunk = this.read()) !== null) { data2 += chunk.toString(); } }); pipe([ file.contents, concat(assert), ], done); }); it('copies all attributes over with null contents', function(done) { var options = { cwd: '/', base: '/test/', path: '/test/test.coffee', contents: null, }; var file = new File(options); var file2 = file.clone(); expect(file2).toNotBe(file); expect(file2.cwd).toEqual(file.cwd); expect(file2.base).toEqual(file.base); expect(file2.path).toEqual(file.path); expect(file2.contents).toNotExist(); done(); }); it('properly clones the `stat` property', function(done) { var options = { cwd: '/', base: '/test/', path: '/test/test.js', contents: new Buffer('test'), stat: fs.statSync(__filename), }; var file = new File(options); var copy = file.clone(); expect(copy.stat.isFile()).toEqual(true); expect(copy.stat.isDirectory()).toEqual(false); expect(file.stat).toBeAn(fs.Stats); expect(copy.stat).toBeAn(fs.Stats); done(); }); it('properly clones the `history` property', function(done) { var options = { cwd: path.normalize('/'), base: path.normalize('/test/'), path: path.normalize('/test/test.js'), contents: new Buffer('test'), }; var file = new File(options); var copy = file.clone(); expect(copy.history[0]).toEqual(options.path); copy.path = 'lol'; expect(file.path).toNotEqual(copy.path); done(); }); it('copies custom properties', function(done) { var options = { cwd: '/', base: '/test/', path: '/test/test.coffee', contents: null, custom: { meta: {} }, }; var file = new File(options); var file2 = file.clone(); expect(file2).toNotBe(file); expect(file2.cwd).toEqual(file.cwd); expect(file2.base).toEqual(file.base); expect(file2.path).toEqual(file.path); expect(file2.custom).toNotBe(file.custom); expect(file2.custom.meta).toNotBe(file.custom.meta); expect(file2.custom).toEqual(file.custom); done(); }); it('copies history', function(done) { var options = { cwd: '/', base: '/test/', path: '/test/test.coffee', contents: null, }; var history = [ path.normalize('/test/test.coffee'), path.normalize('/test/test.js'), path.normalize('/test/test-938di2s.js'), ]; var file = new File(options); file.path = history[1]; file.path = history[2]; var file2 = file.clone(); expect(file2.history).toEqual(history); expect(file2.history).toNotBe(file.history); expect(file2.path).toEqual(history[2]); done(); }); it('supports deep & shallow copy of all attributes', function(done) { var options = { cwd: '/', base: '/test/', path: '/test/test.coffee', contents: null, custom: { meta: {} }, }; var file = new File(options); var file2 = file.clone(); expect(file2.custom).toEqual(file.custom); expect(file2.custom).toNotBe(file.custom); expect(file2.custom.meta).toEqual(file.custom.meta); expect(file2.custom.meta).toNotBe(file.custom.meta); var file3 = file.clone(true); expect(file3.custom).toEqual(file.custom); expect(file3.custom).toNotBe(file.custom); expect(file3.custom.meta).toEqual(file.custom.meta); expect(file3.custom.meta).toNotBe(file.custom.meta); var file4 = file.clone({ deep: true }); expect(file4.custom).toEqual(file.custom); expect(file4.custom).toNotBe(file.custom); expect(file4.custom.meta).toEqual(file.custom.meta); expect(file4.custom.meta).toNotBe(file.custom.meta); var file5 = file.clone(false); expect(file5.custom).toEqual(file.custom); expect(file5.custom).toBe(file.custom); expect(file5.custom.meta).toEqual(file.custom.meta); expect(file5.custom.meta).toBe(file.custom.meta); var file6 = file.clone({ deep: false }); expect(file6.custom).toEqual(file.custom); expect(file6.custom).toBe(file.custom); expect(file6.custom.meta).toEqual(file.custom.meta); expect(file6.custom.meta).toBe(file.custom.meta); done(); }); it('supports inheritance', function(done) { function ExtendedFile() { File.apply(this, arguments); } ExtendedFile.prototype = Object.create(File.prototype); ExtendedFile.prototype.constructor = ExtendedFile; // Just copy static stuff since Object.setPrototypeOf is node >=0.12 Object.keys(File).forEach(function(key) { ExtendedFile[key] = File[key]; }); var file = new ExtendedFile(); var file2 = file.clone(); expect(file2).toNotBe(file); expect(file2.constructor).toBe(ExtendedFile); expect(file2).toBeAn(ExtendedFile); expect(file2).toBeA(File); expect(ExtendedFile.prototype.isPrototypeOf(file2)).toEqual(true); expect(File.prototype.isPrototypeOf(file2)).toEqual(true); done(); }); }); describe('inspect()', function() { it('returns correct format when no contents and no path', function(done) { var file = new File(); var expectation = ''; expect(file.inspect()).toEqual(expectation); expect(util.inspect(file)).toEqual(expectation); if (util.inspect.custom) { expect(file[util.inspect.custom]()).toEqual(expectation); } done(); }); it('returns correct format when Buffer contents and no path', function(done) { var val = new Buffer('test'); var file = new File({ contents: val }); expect(file.inspect()).toEqual('>'); done(); }); it('returns correct format when Buffer contents and relative path', function(done) { var val = new Buffer('test'); var file = new File({ cwd: '/', base: '/test/', path: '/test/test.coffee', contents: val, }); expect(file.inspect()).toEqual('>'); done(); }); it('returns correct format when Stream contents and relative path', function(done) { var file = new File({ cwd: '/', base: '/test/', path: '/test/test.coffee', contents: from([]), }); expect(file.inspect()).toEqual('>'); done(); }); it('returns correct format when null contents and relative path', function(done) { var file = new File({ cwd: '/', base: '/test/', path: '/test/test.coffee', contents: null, }); expect(file.inspect()).toEqual(''); done(); }); }); describe('contents get/set', function() { it('returns _contents', function(done) { var val = new Buffer('test'); var file = new File(); file._contents = val; expect(file.contents).toEqual(val); done(); }); it('sets _contents', function(done) { var val = new Buffer('test'); var file = new File(); file.contents = val; expect(file._contents).toEqual(val); done(); }); it('sets a Buffer', function(done) { var val = new Buffer('test'); var file = new File(); file.contents = val; expect(file.contents).toEqual(val); done(); }); it('wraps Stream in Cloneable', function(done) { var val = from([]); var file = new File(); file.contents = val; expect(isCloneable(file.contents)).toEqual(true); done(); }); it('does not double wrap a Cloneable', function(done) { var val = from([]); var clone = cloneable(val); var file = new File(); file.contents = clone; expect(file.contents._original).toBe(val); done(); }); it('sets null', function(done) { var val = null; var file = new File(); file.contents = val; expect(file.contents).toEqual(null); done(); }); it('does not set a string', function(done) { var val = 'test'; var file = new File(); function invalid() { file.contents = val; } expect(invalid).toThrow(); done(); }); }); describe('cwd get/set', function() { it('returns _cwd', function(done) { var val = '/test'; var file = new File(); file._cwd = val; expect(file.cwd).toEqual(val); done(); }); it('sets _cwd', function(done) { var val = '/test'; var file = new File(); file.cwd = val; expect(file._cwd).toEqual(path.normalize(val)); done(); }); it('normalizes and removes trailing separator on set', function(done) { var val = '/test/foo/../foo/'; var expected = path.normalize(val.slice(0, -1)); var file = new File(); file.cwd = val; expect(file.cwd).toEqual(expected); var val2 = '\\test\\foo\\..\\foo\\'; var expected2 = path.normalize(isWin ? val2.slice(0, -1) : val2); file.cwd = val2; expect(file.cwd).toEqual(expected2); done(); }); it('throws on set with invalid values', function(done) { var invalidValues = [ '', null, undefined, true, false, 0, Infinity, NaN, {}, [], ]; var file = new File(); invalidValues.forEach(function(val) { function invalid() { file.cwd = val; } expect(invalid).toThrow('cwd must be a non-empty string.'); }); done(); }); }); describe('base get/set', function() { it('proxies cwd when omitted', function(done) { var file = new File({ cwd: '/test' }); expect(file.base).toEqual(file.cwd); done(); }); it('proxies cwd when same', function(done) { var file = new File({ cwd: '/test', base: '/test', }); file.cwd = '/foo/'; expect(file.base).toEqual(file.cwd); var file2 = new File({ cwd: '/test', }); file2.base = '/test/'; file2.cwd = '/foo/'; expect(file2.base).toEqual(file.cwd); done(); }); it('proxies to cwd when set to same value', function(done) { var file = new File({ cwd: '/foo', base: '/bar', }); expect(file.base).toNotEqual(file.cwd); file.base = file.cwd; expect(file.base).toEqual(file.cwd); done(); }); it('proxies to cwd when null or undefined', function(done) { var file = new File({ cwd: '/foo', base: '/bar', }); expect(file.base).toNotEqual(file.cwd); file.base = null; expect(file.base).toEqual(file.cwd); file.base = '/bar/'; expect(file.base).toNotEqual(file.cwd); file.base = undefined; expect(file.base).toEqual(file.cwd); done(); }); it('returns _base', function(done) { var val = '/test/'; var file = new File(); file._base = val; expect(file.base).toEqual(val); done(); }); it('sets _base', function(done) { var val = '/test/foo'; var file = new File(); file.base = val; expect(file._base).toEqual(path.normalize(val)); done(); }); it('normalizes and removes trailing separator on set', function(done) { var val = '/test/foo/../foo/'; var expected = path.normalize(val.slice(0, -1)); var file = new File(); file.base = val; expect(file.base).toEqual(expected); var val2 = '\\test\\foo\\..\\foo\\'; var expected2 = path.normalize(isWin ? val2.slice(0, -1) : val2); file.base = val2; expect(file.base).toEqual(expected2); done(); }); it('throws on set with invalid values', function(done) { var invalidValues = [ true, false, 1, 0, Infinity, NaN, '', {}, [], ]; var file = new File(); invalidValues.forEach(function(val) { function invalid() { file.base = val; } expect(invalid).toThrow('base must be a non-empty string, or null/undefined.'); }); done(); }); }); describe('relative get/set', function() { it('throws on set', function(done) { var file = new File(); function invalid() { file.relative = 'test'; } expect(invalid).toThrow('File.relative is generated from the base and path attributes. Do not modify it.'); done(); }); it('throws on get with no path', function(done) { var file = new File(); function invalid() { file.relative; } expect(invalid).toThrow('No path specified! Can not get relative.'); done(); }); it('returns a relative path from base', function(done) { var file = new File({ base: '/test/', path: '/test/test.coffee', }); expect(file.relative).toEqual('test.coffee'); done(); }); it('returns a relative path from cwd', function(done) { var file = new File({ cwd: '/', path: '/test/test.coffee', }); expect(file.relative).toEqual(path.normalize('test/test.coffee')); done(); }); it('does not append separator when directory', function(done) { var file = new File({ base: '/test', path: '/test/foo/bar', stat: { isDirectory: function() { return true; }, }, }); expect(file.relative).toEqual(path.normalize('foo/bar')); done(); }); it('does not append separator when symlink', function(done) { var file = new File({ base: '/test', path: '/test/foo/bar', stat: { isSymbolicLink: function() { return true; }, }, }); expect(file.relative).toEqual(path.normalize('foo/bar')); done(); }); it('does not append separator when directory & symlink', function(done) { var file = new File({ base: '/test', path: '/test/foo/bar', stat: { isDirectory: function() { return true; }, isSymbolicLink: function() { return true; }, }, }); expect(file.relative).toEqual(path.normalize('foo/bar')); done(); }); }); describe('dirname get/set', function() { it('throws on get with no path', function(done) { var file = new File(); function invalid() { file.dirname; } expect(invalid).toThrow('No path specified! Can not get dirname.'); done(); }); it('returns the dirname without trailing separator', function(done) { var file = new File({ cwd: '/', base: '/test', path: '/test/test.coffee', }); expect(file.dirname).toEqual(path.normalize('/test')); done(); }); it('throws on set with no path', function(done) { var file = new File(); function invalid() { file.dirname = '/test'; } expect(invalid).toThrow('No path specified! Can not set dirname.'); done(); }); it('replaces the dirname of the path', function(done) { var file = new File({ cwd: '/', base: '/test/', path: '/test/test.coffee', }); file.dirname = '/test/foo'; expect(file.path).toEqual(path.normalize('/test/foo/test.coffee')); done(); }); }); describe('basename get/set', function() { it('throws on get with no path', function(done) { var file = new File(); function invalid() { a = file.basename; } expect(invalid).toThrow('No path specified! Can not get basename.'); done(); }); it('returns the basename of the path', function(done) { var file = new File({ cwd: '/', base: '/test/', path: '/test/test.coffee', }); expect(file.basename).toEqual('test.coffee'); done(); }); it('does not append trailing separator when directory', function(done) { var file = new File({ path: '/test/foo', stat: { isDirectory: function() { return true; }, }, }); expect(file.basename).toEqual('foo'); done(); }); it('does not append trailing separator when symlink', function(done) { var file = new File({ path: '/test/foo', stat: { isSymbolicLink: function() { return true; }, }, }); expect(file.basename).toEqual('foo'); done(); }); it('does not append trailing separator when directory & symlink', function(done) { var file = new File({ path: '/test/foo', stat: { isDirectory: function() { return true; }, isSymbolicLink: function() { return true; }, }, }); expect(file.basename).toEqual('foo'); done(); }); it('removes trailing separator', function(done) { var file = new File({ path: '/test/foo/', }); expect(file.basename).toEqual('foo'); done(); }); it('removes trailing separator when directory', function(done) { var file = new File({ path: '/test/foo/', stat: { isDirectory: function() { return true; }, }, }); expect(file.basename).toEqual('foo'); done(); }); it('removes trailing separator when symlink', function(done) { var file = new File({ path: '/test/foo/', stat: { isSymbolicLink: function() { return true; }, }, }); expect(file.basename).toEqual('foo'); done(); }); it('removes trailing separator when directory & symlink', function(done) { var file = new File({ path: '/test/foo/', stat: { isDirectory: function() { return true; }, isSymbolicLink: function() { return true; }, }, }); expect(file.basename).toEqual('foo'); done(); }); it('throws on set with no path', function(done) { var file = new File(); function invalid() { file.basename = 'test.coffee'; } expect(invalid).toThrow('No path specified! Can not set basename.'); done(); }); it('replaces the basename of the path', function(done) { var file = new File({ cwd: '/', base: '/test/', path: '/test/test.coffee', }); file.basename = 'foo.png'; expect(file.path).toEqual(path.normalize('/test/foo.png')); done(); }); }); describe('stem get/set', function() { it('throws on get with no path', function(done) { var file = new File(); function invalid() { file.stem; } expect(invalid).toThrow('No path specified! Can not get stem.'); done(); }); it('returns the stem of the path', function(done) { var file = new File({ cwd: '/', base: '/test/', path: '/test/test.coffee', }); expect(file.stem).toEqual('test'); done(); }); it('throws on set with no path', function(done) { var file = new File(); function invalid() { file.stem = 'test.coffee'; } expect(invalid).toThrow('No path specified! Can not set stem.'); done(); }); it('replaces the stem of the path', function(done) { var file = new File({ cwd: '/', base: '/test/', path: '/test/test.coffee', }); file.stem = 'foo'; expect(file.path).toEqual(path.normalize('/test/foo.coffee')); done(); }); }); describe('extname get/set', function() { it('throws on get with no path', function(done) { var file = new File(); function invalid() { file.extname; } expect(invalid).toThrow('No path specified! Can not get extname.'); done(); }); it('returns the extname of the path', function(done) { var file = new File({ cwd: '/', base: '/test/', path: '/test/test.coffee', }); expect(file.extname).toEqual('.coffee'); done(); }); it('throws on set with no path', function(done) { var file = new File(); function invalid() { file.extname = '.coffee'; } expect(invalid).toThrow('No path specified! Can not set extname.'); done(); }); it('replaces the extname of the path', function(done) { var file = new File({ cwd: '/', base: '/test/', path: '/test/test.coffee', }); file.extname = '.png'; expect(file.path).toEqual(path.normalize('/test/test.png')); done(); }); }); describe('path get/set', function() { it('records path in history upon instantiation', function(done) { var file = new File({ cwd: '/', path: '/test/test.coffee', }); var history = [ path.normalize('/test/test.coffee'), ]; expect(file.path).toEqual(history[0]); expect(file.history).toEqual(history); done(); }); it('records path in history when set', function(done) { var val = path.normalize('/test/test.js'); var file = new File({ cwd: '/', path: '/test/test.coffee', }); var history = [ path.normalize('/test/test.coffee'), val, ]; file.path = val; expect(file.path).toEqual(val); expect(file.history).toEqual(history); var val2 = path.normalize('/test/test.es6'); history.push(val2); file.path = val2; expect(file.path).toEqual(val2); expect(file.history).toEqual(history); done(); }); it('does not record path in history when set to the current path', function(done) { var val = path.normalize('/test/test.coffee'); var file = new File({ cwd: '/', path: val, }); var history = [ val, ]; file.path = val; file.path = val; expect(file.path).toEqual(val); expect(file.history).toEqual(history); done(); }); it('does not record path in history when set to empty string', function(done) { var val = path.normalize('/test/test.coffee'); var file = new File({ cwd: '/', path: val, }); var history = [ val, ]; file.path = ''; expect(file.path).toEqual(val); expect(file.history).toEqual(history); done(); }); it('throws on set with null path', function(done) { var file = new File(); expect(file.path).toNotExist(); expect(file.history).toEqual([]); function invalid() { file.path = null; } expect(invalid).toThrow('path should be a string.'); done(); }); it('normalizes the path upon set', function(done) { var val = '/test/foo/../test.coffee'; var expected = path.normalize(val); var file = new File(); file.path = val; expect(file.path).toEqual(expected); expect(file.history).toEqual([expected]); done(); }); it('removes the trailing separator upon set', function(done) { var file = new File(); file.path = '/test/'; expect(file.path).toEqual(path.normalize('/test')); expect(file.history).toEqual([path.normalize('/test')]); done(); }); it('removes the trailing separator upon set when directory', function(done) { var file = new File({ stat: { isDirectory: function() { return true; }, }, }); file.path = '/test/'; expect(file.path).toEqual(path.normalize('/test')); expect(file.history).toEqual([path.normalize('/test')]); done(); }); it('removes the trailing separator upon set when symlink', function(done) { var file = new File({ stat: { isSymbolicLink: function() { return true; }, }, }); file.path = '/test/'; expect(file.path).toEqual(path.normalize('/test')); expect(file.history).toEqual([path.normalize('/test')]); done(); }); it('removes the trailing separator upon set when directory & symlink', function(done) { var file = new File({ stat: { isDirectory: function() { return true; }, isSymbolicLink: function() { return true; }, }, }); file.path = '/test/'; expect(file.path).toEqual(path.normalize('/test')); expect(file.history).toEqual([path.normalize('/test')]); done(); }); }); describe('symlink get/set', function() { it('return null on get with no symlink', function(done) { var file = new File(); expect(file.symlink).toEqual(null); done(); }); it('returns _symlink', function(done) { var val = '/test/test.coffee'; var file = new File(); file._symlink = val; expect(file.symlink).toEqual(val); done(); }); it('throws on set with non-string', function(done) { var file = new File(); function invalid() { file.symlink = null; } expect(invalid).toThrow('symlink should be a string'); done(); }); it('sets _symlink', function(done) { var val = '/test/test.coffee'; var expected = path.normalize(val); var file = new File(); file.symlink = val; expect(file._symlink).toEqual(expected); done(); }); it('allows relative symlink', function(done) { var val = 'test.coffee'; var file = new File(); file.symlink = val; expect(file.symlink).toEqual(val); done(); }); it('normalizes and removes trailing separator upon set', function(done) { var val = '/test/foo/../bar/'; var expected = path.normalize(val.slice(0, -1)); var file = new File(); file.symlink = val; expect(file.symlink).toEqual(expected); done(); }); }); }); vinyl-2.2.0/test/inspect-stream.js000066400000000000000000000032061331317704000171270ustar00rootroot00000000000000'use strict'; var Stream = require('stream'); var expect = require('expect'); var Cloneable = require('cloneable-readable'); var inspectStream = require('../lib/inspect-stream'); describe('inspectStream()', function() { it('works on a Stream', function(done) { var testStream = new Stream(); var result = inspectStream(testStream); expect(result).toEqual(''); done(); }); it('works on a Readable Stream', function(done) { var testStream = new Stream.Readable(); var result = inspectStream(testStream); expect(result).toEqual(''); done(); }); it('works on a Writable Stream', function(done) { var testStream = new Stream.Writable(); var result = inspectStream(testStream); expect(result).toEqual(''); done(); }); it('works on a Duplex Stream', function(done) { var testStream = new Stream.Duplex(); var result = inspectStream(testStream); expect(result).toEqual(''); done(); }); it('works on a Transform Stream', function(done) { var testStream = new Stream.Transform(); var result = inspectStream(testStream); expect(result).toEqual(''); done(); }); it('works on a PassThrough Stream', function(done) { var testStream = new Stream.PassThrough(); var result = inspectStream(testStream); expect(result).toEqual(''); done(); }); it('works on a custom Stream', function(done) { var testStream = new Cloneable(new Stream.Readable()); var result = inspectStream(testStream); expect(result).toEqual(''); done(); }); }); vinyl-2.2.0/test/normalize.js000066400000000000000000000007721331317704000161760ustar00rootroot00000000000000'use strict'; var path = require('path'); var expect = require('expect'); var normalize = require('../lib/normalize'); describe('normalize()', function() { it('leaves empty strings unmodified', function(done) { var result = normalize(''); expect(result).toEqual(''); done(); }); it('applies path.normalize for everything else', function(done) { var str = '/foo//../bar/baz'; var result = normalize(str); expect(result).toEqual(path.normalize(str)); done(); }); });