-
Notifications
You must be signed in to change notification settings - Fork 29.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: refactor test/common/report.js
- Don't unnecessarily require('../common'). - Eliminate state maintained in tmppath. - validate() was being used synchronously, but was actually asynchronous. Make it synchronous. - Other misc. drive by cleanup. PR-URL: #25754 Reviewed-By: Richard Lau <[email protected]> Reviewed-By: Anto Aravinth <[email protected]> Reviewed-By: Gireesh Punathil <[email protected]>
- Loading branch information
Showing
1 changed file
with
24 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,39 @@ | ||
/* eslint-disable node-core/required-modules */ | ||
'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) => { | ||
function findReports(pid, dir) { | ||
// 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); | ||
const files = fs.readdirSync(dir); | ||
const results = []; | ||
|
||
files.forEach((file) => { | ||
if (filePattern.test(file)) | ||
results.push(path.join(dir, file)); | ||
}); | ||
}; | ||
|
||
return results; | ||
} | ||
|
||
exports.validateContent = function validateContent(data, options) { | ||
function validate(report) { | ||
const data = fs.readFileSync(report, 'utf8'); | ||
|
||
validateContent(data); | ||
} | ||
|
||
function validateContent(data) { | ||
const report = JSON.parse(data); | ||
const comp = Object.keys(report); | ||
|
||
// Check all sections are present | ||
REPORT_SECTIONS.forEach((section) => { | ||
assert.ok(comp.includes(section)); | ||
// Verify that all sections are present. | ||
['header', 'javascriptStack', 'nativeStack', 'javascriptHeap', | ||
'libuv', 'environmentVariables', 'sharedObjects'].forEach((section) => { | ||
assert(report.hasOwnProperty(section)); | ||
}); | ||
}; | ||
} | ||
|
||
module.exports = { findReports, validate, validateContent }; |