Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: refactor test/common/report.js #25754

Merged
merged 1 commit into from
Jan 30, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 24 additions & 28 deletions test/common/report.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,39 @@
/* eslint-disable node-core/required-modules */
'use strict';
require('../common');
gireeshpunathil marked this conversation as resolved.
Show resolved Hide resolved
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 };