Skip to content

Commit

Permalink
Rename lazyLoad to lazy
Browse files Browse the repository at this point in the history
  • Loading branch information
tschaub committed Aug 9, 2020
1 parent 2d6d0a1 commit 211c57a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
8 changes: 4 additions & 4 deletions lib/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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!`);
Expand All @@ -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));
Expand Down
8 changes: 4 additions & 4 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

#### <a id='mappingoptions'>options</a>

| 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)`
Expand All @@ -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'
});
Expand Down
12 changes: 6 additions & 6 deletions test/lib/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)()));

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 211c57a

Please sign in to comment.