diff --git a/lib/loader.js b/lib/loader.js index f2d549dc..f8442e4a 100755 --- a/lib/loader.js +++ b/lib/loader.js @@ -10,7 +10,7 @@ const createContext = ({output, options = {}, target}, newContext) => // Assign options and set defaults if needed options: { recursive: options.recursive !== false, - lazyLoad: options.lazyLoad !== false + lazy: options.lazy !== false }, output, target @@ -20,7 +20,7 @@ const createContext = ({output, options = {}, target}, newContext) => function addFile(context, stats, isRoot) { const {output, target} = context; - const {lazyLoad} = context.options; + const {lazy} = context.options; if (!stats.isFile()) { throw new Error(`${target} is not a valid file!`); @@ -29,10 +29,10 @@ function addFile(context, stats, isRoot) { const outputPropKey = isRoot ? target : path.basename(target); output[outputPropKey] = () => { - const content = !lazyLoad ? fs.readFileSync(target) : ''; + const content = !lazy ? fs.readFileSync(target) : ''; const file = FileSystem.file(Object.assign({}, stats, {content}))(); - if (lazyLoad) { + if (lazy) { Object.defineProperty(file, '_content', { get() { const res = bypass(() => fs.readFileSync(target)); diff --git a/readme.md b/readme.md index 3210b498..e56342b2 100644 --- a/readme.md +++ b/readme.md @@ -67,13 +67,13 @@ You can load real files and directories into the mock system using `mock.load()` #### Notes - All stat information is duplicated (dates, permissions, etc) -- By default, all files are lazy-loaded, unless you specify the `{ lazyLoad: false }` option +- By default, all files are lazy-loaded, unless you specify the `{lazy: false}` option #### options | Option | Type | Default | Description | | --------- | ------- | ------- | ------------ -| lazyLoad | boolean | true | File content isn't loaded until explicitly read +| lazy | boolean | true | File content isn't loaded until explicitly read | recursive | boolean | true | Load all files and directories recursively #### `mock.load(path, options)` @@ -84,13 +84,13 @@ mock({ 'my-file.txt': mock.load(path.resolve(__dirname, 'assets/special-file.txt')), // Pre-load js file - 'ready.js': mock.load(path.resolve(__dirname, 'scripts/ready.js'), { lazyLoad: false }), + 'ready.js': mock.load(path.resolve(__dirname, 'scripts/ready.js'), {lazy: false}), // Recursively loads all node_modules 'node_modules': mock.load(path.resolve(__dirname, '../node_modules')), // Creates a directory named /tmp with only the files in /tmp/special_tmp_files (no subdirectories), pre-loading all content - '/tmp': mock.load('/tmp/special_tmp_files', { recursive: false, lazyLoad:false }), + '/tmp': mock.load('/tmp/special_tmp_files', {recursive: false, lazy:false}), 'fakefile.txt': 'content here' }); diff --git a/test/lib/index.spec.js b/test/lib/index.spec.js index 861f05b8..802e011d 100644 --- a/test/lib/index.spec.js +++ b/test/lib/index.spec.js @@ -295,7 +295,7 @@ describe('The API', function() { assert.instanceOf(file, File); assert.deepEqual(filterStats(file), filterStats(stats)); }); - describe('lazyLoad=true', () => { + describe('lazy=true', () => { let file; beforeEach(() => (file = mock.load(filePath)())); @@ -344,9 +344,9 @@ describe('The API', function() { }); }); - it('lazyLoad=false loads file content', () => { + it('lazy=false loads file content', () => { const file = mock.load(path.join(assetsPath, 'file1.txt'), { - lazyLoad: false + lazy: false })(); assert.equal( @@ -383,18 +383,18 @@ describe('The API', function() { assert.instanceOf(baseDirSubdir, Directory); assert.instanceOf(baseDirSubdir._items['file3.txt'], File); }); - it('respects lazyLoad setting', () => { + it('respects lazy setting', () => { let dir; const getFile = () => dir._items.dir._items.subdir._items['file3.txt']; - dir = mock.load(assetsPath, {recursive: true, lazyLoad: true})(); + dir = mock.load(assetsPath, {recursive: true, lazy: true})(); assert.typeOf( Object.getOwnPropertyDescriptor(getFile(), '_content').get, 'function' ); - dir = mock.load(assetsPath, {recursive: true, lazyLoad: false})(); + dir = mock.load(assetsPath, {recursive: true, lazy: false})(); assert.instanceOf( Object.getOwnPropertyDescriptor(getFile(), '_content').value, Buffer