Skip to content

Commit

Permalink
chore: node.js 12 compatibility for object snapshot test. (#1084)
Browse files Browse the repository at this point in the history
node.js 12 changes the format of `util.inspect`, this causes snapshot
mismatch.  Replace our one object snapshot with a JSON stringified array
of `[name, value]` pairs representing the object.  Use an array sorted
by names as JSON.stringify does not guarantee order of elements in an
object.
  • Loading branch information
coreyfarrell committed Apr 24, 2019
1 parent a7bc7ae commit 6fc109f
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 15 deletions.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -7,7 +7,7 @@
"lint": "standard",
"pretest": "npm run lint && npm run clean && npm run instrument",
"test": "tap -t360 --no-cov -b test/*.js",
"snap": "cross-env TAP_SNAPSHOT=1 tap -t360 --no-cov -b test/*.js",
"snap": "cross-env TAP_SNAPSHOT=1 npm test",
"posttest": "npm run report",
"clean": "rimraf ./.nyc_output ./node_modules/.cache ./.self_coverage ./test/fixtures/.nyc_output ./test/fixtures/node_modules/.cache ./self-coverage",
"instrument": "node ./build-self-coverage.js",
Expand Down
47 changes: 38 additions & 9 deletions tap-snapshots/test-nyc-integration.js-TAP.test.js
Expand Up @@ -190,15 +190,44 @@ All files | 50 | 50 | 100 | 50 |
`

exports[`test/nyc-integration.js TAP passes configuration via environment variables > undefined 1`] = `
{ silent: true,
cache: false,
sourceMap: true,
require: 'make-dir',
include: 'env.js',
exclude: 'batman.js',
extension: '.js',
cacheDir: '/tmp',
instrumenter: './lib/instrumenters/istanbul' }
[
[
"cache",
false
],
[
"cacheDir",
"/tmp"
],
[
"exclude",
"batman.js"
],
[
"extension",
".js"
],
[
"include",
"env.js"
],
[
"instrumenter",
"./lib/instrumenters/istanbul"
],
[
"require",
"make-dir"
],
[
"silent",
true
],
[
"sourceMap",
true
]
]
`

exports[`test/nyc-integration.js TAP allows package.json configuration to be overridden with command line args > stdout 1`] = `
Expand Down
13 changes: 8 additions & 5 deletions test/nyc-integration.js
Expand Up @@ -97,14 +97,17 @@ t.test('passes configuration via environment variables', t => {
'extension'
]

const { NYC_CONFIG } = JSON.parse(stdout)
const config = JSON.parse(NYC_CONFIG, (key, value) => {
return key === '' || checkOptions.includes(key) ? value : undefined
})
const config = JSON.parse(JSON.parse(stdout).NYC_CONFIG)

t.is(status, 0)
t.is(stderr, '')
t.matchSnapshot(config)
t.matchSnapshot(
JSON.stringify(
checkOptions.sort().map(option => [option, config[option]]),
null,
2
)
)
})
})

Expand Down

0 comments on commit 6fc109f

Please sign in to comment.