Skip to content
This repository was archived by the owner on Jun 18, 2021. It is now read-only.

Commit 132bc9e

Browse files
committed
Fix version reporting in NodeReport section
Report the versions of Node.js and its components based on the runtime and not compile time constants. Extend the tests to validate the versions reported in the report. Fixes: #29
1 parent 95a046e commit 132bc9e

File tree

2 files changed

+43
-14
lines changed

2 files changed

+43
-14
lines changed

src/node_report.cc

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
#include "node_report.h"
2-
#include "node_version.h"
32
#include "v8.h"
43
#include "time.h"
5-
#include "zlib.h"
6-
#include "ares.h"
74

85
#include <fcntl.h>
96
#include <string.h>
@@ -52,7 +49,7 @@ using v8::String;
5249
using v8::V8;
5350

5451
// Internal/static function declarations
55-
static void PrintVersionInformation(FILE* fp);
52+
static void PrintVersionInformation(FILE* fp, Isolate* isolate);
5653
static void PrintJavaScriptStack(FILE* fp, Isolate* isolate, DumpEvent event, const char* location);
5754
static void PrintStackFromStackTrace(FILE* fp, Isolate* isolate, DumpEvent event);
5855
static void PrintStackFrame(FILE* fp, Isolate* isolate, Local<StackFrame> frame, int index, void* pc);
@@ -317,7 +314,7 @@ void TriggerNodeReport(Isolate* isolate, DumpEvent event, const char* message, c
317314
fflush(fp);
318315

319316
// Print Node.js and OS version information
320-
PrintVersionInformation(fp);
317+
PrintVersionInformation(fp, isolate);
321318
fflush(fp);
322319

323320
// Print summary JavaScript stack backtrace
@@ -369,12 +366,28 @@ void TriggerNodeReport(Isolate* isolate, DumpEvent event, const char* message, c
369366
* Function to print Node.js version, OS version and machine information
370367
*
371368
******************************************************************************/
372-
static void PrintVersionInformation(FILE* fp) {
369+
static void PrintVersionInformation(FILE* fp, Isolate* isolate) {
373370

374371
// Print Node.js and deps component versions
375-
fprintf(fp, "\nNode.js version: %s\n", NODE_VERSION);
376-
fprintf(fp, "(v8: %s, libuv: %s, zlib: %s, ares: %s)\n",
377-
V8::GetVersion(), uv_version_string(), ZLIB_VERSION, ARES_VERSION_STR);
372+
fprintf(fp, "\nprocess.versions = {\n");
373+
{
374+
Nan::MaybeLocal<Value> process = Nan::Get(
375+
isolate->GetCurrentContext()->Global(),
376+
Nan::New<String>("process").ToLocalChecked());
377+
Local<Value> versions = Nan::Get(process.ToLocalChecked().As<Object>(),
378+
Nan::New<String>("versions").ToLocalChecked()).ToLocalChecked();
379+
Local<Object> versionsObj = versions.As<Object>();
380+
Local<v8::Array> keys = Nan::GetOwnPropertyNames(versionsObj)
381+
.ToLocalChecked();
382+
for (uint32_t i=0, nKeys = (*keys)->Length(); i<nKeys; i++) {
383+
Local<Value> keyVal = Nan::Get(keys.As<Object>(), i).ToLocalChecked();
384+
Local<Value> valVal = Nan::Get(versionsObj, keyVal).ToLocalChecked();
385+
Nan::Utf8String name(keyVal);
386+
Nan::Utf8String version(valVal);
387+
fprintf(fp, " %s: %s\n", *name, *version);
388+
}
389+
}
390+
fprintf(fp, "}\n");
378391

379392
// Print operating system and machine information (Windows)
380393
#ifdef _WIN32

test/common.js

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ const REPORT_SECTIONS = [
99
'System Information'
1010
];
1111

12+
const reNewline = '(?:\\r*\\n)'
13+
1214
exports.findReports = (pid) => {
1315
// Default filenames are of the form NodeReport.<date>.<time>.<pid>.<seq>.txt
1416
const format = '^NodeReport\\.\\d+\\.\\d+\\.' + pid + '\\.\\d+\\.txt$';
@@ -29,16 +31,30 @@ exports.validate = (t, report, pid) => {
2931
t.test('Validating ' + report, (t) => {
3032
fs.readFile(report, (err, data) => {
3133
const reportContents = data.toString();
32-
const plan = REPORT_SECTIONS.length + (pid ? 1 : 0);
34+
const nodeComponents = Object.keys(process.versions);
35+
const plan = REPORT_SECTIONS.length + (pid ? 1 : 0)
36+
+ nodeComponents.length;
3337
t.plan(plan);
34-
if (pid) {
35-
t.match(reportContents, new RegExp('Process ID: ' + pid),
36-
'Checking report contains expected process ID ' + pid);
37-
}
3838
REPORT_SECTIONS.forEach((section) => {
3939
t.match(reportContents, new RegExp('==== ' + section),
4040
'Checking report contains ' + section + ' section');
4141
});
42+
const nodeReportSection = getSection(reportContents, 'NodeReport');
43+
if (pid) {
44+
t.match(nodeReportSection, new RegExp('Process ID: ' + pid),
45+
'NodeReport section contains expected process ID');
46+
}
47+
nodeComponents.forEach((c) => {
48+
t.match(nodeReportSection, new RegExp(c + ': ' + process.versions[c]),
49+
'NodeReport section contains expected ' + c + ' version');
50+
});
4251
});
4352
});
4453
};
54+
55+
const getSection = (report, section) => {
56+
const re = new RegExp('==== ' + section + ' =+' + reNewline + '+([\\S\\s]+?)'
57+
+ reNewline + '+={80}' + reNewline);
58+
const match = re.exec(report);
59+
return match ? match[1] : '';
60+
};

0 commit comments

Comments
 (0)