|
| 1 | +/* eslint-disable node-core/required-modules */ |
1 | 2 | 'use strict';
|
2 |
| -require('../common'); |
3 | 3 | const assert = require('assert');
|
4 | 4 | const fs = require('fs');
|
5 | 5 | const path = require('path');
|
6 | 6 |
|
7 |
| -const REPORT_SECTIONS = [ 'header', |
8 |
| - 'javascriptStack', |
9 |
| - 'nativeStack', |
10 |
| - 'javascriptHeap', |
11 |
| - 'libuv', |
12 |
| - 'environmentVariables', |
13 |
| - 'sharedObjects' ]; |
14 |
| - |
15 |
| -let tmppath = ''; |
16 |
| - |
17 |
| -exports.findReports = (pid, path) => { |
| 7 | +function findReports(pid, dir) { |
18 | 8 | // Default filenames are of the form
|
19 | 9 | // report.<date>.<time>.<pid>.<seq>.json
|
20 |
| - tmppath = path; |
21 | 10 | const format = '^report\\.\\d+\\.\\d+\\.' + pid + '\\.\\d+\\.json$';
|
22 | 11 | const filePattern = new RegExp(format);
|
23 |
| - const files = fs.readdirSync(path); |
24 |
| - return files.filter((file) => filePattern.test(file)); |
25 |
| -}; |
26 |
| - |
27 |
| -exports.validate = (report, options) => { |
28 |
| - const jtmp = path.join(tmppath, report); |
29 |
| - fs.readFile(jtmp, (err, data) => { |
30 |
| - this.validateContent(data, options); |
| 12 | + const files = fs.readdirSync(dir); |
| 13 | + const results = []; |
| 14 | + |
| 15 | + files.forEach((file) => { |
| 16 | + if (filePattern.test(file)) |
| 17 | + results.push(path.join(dir, file)); |
31 | 18 | });
|
32 |
| -}; |
33 | 19 |
|
| 20 | + return results; |
| 21 | +} |
34 | 22 |
|
35 |
| -exports.validateContent = function validateContent(data, options) { |
| 23 | +function validate(report) { |
| 24 | + const data = fs.readFileSync(report, 'utf8'); |
| 25 | + |
| 26 | + validateContent(data); |
| 27 | +} |
| 28 | + |
| 29 | +function validateContent(data) { |
36 | 30 | const report = JSON.parse(data);
|
37 |
| - const comp = Object.keys(report); |
38 | 31 |
|
39 |
| - // Check all sections are present |
40 |
| - REPORT_SECTIONS.forEach((section) => { |
41 |
| - assert.ok(comp.includes(section)); |
| 32 | + // Verify that all sections are present. |
| 33 | + ['header', 'javascriptStack', 'nativeStack', 'javascriptHeap', |
| 34 | + 'libuv', 'environmentVariables', 'sharedObjects'].forEach((section) => { |
| 35 | + assert(report.hasOwnProperty(section)); |
42 | 36 | });
|
43 |
| -}; |
| 37 | +} |
| 38 | + |
| 39 | +module.exports = { findReports, validate, validateContent }; |
0 commit comments