diff --git a/lib/sync-changes.js b/lib/sync-changes.js index c01401fe02..4227e4afd7 100644 --- a/lib/sync-changes.js +++ b/lib/sync-changes.js @@ -3,8 +3,9 @@ const EventEmitter = require('events') // npm dependencies const browserSync = require('browser-sync') -const { writeJsonSync } = require('fs-extra') +const { ensureDirSync, writeJsonSync } = require('fs-extra') const path = require('path') +const util = require('util') const { tmpDir } = require('./utils/paths') const fs = require('fs') @@ -19,7 +20,15 @@ function hasRestartedAfterError () { } function flagError (error) { - writeJsonSync(path.join(tmpDir, 'errors.json'), { error }) + const errorFormatted = util.inspect(error, { + compact: false, + depth: Infinity, + maxArrayLength: Infinity, + maxStringLength: Infinity + }) + + ensureDirSync(path.dirname(errorsFile)) + writeJsonSync(errorsFile, { error: errorFormatted }) } function unflagError () { diff --git a/lib/sync-changes.test.js b/lib/sync-changes.test.js index 3974f55901..574adc5d55 100644 --- a/lib/sync-changes.test.js +++ b/lib/sync-changes.test.js @@ -23,11 +23,12 @@ describe('sync-changes', () => { it('flags error correctly', () => { const error = { data: true } + const errorFormatted = '{\n data: true\n}' syncChanges.flagError(error) expect(fse.writeJsonSync).toHaveBeenCalledTimes(1) - expect(fse.writeJsonSync).toHaveBeenCalledWith(errorsFile, { error }) + expect(fse.writeJsonSync).toHaveBeenCalledWith(errorsFile, { error: errorFormatted }) }) it('syncs correctly', () => {