diff options
author | LakshmiSwethaG <lakshmigopireddy@in.ibm.com> | 2018-09-05 10:39:08 -0400 |
---|---|---|
committer | Gireesh Punathil <gpunathi@in.ibm.com> | 2019-01-18 10:36:39 +0530 |
commit | 55e0ad9ae690f6d73b0caff7b813eb4d61195b94 (patch) | |
tree | d85d8d5bf3b8efb24b0d79886af706584a076721 /test/common/report.js | |
parent | 7f4053ed1381d7001dbdaa12f064847aaf4d0ecf (diff) | |
download | node-new-55e0ad9ae690f6d73b0caff7b813eb4d61195b94.tar.gz |
test: add node-report tests
One test per each API, so that additional tests in future are modular.
test/common/report.js contain common functions that tests leverage.
PR-URL: https://github.com/nodejs/node/pull/22712
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michael Dawson <Michael_Dawson@ca.ibm.com>
Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com>
Diffstat (limited to 'test/common/report.js')
-rw-r--r-- | test/common/report.js | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/test/common/report.js b/test/common/report.js new file mode 100644 index 0000000000..646660da49 --- /dev/null +++ b/test/common/report.js @@ -0,0 +1,43 @@ +'use strict'; +require('../common'); +const assert = require('assert'); +const fs = require('fs'); +const path = require('path'); + +const REPORT_SECTIONS = [ 'header', + 'javascriptStack', + 'nativeStack', + 'javascriptHeap', + 'libuv', + 'environmentVariables', + 'sharedObjects' ]; + +let tmppath = ''; + +exports.findReports = (pid, path) => { + // Default filenames are of the form + // report.<date>.<time>.<pid>.<seq>.json + tmppath = path; + const format = '^report\\.\\d+\\.\\d+\\.' + pid + '\\.\\d+\\.json$'; + const filePattern = new RegExp(format); + const files = fs.readdirSync(path); + return files.filter((file) => filePattern.test(file)); +}; + +exports.validate = (report, options) => { + const jtmp = path.join(tmppath, report); + fs.readFile(jtmp, (err, data) => { + this.validateContent(data, options); + }); +}; + + +exports.validateContent = function validateContent(data, options) { + const report = JSON.parse(data); + const comp = Object.keys(report); + + // Check all sections are present + REPORT_SECTIONS.forEach((section) => { + assert.ok(comp.includes(section)); + }); +}; |