summaryrefslogtreecommitdiff
path: root/test/common
diff options
context:
space:
mode:
authorLakshmiSwethaG <lakshmigopireddy@in.ibm.com>2018-09-05 10:39:08 -0400
committerGireesh Punathil <gpunathi@in.ibm.com>2019-01-18 10:36:39 +0530
commit55e0ad9ae690f6d73b0caff7b813eb4d61195b94 (patch)
treed85d8d5bf3b8efb24b0d79886af706584a076721 /test/common
parent7f4053ed1381d7001dbdaa12f064847aaf4d0ecf (diff)
downloadnode-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')
-rw-r--r--test/common/index.js7
-rw-r--r--test/common/report.js43
2 files changed, 50 insertions, 0 deletions
diff --git a/test/common/index.js b/test/common/index.js
index 72ad0c3b77..e7df290c3e 100644
--- a/test/common/index.js
+++ b/test/common/index.js
@@ -632,6 +632,12 @@ function skipIfInspectorDisabled() {
}
}
+function skipIfReportDisabled() {
+ if (!process.config.variables.node_report) {
+ skip('Node Report is disabled');
+ }
+}
+
function skipIf32Bits() {
if (bits < 64) {
skip('The tested feature is not available in 32bit builds');
@@ -758,6 +764,7 @@ module.exports = {
skipIf32Bits,
skipIfEslintMissing,
skipIfInspectorDisabled,
+ skipIfReportDisabled,
skipIfWorker,
get localhostIPv6() { return '::1'; },
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));
+ });
+};