├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── index.js ├── package.json └── test └── main.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .DS_Store -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "0.10" 4 | - "0.12" 5 | - "io.js" 6 | - "stable" 7 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014 Aaron Haurwitz 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # gulp-remember [![NPM version](https://badge.fury.io/js/gulp-remember.png)](http://badge.fury.io/js/gulp-remember) [![Build Status](https://travis-ci.org/ahaurw01/gulp-remember.svg?branch=master)](https://travis-ci.org/ahaurw01/gulp-remember) 2 | 3 | `gulp-remember` is a [gulp](https://github.com/gulpjs/gulp) plugin that remembers files that have passed through it. `gulp-remember` adds all the files it has ever seen back into the stream. 4 | 5 | `gulp-remember` pairs nicely with [gulp-cached](https://github.com/wearefractal/gulp-cached) when you want to only rebuild the files that changed, but still need to operate on all files in the set. 6 | 7 | ```javascript 8 | var remember = require('gulp-remember'); 9 | ``` 10 | 11 | ## Usage 12 | 13 | This example shows a scenario in which you want to wrap all script files in some type of module system, then concatenate into one `app.js` file for consumption. 14 | 15 | As long as your other plugins can keep up, this example showcases the Holy Grail of Build Tools™ - the ability to build once, `git checkout different-branch` (a branch with drastically different files), and have the output be exactly what you would expect. 16 | 17 | ```javascript 18 | var gulp = require('gulp'), 19 | header = require('gulp-header'), 20 | footer = require('gulp-footer'), 21 | concat = require('gulp-concat'), 22 | cache = require('gulp-cached'), 23 | remember = require('gulp-remember'); 24 | 25 | var scriptsGlob = 'src/**/*.js'; 26 | 27 | gulp.task('scripts', function () { 28 | return gulp.src(scriptsGlob) 29 | .pipe(cache('scripts')) // only pass through changed files 30 | .pipe(header('(function () {')) // do special things to the changed files... 31 | .pipe(footer('})();')) // for example, add a stupid-simple module wrap to each file 32 | .pipe(remember('scripts')) // add back all files to the stream 33 | .pipe(concat('app.js')) // do things that require all files 34 | .pipe(gulp.dest('public/')) 35 | }); 36 | 37 | gulp.task('watch', function () { 38 | var watcher = gulp.watch(scriptsGlob, ['scripts']); // watch the same files in our scripts task 39 | watcher.on('change', function (event) { 40 | if (event.type === 'deleted') { // if a file is deleted, forget about it 41 | delete cache.caches['scripts'][event.path]; 42 | remember.forget('scripts', event.path); 43 | } 44 | }); 45 | }); 46 | ``` 47 | 48 | ## API 49 | 50 | ### remember(name) 51 | 52 | Returns a stream ready to remember files. 53 | 54 | #### name (optional) 55 | 56 | Type: `String` 57 | 58 | The name of a specific cache you want to use. You may want to `remember('javascripts')` in one area of your build while also being able to `remember('images')` in another. 59 | 60 | You can choose not to pass any name if you only care about caching one set of files in your whole build. 61 | 62 | ### remember.forget(name, path) 63 | 64 | Drops a file from a remember cache. 65 | 66 | #### name (optional) 67 | 68 | Type: `String` 69 | 70 | The name of the remember cache on which you want to operate. You do not need to pass this if you want to operate on the default remember cache. 71 | 72 | **Note:** If the name does not refer to a cache that exists, a warning is logged. Thanks to @jcppman for this. 73 | 74 | #### path (required) 75 | 76 | Type: `String` 77 | 78 | The path of the file you wish to drop from the remember cache. The path is used under the covers as the unique identifier for the file within one remember cache. 79 | 80 | **Important note!** The path you pass to `forget` must be the path of the *processed* file. You may encounter instances where your source file is `some/path/script.coffee` while the processed file is `some/path/script.js`. Because anything could happen before you `remember` a file, it is up to you to know how you need to `forget` it with the correct path. 81 | 82 | If you want to `forget` files using their name history, you might want to use [gulp-remember-history](https://www.npmjs.com/package/gulp-remember-history). 83 | 84 | **Another note:** If the path does not match a file object that exists in the given cache, a warning is logged. Thanks to @jcppman for this. 85 | 86 | ### remember.forgetAll(name) 87 | 88 | Drops all files from a remember cache. 89 | 90 | #### name (optional) 91 | 92 | Type: `String` 93 | 94 | The name of the remember cache you want to wipe. You do not need to pass this if you want to operate on the default remember cache. 95 | 96 | **Note:** If the name does not refer to a cache that exists, a warning is logged. 97 | 98 | ### remember.cacheFor(name) 99 | 100 | Get a raw remember cache. This can be useful for checking state of the cache, like whether or not a file has been seen before. 101 | 102 | **Note:** Remembering or forgetting files by interacting directly with this returned object is not recommended. 103 | 104 | #### name (optional) 105 | 106 | Type: `String` 107 | 108 | The name of the remember cache you want to retrieve. You do not need to pass this if you want to retrieve the default remember cache. 109 | 110 | ## Gotchas 111 | 112 | ### Forgetting files with altered paths 113 | 114 | See the API note above for the `path` argument when `forget`ing files. `forget` can only drop files by their *processed* path name, not their *source* path name. In common cases, these two things are equivalent. 115 | 116 | Thanks to @brian-mann for bringing this up. 117 | 118 | ### File ordering 119 | 120 | Be aware that this plugin does not make specific attempts to keep your files in any order. For example, if you add a new file governed by a glob you are watching, this file will enter the stream last, even if this file would preceed others alphabetically. 121 | 122 | If your build process depends on file ordering, please make use of the [gulp-order](https://www.npmjs.org/package/gulp-order) plugin after `remember`ing files. 123 | 124 | Thanks to @brian-mann for bringing this up. 125 | 126 | ### Files do not change in the cache 127 | 128 | Files are `.clone()`'d when placed into the cache and when taken out of the cache. This ensures that no other aspects of the build will alter the cache. 129 | 130 | Thanks to @mjancarik for this addition. 131 | 132 | ## License 133 | 134 | (MIT License) 135 | 136 | Copyright (c) 2014 Aaron Haurwitz 137 | 138 | Permission is hereby granted, free of charge, to any person obtaining a copy 139 | of this software and associated documentation files (the "Software"), to deal 140 | in the Software without restriction, including without limitation the rights 141 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 142 | copies of the Software, and to permit persons to whom the Software is 143 | furnished to do so, subject to the following conditions: 144 | 145 | The above copyright notice and this permission notice shall be included in 146 | all copies or substantial portions of the Software. 147 | 148 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 149 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 150 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 151 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 152 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 153 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 154 | THE SOFTWARE. 155 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var through = require('through2'), 4 | PluginError = require('plugin-error'), 5 | log = require('fancy-log'), 6 | pluginName = 'gulp-remember', // name of our plugin for error logging purposes 7 | caches = {}, // will hold named file caches 8 | defaultName = '_default'; // name to give a cache if not provided 9 | 10 | /** 11 | * Return a through stream that will: 12 | * 1. Remember all files that ever pass through it. 13 | * 2. Add all remembered files back into the stream when not present. 14 | * @param cacheName {string} Name to give your cache. 15 | * Caches with different names can know about different sets of files. 16 | */ 17 | function gulpRemember(cacheName) { 18 | var cache; // the files we've ever put our hands on in the current stream 19 | 20 | if (cacheName !== undefined && typeof cacheName !== 'number' && typeof cacheName !== 'string') { 21 | throw new PluginError(pluginName, 'Usage: require("gulp-remember")(name); where name is undefined, number or string'); 22 | } 23 | cacheName = cacheName || defaultName; // maybe need to use a default cache 24 | caches[cacheName] = caches[cacheName] || {}; // maybe initialize the named cache 25 | cache = caches[cacheName]; 26 | 27 | function transform(file, enc, callback) { 28 | var fileKey = file.path.toLowerCase(); 29 | cache[fileKey] = file.clone(); // add file to our cache 30 | callback(); 31 | } 32 | 33 | function flush(callback) { 34 | // add all files we've ever seen back into the stream 35 | for (var key in cache) { 36 | if (cache.hasOwnProperty(key)) { 37 | this.push(cache[key].clone()); // add this file back into the current stream 38 | } 39 | } 40 | callback(); 41 | } 42 | 43 | return through.obj(transform, flush); 44 | } 45 | 46 | /** 47 | * Forget about a file. 48 | * A warning is logged if either the named cache or file do not exist. 49 | * 50 | * @param cacheName {string} name of the cache from which to drop the file 51 | * @param path {string} path of the file to forget 52 | */ 53 | gulpRemember.forget = function (cacheName, path) { 54 | if (arguments.length === 1) { 55 | path = cacheName; 56 | cacheName = defaultName; 57 | } 58 | path = path.toLowerCase(); 59 | if (typeof cacheName !== 'number' && typeof cacheName !== 'string') { 60 | throw new PluginError(pluginName, 'Usage: require("gulp-remember").forget(cacheName, path); where cacheName is undefined, number or string and path is a string'); 61 | } 62 | if (caches[cacheName] === undefined) { 63 | log(pluginName, '- .forget() warning: cache ' + cacheName + ' not found'); 64 | } else if (caches[cacheName][path] === undefined) { 65 | log(pluginName, '- .forget() warning: file ' + path + ' not found in cache ' + cacheName); 66 | } else { 67 | delete caches[cacheName][path]; 68 | } 69 | }; 70 | 71 | /** 72 | * Forget all files in one cache. 73 | * A warning is logged if the cache does not exist. 74 | * 75 | * @param cacheName {string} name of the cache to wipe 76 | */ 77 | gulpRemember.forgetAll = function (cacheName) { 78 | if (arguments.length === 0) { 79 | cacheName = defaultName; 80 | } 81 | if (typeof cacheName !== 'number' && typeof cacheName !== 'string') { 82 | throw new PluginError(pluginName, 'Usage: require("gulp-remember").forgetAll(cacheName); where cacheName is undefined, number or string'); 83 | } 84 | if (caches[cacheName] === undefined) { 85 | log(pluginName, '- .forget() warning: cache ' + cacheName + ' not found'); 86 | } else { 87 | caches[cacheName] = {}; 88 | } 89 | } 90 | 91 | /** 92 | * Return a raw cache by name. 93 | * Useful for checking state. Manually adding or removing files is NOT recommended. 94 | * 95 | * @param cacheName {string} name of the cache to retrieve 96 | */ 97 | gulpRemember.cacheFor = function (cacheName) { 98 | if (arguments.length === 0) { 99 | cacheName = defaultName; 100 | } 101 | if (typeof cacheName !== 'number' && typeof cacheName !== 'string') { 102 | throw new PluginError(pluginName, 'Usage: require("gulp-remember").cacheFor(cacheName); where cacheName is undefined, number or string'); 103 | } 104 | return caches[cacheName]; 105 | } 106 | 107 | module.exports = gulpRemember; 108 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "gulp-remember", 3 | "description": "Adds previously seen files back into the stream.", 4 | "version": "1.0.1", 5 | "homepage": "http://github.com/ahaurw01/gulp-remember", 6 | "repository": "git://github.com/ahaurw01/gulp-remember.git", 7 | "author": "Aaron Haurwitz (http://aaron.haurwitz.com/)", 8 | "main": "./index.js", 9 | "keywords": [ 10 | "gulpplugin" 11 | ], 12 | "dependencies": { 13 | "fancy-log": "^1.3.2", 14 | "plugin-error": "^0.1.2", 15 | "through2": "^0.5.0" 16 | }, 17 | "devDependencies": { 18 | "mocha": "~1.18.2", 19 | "should": "~3.2.0", 20 | "sinon": "^1.12.1", 21 | "vinyl": "^2.1.0" 22 | }, 23 | "scripts": { 24 | "test": "mocha --reporter spec" 25 | }, 26 | "engineStrict": true, 27 | "engines": { 28 | "node": ">= 0.10" 29 | }, 30 | "licenses": [ 31 | { 32 | "type": "MIT", 33 | "url": "http://github.com/ahaurw01/gulp-remember/raw/master/LICENSE" 34 | } 35 | ] 36 | } 37 | -------------------------------------------------------------------------------- /test/main.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var remember = require('../'), 4 | should = require('should'), 5 | sinon = require('sinon'), 6 | File = require('vinyl'); 7 | 8 | function makeTestFile(path, contents) { 9 | contents = contents || 'test file'; 10 | return new File({ 11 | path: path, 12 | contents: new Buffer(contents) 13 | }); 14 | } 15 | 16 | require('mocha'); 17 | 18 | describe('gulp-remember', function () { 19 | describe('remember', function () { 20 | it('should pass one file through a previously empty cache', function (done) { 21 | var stream = remember('passOneThrough'), 22 | file = makeTestFile('/fixture/file.js', 'just a file'), 23 | filesSeen = 0; 24 | stream.on('data', function (file) { 25 | file.path.should.equal('/fixture/file.js'); 26 | file.contents.toString().should.equal('just a file'); 27 | filesSeen++; 28 | }); 29 | stream.once('end', function () { 30 | filesSeen.should.equal(1); 31 | done(); 32 | }); 33 | stream.write(file); 34 | stream.end(); 35 | }); 36 | 37 | it('should pass many files through a previously empty cache', function (done) { 38 | var i, 39 | stream = remember('manyFilesThrough'), 40 | filesSeen = 0; 41 | 42 | stream.on('data', function (file) { 43 | file.path.should.startWith('/fixture/'); 44 | file.path.should.endWith('.js'); 45 | file.contents.toString().should.startWith('file'); 46 | filesSeen++; 47 | }); 48 | stream.once('end', function () { 49 | filesSeen.should.equal(100); 50 | done(); 51 | }); 52 | for (i = 0; i < 100; i++) { 53 | stream.write(makeTestFile('/fixture/' + i + '.js', 'file ' + i)); 54 | } 55 | stream.end(); 56 | }); 57 | 58 | it('should remember the files passed through it on subsequent uses', function (done) { 59 | var stream = remember('remember'), 60 | anotherStream, 61 | filesSeen = 0, 62 | startingFiles = [makeTestFile('/fixture/one'), makeTestFile('/fixture/two')], 63 | oneMoreFile = makeTestFile('/fixture/three'); 64 | 65 | stream.resume(); // don't care about reading the files on this first go-round 66 | stream.once('end', function () { 67 | // done writing for the first time. write another file, then check we have three in total. 68 | anotherStream = remember('remember'); 69 | anotherStream.on('data', function () { 70 | filesSeen++; 71 | }); 72 | anotherStream.once('end', function () { 73 | filesSeen.should.equal(3); 74 | done(); 75 | }); 76 | anotherStream.write(oneMoreFile); 77 | anotherStream.end(); 78 | }); 79 | startingFiles.forEach(function (file) { 80 | stream.write(file); 81 | }); 82 | stream.end(); 83 | }); 84 | 85 | it('should disregard file path case', function (done) { 86 | var stream = remember('case-test'), 87 | anotherStream, 88 | filesSeen = 0, 89 | contentsSeen = '', 90 | file1 = makeTestFile('/fixture/ONE', 'ONE'), 91 | file2 = makeTestFile('/fixture/one', 'one'); 92 | 93 | stream.resume(); // don't care about reading the files on this first go-round 94 | stream.once('end', function () { 95 | anotherStream = remember('case-test'); 96 | anotherStream.on('data', function (f) { 97 | contentsSeen += f.contents.toString(); 98 | filesSeen++; 99 | }); 100 | anotherStream.once('end', function () { 101 | filesSeen.should.equal(1); 102 | contentsSeen.should.equal('one'); 103 | done(); 104 | }); 105 | anotherStream.write(file2); 106 | anotherStream.end(); 107 | }); 108 | stream.write(file1); 109 | stream.end(); 110 | }); 111 | 112 | it('should use the default cache when no name is passed', function (done) { 113 | var stream = remember(), 114 | anotherStream, 115 | filesSeen = 0, 116 | i; 117 | 118 | stream.resume(); // don't care about reading the files on this first go-round 119 | stream.once('end', function () { 120 | anotherStream = remember(); 121 | anotherStream.on('data', function () { 122 | filesSeen++; 123 | }); 124 | anotherStream.on('end', function () { 125 | filesSeen.should.equal(2000); 126 | done(); 127 | }); 128 | for (i = 1000; i < 2000; i++) { 129 | anotherStream.write(makeTestFile('/fixture/' + i + '.js')); 130 | } 131 | anotherStream.end(); 132 | }); 133 | for (i = 0; i < 1000; i++) { 134 | stream.write(makeTestFile('/fixture/' + i + '.js')); 135 | } 136 | stream.end(); 137 | }); 138 | 139 | it('should not pass duplicates through', function (done) { 140 | var stream = remember('noDuplicates'), 141 | anotherStream, 142 | filesSeen = 0; 143 | 144 | stream.resume(); 145 | stream.once('end', function () { 146 | anotherStream = remember('noDuplicates'); 147 | anotherStream.on('data', function () { 148 | filesSeen++; 149 | }); 150 | anotherStream.on('end', function () { 151 | filesSeen.should.equal(6); 152 | done(); 153 | }); 154 | anotherStream.write(makeTestFile('/fixture/three')); 155 | anotherStream.write(makeTestFile('/fixture/four')); 156 | anotherStream.write(makeTestFile('/fixture/five')); 157 | anotherStream.write(makeTestFile('/fixture/six')); 158 | anotherStream.end(); 159 | }); 160 | stream.write(makeTestFile('/fixture/one')); 161 | stream.write(makeTestFile('/fixture/two')); 162 | stream.write(makeTestFile('/fixture/three')); 163 | stream.write(makeTestFile('/fixture/four')); 164 | stream.end(); 165 | }); 166 | 167 | it('should keep immutable file in cache', function (done) { 168 | var stream = remember('noMutation'), 169 | file = makeTestFile('fixture/file.js', 'just a file'); 170 | 171 | stream.on('data', function (file) { 172 | file.contents = new Buffer('Different file'); 173 | }); 174 | stream.once('end', function () { 175 | file.contents.toString().should.equal('just a file'); 176 | done(); 177 | }); 178 | 179 | stream.write(file); 180 | stream.end(); 181 | }); 182 | }); 183 | 184 | describe('forget', function () { 185 | it('should forget a file it used to know', function (done) { 186 | var stream = remember('forget'), 187 | anotherStream, 188 | filesSeen = 0; 189 | stream.resume(); 190 | stream.once('end', function () { 191 | remember.forget('forget', '/fixture/one'); 192 | anotherStream = remember('forget'); 193 | anotherStream.on('data', function (file) { 194 | file.path.should.equal('/fixture/two'); 195 | filesSeen++; 196 | }); 197 | anotherStream.on('end', function () { 198 | filesSeen.should.equal(1); 199 | done(); 200 | }); 201 | anotherStream.write(makeTestFile('/fixture/two')); 202 | anotherStream.end(); 203 | }); 204 | stream.write(makeTestFile('/fixture/one')); 205 | stream.end(); 206 | }); 207 | 208 | it('should not throw when target cache does not exist', function () { 209 | (function () { 210 | remember.forget('peaceAndLove', 'some/file'); 211 | }).should.not.throw(); 212 | }); 213 | 214 | it('should not throw when target cache exists but file does not', function () { 215 | remember('kittens'); 216 | (function () { 217 | remember.forget('kittens', 'Mister_McButtercups'); 218 | }).should.not.throw(); 219 | }); 220 | 221 | it('should log a warning when target cache does not exist', function () { 222 | var logStub = sinon.stub(console, 'log'), 223 | logArgs; 224 | remember.forget('peaceAndLove', 'some/file'); 225 | logStub.called.should.be.true; 226 | logArgs = logStub.args[0]; 227 | // Should append the name of the plugin 228 | logArgs[0].should.equal('gulp-remember'); 229 | // Should warn about the specific cache name 230 | logArgs[1].should.containEql('peaceAndLove'); 231 | 232 | logStub.restore(); 233 | }); 234 | 235 | it('should log a warning when target files does not exist in target cache', function () { 236 | var logStub = sinon.stub(console, 'log'), 237 | logArgs; 238 | remember('cacheThatExists'); 239 | remember.forget('cacheThatExists', 'file/that/doesnt/exist'); 240 | logStub.called.should.be.true; 241 | logArgs = logStub.args[0]; 242 | // Should append the name of the plugin 243 | logArgs[0].should.equal('gulp-remember'); 244 | // Should warn about the specific cache name 245 | logArgs[1].should.containEql('file/that/doesnt/exist'); 246 | 247 | logStub.restore(); 248 | }); 249 | }); 250 | 251 | describe('forgetAll', function () { 252 | it('should forget all files in a populated cache', function (done) { 253 | var stream = remember('forgetAll'), 254 | anotherStream, 255 | filesSeen = 0; 256 | stream.resume(); 257 | stream.once('end', function () { 258 | remember.forgetAll('forgetAll'); 259 | anotherStream = remember('forgetAll'); 260 | anotherStream.on('data', function (file) { 261 | file.path.should.equal('/fixture/three'); 262 | filesSeen++; 263 | }); 264 | anotherStream.on('end', function () { 265 | filesSeen.should.equal(1); 266 | done(); 267 | }); 268 | anotherStream.write(makeTestFile('/fixture/three')); 269 | anotherStream.end(); 270 | }); 271 | stream.write(makeTestFile('/fixture/one')); 272 | stream.write(makeTestFile('/fixture/two')); 273 | stream.end(); 274 | }); 275 | 276 | it('should forget all files in the default cache', function (done) { 277 | var stream = remember(), 278 | anotherStream, 279 | filesSeen = 0; 280 | stream.resume(); 281 | stream.once('end', function () { 282 | remember.forgetAll(); 283 | anotherStream = remember(); 284 | anotherStream.on('data', function (file) { 285 | file.path.should.equal('/fixture/three'); 286 | filesSeen++; 287 | }); 288 | anotherStream.on('end', function () { 289 | filesSeen.should.equal(1); 290 | done(); 291 | }); 292 | anotherStream.write(makeTestFile('/fixture/three')); 293 | anotherStream.end(); 294 | }); 295 | stream.write(makeTestFile('/fixture/one')); 296 | stream.write(makeTestFile('/fixture/two')); 297 | stream.end(); 298 | }); 299 | 300 | it('should not throw when target cache does not exist', function () { 301 | (function () { 302 | remember.forgetAll('peanutButterJellyTime'); 303 | }).should.not.throw(); 304 | }); 305 | 306 | it('should log a warning when target cache does not exist', function () { 307 | var logStub = sinon.stub(console, 'log'), 308 | logArgs; 309 | remember.forgetAll('peanutButterJellyTime'); 310 | logStub.called.should.be.true; 311 | logArgs = logStub.args[0]; 312 | // Should append the name of the plugin 313 | logArgs[0].should.equal('gulp-remember'); 314 | // Should warn about the specific cache name 315 | logArgs[1].should.containEql('peanutButterJellyTime'); 316 | 317 | logStub.restore(); 318 | }); 319 | 320 | it('should not throw on subsequent forgetAll calls', function (done) { 321 | var stream = remember('forgetAllMulti'); 322 | stream.resume(); 323 | stream.once('end', function () { 324 | remember.forgetAll('forgetAllMulti'); 325 | (function () { 326 | remember.forgetAll('forgetAllMulti'); 327 | }).should.not.throw(); 328 | done(); 329 | }); 330 | stream.write(makeTestFile('what/ever')); 331 | stream.end(); 332 | }); 333 | }); 334 | 335 | describe('cacheFor', function () { 336 | it('should return the named cache', function (done) { 337 | var stream = remember('cacheFor'), 338 | cache, 339 | file; 340 | stream.resume(); 341 | stream.once('end', function () { 342 | cache = remember.cacheFor('cacheFor'); 343 | cache.should.be.an.instanceOf(Object); 344 | file = cache['whitehouse/nuclear-codes.rtf']; 345 | file.should.be.an.instanceOf(Object); 346 | file.should.have.property('path', 'whitehouse/nuclear-codes.rtf'); 347 | done(); 348 | }); 349 | stream.write(makeTestFile('whitehouse/nuclear-codes.rtf')); 350 | stream.end(); 351 | }); 352 | 353 | it('should return the default cache', function (done) { 354 | var stream = remember(), 355 | cache, 356 | file; 357 | stream.resume(); 358 | stream.once('end', function () { 359 | cache = remember.cacheFor(); 360 | cache.should.be.an.instanceOf(Object); 361 | file = cache['jennifer-lawrence/fully-clothed.jpg']; 362 | file.should.be.an.instanceOf(Object); 363 | file.should.have.property('path', 'jennifer-lawrence/fully-clothed.jpg'); 364 | done(); 365 | }); 366 | stream.write(makeTestFile('jennifer-lawrence/fully-clothed.jpg')); 367 | stream.end(); 368 | }); 369 | 370 | it('should return nothing if given bogus cache name', function () { 371 | var cache = remember.cacheFor('speculation-on-the-guilt-or-innocence-of-adnan-syed'); 372 | should.not.exist(cache); 373 | }); 374 | }); 375 | }); 376 | --------------------------------------------------------------------------------