Skip to content

Commit

Permalink
Merge pull request #59 from blackflux/dev
Browse files Browse the repository at this point in the history
[Gally]: master <- dev
  • Loading branch information
simlu committed Apr 11, 2019
2 parents 19dfbf5 + 72afb2a commit de99486
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/logic/smart-write.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ module.exports = (filepath, content, options = {}) => {
assert(options instanceof Object && !Array.isArray(options));

const ext = getExt(filepath);
const ctx = Object.assign({
treatAs: ext === 'js' ? 'txt' : ext,
mergeStrategy: (existing, changeset) => changeset
}, options);
const ctx = Object.assign(
{ mergeStrategy: (existing, changeset) => changeset },
options,
{ treatAs: options.treatAs || (ext === 'js' ? 'txt' : ext) }
);
assert(Object.keys(ctx).length === 2, 'Unexpected Option provided!');
assert(typeof ctx.treatAs === 'string');
assert(typeof ctx.mergeStrategy === 'function');
Expand Down
4 changes: 4 additions & 0 deletions test/logic/smart-write.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ describe('Testing smartWrite', () => {
executeTest('file.txt', { key: 'value' }, '{\n "key": "value"\n}\n', { treatAs: 'json' });
});

it('Testing treatAs null', () => {
executeTest('file.txt', ['line1', 'line2'], 'line1\nline2\n', { treatAs: null });
});

it('Testing unchanged content', () => {
executeTest('file.txt', ['line1', 'line2'], 'line1\nline2\n');
executeTest('file.txt', ['line1', 'line2'], 'line1\nline2\n');
Expand Down

0 comments on commit de99486

Please sign in to comment.