Skip to content

Commit fb05fb1

Browse files
authored
fix(server): use flatted for json.stringify (#3220)
Remove json3 dep and use, probably was needed for older node code. Fixes #3215
1 parent 2682bff commit fb05fb1

File tree

5 files changed

+32
-3
lines changed

5 files changed

+32
-3
lines changed

lib/server.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ const spawn = require('child_process').spawn
88
const tmp = require('tmp')
99
const fs = require('fs')
1010
const path = require('path')
11+
1112
const BundleUtils = require('./utils/bundle-utils')
1213
const NetUtils = require('./utils/net-utils')
14+
const JsonUtils = require('./utils/json-utils')
1315
const root = global || window || this
1416

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

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

66-
this.log.debug('Final config', JSON.stringify(config, null, 2))
68+
this.log.debug('Final config', JsonUtils.stringify(config, null, 2))
6769

6870
let modules = [{
6971
helper: ['value', helper],

lib/utils/json-utils.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
const {stringify} = require('flatted/cjs')
3+
4+
const JsonUtils = {
5+
stringify (obj) {
6+
return stringify(obj)
7+
}
8+
}
9+
10+
module.exports = JsonUtils

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,7 @@
412412
"eslint-plugin-promise": "^3.4.2",
413413
"eslint-plugin-react": "^7.0.1",
414414
"eslint-plugin-standard": "^3.0.1",
415+
"flatted": "^2.0.0",
415416
"grunt": "^1.0.0",
416417
"grunt-auto-release": "^0.0.7",
417418
"grunt-browserify": "^5.0.0",
@@ -428,7 +429,6 @@
428429
"http2": "^3.3.6",
429430
"husky": "^0.14.3",
430431
"jasmine-core": "^2.3.4",
431-
"json3": "^3.3.2",
432432
"karma-browserify": "^5.0.1",
433433
"karma-browserstack-launcher": "^1.0.0",
434434
"karma-chai": "^0.1.0",

test/client/karma.spec.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// shim all the things
22
require('core-js/es5')
3-
global.JSON = require('json3')
43
var sinon = require('sinon')
54
var assert = require('assert')
65

test/unit/utils/json-utils.spec.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
'use strict'
2+
3+
const JsonUtils = require('../../../lib/utils/json-utils')
4+
5+
describe('json-utils', () => {
6+
it('stringify-s', () => {
7+
const obj = {a: 'a', i: 1}
8+
const json = JsonUtils.stringify(obj)
9+
expect(json).to.be.equal('[{"a":"1","i":1},"a"]')
10+
})
11+
it('stringify-s circular data', () => {
12+
const a = [{}]
13+
a[0].a = a
14+
a.push(a)
15+
16+
expect(JsonUtils.stringify(a)).to.be.equal('[["1","0"],{"a":"0"}]')
17+
})
18+
})

0 commit comments

Comments
 (0)