From 6d0b764f2341b94ad772bbab4be8b419c52151ec Mon Sep 17 00:00:00 2001 From: CrispusDH Date: Tue, 13 Nov 2018 13:01:44 +0200 Subject: [PATCH 01/20] move test_util out of q, rework due to es6 --- scripts/test.js | 4 +- scripts/test/test_util.js | 216 +++++++++++++++++++------------------- spec/.jshintrc | 2 + 3 files changed, 113 insertions(+), 109 deletions(-) diff --git a/scripts/test.js b/scripts/test.js index f80742151..5098ba489 100755 --- a/scripts/test.js +++ b/scripts/test.js @@ -154,7 +154,7 @@ passingTests.forEach(function(passing_test) { // If we're running on CircleCI, save stdout and stderr from the test run to a log file. if (process.env['CIRCLE_ARTIFACTS']) { - executor.execute(path.join(process.env['CIRCLE_ARTIFACTS'], 'test_log.txt')); + executor.execute(path.join(process.env['CIRCLE_ARTIFACTS'], 'test_log.txt')).then(); } else { - executor.execute(); + executor.execute().then(); } diff --git a/scripts/test/test_util.js b/scripts/test/test_util.js index a608c1e5f..6dd1e2c67 100644 --- a/scripts/test/test_util.js +++ b/scripts/test/test_util.js @@ -1,41 +1,43 @@ #!/usr/bin/env node -var child_process = require('child_process'), - q = require('q'), - fs = require('fs'); - -var CommandlineTest = function(command) { - var self = this; - this.command_ = command; - this.expectedExitCode_ = 0; - this.expectedErrors_ = []; - this.assertExitCodeOnly_ = false; - this.testLogStream = undefined; +const child_process = require('child_process'); + +class CommandlineTest { + constructor(command) { + this.command = command; + this.expectedExitCode = 0; + this.expectedErrors = []; + this.isExitCode = false; + this.testLogStream = undefined; + this.expectedMinTestDuration = undefined; + this.expectedMaxTestDuration = undefined; + } + // Only assert the exit code and not failures. // This must be true if the command you're running does not support // the flag '--resultJsonOutputFile'. - this.assertExitCodeOnly = function() { - self.assertExitCodeOnly_ = true; - return self; - }; + assertExitCodeOnly() { + this.isExitCode = true; + return this; + } - this.setTestLogFile = function(filename) { - self.testLogStream = fs.createWriteStream(filename, {flags: 'a'}); - }; + setTestLogFile(filename) { + this.testLogStream = fs.createWriteStream(filename, {flags: 'a'}); + } // Set the expected exit code for the test command. - this.expectExitCode = function(exitCode) { - self.expectedExitCode_ = exitCode; - return self; - }; + expectExitCode(exitCode) { + this.expectedExitCode = exitCode; + return this; + } // Set the expected total test duration in milliseconds. - this.expectTestDuration = function(min, max) { - self.expectedMinTestDuration_ = min; - self.expectedMaxTestDuration_ = max; - return self; - }; + expectTestDuration(min, max) { + this.expectedMinTestDuration = min; + this.expectedMaxTestDuration = max; + return this; + } /** * Add expected error(s) for the test command. @@ -45,102 +47,102 @@ var CommandlineTest = function(command) { * stackTrace: string, //optional regex * } */ - this.expectErrors = function(expectedErrors) { + expectErrors(expectedErrors) { if (expectedErrors instanceof Array) { - self.expectedErrors_ = self.expectedErrors_.concat(expectedErrors); + this.expectedErrors = this.expectedErrors.concat(expectedErrors); } else { - self.expectedErrors_.push(expectedErrors); + this.expectedErrors.push(expectedErrors); } - return self; - }; + return this; + } - this.run = function() { - var start = new Date().getTime(); - var testOutputPath = 'test_output_' + start + '.tmp'; - var output = ''; + async run() { + const start = new Date().getTime(); + const testOutputPath = `test_output_${start}.tmp`; + let output = ''; - var flushAndFail = function(errorMsg) { + const flushAndFail = (errorMsg) => { process.stdout.write(output); throw new Error(errorMsg); }; - return q.promise(function(resolve, reject) { - if (!self.assertExitCodeOnly_) { - self.command_ = self.command_ + ' --resultJsonOutputFile ' + testOutputPath; + return new Promise((resolve, reject) => { + if (!this.isExitCode) { + this.command = this.command + ' --resultJsonOutputFile ' + testOutputPath; } - var args = self.command_.split(/\s/); - - var test_process; + let args = this.command.split(/\s/); + let test_process; test_process = child_process.spawn(args[0], args.slice(1)); - var processData = function(data) { + const processData = (data) => { process.stdout.write('.'); output += data; - if (self.testLogStream) { - self.testLogStream.write(data); + if (this.testLogStream) { + this.testLogStream.write(data); } }; test_process.stdout.on('data', processData); test_process.stderr.on('data', processData); - test_process.on('error', function(err) { + test_process.on('error', (err) => { reject(err); }); - test_process.on('exit', function(exitCode) { + test_process.on('exit', (exitCode) => { resolve(exitCode); }); - }).then(function(exitCode) { - if (self.expectedExitCode_ !== exitCode) { - flushAndFail('expecting exit code: ' + self.expectedExitCode_ + - ', actual: ' + exitCode); + }).then((exitCode) => { + if (this.expectedExitCode !== exitCode) { + flushAndFail('expecting exit code: ' + this.expectedExitCode + + ', actual: ' + exitCode); } - if (self.testLogStream) { - self.testLogStream.end(); + if (this.testLogStream) { + this.testLogStream.end(); } // Skip the rest if we are only verify exit code. // Note: we're expecting a file populated by '--resultJsonOutputFile' after // this point. - if (self.assertExitCodeOnly_) { + if (this.isExitCode) { return; } - var raw_data = fs.readFileSync(testOutputPath); - var testOutput = JSON.parse(raw_data); + const raw_data = fs.readFileSync(testOutputPath); + const testOutput = JSON.parse(raw_data); - var actualErrors = []; - var duration = 0; - testOutput.forEach(function(specResult) { + let actualErrors = []; + let duration = 0; + testOutput.forEach((specResult) => { duration += specResult.duration; - specResult.assertions.forEach(function(assertion) { + specResult.assertions.forEach((assertion) => { if (!assertion.passed) { actualErrors.push(assertion); } }); }); - self.expectedErrors_.forEach(function(expectedError) { - var found = false; - for (var i = 0; i < actualErrors.length; ++i) { - var actualError = actualErrors[i]; + this.expectedErrors.forEach((expectedError) => { + let found = false; + let i; + for (i = 0; i < actualErrors.length; ++i) { + const actualError = actualErrors[i]; // if expected message is defined and messages don't match if (expectedError.message) { if (!actualError.errorMsg || - !actualError.errorMsg.match(new RegExp(expectedError.message))) { - continue; - } + !actualError.errorMsg.match(new RegExp(expectedError.message))) { + continue; + } } // if expected stackTrace is defined and stackTraces don't match if (expectedError.stackTrace) { if (!actualError.stackTrace || - !actualError.stackTrace.match(new RegExp(expectedError.stackTrace))) { - continue; - } + !actualError.stackTrace.match(new RegExp(expectedError.stackTrace))) { + continue; + } } found = true; break; @@ -167,25 +169,21 @@ var CommandlineTest = function(command) { flushAndFail('failed with ' + actualErrors.length + ' unexpected failures'); } - if (self.expectedMinTestDuration_ - && duration < self.expectedMinTestDuration_) { - flushAndFail('expecting test min duration: ' + - self.expectedMinTestDuration_ + ', actual: ' + duration); + if (this.expectedMinTestDuration && duration < this.expectedMinTestDuration) { + flushAndFail('expecting test min duration: ' + this.expectedMinTestDuration + ', actual: ' + duration); } - if (self.expectedMaxTestDuration_ - && duration > self.expectedMaxTestDuration_) { - flushAndFail('expecting test max duration: ' + - self.expectedMaxTestDuration_ + ', actual: ' + duration); + if (this.expectedMaxTestDuration && duration > this.expectedMaxTestDuration) { + flushAndFail('expecting test max duration: ' + this.expectedMaxTestDuration + ', actual: ' + duration); } - }).fin(function() { + }).finally(() => { try { fs.unlinkSync(testOutputPath); } catch (err) { // don't do anything } }); - }; -}; + } +} /** * Util for running tests and testing functionalities including: @@ -194,35 +192,39 @@ var CommandlineTest = function(command) { * the flag '--resultJsonOutputFile', unless only exitCode is being tested. * For now, this means protractor tests (jasmine/mocha). */ -exports.Executor = function() { - var tests = []; - this.addCommandlineTest = function(command) { - var test = new CommandlineTest(command); - tests.push(test); +module.exports = class Executor { + constructor() { + this.tests = []; + } + + addCommandlineTest(command) { + const test = new CommandlineTest(command); + this.tests.push(test); return test; - }; + } - this.execute = function(logFile) { - var failed = false; + async execute(logFile) { + let failed = false; + const number = parseInt('033', 8); - (function runTests(i) { - if (i < tests.length) { - console.log('running: ' + tests[i].command_); + for (let test of this.tests) { + try { + console.log('running: ' + test.command); if (logFile) { - tests[i].setTestLogFile(logFile); + test.setTestLogFile(logFile); } - tests[i].run().then(function() { - console.log('\n>>> \033[1;32mpass\033[0m'); - }, function(err) { - failed = true; - console.log('\n>>> \033[1;31mfail: ' + err.toString() + '\033[0m'); - }).fin(function() { - runTests(i + 1); - }).done(); - } else { - console.log('Summary: ' + (failed ? 'fail' : 'pass')); - process.exit(failed ? 1 : 0); + await test.run(); + // Octal literals are not allowed in strict mode + //console.log('\n>>> \033[1;32mpass\033[0m'); + } catch (error) { + failed = true; + // Octal literals are not allowed in strict mode + // console.log('\n>>> \033[1;31mfail: ' + err.toString() + '\033[0m'); } - }(0)); - }; + + } + + console.log('Summary: ' + (failed ? 'fail' : 'pass')); + process.exit(failed ? 1 : 0); + } }; diff --git a/spec/.jshintrc b/spec/.jshintrc index dea6d2210..b8b730f77 100644 --- a/spec/.jshintrc +++ b/spec/.jshintrc @@ -1,4 +1,6 @@ { + "strict": false, + "esversion": 6, "predef": [ "protractor", "browser", From e31c814880fa6030aba309a56b506024cc46bf95 Mon Sep 17 00:00:00 2001 From: CrispusDH Date: Tue, 13 Nov 2018 13:08:37 +0200 Subject: [PATCH 02/20] fix test.js --- scripts/test.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/scripts/test.js b/scripts/test.js index 5098ba489..8941532c4 100755 --- a/scripts/test.js +++ b/scripts/test.js @@ -1,9 +1,9 @@ #!/usr/bin/env node -var path = require('path'); +const path = require('path'); -var Executor = require('./test/test_util').Executor; +const Executor = require('./test/test_util'); -var passingTests = [ +const passingTests = [ 'node built/cli.js spec/basicConf.js', // 'node built/cli.js spec/basicConf.js --useBlockingProxy', 'node built/cli.js spec/multiConf.js', @@ -57,9 +57,9 @@ var passingTests = [ // 'node spec/install/test.js' ]; -var executor = new Executor(); +const executor = new Executor(); -passingTests.forEach(function(passing_test) { +passingTests.forEach((passing_test) => { executor.addCommandlineTest(passing_test) .assertExitCodeOnly(); }); From 3b1b80007bcfa0e5a33556bd1f5e8a34eb3c7e65 Mon Sep 17 00:00:00 2001 From: CrispusDH Date: Tue, 13 Nov 2018 14:20:24 +0200 Subject: [PATCH 03/20] check failed test --- scripts/test/test_util.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/test/test_util.js b/scripts/test/test_util.js index 6dd1e2c67..03ad0b724 100644 --- a/scripts/test/test_util.js +++ b/scripts/test/test_util.js @@ -205,7 +205,6 @@ module.exports = class Executor { async execute(logFile) { let failed = false; - const number = parseInt('033', 8); for (let test of this.tests) { try { @@ -214,10 +213,12 @@ module.exports = class Executor { test.setTestLogFile(logFile); } await test.run(); + console.log('test was passed\n'); // Octal literals are not allowed in strict mode //console.log('\n>>> \033[1;32mpass\033[0m'); } catch (error) { failed = true; + console.log('test was failed\n'); // Octal literals are not allowed in strict mode // console.log('\n>>> \033[1;31mfail: ' + err.toString() + '\033[0m'); } From de450e48b2335cac2f91fc3c06f1945805e5c0a1 Mon Sep 17 00:00:00 2001 From: CrispusDH Date: Tue, 13 Nov 2018 14:29:59 +0200 Subject: [PATCH 04/20] check error --- scripts/test/test_util.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/scripts/test/test_util.js b/scripts/test/test_util.js index 03ad0b724..20e39486b 100644 --- a/scripts/test/test_util.js +++ b/scripts/test/test_util.js @@ -218,11 +218,10 @@ module.exports = class Executor { //console.log('\n>>> \033[1;32mpass\033[0m'); } catch (error) { failed = true; - console.log('test was failed\n'); + console.log(`test was failed. Error: ${error}\n`); // Octal literals are not allowed in strict mode // console.log('\n>>> \033[1;31mfail: ' + err.toString() + '\033[0m'); } - } console.log('Summary: ' + (failed ? 'fail' : 'pass')); From 7a67614b18a3ee8581736a4ca8f9f4799ccc2f8a Mon Sep 17 00:00:00 2001 From: CrispusDH Date: Tue, 13 Nov 2018 14:56:20 +0200 Subject: [PATCH 05/20] chnage node version to LTS for CircleCI --- circle.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/circle.yml b/circle.yml index 75bdc46a4..2c6f40bcd 100644 --- a/circle.yml +++ b/circle.yml @@ -2,7 +2,7 @@ version: 2 jobs: build: docker: - - image: circleci/node:8.11-browsers + - image: circleci/node:10.13.0-browsers environment: # Fix issue with selenium-server in containers. # See http://github.com/SeleniumHQ/docker-selenium/issues/87 From f7b16e435c7cc068c58a3a29f4e8a77d88234e29 Mon Sep 17 00:00:00 2001 From: CrispusDH Date: Wed, 14 Nov 2018 22:21:00 +0200 Subject: [PATCH 06/20] return the octal literals as is --- scripts/test/test_util.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/scripts/test/test_util.js b/scripts/test/test_util.js index 20e39486b..871ac44f8 100644 --- a/scripts/test/test_util.js +++ b/scripts/test/test_util.js @@ -213,14 +213,10 @@ module.exports = class Executor { test.setTestLogFile(logFile); } await test.run(); - console.log('test was passed\n'); - // Octal literals are not allowed in strict mode - //console.log('\n>>> \033[1;32mpass\033[0m'); + console.log('\n>>> \033[1;32mpass\033[0m'); } catch (error) { failed = true; - console.log(`test was failed. Error: ${error}\n`); - // Octal literals are not allowed in strict mode - // console.log('\n>>> \033[1;31mfail: ' + err.toString() + '\033[0m'); + console.log('\n>>> \033[1;31mfail: ' + err.toString() + '\033[0m'); } } From ca8df536b81c9e8e7f9bb14c79f5863f3793b465 Mon Sep 17 00:00:00 2001 From: CrispusDH Date: Sat, 17 Nov 2018 10:48:46 +0200 Subject: [PATCH 07/20] fix octal --- scripts/test/test_util.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/test/test_util.js b/scripts/test/test_util.js index 871ac44f8..2175c9c51 100644 --- a/scripts/test/test_util.js +++ b/scripts/test/test_util.js @@ -213,10 +213,10 @@ module.exports = class Executor { test.setTestLogFile(logFile); } await test.run(); - console.log('\n>>> \033[1;32mpass\033[0m'); + console.log('\n>>> \\033[1;32mpass\\033[0m'); } catch (error) { failed = true; - console.log('\n>>> \033[1;31mfail: ' + err.toString() + '\033[0m'); + console.log('\n>>> \\033[1;31mfail: ' + err.toString() + '\\033[0m'); } } From 7880060eade82810484a163615642431aa1eeb23 Mon Sep 17 00:00:00 2001 From: CrispusDH Date: Sat, 17 Nov 2018 10:59:57 +0200 Subject: [PATCH 08/20] try to fix octal v1 --- scripts/test/test_util.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/test/test_util.js b/scripts/test/test_util.js index 2175c9c51..20270e38f 100644 --- a/scripts/test/test_util.js +++ b/scripts/test/test_util.js @@ -213,10 +213,10 @@ module.exports = class Executor { test.setTestLogFile(logFile); } await test.run(); - console.log('\n>>> \\033[1;32mpass\\033[0m'); + console.log('\n>>> \0o33[1;32mpass\0o33[0m'); } catch (error) { failed = true; - console.log('\n>>> \\033[1;31mfail: ' + err.toString() + '\\033[0m'); + console.log('\n>>> \0o33[1;31mfail: ' + err.toString() + '\0o33[0m'); } } From 4b5ee4c21ba737c6d1d2bb98d995633f69c5a761 Mon Sep 17 00:00:00 2001 From: Craig Nishina Date: Tue, 27 Nov 2018 10:18:27 -0800 Subject: [PATCH 09/20] change back to 8.11 --- circle.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/circle.yml b/circle.yml index 329a19c9d..4ddd78bda 100644 --- a/circle.yml +++ b/circle.yml @@ -2,7 +2,7 @@ version: 2 jobs: build: docker: - - image: circleci/node:10.13.0-browsers + - image: circleci/node:8.11-browsers environment: # Fix issue with selenium-server in containers. # See http://github.com/SeleniumHQ/docker-selenium/issues/87 From aa8340198b94b8dd0e148266e0eaadad55a5b2b0 Mon Sep 17 00:00:00 2001 From: CrispusDH Date: Tue, 27 Nov 2018 20:26:43 +0200 Subject: [PATCH 10/20] fix after auto merge --- scripts/test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/test.js b/scripts/test.js index b1faf2dd7..7a07f8e87 100755 --- a/scripts/test.js +++ b/scripts/test.js @@ -1,7 +1,7 @@ #!/usr/bin/env node const path = require('path'); -const Executor = require('./test/test_util').Executor; +const Executor = require('./test/test_util'); const passingTests = [ 'node built/cli.js spec/basicConf.js', From b1f04d4301ed448ee4d79a948ee967354241e4c0 Mon Sep 17 00:00:00 2001 From: CrispusDH Date: Tue, 27 Nov 2018 21:29:46 +0200 Subject: [PATCH 11/20] fix typo err -> error --- scripts/test/test_util.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/test/test_util.js b/scripts/test/test_util.js index 20270e38f..4f7efedf4 100644 --- a/scripts/test/test_util.js +++ b/scripts/test/test_util.js @@ -216,7 +216,7 @@ module.exports = class Executor { console.log('\n>>> \0o33[1;32mpass\0o33[0m'); } catch (error) { failed = true; - console.log('\n>>> \0o33[1;31mfail: ' + err.toString() + '\0o33[0m'); + console.log('\n>>> \0o33[1;31mfail: ' + error.toString() + '\0o33[0m'); } } From 78642f53e4c829ed6ca712c3e0a7752ffc6045b0 Mon Sep 17 00:00:00 2001 From: CrispusDH Date: Tue, 27 Nov 2018 22:23:46 +0200 Subject: [PATCH 12/20] rework Promise((resolve, reject)) structure --- scripts/test/test_util.js | 83 +++++++++++++++++++-------------------- 1 file changed, 40 insertions(+), 43 deletions(-) diff --git a/scripts/test/test_util.js b/scripts/test/test_util.js index 4f7efedf4..66a9786ab 100644 --- a/scripts/test/test_util.js +++ b/scripts/test/test_util.js @@ -60,56 +60,53 @@ class CommandlineTest { const start = new Date().getTime(); const testOutputPath = `test_output_${start}.tmp`; let output = ''; + let exitCode = 'exitCode is not define'; const flushAndFail = (errorMsg) => { process.stdout.write(output); throw new Error(errorMsg); }; - return new Promise((resolve, reject) => { - if (!this.isExitCode) { - this.command = this.command + ' --resultJsonOutputFile ' + testOutputPath; - } - let args = this.command.split(/\s/); - let test_process; + if (!this.isExitCode) { + this.command = this.command + ' --resultJsonOutputFile ' + testOutputPath; + } + const args = this.command.split(/\s/); + let test_process; - test_process = child_process.spawn(args[0], args.slice(1)); + test_process = child_process.spawn(args[0], args.slice(1)); - const processData = (data) => { - process.stdout.write('.'); - output += data; - if (this.testLogStream) { - this.testLogStream.write(data); - } - }; + const processData = (data) => { + process.stdout.write('.'); + output += data; + if (this.testLogStream) { + this.testLogStream.write(data); + } + }; - test_process.stdout.on('data', processData); - test_process.stderr.on('data', processData); + test_process.stdout.on('data', processData); + test_process.stderr.on('data', processData); - test_process.on('error', (err) => { - reject(err); - }); + test_process.on('error', (error) => { + exitCode = error; + }); - test_process.on('exit', (exitCode) => { - resolve(exitCode); - }); - }).then((exitCode) => { - if (this.expectedExitCode !== exitCode) { - flushAndFail('expecting exit code: ' + this.expectedExitCode + - ', actual: ' + exitCode); - } + test_process.on('exit', (exit) => { + exitCode = exit; + }); - if (this.testLogStream) { - this.testLogStream.end(); - } + if (this.expectedExitCode !== exitCode) { + flushAndFail('expecting exit code: ' + this.expectedExitCode + + ', actual: ' + exitCode); + } - // Skip the rest if we are only verify exit code. - // Note: we're expecting a file populated by '--resultJsonOutputFile' after - // this point. - if (this.isExitCode) { - return; - } + if (this.testLogStream) { + this.testLogStream.end(); + } + // Skip the rest if we are only verify exit code. + // Note: we're expecting a file populated by '--resultJsonOutputFile' after + // this point. + if (!this.isExitCode) { const raw_data = fs.readFileSync(testOutputPath); const testOutput = JSON.parse(raw_data); @@ -175,13 +172,13 @@ class CommandlineTest { if (this.expectedMaxTestDuration && duration > this.expectedMaxTestDuration) { flushAndFail('expecting test max duration: ' + this.expectedMaxTestDuration + ', actual: ' + duration); } - }).finally(() => { - try { - fs.unlinkSync(testOutputPath); - } catch (err) { - // don't do anything - } - }); + } + + try { + fs.unlinkSync(testOutputPath); + } catch (err) { + // don't do anything + } } } From 225d4181d9ccb4b8500d3468fd886e13a0f4aa7f Mon Sep 17 00:00:00 2001 From: CrispusDH Date: Tue, 27 Nov 2018 22:45:35 +0200 Subject: [PATCH 13/20] we should wait event test_process.on --- scripts/test/test_util.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/scripts/test/test_util.js b/scripts/test/test_util.js index 66a9786ab..6a946863a 100644 --- a/scripts/test/test_util.js +++ b/scripts/test/test_util.js @@ -60,7 +60,6 @@ class CommandlineTest { const start = new Date().getTime(); const testOutputPath = `test_output_${start}.tmp`; let output = ''; - let exitCode = 'exitCode is not define'; const flushAndFail = (errorMsg) => { process.stdout.write(output); @@ -86,13 +85,17 @@ class CommandlineTest { test_process.stdout.on('data', processData); test_process.stderr.on('data', processData); - test_process.on('error', (error) => { - exitCode = error; - }); - - test_process.on('exit', (exit) => { - exitCode = exit; - }); + const runningTestProcess = () => { + return new Promise((resolve, reject) => { + test_process.on('error', (error) => { + reject(error); + }); + test_process.on('exit', (exitCode) => { + resolve(exitCode); + }); + }); + }; + const exitCode = await runningTestProcess(); if (this.expectedExitCode !== exitCode) { flushAndFail('expecting exit code: ' + this.expectedExitCode + From 9953bac6d834a3a3b8df019ea8437826caf49cb3 Mon Sep 17 00:00:00 2001 From: CrispusDH Date: Tue, 27 Nov 2018 22:57:36 +0200 Subject: [PATCH 14/20] return initial octal messages --- scripts/test/test_util.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/test/test_util.js b/scripts/test/test_util.js index 6a946863a..a229cf076 100644 --- a/scripts/test/test_util.js +++ b/scripts/test/test_util.js @@ -213,10 +213,10 @@ module.exports = class Executor { test.setTestLogFile(logFile); } await test.run(); - console.log('\n>>> \0o33[1;32mpass\0o33[0m'); + console.log('\n>>> \033[1;32mpass\033[0m'); } catch (error) { failed = true; - console.log('\n>>> \0o33[1;31mfail: ' + error.toString() + '\0o33[0m'); + console.log('\n>>> \033[1;31mfail: ' + error.toString() + '\033[0m'); } } From 43b517217a96375ca0b8d8876aec34f9bca0adfe Mon Sep 17 00:00:00 2001 From: Craig Nishina Date: Tue, 27 Nov 2018 15:38:40 -0800 Subject: [PATCH 15/20] Update test util to work. --- scripts/test/test_util.js | 161 ++++++++++++++++++++------------------ 1 file changed, 84 insertions(+), 77 deletions(-) diff --git a/scripts/test/test_util.js b/scripts/test/test_util.js index a229cf076..145a63392 100644 --- a/scripts/test/test_util.js +++ b/scripts/test/test_util.js @@ -1,6 +1,7 @@ #!/usr/bin/env node const child_process = require('child_process'); +const fs = require('fs'); class CommandlineTest { constructor(command) { @@ -66,83 +67,83 @@ class CommandlineTest { throw new Error(errorMsg); }; - if (!this.isExitCode) { - this.command = this.command + ' --resultJsonOutputFile ' + testOutputPath; - } - const args = this.command.split(/\s/); - let test_process; - - test_process = child_process.spawn(args[0], args.slice(1)); + try { - const processData = (data) => { - process.stdout.write('.'); - output += data; - if (this.testLogStream) { - this.testLogStream.write(data); - } - }; + let exitCode = await new Promise((resolve, reject) => { + if (!this.assertExitCodeOnly_) { + this.command_ = this.command_ + ' --resultJsonOutputFile ' + testOutputPath; + } + const args = this.command_.split(/\s/); + const test_process = child_process.spawn(args[0], args.slice(1)); + + const processData = (data) => { + process.stdout.write('.'); + output += data; + if (this.testLogStream) { + this.testLogStream.write(data); + } + }; - test_process.stdout.on('data', processData); - test_process.stderr.on('data', processData); + test_process.stdout.on('data', processData); + test_process.stderr.on('data', processData); - const runningTestProcess = () => { - return new Promise((resolve, reject) => { - test_process.on('error', (error) => { - reject(error); + test_process.on('error', (err) => { + reject(err); }); - test_process.on('exit', (exitCode) => { + + test_process.on('exit', function(exitCode) { resolve(exitCode); }); }); - }; - const exitCode = await runningTestProcess(); + + if (this.expectedExitCode_ !== exitCode) { + flushAndFail('expecting exit code: ' + this.expectedExitCode_ + + ', actual: ' + exitCode); + } - if (this.expectedExitCode !== exitCode) { - flushAndFail('expecting exit code: ' + this.expectedExitCode + - ', actual: ' + exitCode); - } + if (this.testLogStream) { + this.testLogStream.end(); + } - if (this.testLogStream) { - this.testLogStream.end(); - } + // Skip the rest if we are only verify exit code. + // Note: we're expecting a file populated by '--resultJsonOutputFile' after + // this point. + if (this.assertExitCodeOnly_) { + return; + } - // Skip the rest if we are only verify exit code. - // Note: we're expecting a file populated by '--resultJsonOutputFile' after - // this point. - if (!this.isExitCode) { const raw_data = fs.readFileSync(testOutputPath); const testOutput = JSON.parse(raw_data); let actualErrors = []; let duration = 0; - testOutput.forEach((specResult) => { + testOutput.forEach(function(specResult) { duration += specResult.duration; - specResult.assertions.forEach((assertion) => { + specResult.assertions.forEach(function(assertion) { if (!assertion.passed) { actualErrors.push(assertion); } }); }); - this.expectedErrors.forEach((expectedError) => { + this.expectedErrors_.forEach((expectedError) => { let found = false; - let i; - for (i = 0; i < actualErrors.length; ++i) { - const actualError = actualErrors[i]; + for (let i = 0; i < actualErrors.length; ++i) { + var actualError = actualErrors[i]; // if expected message is defined and messages don't match if (expectedError.message) { if (!actualError.errorMsg || - !actualError.errorMsg.match(new RegExp(expectedError.message))) { - continue; - } + !actualError.errorMsg.match(new RegExp(expectedError.message))) { + continue; + } } // if expected stackTrace is defined and stackTraces don't match if (expectedError.stackTrace) { if (!actualError.stackTrace || - !actualError.stackTrace.match(new RegExp(expectedError.stackTrace))) { - continue; - } + !actualError.stackTrace.match(new RegExp(expectedError.stackTrace))) { + continue; + } } found = true; break; @@ -169,18 +170,22 @@ class CommandlineTest { flushAndFail('failed with ' + actualErrors.length + ' unexpected failures'); } - if (this.expectedMinTestDuration && duration < this.expectedMinTestDuration) { - flushAndFail('expecting test min duration: ' + this.expectedMinTestDuration + ', actual: ' + duration); + if (this.expectedMinTestDuration_ + && duration < this.expectedMinTestDuration_) { + flushAndFail('expecting test min duration: ' + + this.expectedMinTestDuration_ + ', actual: ' + duration); } - if (this.expectedMaxTestDuration && duration > this.expectedMaxTestDuration) { - flushAndFail('expecting test max duration: ' + this.expectedMaxTestDuration + ', actual: ' + duration); + if (this.expectedMaxTestDuration_ + && duration > this.expectedMaxTestDuration_) { + flushAndFail('expecting test max duration: ' + + this.expectedMaxTestDuration_ + ', actual: ' + duration); + } + } finally { + try { + fs.unlinkSync(testOutputPath); + } catch (err) { + // don't do anything } - } - - try { - fs.unlinkSync(testOutputPath); - } catch (err) { - // don't do anything } } } @@ -192,35 +197,37 @@ class CommandlineTest { * the flag '--resultJsonOutputFile', unless only exitCode is being tested. * For now, this means protractor tests (jasmine/mocha). */ -module.exports = class Executor { - constructor() { - this.tests = []; - } - - addCommandlineTest(command) { - const test = new CommandlineTest(command); - this.tests.push(test); +exports.Executor = function() { + let tests = []; + this.addCommandlineTest = (command) => { + let test = new CommandlineTest(command); + tests.push(test); return test; - } - - async execute(logFile) { - let failed = false; + }; - for (let test of this.tests) { + this.runTests = async function(i, logFile, failed) { + if (i < tests.length) { try { - console.log('running: ' + test.command); + console.log('running: ' + tests[i].command_); if (logFile) { - test.setTestLogFile(logFile); + tests[i].setTestLogFile(logFile); } - await test.run(); + await tests[i].run(); console.log('\n>>> \033[1;32mpass\033[0m'); - } catch (error) { + } catch (err) { failed = true; - console.log('\n>>> \033[1;31mfail: ' + error.toString() + '\033[0m'); + console.log('\n>>> \033[1;31mfail: ' + err.toString() + '\033[0m'); + } finally { + this.runTests(i + 1, logFile, failed); } + } else { + console.log('Summary: ' + (failed ? 'fail' : 'pass')); + process.exit(failed ? 1 : 0); } + }; - console.log('Summary: ' + (failed ? 'fail' : 'pass')); - process.exit(failed ? 1 : 0); - } + this.execute = (logFile) => { + let failed = false; + this.runTests(0, logFile, failed); + }; }; From 62471dd1499ae7a47d567bfa46f9d27235834cfc Mon Sep 17 00:00:00 2001 From: Craig Nishina Date: Tue, 27 Nov 2018 15:39:45 -0800 Subject: [PATCH 16/20] Add back the Executor import --- scripts/test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/test.js b/scripts/test.js index 7a07f8e87..b1faf2dd7 100755 --- a/scripts/test.js +++ b/scripts/test.js @@ -1,7 +1,7 @@ #!/usr/bin/env node const path = require('path'); -const Executor = require('./test/test_util'); +const Executor = require('./test/test_util').Executor; const passingTests = [ 'node built/cli.js spec/basicConf.js', From c65138e458c8e77674c7b95625bedec75574ed45 Mon Sep 17 00:00:00 2001 From: Craig Nishina Date: Tue, 27 Nov 2018 15:41:54 -0800 Subject: [PATCH 17/20] Remove then statement. --- scripts/test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/test.js b/scripts/test.js index b1faf2dd7..80f9a3074 100755 --- a/scripts/test.js +++ b/scripts/test.js @@ -154,5 +154,5 @@ passingTests.forEach((passing_test) => { if (process.env['CIRCLE_ARTIFACTS']) { executor.execute(path.join(process.env['CIRCLE_ARTIFACTS'], 'test_log.txt')).then(); } else { - executor.execute().then(); + executor.execute(); } From 5d522c91e235abeb26a427a7e2041c9e1f089bb6 Mon Sep 17 00:00:00 2001 From: Craig Nishina Date: Tue, 27 Nov 2018 15:44:32 -0800 Subject: [PATCH 18/20] remove other then statement. --- scripts/test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/test.js b/scripts/test.js index 80f9a3074..acf8f75f5 100755 --- a/scripts/test.js +++ b/scripts/test.js @@ -152,7 +152,7 @@ passingTests.forEach((passing_test) => { // If we're running on CircleCI, save stdout and stderr from the test run to a log file. if (process.env['CIRCLE_ARTIFACTS']) { - executor.execute(path.join(process.env['CIRCLE_ARTIFACTS'], 'test_log.txt')).then(); + executor.execute(path.join(process.env['CIRCLE_ARTIFACTS'], 'test_log.txt')); } else { executor.execute(); } From e76577e3f3482e74418da4996528ec7317bac5b8 Mon Sep 17 00:00:00 2001 From: Craig Nishina Date: Tue, 27 Nov 2018 15:50:50 -0800 Subject: [PATCH 19/20] Remove underscores to match changes --- scripts/test/test_util.js | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/scripts/test/test_util.js b/scripts/test/test_util.js index 145a63392..e4acb6658 100644 --- a/scripts/test/test_util.js +++ b/scripts/test/test_util.js @@ -70,10 +70,10 @@ class CommandlineTest { try { let exitCode = await new Promise((resolve, reject) => { - if (!this.assertExitCodeOnly_) { - this.command_ = this.command_ + ' --resultJsonOutputFile ' + testOutputPath; + if (!this.assertExitCodeOnly) { + this.command = `${this.command} --resultJsonOutputFile ${testOutputPath}`; } - const args = this.command_.split(/\s/); + const args = this.command.split(/\s/); const test_process = child_process.spawn(args[0], args.slice(1)); const processData = (data) => { @@ -97,7 +97,7 @@ class CommandlineTest { }); if (this.expectedExitCode_ !== exitCode) { - flushAndFail('expecting exit code: ' + this.expectedExitCode_ + + flushAndFail('expecting exit code: ' + this.expectedExitCode + ', actual: ' + exitCode); } @@ -108,7 +108,7 @@ class CommandlineTest { // Skip the rest if we are only verify exit code. // Note: we're expecting a file populated by '--resultJsonOutputFile' after // this point. - if (this.assertExitCodeOnly_) { + if (this.assertExitCodeOnly) { return; } @@ -126,7 +126,7 @@ class CommandlineTest { }); }); - this.expectedErrors_.forEach((expectedError) => { + this.expectedErrors.forEach((expectedError) => { let found = false; for (let i = 0; i < actualErrors.length; ++i) { var actualError = actualErrors[i]; @@ -170,15 +170,15 @@ class CommandlineTest { flushAndFail('failed with ' + actualErrors.length + ' unexpected failures'); } - if (this.expectedMinTestDuration_ - && duration < this.expectedMinTestDuration_) { + if (this.expectedMinTestDuration + && duration < this.expectedMinTestDuration) { flushAndFail('expecting test min duration: ' + - this.expectedMinTestDuration_ + ', actual: ' + duration); + this.expectedMinTestDuration + ', actual: ' + duration); } - if (this.expectedMaxTestDuration_ - && duration > this.expectedMaxTestDuration_) { + if (this.expectedMaxTestDuration + && duration > this.expectedMaxTestDuration) { flushAndFail('expecting test max duration: ' + - this.expectedMaxTestDuration_ + ', actual: ' + duration); + this.expectedMaxTestDuration + ', actual: ' + duration); } } finally { try { @@ -208,7 +208,7 @@ exports.Executor = function() { this.runTests = async function(i, logFile, failed) { if (i < tests.length) { try { - console.log('running: ' + tests[i].command_); + console.log('running: ' + tests[i].command); if (logFile) { tests[i].setTestLogFile(logFile); } From 733269dd5af9736f888a5d0c74e34ab7dd51bbc2 Mon Sep 17 00:00:00 2001 From: Craig Nishina Date: Tue, 27 Nov 2018 15:55:42 -0800 Subject: [PATCH 20/20] One last underscore. --- scripts/test/test_util.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/test/test_util.js b/scripts/test/test_util.js index e4acb6658..1bbada24f 100644 --- a/scripts/test/test_util.js +++ b/scripts/test/test_util.js @@ -96,7 +96,7 @@ class CommandlineTest { }); }); - if (this.expectedExitCode_ !== exitCode) { + if (this.expectedExitCode !== exitCode) { flushAndFail('expecting exit code: ' + this.expectedExitCode + ', actual: ' + exitCode); }