Skip to content

Commit

Permalink
Merge pull request #451 from dadi/feature/447_update-circular-json-de…
Browse files Browse the repository at this point in the history
…pendency

Replace CircularJSON package
  • Loading branch information
jimlambie committed Dec 4, 2018
2 parents 77c99d8 + afb003c commit 84bbff3
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 18 deletions.
4 changes: 2 additions & 2 deletions dadi/lib/debug/views.js
@@ -1,5 +1,5 @@
const path = require('path')
const CircularJSON = require('circular-json')
const stringify = require('json-stringify-safe')
const help = require(path.join(__dirname, '/../help'))

/**
Expand Down Expand Up @@ -117,7 +117,7 @@ module.exports.debug = function (debug) {
function encode (data) {
data =
typeof data === 'object'
? CircularJSON.stringify(data, null, 2)
? stringify(data)
: data.toString()
return data
.replace(/&/g, '&')
Expand Down
4 changes: 2 additions & 2 deletions dadi/lib/view/send.js
Expand Up @@ -2,7 +2,7 @@ const path = require('path')
const zlib = require('zlib')
const brotli = require('iltorb')
const compressible = require('compressible')
const CircularJSON = require('circular-json')
const stringify = require('json-stringify-safe')

const config = require(path.join(__dirname, '/../../../config.js'))
const help = require(path.join(__dirname, '/../help'))
Expand All @@ -16,7 +16,7 @@ module.exports.json = function (statusCode, res, next) {
return function (err, results) {
if (err) return next(err)

const resBody = CircularJSON.stringify(results, null, 2)
const resBody = stringify(results)

// Only if nothing else has responsed e.g., errorView
if (!res.headersSent) {
Expand Down
12 changes: 8 additions & 4 deletions package.json
Expand Up @@ -10,8 +10,6 @@
"posttest": "node ./scripts/coverage.js",
"snyk-protect": "snyk protect",
"prepublishOnly": "npm run snyk-protect",
"precommit": "node scripts/precommit.js && lint-staged",
"commitmsg": "commitlint -e",
"format": "prettier-standard '{dadi,scripts,test}/{!(app),*}/*.js'",
"prepare": "npm run snyk-protect"
},
Expand All @@ -38,7 +36,6 @@
"async": "~1.5.2",
"body-parser": "~1.18.2",
"chokidar": "~2.0.0",
"circular-json": "~0.5.1",
"clone": "~2.1.1",
"colors": "~1.1.2",
"compressible": "~2.0.11",
Expand All @@ -58,6 +55,7 @@
"get-value": "~3.0.0",
"iltorb": "~2.4.0",
"js-yaml": "~3.12.0",
"json-stringify-safe": "^5.0.1",
"kinesis": "~1.2.2",
"marked": "~0.3.9",
"mime-types": "~2.1.17",
Expand Down Expand Up @@ -124,5 +122,11 @@
},
"author": "DADI <team@dadi.tech>",
"license": "SEE LICENSE IN GPL.md",
"snyk": true
"snyk": true,
"husky": {
"hooks": {
"commit-msg": "commitlint -e",
"pre-commit": "node scripts/precommit.js && lint-staged"
}
}
}
1 change: 1 addition & 0 deletions test/mocha.opts
Expand Up @@ -4,3 +4,4 @@
--recursive
--require=env-test
--require test/pretest.js
--exit
23 changes: 13 additions & 10 deletions test/unit/Z_debug.js
Expand Up @@ -30,11 +30,15 @@ describe('Debug view', done => {
})

afterEach(done => {
TestHelper.resetConfig().then(() => {
TestHelper.stopServer(() => {
setTimeout(() => {
done()
}, 200)
TestHelper.updateConfig({
allowDebugView: false
}).then(() => {
TestHelper.resetConfig().then(() => {
TestHelper.stopServer(() => {
setTimeout(() => {
done()
}, 200)
})
})
})
})
Expand Down Expand Up @@ -137,7 +141,7 @@ describe('Debug view', done => {
.toString()
.trim()
.should.startWith(
"var data = new JSONEditor(document.getElementById('data'), {mode: 'view'}, {\n \"query\": {}"
"var data = new JSONEditor(document.getElementById('data'), {mode: 'view'}, {\"query\":{}"
)

done()
Expand Down Expand Up @@ -165,7 +169,7 @@ describe('Debug view', done => {
.toString()
.trim()
.should.startWith(
'var data = new JSONEditor(document.getElementById(\'data\'), {mode: \'view\'}, {\n "name": "page1"'
'var data = new JSONEditor(document.getElementById(\'data\'), {mode: \'view\'}, {"name":"page1"'
)

done()
Expand Down Expand Up @@ -223,9 +227,8 @@ describe('Debug view', done => {
.toString()
.trim()
.should.startWith(
"var data = new JSONEditor(document.getElementById('data'), {mode: 'view'}, {\n \"request\""
"var data = new JSONEditor(document.getElementById('data'), {mode: 'view'}, {\"request\""
)

done()
})
})
Expand Down Expand Up @@ -264,7 +267,7 @@ describe('Debug view', done => {
.toString()
.trim()
.should.startWith(
"var data = new JSONEditor(document.getElementById('data'), {mode: 'view'}, {\n \"get\""
"var data = new JSONEditor(document.getElementById('data'), {mode: 'view'}, {\"get\""
)

done()
Expand Down

0 comments on commit 84bbff3

Please sign in to comment.