Skip to content

Commit

Permalink
fix(server): use flatted for json.stringify (#3220)
Browse files Browse the repository at this point in the history
Remove json3 dep and use, probably was needed for older node code.
Fixes #3215
  • Loading branch information
johnjbarton committed Nov 28, 2018
1 parent 2682bff commit fb05fb1
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 3 deletions.
4 changes: 3 additions & 1 deletion lib/server.js
Expand Up @@ -8,8 +8,10 @@ const spawn = require('child_process').spawn
const tmp = require('tmp')
const fs = require('fs')
const path = require('path')

const BundleUtils = require('./utils/bundle-utils')
const NetUtils = require('./utils/net-utils')
const JsonUtils = require('./utils/json-utils')
const root = global || window || this

const cfg = require('./config')
Expand Down Expand Up @@ -63,7 +65,7 @@ class Server extends KarmaEventEmitter {

const config = cfg.parseConfig(cliOptions.configFile, cliOptions)

this.log.debug('Final config', JSON.stringify(config, null, 2))
this.log.debug('Final config', JsonUtils.stringify(config, null, 2))

let modules = [{
helper: ['value', helper],
Expand Down
10 changes: 10 additions & 0 deletions lib/utils/json-utils.js
@@ -0,0 +1,10 @@

const {stringify} = require('flatted/cjs')

const JsonUtils = {
stringify (obj) {
return stringify(obj)
}
}

module.exports = JsonUtils
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -412,6 +412,7 @@
"eslint-plugin-promise": "^3.4.2",
"eslint-plugin-react": "^7.0.1",
"eslint-plugin-standard": "^3.0.1",
"flatted": "^2.0.0",
"grunt": "^1.0.0",
"grunt-auto-release": "^0.0.7",
"grunt-browserify": "^5.0.0",
Expand All @@ -428,7 +429,6 @@
"http2": "^3.3.6",
"husky": "^0.14.3",
"jasmine-core": "^2.3.4",
"json3": "^3.3.2",
"karma-browserify": "^5.0.1",
"karma-browserstack-launcher": "^1.0.0",
"karma-chai": "^0.1.0",
Expand Down
1 change: 0 additions & 1 deletion test/client/karma.spec.js
@@ -1,6 +1,5 @@
// shim all the things
require('core-js/es5')
global.JSON = require('json3')
var sinon = require('sinon')
var assert = require('assert')

Expand Down
18 changes: 18 additions & 0 deletions test/unit/utils/json-utils.spec.js
@@ -0,0 +1,18 @@
'use strict'

const JsonUtils = require('../../../lib/utils/json-utils')

describe('json-utils', () => {
it('stringify-s', () => {
const obj = {a: 'a', i: 1}
const json = JsonUtils.stringify(obj)
expect(json).to.be.equal('[{"a":"1","i":1},"a"]')
})
it('stringify-s circular data', () => {
const a = [{}]
a[0].a = a
a.push(a)

expect(JsonUtils.stringify(a)).to.be.equal('[["1","0"],{"a":"0"}]')
})
})

0 comments on commit fb05fb1

Please sign in to comment.