Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(server): use flatted for json.stringify #3220

Merged
merged 1 commit into from
Nov 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/server.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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"}]')
})
})