From 111ab4af3484663c7c37fec2b142dda374547786 Mon Sep 17 00:00:00 2001 From: Richard Lau Date: Fri, 17 Feb 2017 15:08:28 -0500 Subject: [PATCH] test: Move OS version tests to common.js --- test/common.js | 28 +++++++++++++++++++++++++++- test/test-os-version.js | 34 ---------------------------------- 2 files changed, 27 insertions(+), 35 deletions(-) delete mode 100644 test/test-os-version.js diff --git a/test/common.js b/test/common.js index ed1a67a..a0535c4 100644 --- a/test/common.js +++ b/test/common.js @@ -1,6 +1,15 @@ 'use strict'; const fs = require('fs'); +const os = require('os'); + +const osMap = { + 'aix': 'AIX', + 'darwin': 'Darwin', + 'linux': 'Linux', + 'sunos': 'SunOS', + 'win32': 'Windows', +}; const REPORT_SECTIONS = [ 'Node Report', @@ -48,7 +57,7 @@ exports.validateContent = function validateContent(data, t, options) { const expectedVersions = options ? options.expectedVersions || nodeComponents : nodeComponents; - var plan = REPORT_SECTIONS.length + nodeComponents.length + 4; + var plan = REPORT_SECTIONS.length + nodeComponents.length + 5; if (options.commandline) plan++; t.plan(plan); // Check all sections are present @@ -115,6 +124,23 @@ exports.validateContent = function validateContent(data, t, options) { 'Checking machine name in report header section contains os.hostname()'); } + const osName = osMap[os.platform()]; + const osVersion = nodeReportSection.match(/OS version: .*(?:\r*\n)/); + if (this.isWindows()) { + t.match(osVersion, + new RegExp('OS version: ' + osName), 'Checking OS version'); + } else if (this.isAIX() && !os.release().includes('.')) { + // For Node.js prior to os.release() fix for AIX: + // https://github.com/nodejs/node/pull/10245 + t.match(osVersion, + new RegExp('OS version: ' + osName + ' \\d+.' + os.release()), + 'Checking OS version'); + } else { + t.match(osVersion, + new RegExp('OS version: ' + osName + ' .*' + os.release()), + 'Checking OS version'); + } + // Check report System Information section const sysInfoSection = getSection(reportContents, 'System Information'); // Find a line which ends with "/api.node" or "\api.node" (Unix or diff --git a/test/test-os-version.js b/test/test-os-version.js deleted file mode 100644 index 9e96019..0000000 --- a/test/test-os-version.js +++ /dev/null @@ -1,34 +0,0 @@ -'use strict'; - -// Testcase for validating reported OS version - -const common = require('./common.js'); -const nodereport = require('../'); -const os = require('os'); -const tap = require('tap'); - -const os_map = { - 'aix': 'AIX', - 'darwin': 'Darwin', - 'linux': 'Linux', - 'win32': 'Windows', - 'sunos': 'SunOS', -}; -const os_name = os_map[os.platform()]; -const report_str = nodereport.getReport(); -const version_str = report_str.match(/OS version: .*(?:\r*\n)/); -if (common.isWindows()) { - tap.match(version_str, - new RegExp('OS version: ' + os_name), 'Checking OS version'); -} else if (common.isAIX() && !os.release().includes('.')) { - // For Node.js prior to os.release() fix for AIX: - // https://github.com/nodejs/node/pull/10245 - tap.match(version_str, - new RegExp('OS version: ' + os_name + ' \\d+.' + os.release()), - 'Checking OS version'); -} else { - tap.match(version_str, - new RegExp('OS version: ' + os_name + ' .*' + os.release()), - 'Checking OS version'); -} -