Skip to content

Commit

Permalink
Implement getStateSnapshot (#153)
Browse files Browse the repository at this point in the history
  • Loading branch information
mshima committed May 17, 2021
1 parent 42f5d56 commit 735a86c
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 3 deletions.
13 changes: 13 additions & 0 deletions lib/run-result.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,19 @@ class RunResult {
return this.fs.dump(this.cwd, filter);
}

/**
* Return an object with filenames with state.
* @param {Function} filter - parameter forwarded to mem-fs-editor#dump
* @returns {Object}
*/
getStateSnapshot(filter) {
const snapshot = this.getSnapshot(filter);
Object.values(snapshot).forEach((dump) => {
delete dump.contents;
});
return snapshot;
}

/**
* Prints files names and contents from mem-fs
* @param {...string} files - Files to print or empty for entire mem-fs
Expand Down
37 changes: 34 additions & 3 deletions test/run-result.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,40 @@ describe('run-result', () => {
runResult.fs.write(path.resolve('test2.txt'), 'test2 content');
});
it('should return every changed file', () => {
assert.equal(Object.keys(runResult.getSnapshot()).length, 2);
assert(runResult.getSnapshot()['test.txt']);
assert(runResult.getSnapshot()['test2.txt']);
assert.deepEqual(runResult.getSnapshot(), {
'test.txt': {
contents: 'test content',
state: 'modified'
},
'test2.txt': {
contents: 'test2 content',
state: 'modified'
}
});
});
});
describe('#getSnapshotState', () => {
let runResult;
beforeEach(() => {
const memFs = MemFs.create();
const memFsEditor = MemFsEditor.create(memFs);
runResult = new RunResult({
memFs,
fs: memFsEditor,
cwd: process.cwd()
});
runResult.fs.write(path.resolve('test.txt'), 'test content');
runResult.fs.write(path.resolve('test2.txt'), 'test2 content');
});
it('should return every changed file', () => {
assert.deepEqual(runResult.getStateSnapshot(), {
'test.txt': {
state: 'modified'
},
'test2.txt': {
state: 'modified'
}
});
});
});
describe('#cleanup', () => {
Expand Down

0 comments on commit 735a86c

Please sign in to comment.