diff --git a/src/logic/smart-write.js b/src/logic/smart-write.js index 0b04dda2..41a1c74b 100644 --- a/src/logic/smart-write.js +++ b/src/logic/smart-write.js @@ -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'); diff --git a/test/logic/smart-write.spec.js b/test/logic/smart-write.spec.js index b51f466f..bc6a0451 100644 --- a/test/logic/smart-write.spec.js +++ b/test/logic/smart-write.spec.js @@ -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');