From 5ba94ea66fe69e0811185f9ff8ddda66c40704e2 Mon Sep 17 00:00:00 2001 From: Aamir Mahmood Date: Fri, 18 Jun 2021 18:39:07 +0500 Subject: [PATCH 01/70] first draft --- lib/main.js | 18 ++-- lib/step.js | 235 ++++++++++++++++++++++++++++++++++++++++++++++ package-lock.json | 2 +- package.json | 3 +- 4 files changed, 250 insertions(+), 8 deletions(-) create mode 100644 lib/step.js diff --git a/lib/main.js b/lib/main.js index b47852a..004e6f1 100644 --- a/lib/main.js +++ b/lib/main.js @@ -8,6 +8,7 @@ const csvLocal = require('./csv-local.js'); const wdio = require('./wdio-commands'); const eventsWatcher = require('./events-watcher'); const EventEmitter = require('events'); +const TestableTest = require('step'); const LocalInfo = { expectedFinishTimestamp: -1, @@ -15,24 +16,24 @@ const LocalInfo = { client: 0, globalClientIndex: 0, regionalClientIndex: 0, - chunk: { + chunk: { id: -1, executionType: 'Main', agent: 'local', createdAt: Date.now(), updatedAt: Date.now(), startedAt: Date.now(), - concurrentClients: 1 + concurrentClients: 1 }, agent: 'local', - execution: { + execution: { id: -1, createdAt: Date.now(), updatedAt: Date.now(), startedAt: Date.now(), concurrentClients: 1 }, - region: { + region: { id: 1, createdAt: Date.now(), updatedAt: Date.now(), @@ -41,7 +42,7 @@ const LocalInfo = { latitude: 39.0436, longitude: -77.4878, description: 'Local', - active: true + active: true }, outputDir: process.cwd() }; @@ -133,13 +134,18 @@ if (registerCommands) { }); } +function startTest(name){ + return new TestableTest(name); +} + module.exports.isLocal = isLocal; module.exports.isSmokeTest = isSmokeTest; module.exports.info = info; module.exports.log = log; module.exports.results = results; +module.exports.startTest = startTest; module.exports.stopwatch = stopwatch; module.exports.execute = execute; module.exports.events = events; module.exports.dataTable = csv; -module.exports.waitForFinish = waitForFinish; \ No newline at end of file +module.exports.waitForFinish = waitForFinish; diff --git a/lib/step.js b/lib/step.js new file mode 100644 index 0000000..11321c5 --- /dev/null +++ b/lib/step.js @@ -0,0 +1,235 @@ + +class TestableStartSuiteTest { + + suiteUuid; + suiteName; + uuid; + name; + started; + + constructor(startSuite, name, started) { + this.suiteUuid = startSuite.getUuid(); + this.suiteName = startSuite.getName(); + this.uuid = uuidv4(); + this.name = name; + this.started = started; + } + + getSuiteUuid() { return this.suiteUuid; } + + getSuiteName() { return this.suiteName; } + + getUuid() { return this.uuid; } + + getName() { return this.name; } + + getStarted() { return this.started; } + +} + +class TestableStartSuite { + + uuid; + name; + started; + + constructor(name, started) { + this.uuid = uuidv4(); + this.name = name; + this.started = started; + } + + getUuid() { return this.uuid; } + + getName() { return this.name; } + + getStarted() { return this.started; } + +} + +class TestableFinishSuite { + + uuid; + name; + finished = new Date().getMilliseconds(); + duration; + hasError; + + constructor(start, hasError) { + this.uuid = start.uuid(); + this.name = start.name(); + this.duration = new Date().getMilliseconds() - start.started(); + this.hasError = hasError; + } + + getUuid() { + return this.uuid; + } + + getName() { + return this.name; + } + + getFinished() { + return this.finished; + } + + getDuration() { return this.duration; } + + isHasError() { return this.hasError; } +} + +class TestableFinishSuiteTest { + + suiteUuid; + suiteName; + uuid; + name; + finished; + duration; + state; + errorType; + error; + errorTrace; + + constructor(startSuiteTest, passed, e, captureTrace) { + this.suiteUuid = startSuiteTest.getSuiteUuid(); + this.suiteName = startSuiteTest.getSuiteName(); + this.uuid = startSuiteTest.getUuid(); + this.name = startSuiteTest.getName(); + this.finished = startSuiteTest.getStarted() > 0 ? new Date().getMilliseconds() : 0; + this.duration = startSuiteTest.getStarted() > 0 ? this.finished - startSuiteTest.started() : 0; + this.state = e !== null ? "failed" : "passed"; + if ( e !== null ) { + this.errorType = e.class().simpleName(); + this.error = e.message(); + if ( captureTrace ) { + sw = new StringWriter(); + pw = new PrintWriter(sw); + e.printStackTrace(pw); + this.errorTrace = sw.toString(); + } else { + this.errorTrace = null; + } + } else { + this.errorType = null; + this.error = null; + this.errorTrace = null; + } + } + + static passed(startSuiteTest) { + return new TestableFinishSuiteTest(startSuiteTest, true, null, false); + } + + static failed(startSuiteTest, e) { + return new TestableFinishSuiteTest(startSuiteTest, false, e, true); + } + + static failedException(startSuiteTest, msg) { + return new TestableFinishSuiteTest(startSuiteTest, false, new Exception(msg), false); + } + + getSuiteUuid() { return this.suiteUuid; } + + getSuiteName() { return this.suiteName; } + + getUuid() { return this.uuid; } + + getName() { return this.name; } + + getFinished() { return this.finished; } + + getDuration() { return this.duration; } + + getState() { return this.state; } + + getErrorType() { return this.errorType; } + + getError() { return this.error; } + + getErrorTrace() { return this.errorTrace; } +} + +class TestableTest { + startSuite; + currentTest = null; + hasError = false; + + constructor(name) { + this.startSuite = new TestableStartSuite(name, new Date().getMilliseconds()); + TestableTest.write("StartSuite", this.startSuite); + + } + + runStep(name, step) { + try { + this.startStep(name); + step.run(); + this.finishSuccessfulStep(); + } catch (e) { + this.finishFailedStep(e); + } + } + + startStep(name) { + this.currentTest = new TestableStartSuiteTest(this.startSuite, name, new Date().getMilliseconds()); + TestableTest.write('StartSuiteTest', this.currentTest); + } + + finishSuccessfulStep() { + this.finishStep(TestableFinishSuiteTest.passed(this.currentTest)); + } + + finishFailedStep(errorMsg) { + this.finishStep(TestableFinishSuiteTest.failed(this.currentTest, errorMsg)); + } + + finishStep(finishMsg) { + if ( this.currentTest !== null ) { + TestableTest.write("FinishSuiteTest", finishMsg); + if ( finishMsg.getError() !== null ) + this.hasError = true; + this.currentTest = null; + } + } + + assertionPassed(assertion, duration) { + this.currentTest = new TestableStartSuiteTest(this.startSuite, assertion, new Date().getMilliseconds() - duration); + TestableTest.write("StartSuiteTest", this.currentTest); + this.finishStep(TestableFinishSuiteTest.passed(this.currentTest)); + } + + assertionFailed(assertion, duration, errorMessage) { + this.currentTest = new TestableStartSuiteTest(this.startSuite, assertion, new Date().getMilliseconds() - duration); + TestableTest.write("StartSuiteTest", this.currentTest); + this.finishStep(TestableFinishSuiteTest.failed(this.currentTest, errorMessage)); + } + + finish() { + if ( this.currentTest !== null ) { + TestableTest.write("FinishSuiteTest", TestableFinishSuiteTest.passed(this.currentTest)); + } + TestableTest.write("FinishSuite", new TestableFinishSuite(this.startSuite, this.hasError)); + } + + static write(type, event) { + // todo: pending writing the events + // TestableTest.writeToStream() + } +} + +module.exports = TestableTest; + +/* + +const test = TestableSelenium.startTest("Google Related"); +test.startStep("Open google home page"); +driver.get("https://www.google.com"); +test.finishSuccessfulStep(); // or test.finishFailedStep("My error message"); +test.runStep("Open google news using Runnable", new Runnable() { + run() { + driver.get("https://news.google.com"); // any exception here gets logged as a test step failure + } +}); +test.finish();*/ diff --git a/package-lock.json b/package-lock.json index 0a4537d..110f230 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "testable-utils", - "version": "0.5.8", + "version": "0.5.9", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 8a13944..9edcc68 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,8 @@ "always-tail": "^0.2.0", "babyparse": "^0.4.6", "lodash": "^4.17.15", - "request": "^2.88.2" + "request": "^2.88.2", + "uuid": "^3.4.0" }, "typings": "./index.d.ts" } From 89cd7ac2d27352f5b9e819a3c43c058041aa1d1c Mon Sep 17 00:00:00 2001 From: Aamir Mahmood Date: Fri, 18 Jun 2021 19:24:41 +0500 Subject: [PATCH 02/70] export class by default --- lib/step.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/step.js b/lib/step.js index 11321c5..edc632f 100644 --- a/lib/step.js +++ b/lib/step.js @@ -219,7 +219,7 @@ class TestableTest { } } -module.exports = TestableTest; +export default TestableTest; /* From f4158cc7ef1eab387b07d641f8d36bd174e41211 Mon Sep 17 00:00:00 2001 From: Aamir Mahmood Date: Fri, 18 Jun 2021 19:25:53 +0500 Subject: [PATCH 03/70] export class by default --- lib/main.js | 3 +++ lib/step.js | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/lib/main.js b/lib/main.js index 004e6f1..93fbeee 100644 --- a/lib/main.js +++ b/lib/main.js @@ -135,6 +135,9 @@ if (registerCommands) { } function startTest(name){ + console.log('---------'); + console.log('---------'); + console.log(name); return new TestableTest(name); } diff --git a/lib/step.js b/lib/step.js index edc632f..469d05b 100644 --- a/lib/step.js +++ b/lib/step.js @@ -157,6 +157,11 @@ class TestableTest { hasError = false; constructor(name) { + + console.log('---------'); + console.log('---------'); + console.log('INSIDE CONSTRUCTOR'); + this.startSuite = new TestableStartSuite(name, new Date().getMilliseconds()); TestableTest.write("StartSuite", this.startSuite); From 81a085281055baaa4e54857922e232147a324af4 Mon Sep 17 00:00:00 2001 From: Aamir Mahmood Date: Fri, 18 Jun 2021 20:27:35 +0500 Subject: [PATCH 04/70] paths adjusted --- lib/main.js | 10 +++++----- lib/{step.js => testableTest.js} | 0 2 files changed, 5 insertions(+), 5 deletions(-) rename lib/{step.js => testableTest.js} (100%) diff --git a/lib/main.js b/lib/main.js index 93fbeee..af02480 100644 --- a/lib/main.js +++ b/lib/main.js @@ -1,14 +1,14 @@ const fs = require('fs'); const _ = require('lodash'); -const createLog = require('./log.js'); -const createResults = require('./results.js'); -const csvRemote = require('./csv-remote.js'); -const csvLocal = require('./csv-local.js'); +const createLog = require('./log'); +const createResults = require('./results'); +const csvRemote = require('./csv-remote'); +const csvLocal = require('./csv-local'); const wdio = require('./wdio-commands'); const eventsWatcher = require('./events-watcher'); const EventEmitter = require('events'); -const TestableTest = require('step'); +const TestableTest = require('./testableTest'); const LocalInfo = { expectedFinishTimestamp: -1, diff --git a/lib/step.js b/lib/testableTest.js similarity index 100% rename from lib/step.js rename to lib/testableTest.js From b310777bbc2eacc8d732dc798fd88dea06f52fb4 Mon Sep 17 00:00:00 2001 From: Aamir Mahmood Date: Fri, 18 Jun 2021 20:31:08 +0500 Subject: [PATCH 05/70] export fixed --- lib/testableTest.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/testableTest.js b/lib/testableTest.js index 469d05b..f0895b7 100644 --- a/lib/testableTest.js +++ b/lib/testableTest.js @@ -224,7 +224,7 @@ class TestableTest { } } -export default TestableTest; +module.exports = TestableTest; /* From 557352264360ac7782a46e56ab00208083434b1a Mon Sep 17 00:00:00 2001 From: Aamir Mahmood Date: Fri, 18 Jun 2021 20:33:57 +0500 Subject: [PATCH 06/70] uuid required --- lib/testableTest.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/testableTest.js b/lib/testableTest.js index f0895b7..711b054 100644 --- a/lib/testableTest.js +++ b/lib/testableTest.js @@ -1,3 +1,4 @@ +const { v4: uuidv4 } = require('uuid'); class TestableStartSuiteTest { From 8f308ab8e202863bc6f0ced463d47007c911ce04 Mon Sep 17 00:00:00 2001 From: Aamir Mahmood Date: Fri, 18 Jun 2021 20:37:19 +0500 Subject: [PATCH 07/70] console removed --- lib/main.js | 3 --- lib/testableTest.js | 6 ------ 2 files changed, 9 deletions(-) diff --git a/lib/main.js b/lib/main.js index af02480..f83bd5e 100644 --- a/lib/main.js +++ b/lib/main.js @@ -135,9 +135,6 @@ if (registerCommands) { } function startTest(name){ - console.log('---------'); - console.log('---------'); - console.log(name); return new TestableTest(name); } diff --git a/lib/testableTest.js b/lib/testableTest.js index 711b054..0b8d880 100644 --- a/lib/testableTest.js +++ b/lib/testableTest.js @@ -158,14 +158,8 @@ class TestableTest { hasError = false; constructor(name) { - - console.log('---------'); - console.log('---------'); - console.log('INSIDE CONSTRUCTOR'); - this.startSuite = new TestableStartSuite(name, new Date().getMilliseconds()); TestableTest.write("StartSuite", this.startSuite); - } runStep(name, step) { From 7520eea3b046ef54f83e44d0a4fdbd3f0e1478f9 Mon Sep 17 00:00:00 2001 From: Aamir Mahmood Date: Fri, 18 Jun 2021 20:46:00 +0500 Subject: [PATCH 08/70] getter function fixed --- lib/testableTest.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/testableTest.js b/lib/testableTest.js index 0b8d880..4928848 100644 --- a/lib/testableTest.js +++ b/lib/testableTest.js @@ -99,7 +99,7 @@ class TestableFinishSuiteTest { this.uuid = startSuiteTest.getUuid(); this.name = startSuiteTest.getName(); this.finished = startSuiteTest.getStarted() > 0 ? new Date().getMilliseconds() : 0; - this.duration = startSuiteTest.getStarted() > 0 ? this.finished - startSuiteTest.started() : 0; + this.duration = startSuiteTest.getStarted() > 0 ? this.finished - startSuiteTest.getStarted() : 0; this.state = e !== null ? "failed" : "passed"; if ( e !== null ) { this.errorType = e.class().simpleName(); From 2bf709a3d9e4541d7d1ed79049afc9e2417f65ca Mon Sep 17 00:00:00 2001 From: Aamir Mahmood Date: Fri, 18 Jun 2021 20:52:03 +0500 Subject: [PATCH 09/70] getter function fixed --- lib/testableTest.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/testableTest.js b/lib/testableTest.js index 4928848..c824bc9 100644 --- a/lib/testableTest.js +++ b/lib/testableTest.js @@ -57,9 +57,9 @@ class TestableFinishSuite { hasError; constructor(start, hasError) { - this.uuid = start.uuid(); - this.name = start.name(); - this.duration = new Date().getMilliseconds() - start.started(); + this.uuid = start.getUuid(); + this.name = start.getName(); + this.duration = new Date().getMilliseconds() - start.getStarted(); this.hasError = hasError; } From 9ec146476c985c4e4dfb235519a2cb0e413907e0 Mon Sep 17 00:00:00 2001 From: Aamir Mahmood Date: Sat, 19 Jun 2021 00:40:00 +0500 Subject: [PATCH 10/70] removed comments --- lib/testableTest.js | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/lib/testableTest.js b/lib/testableTest.js index c824bc9..8632e1a 100644 --- a/lib/testableTest.js +++ b/lib/testableTest.js @@ -220,16 +220,3 @@ class TestableTest { } module.exports = TestableTest; - -/* - -const test = TestableSelenium.startTest("Google Related"); -test.startStep("Open google home page"); -driver.get("https://www.google.com"); -test.finishSuccessfulStep(); // or test.finishFailedStep("My error message"); -test.runStep("Open google news using Runnable", new Runnable() { - run() { - driver.get("https://news.google.com"); // any exception here gets logged as a test step failure - } -}); -test.finish();*/ From 1a5fe79836818d1bca7c3631b16aba536fb4db23 Mon Sep 17 00:00:00 2001 From: Aamir Mahmood Date: Mon, 21 Jun 2021 18:27:27 +0500 Subject: [PATCH 11/70] steps updated --- lib/main.js | 29 ++++- lib/testable-test.js | 282 +++++++++++++++++++++++++++++++++++++++++++ lib/testableTest.js | 222 ---------------------------------- package.json | 3 +- 4 files changed, 309 insertions(+), 227 deletions(-) create mode 100644 lib/testable-test.js delete mode 100644 lib/testableTest.js diff --git a/lib/main.js b/lib/main.js index f83bd5e..99c217e 100644 --- a/lib/main.js +++ b/lib/main.js @@ -8,7 +8,7 @@ const csvLocal = require('./csv-local'); const wdio = require('./wdio-commands'); const eventsWatcher = require('./events-watcher'); const EventEmitter = require('events'); -const TestableTest = require('./testableTest'); +const TestSteps = require('./testable-test'); const LocalInfo = { expectedFinishTimestamp: -1, @@ -134,18 +134,39 @@ if (registerCommands) { }); } -function startTest(name){ - return new TestableTest(name); +let steps; +function testSteps(name){ + steps = new TestSteps(name); + + // const stepsObj = {}; + // stepsObj.describe = StepsClass.describe.bind(StepsClass); + // stepsObj.it = StepsClass.it.bind(StepsClass); + // stepsObj.before = StepsClass.before.bind(StepsClass); + // stepsObj.after = StepsClass.after.bind(StepsClass); + // stepsObj.beforeEach = StepsClass.beforeEach.bind(StepsClass); + // stepsObj.afterEach = StepsClass.afterEach.bind(StepsClass); + // + // steps = stepsObj; + // } +testSteps(); module.exports.isLocal = isLocal; module.exports.isSmokeTest = isSmokeTest; module.exports.info = info; module.exports.log = log; module.exports.results = results; -module.exports.startTest = startTest; module.exports.stopwatch = stopwatch; module.exports.execute = execute; module.exports.events = events; module.exports.dataTable = csv; module.exports.waitForFinish = waitForFinish; + + +module.exports.describe = steps.describe; +module.exports.it = steps.it; +module.exports.before = steps.before; +module.exports.after = steps.after; +module.exports.beforeEach = steps.beforeEach; +module.exports.afterEach = steps.afterEach; + diff --git a/lib/testable-test.js b/lib/testable-test.js new file mode 100644 index 0000000..c2ee97b --- /dev/null +++ b/lib/testable-test.js @@ -0,0 +1,282 @@ +const { v4: uuidv4 } = require('uuid'); +const wrappedHelper = require('./../protocols/wrapped-helper'); +let VError = require('verror'); +let util = require('util'); + +class TestSteps { + constructor(cb) { + this.cb = cb; + this.finish(); + } + + get currentSuite() { + return this.suites.length > 0 ? this.suites[this.suites.length - 1] : null; + } + + get currentTest() { + const currentSuite = this.currentSuite; + if ( !currentSuite || currentSuite.tests.length === 0 ) + return null; + return currentSuite.tests[currentSuite.tests.length - 1]; + } + + async finish() { + if ( this.suites ) + for ( const suite of this.suites ) { + await this._onSuiteFinish(suite); + } + + this.suites = []; + this._before = null; + this._beforeEach = null; + this._after = null; + this._afterEach = null; + } + + async describe(suiteName, fn) { + const suite = this._createSuite(this._getSuitePrefix() + suiteName, false); + fn(); + await this._executeSuite(suite); + } + + async it(testName, fn) { + let suite = this.currentSuite; + if ( !suite ) { + suite = this._createSuite('Default Suite', true); + this._onSuiteStart(suite); + } + let test = this._createTest(suite, testName, fn); + if ( suite.executeTestsImmediately ) { + await this._executeTest(suite, test); + this._onSuiteFinish(suite); + } else + suite.tests.push(test); + } + + before(fn) { + this._register('_before', fn); + } + + beforeEach(fn) { + this._register('_beforeEach', fn); + } + + after(fn) { + this._register('_after', fn); + } + + afterEach(fn) { + this._register('_afterEach', fn); + } + + _getSuitePrefix() { + if ( this.suites.length === 0 ) + return ''; + let answer = ''; + for ( const suite of this.suites ) + answer += `${suite.name} => `; + return answer; + } + + _register(hook, fn) { + const suite = this.currentSuite; + if ( suite ) + suite[hook] = fn; + else + this[hook] = fn; + } + + _createSuite(suiteName, isDefault) { + const suite = { + uuid: uuidv4(), + name: suiteName, + tests: [], + started: Date.now(), + hasError: false, + executeTestsImmediately: isDefault + }; + this.suites.push(suite); + return suite; + } + + _createTest(suite, name, fn) { + return { + suiteUuid: suite.uuid, + suiteName: suite.name, + uuid: uuidv4(), + name: name, + fn: fn, + started: Date.now() + }; + } + + async _executeSuite(suite) { + this._onSuiteStart(suite); + + if ( suite.tests ) + for ( const test of suite.tests ) { + await this._executeTest(suite, test); + } + + this._onSuiteFinish(suite); + } + + async _onSuiteStart(suite) { + const before = suite._before || this._before; + if ( before ) + await this._executeFn(before); + + if ( this.cb.startSuite ) + this.cb.startSuite(suite); + } + + async _onSuiteFinish(suite) { + suite.finished = Date.now(); + suite.duration = Date.now() - suite.started; + + const after = suite._after || this._after; + if ( after ) + await this._executeFn(after); + + this.suites.pop(); + if ( this.cb.finishSuite ) + this.cb.finishSuite(suite); + } + + async _executeTest(suite, test) { + const beforeEach = suite._beforeEach || this._beforeEach; + if ( beforeEach ) + await this._executeFn(beforeEach); + + await this._executeStep(test.fn, suite, test); + + const afterEach = suite._afterEach || this._afterEach; + if ( afterEach ) + await this._executeFn(afterEach); + } + + async _executeStep(fn, suite, test) { + if ( this.cb.startTest ) + this.cb.startTest(test, suite); + + try { + await this._executeFn(fn); + test.state = 'passed'; + } catch (err) { + suite.hasError = true; + test.state = 'failed'; + test.errorType = err.name; + if ( err.message ) + test.error = err.message; + if ( err.stack ) + test.errorTrace = wrappedHelper.toErrorContent(err); + } + test.finished = Date.now(); + test.duration = Date.now() - test.started; + + if ( this.cb.finishTest ) + this.cb.finishTest(test, suite); + } + + async _executeFn(fn) { + const isAsync = fn.constructor.name === 'AsyncFunction'; + if ( isAsync ) + await fn(); + else if ( fn.length === 1 ) + await new Promise(function (resolve, reject) { + fn(function (err) { + if ( err ) + reject(new Error(err)); + else + resolve(); + }); + }); + else + fn(); + } + + filterStackTrace(stack) { + const lines = stack.split('\n'); + var answer = ''; + var hitScriptLine = false; + _.forEach(lines, function (line) { + var trimmedLine = line.trim(); + if (!hitScriptLine) + answer += line + '\n'; + if (trimmedLine.indexOf('at script.js') === 0 || trimmedLine.indexOf('(script.js') > 0) + hitScriptLine = true; + }); + return answer; + } + + toErrorContent(error, msgOnly) { + if (_.isUndefined(error) || error === null) + return ""; + if (_.isString(error)) + return error; + if (!_.isError(error) && _.isBuffer(error)) + return error.toString(); + if (!_.isError(error) && _.isObject(error)) + return util.inspect(error); + if (!_.isError(error)) + return '' + error; + if (_.isUndefined(error.message)) + return "Unknown error"; + switch (error.message) { + case "Error: read ECONNRESET": + case "Error: socket hang up": + return "Connection closed unexpectedly"; + case "connect ETIMEDOUT": + return "Connect timed out"; + default: + return msgOnly ? error.message : this.filterStackTrace(VError.fullStack(error)); + } + } + +} + +module.exports = TestSteps; + + + +const webdriver = require('selenium-webdriver'); +const util = require('util'); +const fs = require('fs'); +const writeFile = util.promisify(fs.writeFile); +const path = require('path'); +const { expect } = require('chai'); + +async function takeScreenshot(driver, file){ + let image = await driver.takeScreenshot(); + await writeFile(file, image, 'base64'); +} +/* + +describe('DefaultTest', () => { + let driver = new webdriver.Builder() + .withCapabilities(webdriver.Capabilities.chrome()) + .build(); + + it('should go to google.com and check title', async () => { + await driver.get('https://www.google.com'); + await takeScreenshot(driver, path.join(process.env.OUTPUT_DIR || '.', 'HomePage.png')); + const title = await driver.getTitle(); + expect(title).to.equal('Google'); + }); + + after(async () => driver.quit()); +}); + + +{ + "name": "webdriver-testable-demo", + "version": "0.0.1", + "description": "Simple Webdriver Javascript Example", + "author": "Testable", + "devDependencies": { + "testable-utils": "0.5.9", + "selenium-webdriver": "3.6.0", + "mocha": "8.1.3", + "chai": "4.2.0" +} +}*/ diff --git a/lib/testableTest.js b/lib/testableTest.js deleted file mode 100644 index 8632e1a..0000000 --- a/lib/testableTest.js +++ /dev/null @@ -1,222 +0,0 @@ -const { v4: uuidv4 } = require('uuid'); - -class TestableStartSuiteTest { - - suiteUuid; - suiteName; - uuid; - name; - started; - - constructor(startSuite, name, started) { - this.suiteUuid = startSuite.getUuid(); - this.suiteName = startSuite.getName(); - this.uuid = uuidv4(); - this.name = name; - this.started = started; - } - - getSuiteUuid() { return this.suiteUuid; } - - getSuiteName() { return this.suiteName; } - - getUuid() { return this.uuid; } - - getName() { return this.name; } - - getStarted() { return this.started; } - -} - -class TestableStartSuite { - - uuid; - name; - started; - - constructor(name, started) { - this.uuid = uuidv4(); - this.name = name; - this.started = started; - } - - getUuid() { return this.uuid; } - - getName() { return this.name; } - - getStarted() { return this.started; } - -} - -class TestableFinishSuite { - - uuid; - name; - finished = new Date().getMilliseconds(); - duration; - hasError; - - constructor(start, hasError) { - this.uuid = start.getUuid(); - this.name = start.getName(); - this.duration = new Date().getMilliseconds() - start.getStarted(); - this.hasError = hasError; - } - - getUuid() { - return this.uuid; - } - - getName() { - return this.name; - } - - getFinished() { - return this.finished; - } - - getDuration() { return this.duration; } - - isHasError() { return this.hasError; } -} - -class TestableFinishSuiteTest { - - suiteUuid; - suiteName; - uuid; - name; - finished; - duration; - state; - errorType; - error; - errorTrace; - - constructor(startSuiteTest, passed, e, captureTrace) { - this.suiteUuid = startSuiteTest.getSuiteUuid(); - this.suiteName = startSuiteTest.getSuiteName(); - this.uuid = startSuiteTest.getUuid(); - this.name = startSuiteTest.getName(); - this.finished = startSuiteTest.getStarted() > 0 ? new Date().getMilliseconds() : 0; - this.duration = startSuiteTest.getStarted() > 0 ? this.finished - startSuiteTest.getStarted() : 0; - this.state = e !== null ? "failed" : "passed"; - if ( e !== null ) { - this.errorType = e.class().simpleName(); - this.error = e.message(); - if ( captureTrace ) { - sw = new StringWriter(); - pw = new PrintWriter(sw); - e.printStackTrace(pw); - this.errorTrace = sw.toString(); - } else { - this.errorTrace = null; - } - } else { - this.errorType = null; - this.error = null; - this.errorTrace = null; - } - } - - static passed(startSuiteTest) { - return new TestableFinishSuiteTest(startSuiteTest, true, null, false); - } - - static failed(startSuiteTest, e) { - return new TestableFinishSuiteTest(startSuiteTest, false, e, true); - } - - static failedException(startSuiteTest, msg) { - return new TestableFinishSuiteTest(startSuiteTest, false, new Exception(msg), false); - } - - getSuiteUuid() { return this.suiteUuid; } - - getSuiteName() { return this.suiteName; } - - getUuid() { return this.uuid; } - - getName() { return this.name; } - - getFinished() { return this.finished; } - - getDuration() { return this.duration; } - - getState() { return this.state; } - - getErrorType() { return this.errorType; } - - getError() { return this.error; } - - getErrorTrace() { return this.errorTrace; } -} - -class TestableTest { - startSuite; - currentTest = null; - hasError = false; - - constructor(name) { - this.startSuite = new TestableStartSuite(name, new Date().getMilliseconds()); - TestableTest.write("StartSuite", this.startSuite); - } - - runStep(name, step) { - try { - this.startStep(name); - step.run(); - this.finishSuccessfulStep(); - } catch (e) { - this.finishFailedStep(e); - } - } - - startStep(name) { - this.currentTest = new TestableStartSuiteTest(this.startSuite, name, new Date().getMilliseconds()); - TestableTest.write('StartSuiteTest', this.currentTest); - } - - finishSuccessfulStep() { - this.finishStep(TestableFinishSuiteTest.passed(this.currentTest)); - } - - finishFailedStep(errorMsg) { - this.finishStep(TestableFinishSuiteTest.failed(this.currentTest, errorMsg)); - } - - finishStep(finishMsg) { - if ( this.currentTest !== null ) { - TestableTest.write("FinishSuiteTest", finishMsg); - if ( finishMsg.getError() !== null ) - this.hasError = true; - this.currentTest = null; - } - } - - assertionPassed(assertion, duration) { - this.currentTest = new TestableStartSuiteTest(this.startSuite, assertion, new Date().getMilliseconds() - duration); - TestableTest.write("StartSuiteTest", this.currentTest); - this.finishStep(TestableFinishSuiteTest.passed(this.currentTest)); - } - - assertionFailed(assertion, duration, errorMessage) { - this.currentTest = new TestableStartSuiteTest(this.startSuite, assertion, new Date().getMilliseconds() - duration); - TestableTest.write("StartSuiteTest", this.currentTest); - this.finishStep(TestableFinishSuiteTest.failed(this.currentTest, errorMessage)); - } - - finish() { - if ( this.currentTest !== null ) { - TestableTest.write("FinishSuiteTest", TestableFinishSuiteTest.passed(this.currentTest)); - } - TestableTest.write("FinishSuite", new TestableFinishSuite(this.startSuite, this.hasError)); - } - - static write(type, event) { - // todo: pending writing the events - // TestableTest.writeToStream() - } -} - -module.exports = TestableTest; diff --git a/package.json b/package.json index 9edcc68..7fb51ba 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,8 @@ "babyparse": "^0.4.6", "lodash": "^4.17.15", "request": "^2.88.2", - "uuid": "^3.4.0" + "uuid": "^3.4.0", + "verror": "^1.10.0" }, "typings": "./index.d.ts" } From a5d06c01a3e85780852d08cf2d563494ef39ddc4 Mon Sep 17 00:00:00 2001 From: Aamir Mahmood Date: Mon, 21 Jun 2021 18:34:46 +0500 Subject: [PATCH 12/70] comments fixed --- lib/testable-test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/testable-test.js b/lib/testable-test.js index c2ee97b..199daf3 100644 --- a/lib/testable-test.js +++ b/lib/testable-test.js @@ -238,6 +238,7 @@ class TestSteps { module.exports = TestSteps; +/* const webdriver = require('selenium-webdriver'); const util = require('util'); @@ -250,7 +251,6 @@ async function takeScreenshot(driver, file){ let image = await driver.takeScreenshot(); await writeFile(file, image, 'base64'); } -/* describe('DefaultTest', () => { let driver = new webdriver.Builder() From 74a298718fb208ca15feb51bebbe48e54263c5c9 Mon Sep 17 00:00:00 2001 From: Aamir Mahmood Date: Mon, 21 Jun 2021 18:36:12 +0500 Subject: [PATCH 13/70] removed wrappedHelper --- lib/testable-test.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/testable-test.js b/lib/testable-test.js index 199daf3..fd40f9d 100644 --- a/lib/testable-test.js +++ b/lib/testable-test.js @@ -1,5 +1,4 @@ const { v4: uuidv4 } = require('uuid'); -const wrappedHelper = require('./../protocols/wrapped-helper'); let VError = require('verror'); let util = require('util'); @@ -169,7 +168,7 @@ class TestSteps { if ( err.message ) test.error = err.message; if ( err.stack ) - test.errorTrace = wrappedHelper.toErrorContent(err); + test.errorTrace = this.toErrorContent(err); } test.finished = Date.now(); test.duration = Date.now() - test.started; From ebbe3d56582fa01a81e85edebb3ca681ddc57ee7 Mon Sep 17 00:00:00 2001 From: Aamir Mahmood Date: Mon, 21 Jun 2021 18:38:12 +0500 Subject: [PATCH 14/70] binding updated --- lib/main.js | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/main.js b/lib/main.js index 99c217e..2206203 100644 --- a/lib/main.js +++ b/lib/main.js @@ -136,18 +136,18 @@ if (registerCommands) { let steps; function testSteps(name){ - steps = new TestSteps(name); - - // const stepsObj = {}; - // stepsObj.describe = StepsClass.describe.bind(StepsClass); - // stepsObj.it = StepsClass.it.bind(StepsClass); - // stepsObj.before = StepsClass.before.bind(StepsClass); - // stepsObj.after = StepsClass.after.bind(StepsClass); - // stepsObj.beforeEach = StepsClass.beforeEach.bind(StepsClass); - // stepsObj.afterEach = StepsClass.afterEach.bind(StepsClass); - // - // steps = stepsObj; - // + const StepsClass = new TestSteps(name); + + const stepsObj = {}; + stepsObj.describe = StepsClass.describe.bind(StepsClass); + stepsObj.it = StepsClass.it.bind(StepsClass); + stepsObj.before = StepsClass.before.bind(StepsClass); + stepsObj.after = StepsClass.after.bind(StepsClass); + stepsObj.beforeEach = StepsClass.beforeEach.bind(StepsClass); + stepsObj.afterEach = StepsClass.afterEach.bind(StepsClass); + + steps = stepsObj; + } testSteps(); From a0cca1e9400b2795367ba792aaa620fd21c32cc8 Mon Sep 17 00:00:00 2001 From: Aamir Mahmood Date: Mon, 21 Jun 2021 20:43:49 +0500 Subject: [PATCH 15/70] callback functions added --- lib/testable-test.js | 72 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 70 insertions(+), 2 deletions(-) diff --git a/lib/testable-test.js b/lib/testable-test.js index fd40f9d..7c91e00 100644 --- a/lib/testable-test.js +++ b/lib/testable-test.js @@ -2,9 +2,16 @@ const { v4: uuidv4 } = require('uuid'); let VError = require('verror'); let util = require('util'); +const EarlyTerminationMsg = 'Connection closed early when test was stopped'; + + class TestSteps { - constructor(cb) { - this.cb = cb; + + requestsInProgress = 0; + scriptRunning = false; + + constructor() { + this.cb = this.callback; this.finish(); } @@ -232,6 +239,67 @@ class TestSteps { } } + + callback (){ + const self = this; + return { + startSuite: function(suite) { + self.reportTestSuiteActions([ { type: 'StartSuite', data: suite }]); + // self._requestStarted(); + }, + finishSuite: function(suite) { + self.reportTestSuiteActions([ { type: 'FinishSuite', data: suite }]); + // self._requestFinished(); + }, + startTest: function(test) { + self.reportTestSuiteActions([ { type: 'StartSuiteTest', data: test }]); + // self._requestStarted(); + }, + finishTest: function(test) { + self.reportTestSuiteActions([ { type: 'FinishSuiteTest', data: test }]); + // self._requestFinished(); + } + } + } + + _requestStarted(){ + this.requestsInProgress = this.requestsInProgress + 1; + } + reportTestSuiteActions(suiteActions){ + // this.sendMsg({ + // type: "TestSuiteActions", + // data: suiteActions + // }); + } + _requestFinished(result){ + this.requestsInProgress = this.requestsInProgress - 1; + this.resultFinished(result); + if (this.requestsInProgress === 0 && !this.scriptRunning) { + // this._done(); + } + } + + resultFinished(result, earlyTermination) { + if (_.isObject(result) && !result.isFinished) { + if (earlyTermination && result.data.url) { + result.setTraceStatus('Terminated Early', EarlyTerminationMsg); + result.addTrace('Error', {}, EarlyTerminationMsg); + } + result.finished(); + if (!result.isEmpty()) { + this.sendMsg({ + type: "Result", + data: result.data + }); + } + let index = this.activeResults.indexOf(result); + if (index !== -1) + this.activeResults.splice(index, 1); + if (result.id) + this.resultsById.delete(result.id); + } + } + } module.exports = TestSteps; From 2586b451b4fa37652aac3f9fcf8fb7451945bf87 Mon Sep 17 00:00:00 2001 From: Aamir Mahmood Date: Mon, 21 Jun 2021 20:46:12 +0500 Subject: [PATCH 16/70] lodash added --- lib/testable-test.js | 1 + package.json | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/testable-test.js b/lib/testable-test.js index 7c91e00..93d93cc 100644 --- a/lib/testable-test.js +++ b/lib/testable-test.js @@ -1,6 +1,7 @@ const { v4: uuidv4 } = require('uuid'); let VError = require('verror'); let util = require('util'); +const _ = require("lodash"); const EarlyTerminationMsg = 'Connection closed early when test was stopped'; diff --git a/package.json b/package.json index 7fb51ba..9f8b9d2 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,7 @@ "dependencies": { "always-tail": "^0.2.0", "babyparse": "^0.4.6", - "lodash": "^4.17.15", + "lodash": "^4.17.21", "request": "^2.88.2", "uuid": "^3.4.0", "verror": "^1.10.0" From 1baec456d4d484fa56241172095ec1fdb86e54c4 Mon Sep 17 00:00:00 2001 From: Aamir Mahmood Date: Mon, 21 Jun 2021 21:03:42 +0500 Subject: [PATCH 17/70] sendMsg implemented, hope this works --- lib/testable-test.js | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/lib/testable-test.js b/lib/testable-test.js index 93d93cc..28f5212 100644 --- a/lib/testable-test.js +++ b/lib/testable-test.js @@ -10,6 +10,8 @@ class TestSteps { requestsInProgress = 0; scriptRunning = false; + activeResults = []; + resultsById = new Map(); constructor() { this.cb = this.callback; @@ -246,19 +248,19 @@ class TestSteps { return { startSuite: function(suite) { self.reportTestSuiteActions([ { type: 'StartSuite', data: suite }]); - // self._requestStarted(); + self._requestStarted(); }, finishSuite: function(suite) { self.reportTestSuiteActions([ { type: 'FinishSuite', data: suite }]); - // self._requestFinished(); + self._requestFinished(); }, startTest: function(test) { self.reportTestSuiteActions([ { type: 'StartSuiteTest', data: test }]); - // self._requestStarted(); + self._requestStarted(); }, finishTest: function(test) { self.reportTestSuiteActions([ { type: 'FinishSuiteTest', data: test }]); - // self._requestFinished(); + self._requestFinished(); } } } @@ -267,10 +269,10 @@ class TestSteps { this.requestsInProgress = this.requestsInProgress + 1; } reportTestSuiteActions(suiteActions){ - // this.sendMsg({ - // type: "TestSuiteActions", - // data: suiteActions - // }); + this.sendMsg({ + type: "TestSuiteActions", + data: suiteActions + }); } _requestFinished(result){ this.requestsInProgress = this.requestsInProgress - 1; @@ -284,7 +286,7 @@ class TestSteps { if (_.isObject(result) && !result.isFinished) { if (earlyTermination && result.data.url) { result.setTraceStatus('Terminated Early', EarlyTerminationMsg); - result.addTrace('Error', {}, EarlyTerminationMsg); + // result.addTrace('Error', {}, EarlyTerminationMsg); } result.finished(); if (!result.isEmpty()) { @@ -301,6 +303,17 @@ class TestSteps { } } + sendMsg(result){ + return new Promise(function (resolve, reject) { + if (process.env.TESTABLE_RESULT_FILE) { + fs.writeFile(process.env.TESTABLE_RESULT_FILE, JSON.stringify(result) + '\n', { encoding: 'utf8', flag: 'a' }, resolve); + } else { + console.log('[Result] ' + JSON.stringify(result, null, '\t')); + resolve(); + } + }); + } + } module.exports = TestSteps; From 062916a3f0f772c5533c6e7a00ff3fd4730c27f0 Mon Sep 17 00:00:00 2001 From: Aamir Mahmood Date: Mon, 21 Jun 2021 23:14:19 +0500 Subject: [PATCH 18/70] logs added --- lib/testable-test.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/testable-test.js b/lib/testable-test.js index 28f5212..42cf802 100644 --- a/lib/testable-test.js +++ b/lib/testable-test.js @@ -266,15 +266,21 @@ class TestSteps { } _requestStarted(){ + console.log('---------') + console.log('requestStarted'); this.requestsInProgress = this.requestsInProgress + 1; } reportTestSuiteActions(suiteActions){ + console.log('---------') + console.log('reportTestSuiteActions'); this.sendMsg({ type: "TestSuiteActions", data: suiteActions }); } _requestFinished(result){ + console.log('---------') + console.log('_requestFinished'); this.requestsInProgress = this.requestsInProgress - 1; this.resultFinished(result); if (this.requestsInProgress === 0 && !this.scriptRunning) { @@ -283,6 +289,8 @@ class TestSteps { } resultFinished(result, earlyTermination) { + console.log('---------') + console.log('resultFinished'); if (_.isObject(result) && !result.isFinished) { if (earlyTermination && result.data.url) { result.setTraceStatus('Terminated Early', EarlyTerminationMsg); @@ -304,6 +312,8 @@ class TestSteps { } sendMsg(result){ + console.log('---------') + console.log('sendMsg'); return new Promise(function (resolve, reject) { if (process.env.TESTABLE_RESULT_FILE) { fs.writeFile(process.env.TESTABLE_RESULT_FILE, JSON.stringify(result) + '\n', { encoding: 'utf8', flag: 'a' }, resolve); From 94e3d29387fc955aa7ed5135e3ab57beece14440 Mon Sep 17 00:00:00 2001 From: Aamir Mahmood Date: Mon, 21 Jun 2021 23:24:02 +0500 Subject: [PATCH 19/70] test 1 --- lib/testable-test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/testable-test.js b/lib/testable-test.js index 42cf802..8c58e1d 100644 --- a/lib/testable-test.js +++ b/lib/testable-test.js @@ -14,7 +14,7 @@ class TestSteps { resultsById = new Map(); constructor() { - this.cb = this.callback; + // this.cb = this.callback; this.finish(); } From 9ab0c10256f9234a5346e0485403fb8f224fa5ac Mon Sep 17 00:00:00 2001 From: Aamir Mahmood Date: Mon, 21 Jun 2021 23:26:17 +0500 Subject: [PATCH 20/70] test 1 --- lib/testable-test.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/testable-test.js b/lib/testable-test.js index 8c58e1d..a53cba5 100644 --- a/lib/testable-test.js +++ b/lib/testable-test.js @@ -14,7 +14,8 @@ class TestSteps { resultsById = new Map(); constructor() { - // this.cb = this.callback; + this.cb = this.callback; + console.log(this.cb); this.finish(); } From 43eaebf247a20cfcafbdfaa31fb288694d2042d6 Mon Sep 17 00:00:00 2001 From: Aamir Mahmood Date: Mon, 21 Jun 2021 23:28:45 +0500 Subject: [PATCH 21/70] callback function update --- lib/testable-test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/testable-test.js b/lib/testable-test.js index a53cba5..e465505 100644 --- a/lib/testable-test.js +++ b/lib/testable-test.js @@ -244,7 +244,7 @@ class TestSteps { } - callback (){ + callback = function (){ const self = this; return { startSuite: function(suite) { From e58dacdea83d03376903180474f496c632c7ec1f Mon Sep 17 00:00:00 2001 From: Aamir Mahmood Date: Mon, 21 Jun 2021 23:37:01 +0500 Subject: [PATCH 22/70] more consoles --- lib/testable-test.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/testable-test.js b/lib/testable-test.js index e465505..43b8399 100644 --- a/lib/testable-test.js +++ b/lib/testable-test.js @@ -44,12 +44,16 @@ class TestSteps { } async describe(suiteName, fn) { + console.log('------------') + console.log('describe') const suite = this._createSuite(this._getSuitePrefix() + suiteName, false); fn(); await this._executeSuite(suite); } async it(testName, fn) { + console.log('------------') + console.log('it') let suite = this.currentSuite; if ( !suite ) { suite = this._createSuite('Default Suite', true); From 19f076dc106fbb39012a06769789fb6b15d864ee Mon Sep 17 00:00:00 2001 From: Aamir Mahmood Date: Mon, 21 Jun 2021 23:42:27 +0500 Subject: [PATCH 23/70] more consoles --- lib/testable-test.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/testable-test.js b/lib/testable-test.js index 43b8399..e38b3ec 100644 --- a/lib/testable-test.js +++ b/lib/testable-test.js @@ -55,14 +55,15 @@ class TestSteps { console.log('------------') console.log('it') let suite = this.currentSuite; + console.log(suite.name); if ( !suite ) { suite = this._createSuite('Default Suite', true); - this._onSuiteStart(suite); + await this._onSuiteStart(suite); } let test = this._createTest(suite, testName, fn); if ( suite.executeTestsImmediately ) { await this._executeTest(suite, test); - this._onSuiteFinish(suite); + await this._onSuiteFinish(suite); } else suite.tests.push(test); } @@ -125,14 +126,14 @@ class TestSteps { } async _executeSuite(suite) { - this._onSuiteStart(suite); + await this._onSuiteStart(suite); if ( suite.tests ) for ( const test of suite.tests ) { await this._executeTest(suite, test); } - this._onSuiteFinish(suite); + await this._onSuiteFinish(suite); } async _onSuiteStart(suite) { From 558418534526ecb4315fe6cf079df2a564b5b170 Mon Sep 17 00:00:00 2001 From: Aamir Mahmood Date: Mon, 21 Jun 2021 23:46:29 +0500 Subject: [PATCH 24/70] more consoles --- lib/testable-test.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/testable-test.js b/lib/testable-test.js index e38b3ec..0c42458 100644 --- a/lib/testable-test.js +++ b/lib/testable-test.js @@ -15,7 +15,6 @@ class TestSteps { constructor() { this.cb = this.callback; - console.log(this.cb); this.finish(); } @@ -61,6 +60,8 @@ class TestSteps { await this._onSuiteStart(suite); } let test = this._createTest(suite, testName, fn); + console.log(test); + console.log(suite.executeTestsImmediately ); if ( suite.executeTestsImmediately ) { await this._executeTest(suite, test); await this._onSuiteFinish(suite); From 163eb043cb25fa848c0baf6b6561bf688d121675 Mon Sep 17 00:00:00 2001 From: Aamir Mahmood Date: Mon, 21 Jun 2021 23:51:44 +0500 Subject: [PATCH 25/70] more consoles --- lib/testable-test.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/testable-test.js b/lib/testable-test.js index 0c42458..7e4eeda 100644 --- a/lib/testable-test.js +++ b/lib/testable-test.js @@ -127,6 +127,10 @@ class TestSteps { } async _executeSuite(suite) { + + console.log('-------------'); + console.log('_executeSuite'); + console.log(suite.tests); await this._onSuiteStart(suite); if ( suite.tests ) From c33e7b9d00223bdf724f9403951d3147a0c9d9f7 Mon Sep 17 00:00:00 2001 From: Aamir Mahmood Date: Mon, 21 Jun 2021 23:56:13 +0500 Subject: [PATCH 26/70] more consoles --- lib/testable-test.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/testable-test.js b/lib/testable-test.js index 7e4eeda..20008d4 100644 --- a/lib/testable-test.js +++ b/lib/testable-test.js @@ -164,6 +164,8 @@ class TestSteps { } async _executeTest(suite, test) { + console.log('--------------'); + console.log('_executeTest'); const beforeEach = suite._beforeEach || this._beforeEach; if ( beforeEach ) await this._executeFn(beforeEach); @@ -258,6 +260,7 @@ class TestSteps { const self = this; return { startSuite: function(suite) { + console.log('------ suite started'); self.reportTestSuiteActions([ { type: 'StartSuite', data: suite }]); self._requestStarted(); }, From 15802130958c4d1dbe792ad0ccae8f3ee1472547 Mon Sep 17 00:00:00 2001 From: Aamir Mahmood Date: Mon, 21 Jun 2021 23:59:50 +0500 Subject: [PATCH 27/70] more consoles --- lib/testable-test.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/testable-test.js b/lib/testable-test.js index 20008d4..87a1f63 100644 --- a/lib/testable-test.js +++ b/lib/testable-test.js @@ -178,6 +178,8 @@ class TestSteps { } async _executeStep(fn, suite, test) { + console.log('--------------'); + console.log('_executeStep'); if ( this.cb.startTest ) this.cb.startTest(test, suite); @@ -201,6 +203,8 @@ class TestSteps { } async _executeFn(fn) { + console.log('--------------'); + console.log('_executeFn'); const isAsync = fn.constructor.name === 'AsyncFunction'; if ( isAsync ) await fn(); From 735388491299711a85c3b79debc41c349dc5c391 Mon Sep 17 00:00:00 2001 From: Aamir Mahmood Date: Tue, 22 Jun 2021 00:05:46 +0500 Subject: [PATCH 28/70] more consoles --- lib/testable-test.js | 76 +++++++++++++++++++++++++------------------- 1 file changed, 43 insertions(+), 33 deletions(-) diff --git a/lib/testable-test.js b/lib/testable-test.js index 87a1f63..69701df 100644 --- a/lib/testable-test.js +++ b/lib/testable-test.js @@ -61,7 +61,7 @@ class TestSteps { } let test = this._createTest(suite, testName, fn); console.log(test); - console.log(suite.executeTestsImmediately ); + console.log(suite.executeTestsImmediately); if ( suite.executeTestsImmediately ) { await this._executeTest(suite, test); await this._onSuiteFinish(suite); @@ -205,10 +205,13 @@ class TestSteps { async _executeFn(fn) { console.log('--------------'); console.log('_executeFn'); + console.log(fn.length); const isAsync = fn.constructor.name === 'AsyncFunction'; - if ( isAsync ) + if ( isAsync ) { + console.log('inAsync'); await fn(); - else if ( fn.length === 1 ) + } else if ( fn.length === 1 ) { + console.log('in if else'); await new Promise(function (resolve, reject) { fn(function (err) { if ( err ) @@ -217,8 +220,10 @@ class TestSteps { resolve(); }); }); - else + } else { + console.log('in fn'); fn(); + } } filterStackTrace(stack) { @@ -227,26 +232,26 @@ class TestSteps { var hitScriptLine = false; _.forEach(lines, function (line) { var trimmedLine = line.trim(); - if (!hitScriptLine) + if ( !hitScriptLine ) answer += line + '\n'; - if (trimmedLine.indexOf('at script.js') === 0 || trimmedLine.indexOf('(script.js') > 0) + if ( trimmedLine.indexOf('at script.js') === 0 || trimmedLine.indexOf('(script.js') > 0 ) hitScriptLine = true; }); return answer; } toErrorContent(error, msgOnly) { - if (_.isUndefined(error) || error === null) + if ( _.isUndefined(error) || error === null ) return ""; - if (_.isString(error)) + if ( _.isString(error) ) return error; - if (!_.isError(error) && _.isBuffer(error)) + if ( !_.isError(error) && _.isBuffer(error) ) return error.toString(); - if (!_.isError(error) && _.isObject(error)) + if ( !_.isError(error) && _.isObject(error) ) return util.inspect(error); - if (!_.isError(error)) + if ( !_.isError(error) ) return '' + error; - if (_.isUndefined(error.message)) + if ( _.isUndefined(error.message) ) return "Unknown error"; switch (error.message) { case "Error: read ECONNRESET": @@ -260,35 +265,36 @@ class TestSteps { } - callback = function (){ + callback = function () { const self = this; return { - startSuite: function(suite) { + startSuite: function (suite) { console.log('------ suite started'); - self.reportTestSuiteActions([ { type: 'StartSuite', data: suite }]); + self.reportTestSuiteActions([{ type: 'StartSuite', data: suite }]); self._requestStarted(); }, - finishSuite: function(suite) { - self.reportTestSuiteActions([ { type: 'FinishSuite', data: suite }]); + finishSuite: function (suite) { + self.reportTestSuiteActions([{ type: 'FinishSuite', data: suite }]); self._requestFinished(); }, - startTest: function(test) { - self.reportTestSuiteActions([ { type: 'StartSuiteTest', data: test }]); + startTest: function (test) { + self.reportTestSuiteActions([{ type: 'StartSuiteTest', data: test }]); self._requestStarted(); }, - finishTest: function(test) { - self.reportTestSuiteActions([ { type: 'FinishSuiteTest', data: test }]); + finishTest: function (test) { + self.reportTestSuiteActions([{ type: 'FinishSuiteTest', data: test }]); self._requestFinished(); } } } - _requestStarted(){ + _requestStarted() { console.log('---------') console.log('requestStarted'); this.requestsInProgress = this.requestsInProgress + 1; } - reportTestSuiteActions(suiteActions){ + + reportTestSuiteActions(suiteActions) { console.log('---------') console.log('reportTestSuiteActions'); this.sendMsg({ @@ -296,12 +302,13 @@ class TestSteps { data: suiteActions }); } - _requestFinished(result){ + + _requestFinished(result) { console.log('---------') console.log('_requestFinished'); this.requestsInProgress = this.requestsInProgress - 1; this.resultFinished(result); - if (this.requestsInProgress === 0 && !this.scriptRunning) { + if ( this.requestsInProgress === 0 && !this.scriptRunning ) { // this._done(); } } @@ -309,32 +316,35 @@ class TestSteps { resultFinished(result, earlyTermination) { console.log('---------') console.log('resultFinished'); - if (_.isObject(result) && !result.isFinished) { - if (earlyTermination && result.data.url) { + if ( _.isObject(result) && !result.isFinished ) { + if ( earlyTermination && result.data.url ) { result.setTraceStatus('Terminated Early', EarlyTerminationMsg); // result.addTrace('Error', {}, EarlyTerminationMsg); } result.finished(); - if (!result.isEmpty()) { + if ( !result.isEmpty() ) { this.sendMsg({ type: "Result", data: result.data }); } let index = this.activeResults.indexOf(result); - if (index !== -1) + if ( index !== -1 ) this.activeResults.splice(index, 1); - if (result.id) + if ( result.id ) this.resultsById.delete(result.id); } } - sendMsg(result){ + sendMsg(result) { console.log('---------') console.log('sendMsg'); return new Promise(function (resolve, reject) { - if (process.env.TESTABLE_RESULT_FILE) { - fs.writeFile(process.env.TESTABLE_RESULT_FILE, JSON.stringify(result) + '\n', { encoding: 'utf8', flag: 'a' }, resolve); + if ( process.env.TESTABLE_RESULT_FILE ) { + fs.writeFile(process.env.TESTABLE_RESULT_FILE, JSON.stringify(result) + '\n', { + encoding: 'utf8', + flag: 'a' + }, resolve); } else { console.log('[Result] ' + JSON.stringify(result, null, '\t')); resolve(); From 42c1c09cda2529fe57d86c6891c3a72623885be6 Mon Sep 17 00:00:00 2001 From: Aamir Mahmood Date: Tue, 22 Jun 2021 00:30:45 +0500 Subject: [PATCH 29/70] more consoles --- lib/testable-test.js | 44 -------------------------------------------- 1 file changed, 44 deletions(-) diff --git a/lib/testable-test.js b/lib/testable-test.js index 69701df..a9565d2 100644 --- a/lib/testable-test.js +++ b/lib/testable-test.js @@ -355,47 +355,3 @@ class TestSteps { } module.exports = TestSteps; - - -/* - -const webdriver = require('selenium-webdriver'); -const util = require('util'); -const fs = require('fs'); -const writeFile = util.promisify(fs.writeFile); -const path = require('path'); -const { expect } = require('chai'); - -async function takeScreenshot(driver, file){ - let image = await driver.takeScreenshot(); - await writeFile(file, image, 'base64'); -} - -describe('DefaultTest', () => { - let driver = new webdriver.Builder() - .withCapabilities(webdriver.Capabilities.chrome()) - .build(); - - it('should go to google.com and check title', async () => { - await driver.get('https://www.google.com'); - await takeScreenshot(driver, path.join(process.env.OUTPUT_DIR || '.', 'HomePage.png')); - const title = await driver.getTitle(); - expect(title).to.equal('Google'); - }); - - after(async () => driver.quit()); -}); - - -{ - "name": "webdriver-testable-demo", - "version": "0.0.1", - "description": "Simple Webdriver Javascript Example", - "author": "Testable", - "devDependencies": { - "testable-utils": "0.5.9", - "selenium-webdriver": "3.6.0", - "mocha": "8.1.3", - "chai": "4.2.0" -} -}*/ From 87abf2ecd3755aaa473d9213f8da9a9f6c403208 Mon Sep 17 00:00:00 2001 From: Aamir Mahmood Date: Tue, 22 Jun 2021 15:26:46 +0500 Subject: [PATCH 30/70] removed extra code --- lib/main.js | 4 +-- lib/testable-test.js | 86 -------------------------------------------- 2 files changed, 2 insertions(+), 88 deletions(-) diff --git a/lib/main.js b/lib/main.js index 2206203..2d6bcd6 100644 --- a/lib/main.js +++ b/lib/main.js @@ -135,8 +135,8 @@ if (registerCommands) { } let steps; -function testSteps(name){ - const StepsClass = new TestSteps(name); +function testSteps(){ + const StepsClass = new TestSteps(); const stepsObj = {}; stepsObj.describe = StepsClass.describe.bind(StepsClass); diff --git a/lib/testable-test.js b/lib/testable-test.js index a9565d2..993e349 100644 --- a/lib/testable-test.js +++ b/lib/testable-test.js @@ -8,11 +8,6 @@ const EarlyTerminationMsg = 'Connection closed early when test was stopped'; class TestSteps { - requestsInProgress = 0; - scriptRunning = false; - activeResults = []; - resultsById = new Map(); - constructor() { this.cb = this.callback; this.finish(); @@ -226,73 +221,25 @@ class TestSteps { } } - filterStackTrace(stack) { - const lines = stack.split('\n'); - var answer = ''; - var hitScriptLine = false; - _.forEach(lines, function (line) { - var trimmedLine = line.trim(); - if ( !hitScriptLine ) - answer += line + '\n'; - if ( trimmedLine.indexOf('at script.js') === 0 || trimmedLine.indexOf('(script.js') > 0 ) - hitScriptLine = true; - }); - return answer; - } - - toErrorContent(error, msgOnly) { - if ( _.isUndefined(error) || error === null ) - return ""; - if ( _.isString(error) ) - return error; - if ( !_.isError(error) && _.isBuffer(error) ) - return error.toString(); - if ( !_.isError(error) && _.isObject(error) ) - return util.inspect(error); - if ( !_.isError(error) ) - return '' + error; - if ( _.isUndefined(error.message) ) - return "Unknown error"; - switch (error.message) { - case "Error: read ECONNRESET": - case "Error: socket hang up": - return "Connection closed unexpectedly"; - case "connect ETIMEDOUT": - return "Connect timed out"; - default: - return msgOnly ? error.message : this.filterStackTrace(VError.fullStack(error)); - } - } - - callback = function () { const self = this; return { startSuite: function (suite) { console.log('------ suite started'); self.reportTestSuiteActions([{ type: 'StartSuite', data: suite }]); - self._requestStarted(); }, finishSuite: function (suite) { self.reportTestSuiteActions([{ type: 'FinishSuite', data: suite }]); - self._requestFinished(); }, startTest: function (test) { self.reportTestSuiteActions([{ type: 'StartSuiteTest', data: test }]); - self._requestStarted(); }, finishTest: function (test) { self.reportTestSuiteActions([{ type: 'FinishSuiteTest', data: test }]); - self._requestFinished(); } } } - _requestStarted() { - console.log('---------') - console.log('requestStarted'); - this.requestsInProgress = this.requestsInProgress + 1; - } reportTestSuiteActions(suiteActions) { console.log('---------') @@ -303,39 +250,6 @@ class TestSteps { }); } - _requestFinished(result) { - console.log('---------') - console.log('_requestFinished'); - this.requestsInProgress = this.requestsInProgress - 1; - this.resultFinished(result); - if ( this.requestsInProgress === 0 && !this.scriptRunning ) { - // this._done(); - } - } - - resultFinished(result, earlyTermination) { - console.log('---------') - console.log('resultFinished'); - if ( _.isObject(result) && !result.isFinished ) { - if ( earlyTermination && result.data.url ) { - result.setTraceStatus('Terminated Early', EarlyTerminationMsg); - // result.addTrace('Error', {}, EarlyTerminationMsg); - } - result.finished(); - if ( !result.isEmpty() ) { - this.sendMsg({ - type: "Result", - data: result.data - }); - } - let index = this.activeResults.indexOf(result); - if ( index !== -1 ) - this.activeResults.splice(index, 1); - if ( result.id ) - this.resultsById.delete(result.id); - } - } - sendMsg(result) { console.log('---------') console.log('sendMsg'); From 2fae74b554bff3e5a6caf2560f9fc5371714ae4a Mon Sep 17 00:00:00 2001 From: Aamir Mahmood Date: Tue, 22 Jun 2021 15:46:32 +0500 Subject: [PATCH 31/70] more logs --- lib/testable-test.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/testable-test.js b/lib/testable-test.js index 993e349..c82add0 100644 --- a/lib/testable-test.js +++ b/lib/testable-test.js @@ -25,6 +25,9 @@ class TestSteps { } async finish() { + + console.log('-------------'); + console.log('finish'); if ( this.suites ) for ( const suite of this.suites ) { await this._onSuiteFinish(suite); @@ -137,6 +140,8 @@ class TestSteps { } async _onSuiteStart(suite) { + console.log('-------------'); + console.log('_onSuiteStart'); const before = suite._before || this._before; if ( before ) await this._executeFn(before); @@ -146,6 +151,9 @@ class TestSteps { } async _onSuiteFinish(suite) { + + console.log('-------------'); + console.log('_onSuiteFinish'); suite.finished = Date.now(); suite.duration = Date.now() - suite.started; From 189cb4eb5248565e55524b1e7c32e0c09c76151c Mon Sep 17 00:00:00 2001 From: Aamir Mahmood Date: Tue, 22 Jun 2021 15:53:18 +0500 Subject: [PATCH 32/70] more logs --- lib/testable-test.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/testable-test.js b/lib/testable-test.js index c82add0..e696f76 100644 --- a/lib/testable-test.js +++ b/lib/testable-test.js @@ -162,6 +162,9 @@ class TestSteps { await this._executeFn(after); this.suites.pop(); + console.log('-------------'); + console.log('this.cb.finishSuite'); + console.log(this.cb.finishSuite); if ( this.cb.finishSuite ) this.cb.finishSuite(suite); } @@ -237,12 +240,15 @@ class TestSteps { self.reportTestSuiteActions([{ type: 'StartSuite', data: suite }]); }, finishSuite: function (suite) { + console.log('------ suite started'); self.reportTestSuiteActions([{ type: 'FinishSuite', data: suite }]); }, startTest: function (test) { + console.log('------ suite started'); self.reportTestSuiteActions([{ type: 'StartSuiteTest', data: test }]); }, finishTest: function (test) { + console.log('------ suite started'); self.reportTestSuiteActions([{ type: 'FinishSuiteTest', data: test }]); } } From bff6ab307ea34b33f61eaf4fb2c553e001ff9212 Mon Sep 17 00:00:00 2001 From: Aamir Mahmood Date: Tue, 22 Jun 2021 15:59:23 +0500 Subject: [PATCH 33/70] some code fixes --- lib/testable-test.js | 29 +++++++++++++++++++++-------- package.json | 3 +-- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/lib/testable-test.js b/lib/testable-test.js index e696f76..873d9bf 100644 --- a/lib/testable-test.js +++ b/lib/testable-test.js @@ -1,10 +1,4 @@ const { v4: uuidv4 } = require('uuid'); -let VError = require('verror'); -let util = require('util'); -const _ = require("lodash"); - -const EarlyTerminationMsg = 'Connection closed early when test was stopped'; - class TestSteps { @@ -232,6 +226,25 @@ class TestSteps { } } + callback = { + startSuite: function (suite) { + console.log('------ suite started'); + TestSteps.reportTestSuiteActions([{ type: 'StartSuite', data: suite }]); + }, + finishSuite: function (suite) { + console.log('------ suite started'); + TestSteps.reportTestSuiteActions([{ type: 'FinishSuite', data: suite }]); + }, + startTest: function (test) { + console.log('------ suite started'); + TestSteps.reportTestSuiteActions([{ type: 'StartSuiteTest', data: test }]); + }, + finishTest: function (test) { + console.log('------ suite started'); + TestSteps.reportTestSuiteActions([{ type: 'FinishSuiteTest', data: test }]); + } + } + /* callback = function () { const self = this; return { @@ -253,9 +266,9 @@ class TestSteps { } } } +*/ - - reportTestSuiteActions(suiteActions) { + static reportTestSuiteActions(suiteActions) { console.log('---------') console.log('reportTestSuiteActions'); this.sendMsg({ diff --git a/package.json b/package.json index 9f8b9d2..37d7ae2 100644 --- a/package.json +++ b/package.json @@ -22,8 +22,7 @@ "babyparse": "^0.4.6", "lodash": "^4.17.21", "request": "^2.88.2", - "uuid": "^3.4.0", - "verror": "^1.10.0" + "uuid": "^3.4.0" }, "typings": "./index.d.ts" } From a58e2e3ec87f2e4d3228be9cee5e8668eb4fe4a2 Mon Sep 17 00:00:00 2001 From: Aamir Mahmood Date: Tue, 22 Jun 2021 16:00:42 +0500 Subject: [PATCH 34/70] some code fixes --- lib/testable-test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/testable-test.js b/lib/testable-test.js index 873d9bf..0d3009a 100644 --- a/lib/testable-test.js +++ b/lib/testable-test.js @@ -271,13 +271,13 @@ class TestSteps { static reportTestSuiteActions(suiteActions) { console.log('---------') console.log('reportTestSuiteActions'); - this.sendMsg({ + TestSteps.sendMsg({ type: "TestSuiteActions", data: suiteActions }); } - sendMsg(result) { + static sendMsg(result) { console.log('---------') console.log('sendMsg'); return new Promise(function (resolve, reject) { From 08aac1faf221533402fb658bf8e24127cb9623ef Mon Sep 17 00:00:00 2001 From: Aamir Mahmood Date: Tue, 22 Jun 2021 16:02:50 +0500 Subject: [PATCH 35/70] fs undefined fixed --- lib/testable-test.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/testable-test.js b/lib/testable-test.js index 0d3009a..26f2aef 100644 --- a/lib/testable-test.js +++ b/lib/testable-test.js @@ -1,4 +1,5 @@ const { v4: uuidv4 } = require('uuid'); +const fs = require('fs'); class TestSteps { From d5c27dbd2651e29ca2eb570afaf8bac9ac2c142d Mon Sep 17 00:00:00 2001 From: Aamir Mahmood Date: Tue, 22 Jun 2021 16:08:41 +0500 Subject: [PATCH 36/70] removed consoles --- lib/testable-test.js | 65 ++------------------------------------------ 1 file changed, 2 insertions(+), 63 deletions(-) diff --git a/lib/testable-test.js b/lib/testable-test.js index 26f2aef..e485de7 100644 --- a/lib/testable-test.js +++ b/lib/testable-test.js @@ -20,9 +20,6 @@ class TestSteps { } async finish() { - - console.log('-------------'); - console.log('finish'); if ( this.suites ) for ( const suite of this.suites ) { await this._onSuiteFinish(suite); @@ -36,25 +33,18 @@ class TestSteps { } async describe(suiteName, fn) { - console.log('------------') - console.log('describe') const suite = this._createSuite(this._getSuitePrefix() + suiteName, false); fn(); await this._executeSuite(suite); } async it(testName, fn) { - console.log('------------') - console.log('it') let suite = this.currentSuite; - console.log(suite.name); if ( !suite ) { suite = this._createSuite('Default Suite', true); await this._onSuiteStart(suite); } let test = this._createTest(suite, testName, fn); - console.log(test); - console.log(suite.executeTestsImmediately); if ( suite.executeTestsImmediately ) { await this._executeTest(suite, test); await this._onSuiteFinish(suite); @@ -120,10 +110,6 @@ class TestSteps { } async _executeSuite(suite) { - - console.log('-------------'); - console.log('_executeSuite'); - console.log(suite.tests); await this._onSuiteStart(suite); if ( suite.tests ) @@ -135,8 +121,6 @@ class TestSteps { } async _onSuiteStart(suite) { - console.log('-------------'); - console.log('_onSuiteStart'); const before = suite._before || this._before; if ( before ) await this._executeFn(before); @@ -146,9 +130,6 @@ class TestSteps { } async _onSuiteFinish(suite) { - - console.log('-------------'); - console.log('_onSuiteFinish'); suite.finished = Date.now(); suite.duration = Date.now() - suite.started; @@ -157,16 +138,11 @@ class TestSteps { await this._executeFn(after); this.suites.pop(); - console.log('-------------'); - console.log('this.cb.finishSuite'); - console.log(this.cb.finishSuite); if ( this.cb.finishSuite ) this.cb.finishSuite(suite); } async _executeTest(suite, test) { - console.log('--------------'); - console.log('_executeTest'); const beforeEach = suite._beforeEach || this._beforeEach; if ( beforeEach ) await this._executeFn(beforeEach); @@ -179,8 +155,6 @@ class TestSteps { } async _executeStep(fn, suite, test) { - console.log('--------------'); - console.log('_executeStep'); if ( this.cb.startTest ) this.cb.startTest(test, suite); @@ -204,15 +178,10 @@ class TestSteps { } async _executeFn(fn) { - console.log('--------------'); - console.log('_executeFn'); - console.log(fn.length); const isAsync = fn.constructor.name === 'AsyncFunction'; if ( isAsync ) { - console.log('inAsync'); await fn(); } else if ( fn.length === 1 ) { - console.log('in if else'); await new Promise(function (resolve, reject) { fn(function (err) { if ( err ) @@ -222,56 +191,26 @@ class TestSteps { }); }); } else { - console.log('in fn'); fn(); } } callback = { startSuite: function (suite) { - console.log('------ suite started'); TestSteps.reportTestSuiteActions([{ type: 'StartSuite', data: suite }]); }, finishSuite: function (suite) { - console.log('------ suite started'); TestSteps.reportTestSuiteActions([{ type: 'FinishSuite', data: suite }]); }, startTest: function (test) { - console.log('------ suite started'); TestSteps.reportTestSuiteActions([{ type: 'StartSuiteTest', data: test }]); }, finishTest: function (test) { - console.log('------ suite started'); TestSteps.reportTestSuiteActions([{ type: 'FinishSuiteTest', data: test }]); } } - /* - callback = function () { - const self = this; - return { - startSuite: function (suite) { - console.log('------ suite started'); - self.reportTestSuiteActions([{ type: 'StartSuite', data: suite }]); - }, - finishSuite: function (suite) { - console.log('------ suite started'); - self.reportTestSuiteActions([{ type: 'FinishSuite', data: suite }]); - }, - startTest: function (test) { - console.log('------ suite started'); - self.reportTestSuiteActions([{ type: 'StartSuiteTest', data: test }]); - }, - finishTest: function (test) { - console.log('------ suite started'); - self.reportTestSuiteActions([{ type: 'FinishSuiteTest', data: test }]); - } - } - } -*/ static reportTestSuiteActions(suiteActions) { - console.log('---------') - console.log('reportTestSuiteActions'); TestSteps.sendMsg({ type: "TestSuiteActions", data: suiteActions @@ -279,8 +218,8 @@ class TestSteps { } static sendMsg(result) { - console.log('---------') - console.log('sendMsg'); + console.log('---------: sendMsg') + console.log(result); return new Promise(function (resolve, reject) { if ( process.env.TESTABLE_RESULT_FILE ) { fs.writeFile(process.env.TESTABLE_RESULT_FILE, JSON.stringify(result) + '\n', { From 1b7b746b4f5121c03792d171ea58883220f6f139 Mon Sep 17 00:00:00 2001 From: Aamir Mahmood Date: Tue, 22 Jun 2021 16:16:22 +0500 Subject: [PATCH 37/70] stringify log --- lib/testable-test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/testable-test.js b/lib/testable-test.js index e485de7..7c1d206 100644 --- a/lib/testable-test.js +++ b/lib/testable-test.js @@ -219,7 +219,7 @@ class TestSteps { static sendMsg(result) { console.log('---------: sendMsg') - console.log(result); + console.log(JSON.stringify(result) ); return new Promise(function (resolve, reject) { if ( process.env.TESTABLE_RESULT_FILE ) { fs.writeFile(process.env.TESTABLE_RESULT_FILE, JSON.stringify(result) + '\n', { From 2da70aeb417c82ed474b931ce19cd1eaf66ddb0a Mon Sep 17 00:00:00 2001 From: Aamir Mahmood Date: Tue, 22 Jun 2021 16:19:46 +0500 Subject: [PATCH 38/70] filepath test --- lib/testable-test.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/testable-test.js b/lib/testable-test.js index 7c1d206..6917a5f 100644 --- a/lib/testable-test.js +++ b/lib/testable-test.js @@ -220,6 +220,7 @@ class TestSteps { static sendMsg(result) { console.log('---------: sendMsg') console.log(JSON.stringify(result) ); + console.log(process.env.TESTABLE_RESULT_FILE ); return new Promise(function (resolve, reject) { if ( process.env.TESTABLE_RESULT_FILE ) { fs.writeFile(process.env.TESTABLE_RESULT_FILE, JSON.stringify(result) + '\n', { From c88657445716664172fb59e83b413809d4173e20 Mon Sep 17 00:00:00 2001 From: Aamir Mahmood Date: Tue, 22 Jun 2021 16:53:38 +0500 Subject: [PATCH 39/70] arrow functions --- lib/main.js | 2 -- lib/testable-test.js | 35 +++++++++++++++++------------------ 2 files changed, 17 insertions(+), 20 deletions(-) diff --git a/lib/main.js b/lib/main.js index 2d6bcd6..e8640bc 100644 --- a/lib/main.js +++ b/lib/main.js @@ -147,7 +147,6 @@ function testSteps(){ stepsObj.afterEach = StepsClass.afterEach.bind(StepsClass); steps = stepsObj; - } testSteps(); @@ -169,4 +168,3 @@ module.exports.before = steps.before; module.exports.after = steps.after; module.exports.beforeEach = steps.beforeEach; module.exports.afterEach = steps.afterEach; - diff --git a/lib/testable-test.js b/lib/testable-test.js index 6917a5f..44a4609 100644 --- a/lib/testable-test.js +++ b/lib/testable-test.js @@ -182,8 +182,8 @@ class TestSteps { if ( isAsync ) { await fn(); } else if ( fn.length === 1 ) { - await new Promise(function (resolve, reject) { - fn(function (err) { + await new Promise((resolve, reject) => { + fn((err) => { if ( err ) reject(new Error(err)); else @@ -195,33 +195,33 @@ class TestSteps { } } - callback = { - startSuite: function (suite) { - TestSteps.reportTestSuiteActions([{ type: 'StartSuite', data: suite }]); + callback = { + startSuite: (suite) => { + this.reportTestSuiteActions([{ type: 'StartSuite', data: suite }]); }, - finishSuite: function (suite) { - TestSteps.reportTestSuiteActions([{ type: 'FinishSuite', data: suite }]); + finishSuite: (suite) => { + this.reportTestSuiteActions([{ type: 'FinishSuite', data: suite }]); }, - startTest: function (test) { - TestSteps.reportTestSuiteActions([{ type: 'StartSuiteTest', data: test }]); + startTest: (test) => { + this.reportTestSuiteActions([{ type: 'StartSuiteTest', data: test }]); }, - finishTest: function (test) { - TestSteps.reportTestSuiteActions([{ type: 'FinishSuiteTest', data: test }]); + finishTest: (test) => { + this.reportTestSuiteActions([{ type: 'FinishSuiteTest', data: test }]); } } - static reportTestSuiteActions(suiteActions) { - TestSteps.sendMsg({ + reportTestSuiteActions(suiteActions) { + this.sendMsg({ type: "TestSuiteActions", data: suiteActions }); } - static sendMsg(result) { + sendMsg(result) { console.log('---------: sendMsg') - console.log(JSON.stringify(result) ); - console.log(process.env.TESTABLE_RESULT_FILE ); - return new Promise(function (resolve, reject) { + console.log(JSON.stringify(result)); + console.log(process.env.TESTABLE_RESULT_FILE); + return new Promise((resolve, reject) => { if ( process.env.TESTABLE_RESULT_FILE ) { fs.writeFile(process.env.TESTABLE_RESULT_FILE, JSON.stringify(result) + '\n', { encoding: 'utf8', @@ -233,7 +233,6 @@ class TestSteps { } }); } - } module.exports = TestSteps; From 427cecdc2b9e3de38a2b9a16becb49b486b6a5d9 Mon Sep 17 00:00:00 2001 From: Aamir Mahmood Date: Tue, 22 Jun 2021 16:56:58 +0500 Subject: [PATCH 40/70] console removed --- lib/testable-test.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/testable-test.js b/lib/testable-test.js index 44a4609..1e3a136 100644 --- a/lib/testable-test.js +++ b/lib/testable-test.js @@ -218,9 +218,6 @@ class TestSteps { } sendMsg(result) { - console.log('---------: sendMsg') - console.log(JSON.stringify(result)); - console.log(process.env.TESTABLE_RESULT_FILE); return new Promise((resolve, reject) => { if ( process.env.TESTABLE_RESULT_FILE ) { fs.writeFile(process.env.TESTABLE_RESULT_FILE, JSON.stringify(result) + '\n', { From 7876d80b4b8b6b4eddcbba1cd7cb8fd8a954e97d Mon Sep 17 00:00:00 2001 From: Aamir Mahmood Date: Tue, 22 Jun 2021 17:54:13 +0500 Subject: [PATCH 41/70] code commented to check why its not closing --- lib/main.js | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/lib/main.js b/lib/main.js index e8640bc..f6791d8 100644 --- a/lib/main.js +++ b/lib/main.js @@ -133,22 +133,22 @@ if (registerCommands) { wdio.registerEventsCommands(brwsr, events, doNotWait, waitForFinish); }); } - -let steps; -function testSteps(){ - const StepsClass = new TestSteps(); - - const stepsObj = {}; - stepsObj.describe = StepsClass.describe.bind(StepsClass); - stepsObj.it = StepsClass.it.bind(StepsClass); - stepsObj.before = StepsClass.before.bind(StepsClass); - stepsObj.after = StepsClass.after.bind(StepsClass); - stepsObj.beforeEach = StepsClass.beforeEach.bind(StepsClass); - stepsObj.afterEach = StepsClass.afterEach.bind(StepsClass); - - steps = stepsObj; -} -testSteps(); +// +// let steps; +// function testSteps(){ +// const StepsClass = new TestSteps(); +// +// const stepsObj = {}; +// stepsObj.describe = StepsClass.describe.bind(StepsClass); +// stepsObj.it = StepsClass.it.bind(StepsClass); +// stepsObj.before = StepsClass.before.bind(StepsClass); +// stepsObj.after = StepsClass.after.bind(StepsClass); +// stepsObj.beforeEach = StepsClass.beforeEach.bind(StepsClass); +// stepsObj.afterEach = StepsClass.afterEach.bind(StepsClass); +// +// steps = stepsObj; +// } +// testSteps(); module.exports.isLocal = isLocal; module.exports.isSmokeTest = isSmokeTest; @@ -161,10 +161,10 @@ module.exports.events = events; module.exports.dataTable = csv; module.exports.waitForFinish = waitForFinish; - -module.exports.describe = steps.describe; -module.exports.it = steps.it; -module.exports.before = steps.before; -module.exports.after = steps.after; -module.exports.beforeEach = steps.beforeEach; -module.exports.afterEach = steps.afterEach; +// +// module.exports.describe = steps.describe; +// module.exports.it = steps.it; +// module.exports.before = steps.before; +// module.exports.after = steps.after; +// module.exports.beforeEach = steps.beforeEach; +// module.exports.afterEach = steps.afterEach; From 9e5c13ade0d44cab149bd7988a4c1488ca08be36 Mon Sep 17 00:00:00 2001 From: Aamir Mahmood Date: Tue, 22 Jun 2021 18:49:20 +0500 Subject: [PATCH 42/70] code uncommented --- lib/main.js | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/lib/main.js b/lib/main.js index f6791d8..e8640bc 100644 --- a/lib/main.js +++ b/lib/main.js @@ -133,22 +133,22 @@ if (registerCommands) { wdio.registerEventsCommands(brwsr, events, doNotWait, waitForFinish); }); } -// -// let steps; -// function testSteps(){ -// const StepsClass = new TestSteps(); -// -// const stepsObj = {}; -// stepsObj.describe = StepsClass.describe.bind(StepsClass); -// stepsObj.it = StepsClass.it.bind(StepsClass); -// stepsObj.before = StepsClass.before.bind(StepsClass); -// stepsObj.after = StepsClass.after.bind(StepsClass); -// stepsObj.beforeEach = StepsClass.beforeEach.bind(StepsClass); -// stepsObj.afterEach = StepsClass.afterEach.bind(StepsClass); -// -// steps = stepsObj; -// } -// testSteps(); + +let steps; +function testSteps(){ + const StepsClass = new TestSteps(); + + const stepsObj = {}; + stepsObj.describe = StepsClass.describe.bind(StepsClass); + stepsObj.it = StepsClass.it.bind(StepsClass); + stepsObj.before = StepsClass.before.bind(StepsClass); + stepsObj.after = StepsClass.after.bind(StepsClass); + stepsObj.beforeEach = StepsClass.beforeEach.bind(StepsClass); + stepsObj.afterEach = StepsClass.afterEach.bind(StepsClass); + + steps = stepsObj; +} +testSteps(); module.exports.isLocal = isLocal; module.exports.isSmokeTest = isSmokeTest; @@ -161,10 +161,10 @@ module.exports.events = events; module.exports.dataTable = csv; module.exports.waitForFinish = waitForFinish; -// -// module.exports.describe = steps.describe; -// module.exports.it = steps.it; -// module.exports.before = steps.before; -// module.exports.after = steps.after; -// module.exports.beforeEach = steps.beforeEach; -// module.exports.afterEach = steps.afterEach; + +module.exports.describe = steps.describe; +module.exports.it = steps.it; +module.exports.before = steps.before; +module.exports.after = steps.after; +module.exports.beforeEach = steps.beforeEach; +module.exports.afterEach = steps.afterEach; From 57000e328c4681665ee3e97cc2a073afdc1d7ad2 Mon Sep 17 00:00:00 2001 From: Aamir Mahmood Date: Tue, 22 Jun 2021 19:20:15 +0500 Subject: [PATCH 43/70] callback function updated --- lib/testable-test.js | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/lib/testable-test.js b/lib/testable-test.js index 1e3a136..f454445 100644 --- a/lib/testable-test.js +++ b/lib/testable-test.js @@ -4,7 +4,21 @@ const fs = require('fs'); class TestSteps { constructor() { - this.cb = this.callback; + this.cb = { + startSuite: (suite) => { + this.reportTestSuiteActions([{ type: 'StartSuite', data: suite }]); + }, + finishSuite: (suite) => { + this.reportTestSuiteActions([{ type: 'FinishSuite', data: suite }]); + }, + startTest: (test) => { + this.reportTestSuiteActions([{ type: 'StartSuiteTest', data: test }]); + }, + finishTest: (test) => { + this.reportTestSuiteActions([{ type: 'FinishSuiteTest', data: test }]); + } + }; + this.finish(); } @@ -195,21 +209,6 @@ class TestSteps { } } - callback = { - startSuite: (suite) => { - this.reportTestSuiteActions([{ type: 'StartSuite', data: suite }]); - }, - finishSuite: (suite) => { - this.reportTestSuiteActions([{ type: 'FinishSuite', data: suite }]); - }, - startTest: (test) => { - this.reportTestSuiteActions([{ type: 'StartSuiteTest', data: test }]); - }, - finishTest: (test) => { - this.reportTestSuiteActions([{ type: 'FinishSuiteTest', data: test }]); - } - } - reportTestSuiteActions(suiteActions) { this.sendMsg({ type: "TestSuiteActions", From 450f452bb07f3693b83b7193bedd233df268a010 Mon Sep 17 00:00:00 2001 From: Aamir Mahmood Date: Tue, 22 Jun 2021 19:46:09 +0500 Subject: [PATCH 44/70] code removed for testing --- lib/main.js | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/lib/main.js b/lib/main.js index e8640bc..f1ad519 100644 --- a/lib/main.js +++ b/lib/main.js @@ -133,22 +133,22 @@ if (registerCommands) { wdio.registerEventsCommands(brwsr, events, doNotWait, waitForFinish); }); } - -let steps; -function testSteps(){ - const StepsClass = new TestSteps(); - - const stepsObj = {}; - stepsObj.describe = StepsClass.describe.bind(StepsClass); - stepsObj.it = StepsClass.it.bind(StepsClass); - stepsObj.before = StepsClass.before.bind(StepsClass); - stepsObj.after = StepsClass.after.bind(StepsClass); - stepsObj.beforeEach = StepsClass.beforeEach.bind(StepsClass); - stepsObj.afterEach = StepsClass.afterEach.bind(StepsClass); - - steps = stepsObj; -} -testSteps(); +// +// let steps; +// function testSteps(){ +// const StepsClass = new TestSteps(); +// +// const stepsObj = {}; +// stepsObj.describe = StepsClass.describe.bind(StepsClass); +// stepsObj.it = StepsClass.it.bind(StepsClass); +// stepsObj.before = StepsClass.before.bind(StepsClass); +// stepsObj.after = StepsClass.after.bind(StepsClass); +// stepsObj.beforeEach = StepsClass.beforeEach.bind(StepsClass); +// stepsObj.afterEach = StepsClass.afterEach.bind(StepsClass); +// +// steps = stepsObj; +// } +// testSteps(); module.exports.isLocal = isLocal; module.exports.isSmokeTest = isSmokeTest; @@ -162,9 +162,9 @@ module.exports.dataTable = csv; module.exports.waitForFinish = waitForFinish; -module.exports.describe = steps.describe; -module.exports.it = steps.it; -module.exports.before = steps.before; -module.exports.after = steps.after; -module.exports.beforeEach = steps.beforeEach; -module.exports.afterEach = steps.afterEach; +// module.exports.describe = steps.describe; +// module.exports.it = steps.it; +// module.exports.before = steps.before; +// module.exports.after = steps.after; +// module.exports.beforeEach = steps.beforeEach; +// module.exports.afterEach = steps.afterEach; From 46623d0a647754fce929910bedc3dff6eadc7b5c Mon Sep 17 00:00:00 2001 From: Aamir Mahmood Date: Tue, 22 Jun 2021 20:01:12 +0500 Subject: [PATCH 45/70] why is node running added --- lib/main.js | 50 ++++++++++++++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 22 deletions(-) diff --git a/lib/main.js b/lib/main.js index f1ad519..c10b991 100644 --- a/lib/main.js +++ b/lib/main.js @@ -1,3 +1,4 @@ +const log = require('why-is-node-running') // should be your first require const fs = require('fs'); const _ = require('lodash'); @@ -133,22 +134,27 @@ if (registerCommands) { wdio.registerEventsCommands(brwsr, events, doNotWait, waitForFinish); }); } -// -// let steps; -// function testSteps(){ -// const StepsClass = new TestSteps(); -// -// const stepsObj = {}; -// stepsObj.describe = StepsClass.describe.bind(StepsClass); -// stepsObj.it = StepsClass.it.bind(StepsClass); -// stepsObj.before = StepsClass.before.bind(StepsClass); -// stepsObj.after = StepsClass.after.bind(StepsClass); -// stepsObj.beforeEach = StepsClass.beforeEach.bind(StepsClass); -// stepsObj.afterEach = StepsClass.afterEach.bind(StepsClass); -// -// steps = stepsObj; -// } -// testSteps(); + +let steps; +function testSteps(){ + const StepsClass = new TestSteps(); + + const stepsObj = {}; + stepsObj.describe = StepsClass.describe.bind(StepsClass); + stepsObj.it = StepsClass.it.bind(StepsClass); + stepsObj.before = StepsClass.before.bind(StepsClass); + stepsObj.after = StepsClass.after.bind(StepsClass); + stepsObj.beforeEach = StepsClass.beforeEach.bind(StepsClass); + stepsObj.afterEach = StepsClass.afterEach.bind(StepsClass); + + steps = stepsObj; +} +testSteps(); + + +setTimeout(function () { + log() // logs out active handles that are keeping node running +}, 1000); module.exports.isLocal = isLocal; module.exports.isSmokeTest = isSmokeTest; @@ -162,9 +168,9 @@ module.exports.dataTable = csv; module.exports.waitForFinish = waitForFinish; -// module.exports.describe = steps.describe; -// module.exports.it = steps.it; -// module.exports.before = steps.before; -// module.exports.after = steps.after; -// module.exports.beforeEach = steps.beforeEach; -// module.exports.afterEach = steps.afterEach; +module.exports.describe = steps.describe; +module.exports.it = steps.it; +module.exports.before = steps.before; +module.exports.after = steps.after; +module.exports.beforeEach = steps.beforeEach; +module.exports.afterEach = steps.afterEach; From fd7ad87c9193216a87f1b6647009fed0ee7efee2 Mon Sep 17 00:00:00 2001 From: Aamir Mahmood Date: Tue, 22 Jun 2021 20:08:15 +0500 Subject: [PATCH 46/70] why is node running added --- lib/main.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/main.js b/lib/main.js index c10b991..add1d6d 100644 --- a/lib/main.js +++ b/lib/main.js @@ -1,4 +1,4 @@ -const log = require('why-is-node-running') // should be your first require +const runningLog = require('why-is-node-running') // should be your first require const fs = require('fs'); const _ = require('lodash'); @@ -153,7 +153,7 @@ testSteps(); setTimeout(function () { - log() // logs out active handles that are keeping node running + runningLog() // logs out active handles that are keeping node running }, 1000); module.exports.isLocal = isLocal; From dbb49967aff43cf98a219c7098ec5afc454d496b Mon Sep 17 00:00:00 2001 From: Aamir Mahmood Date: Tue, 22 Jun 2021 20:10:41 +0500 Subject: [PATCH 47/70] why is node running removed --- .gitignore | 1 + lib/main.js | 7 ------- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index 86416e1..20b583b 100644 --- a/.gitignore +++ b/.gitignore @@ -37,3 +37,4 @@ jspm_packages .node_repl_history test/ +.idea diff --git a/lib/main.js b/lib/main.js index add1d6d..3ee3001 100644 --- a/lib/main.js +++ b/lib/main.js @@ -1,5 +1,3 @@ -const runningLog = require('why-is-node-running') // should be your first require - const fs = require('fs'); const _ = require('lodash'); const createLog = require('./log'); @@ -151,11 +149,6 @@ function testSteps(){ } testSteps(); - -setTimeout(function () { - runningLog() // logs out active handles that are keeping node running -}, 1000); - module.exports.isLocal = isLocal; module.exports.isSmokeTest = isSmokeTest; module.exports.info = info; From 6500cb7796e977b1850d8fc17b6e712a5bead0c5 Mon Sep 17 00:00:00 2001 From: Aamir Mahmood Date: Tue, 22 Jun 2021 20:26:14 +0500 Subject: [PATCH 48/70] event watcher commented --- lib/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/main.js b/lib/main.js index 3ee3001..dd101c7 100644 --- a/lib/main.js +++ b/lib/main.js @@ -112,7 +112,7 @@ const registerCommands = typeof browser !== 'undefined' && _.isUndefined(browser const events = new EventEmitter(); if (process.env.TESTABLE_EVENTS_FILE) { - eventsWatcher(process.env.TESTABLE_EVENTS_FILE, events, log); + // eventsWatcher(process.env.TESTABLE_EVENTS_FILE, events, log); } if (registerCommands) { From d36e23fc771162723b313f87150e6a2d2fa1c5ba Mon Sep 17 00:00:00 2001 From: Aamir Mahmood Date: Tue, 22 Jun 2021 20:38:47 +0500 Subject: [PATCH 49/70] event watcher enabled --- lib/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/main.js b/lib/main.js index dd101c7..3ee3001 100644 --- a/lib/main.js +++ b/lib/main.js @@ -112,7 +112,7 @@ const registerCommands = typeof browser !== 'undefined' && _.isUndefined(browser const events = new EventEmitter(); if (process.env.TESTABLE_EVENTS_FILE) { - // eventsWatcher(process.env.TESTABLE_EVENTS_FILE, events, log); + eventsWatcher(process.env.TESTABLE_EVENTS_FILE, events, log); } if (registerCommands) { From d1b34123d5d88765ef7dd4967768920a547f717f Mon Sep 17 00:00:00 2001 From: Aamir Mahmood Date: Tue, 22 Jun 2021 21:40:18 +0500 Subject: [PATCH 50/70] events watcher updated --- lib/events-watcher.js | 3 ++- lib/main.js | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/events-watcher.js b/lib/events-watcher.js index 5bc8f24..480ff2c 100644 --- a/lib/events-watcher.js +++ b/lib/events-watcher.js @@ -22,7 +22,8 @@ function watchForEvents(fileName, events, log) { log.error('Error tailing live event', data); }); tail.watch(); + events.finish = () => { tail.unwatch(); } return tail; } -module.exports = watchForEvents; \ No newline at end of file +module.exports = watchForEvents; diff --git a/lib/main.js b/lib/main.js index 3ee3001..57fe24f 100644 --- a/lib/main.js +++ b/lib/main.js @@ -112,7 +112,9 @@ const registerCommands = typeof browser !== 'undefined' && _.isUndefined(browser const events = new EventEmitter(); if (process.env.TESTABLE_EVENTS_FILE) { + events.once('newListener', () => { // i.e. run this init code one time upon a new listener being registered eventsWatcher(process.env.TESTABLE_EVENTS_FILE, events, log); + }) } if (registerCommands) { From 1bbafda5c2196b8f353393b89291e7e42ff40603 Mon Sep 17 00:00:00 2001 From: Aamir Mahmood Date: Tue, 22 Jun 2021 21:50:33 +0500 Subject: [PATCH 51/70] events.finish(); added in README.md --- README.md | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 490a14c..8fcc9a5 100644 --- a/README.md +++ b/README.md @@ -289,7 +289,7 @@ dataTable #### Iterate CSV -Iterate over the CSV file, retrieving 1 or more rows. The iterator is global across the entire test execution. +Iterate over the CSV file, retrieving 1 or more rows. The iterator is global across the entire test execution. The `next()` function takes an optional `options` object that supports the following properties: @@ -311,7 +311,7 @@ dataTable **Node.js Only** -When running a Node.js script on Testable and use a 3rd party module that performs async actions you might need to tell Testable when the action is finished. Testable automatically instruments many modules so you don't need to do this including async, http, https, request, net, ws, socketio, engineio, tls, setTimeout, setInterval. +When running a Node.js script on Testable and use a 3rd party module that performs async actions you might need to tell Testable when the action is finished. Testable automatically instruments many modules so you don't need to do this including async, http, https, request, net, ws, socketio, engineio, tls, setTimeout, setInterval. For other async code use the below. @@ -347,8 +347,9 @@ execute(function(finished) { }); if (fireNow) { - // trigger the event when smoke testing or run locally for testing - events.emit('my-event', 'MSFT'); + // trigger the event when smoke testing or run locally for testing + events.emit('my-event', 'MSFT'); + events.finish() } ``` @@ -406,7 +407,7 @@ One command that has no `testable-utils` equivalent is `browser.testableScreensh
info
-
var result = 
+		
var result =
   browser.testableCsvGet(csvFile, index);
dataTable
   .open(csvFile)
@@ -414,7 +415,7 @@ One command that has no `testable-utils` equivalent is `browser.testableScreensh
   .then(function(result) { ... }
-
var result = 
+		
var result =
   browser.testableCsvRandom(csvFile);
dataTable
   .open(csvFile)
@@ -422,7 +423,7 @@ One command that has no `testable-utils` equivalent is `browser.testableScreensh
   .then(function(result) { ... }
-
var results = 
+		
var results =
   browser.testableCsvNext(csvFile[, options]);
dataTable
   .open(csvFile)
@@ -430,34 +431,34 @@ One command that has no `testable-utils` equivalent is `browser.testableScreensh
   .then(function(results) { ... }
-
var result = 
+		
var result =
   browser.testableResult([resource], [url]);
 browser.testableCounter(
-  result, 
-  name, 
-  [increment], 
+  result,
+  name,
+  [increment],
   [units]);
results([resource], [url])
   .counter(name, [increment], [units]);
-
var result = 
+		
var result =
   browser.testableResult([resource], [url]);
 browser.testableTiming(
-  result, 
-  name, 
-  timing, 
+  result,
+  name,
+  timing,
   [units]);
results([resource], [url])
   .timing(name, timing, [units]);
-
var result = 
+		
var result =
   browser.testableResult([resource], [url]);
 browser.testableHistogram(
-  result, 
-  name, 
-  bucket, 
+  result,
+  name,
+  bucket,
   [increment]);
results([resource], [url])
   .histogram(name, bucket, [increment]);
From da81a9b144bd1ef900142597595790a3d541f913 Mon Sep 17 00:00:00 2001 From: Aamir Mahmood Date: Tue, 22 Jun 2021 22:09:57 +0500 Subject: [PATCH 52/70] reporting message are updated --- lib/testable-test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/testable-test.js b/lib/testable-test.js index f454445..af6b1cf 100644 --- a/lib/testable-test.js +++ b/lib/testable-test.js @@ -211,8 +211,8 @@ class TestSteps { reportTestSuiteActions(suiteActions) { this.sendMsg({ - type: "TestSuiteActions", - data: suiteActions + type: suiteActions.type,//"TestSuiteActions", + data: suiteActions.data, }); } From 57d758b13124783049eb66e03057acec9ec23c1e Mon Sep 17 00:00:00 2001 From: Aamir Mahmood Date: Tue, 22 Jun 2021 22:14:53 +0500 Subject: [PATCH 53/70] report actions updated --- lib/testable-test.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/testable-test.js b/lib/testable-test.js index af6b1cf..9365269 100644 --- a/lib/testable-test.js +++ b/lib/testable-test.js @@ -210,13 +210,18 @@ class TestSteps { } reportTestSuiteActions(suiteActions) { - this.sendMsg({ - type: suiteActions.type,//"TestSuiteActions", - data: suiteActions.data, - }); - } - sendMsg(result) { + let type = suiteActions.type; + let contents = suiteActions.data; + + const currentSuite = this.currentSuite; + if ( currentSuite && type === 'FinishSuiteTest' && contents && contents.state === 'failed' ) + currentSuite.hasError = true; + + const result = { type: type, data: contents }; + + console.log('------------'); + console.log(JSON.stringify(result)); return new Promise((resolve, reject) => { if ( process.env.TESTABLE_RESULT_FILE ) { fs.writeFile(process.env.TESTABLE_RESULT_FILE, JSON.stringify(result) + '\n', { From 8bd00ae81913f3e9f9c89b01afcd41bf4197f179 Mon Sep 17 00:00:00 2001 From: Aamir Mahmood Date: Tue, 22 Jun 2021 22:19:14 +0500 Subject: [PATCH 54/70] report actions updated --- lib/testable-test.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/testable-test.js b/lib/testable-test.js index 9365269..35bcb02 100644 --- a/lib/testable-test.js +++ b/lib/testable-test.js @@ -6,16 +6,16 @@ class TestSteps { constructor() { this.cb = { startSuite: (suite) => { - this.reportTestSuiteActions([{ type: 'StartSuite', data: suite }]); + this.reportTestSuiteActions('StartSuite', suite ); }, finishSuite: (suite) => { - this.reportTestSuiteActions([{ type: 'FinishSuite', data: suite }]); + this.reportTestSuiteActions('FinishSuite', suite ); }, startTest: (test) => { - this.reportTestSuiteActions([{ type: 'StartSuiteTest', data: test }]); + this.reportTestSuiteActions('StartSuiteTest', test ); }, finishTest: (test) => { - this.reportTestSuiteActions([{ type: 'FinishSuiteTest', data: test }]); + this.reportTestSuiteActions('FinishSuiteTest', test ); } }; @@ -209,10 +209,10 @@ class TestSteps { } } - reportTestSuiteActions(suiteActions) { - - let type = suiteActions.type; - let contents = suiteActions.data; + reportTestSuiteActions(type, contents) { + // console.log(suiteActions); + // let type = suiteActions.type; + // let contents = suiteActions.data; const currentSuite = this.currentSuite; if ( currentSuite && type === 'FinishSuiteTest' && contents && contents.state === 'failed' ) From 4b293130a07f9a76acd2f15c307ffdf05409c770 Mon Sep 17 00:00:00 2001 From: Aamir Mahmood Date: Tue, 22 Jun 2021 22:20:53 +0500 Subject: [PATCH 55/70] console removed --- lib/testable-test.js | 7 ------- 1 file changed, 7 deletions(-) diff --git a/lib/testable-test.js b/lib/testable-test.js index 35bcb02..850db15 100644 --- a/lib/testable-test.js +++ b/lib/testable-test.js @@ -210,18 +210,11 @@ class TestSteps { } reportTestSuiteActions(type, contents) { - // console.log(suiteActions); - // let type = suiteActions.type; - // let contents = suiteActions.data; - const currentSuite = this.currentSuite; if ( currentSuite && type === 'FinishSuiteTest' && contents && contents.state === 'failed' ) currentSuite.hasError = true; const result = { type: type, data: contents }; - - console.log('------------'); - console.log(JSON.stringify(result)); return new Promise((resolve, reject) => { if ( process.env.TESTABLE_RESULT_FILE ) { fs.writeFile(process.env.TESTABLE_RESULT_FILE, JSON.stringify(result) + '\n', { From 0944afe3ea397c42289667f01647d2d76ccc607b Mon Sep 17 00:00:00 2001 From: Aamir Mahmood Date: Tue, 22 Jun 2021 22:29:44 +0500 Subject: [PATCH 56/70] error reporting added --- lib/testable-test.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/lib/testable-test.js b/lib/testable-test.js index 850db15..4e45b8e 100644 --- a/lib/testable-test.js +++ b/lib/testable-test.js @@ -1,5 +1,6 @@ const { v4: uuidv4 } = require('uuid'); const fs = require('fs'); +const util = require('util'); class TestSteps { @@ -227,6 +228,30 @@ class TestSteps { } }); } + + toErrorContent(error, msgOnly) { + if (_.isUndefined(error) || error === null) + return ""; + if (_.isString(error)) + return error; + if (!_.isError(error) && _.isBuffer(error)) + return error.toString(); + if (!_.isError(error) && _.isObject(error)) + return util.inspect(error); + if (!_.isError(error)) + return '' + error; + if (_.isUndefined(error.message)) + return "Unknown error"; + switch (error.message) { + case "Error: read ECONNRESET": + case "Error: socket hang up": + return "Connection closed unexpectedly"; + case "connect ETIMEDOUT": + return "Connect timed out"; + default: + return error.message; + } + } } module.exports = TestSteps; From b68b4d07f82f11ad912ab3edafdd1d808e41d168 Mon Sep 17 00:00:00 2001 From: Aamir Mahmood Date: Tue, 22 Jun 2021 22:32:09 +0500 Subject: [PATCH 57/70] lodash --- lib/testable-test.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/testable-test.js b/lib/testable-test.js index 4e45b8e..3206a70 100644 --- a/lib/testable-test.js +++ b/lib/testable-test.js @@ -1,6 +1,7 @@ const { v4: uuidv4 } = require('uuid'); const fs = require('fs'); const util = require('util'); +var _ = require('lodash'); class TestSteps { From 0bd1681a5431c1a95d13b8a8f3cbfaffc1cdc4eb Mon Sep 17 00:00:00 2001 From: Aamir Mahmood Date: Tue, 22 Jun 2021 22:43:39 +0500 Subject: [PATCH 58/70] code cleanup --- lib/testable-test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/testable-test.js b/lib/testable-test.js index 3206a70..f37c459 100644 --- a/lib/testable-test.js +++ b/lib/testable-test.js @@ -230,7 +230,7 @@ class TestSteps { }); } - toErrorContent(error, msgOnly) { + toErrorContent(error) { if (_.isUndefined(error) || error === null) return ""; if (_.isString(error)) From 49e4e9023723e685ede3731171b3db76a19fe02c Mon Sep 17 00:00:00 2001 From: Aamir Mahmood Date: Wed, 23 Jun 2021 01:10:56 +0500 Subject: [PATCH 59/70] PR Feedback --- README.md | 85 +++++++++++++++++++++++++++++++++++++++++++ lib/events-watcher.js | 38 +++++++++---------- lib/main.js | 29 ++++----------- lib/testable-test.js | 10 ----- 4 files changed, 111 insertions(+), 51 deletions(-) diff --git a/README.md b/README.md index 8fcc9a5..7d9de35 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,7 @@ A set of utility APIs for use while running [Testable](https://testable.io) scen * [Iterate CSV](#iterate-csv) * [Async code](#async-code) * [Manual live event](#manual-live-event) +* [Suite and Tests](#suite-and-tests) * [Wait for finish](#wait-for-finish) * [Webdriver.io custom commands](#webdriverio-commands) * [Screenshots](#screenshots) @@ -342,6 +343,7 @@ const execute = testableUtils.execute; execute(function(finished) { events.on('my-event', function(symbol) { request.get('http://sample.testable.io/stocks/' + symbol); + events.finish() finished(); }); }); @@ -370,6 +372,89 @@ describe('Load Url Requested in Event', function() { }); ``` +### Suite and Tests +You can run your tests in with same Webdriver.io API and can have multiple test suites. + +Example (Selenium Webdriver): + +```javascript +const webdriver = require('selenium-webdriver'); +const util = require('util'); +const fs = require('fs'); +const writeFile = util.promisify(fs.writeFile); +const path = require('path'); + +const testableUtils = require('testable-utils'); +const describe = testableUtils.describe; +const it = testableUtils.it; + +async function takeScreenshot(driver, file){ + let image = await driver.takeScreenshot(); + await writeFile(file, image, 'base64'); +} + +(async function example() { + global.driver = await new webdriver.Builder() + .withCapabilities(webdriver.Capabilities.chrome()) + .build(); + + try { + await describe('Google Related', async function() { + await it('Open google home page', async function() { + await driver.get('http://www.google.com'); + await takeScreenshot(driver, path.join(process.env.OUTPUT_DIR || '.', 'HomePage.png')); + await driver.wait(webdriver.until.titleIs('Google'), 10000); + }); + + await it('Open google home page', async function() { + await driver.get("https://news.google.com"); + await takeScreenshot(driver, path.join(process.env.OUTPUT_DIR || '.', 'News.png')); + await driver.wait(webdriver.until.titleIs('Google News'), 10000); + }); + }); + } finally { + await driver.quit(); + } +})(); +``` + +Example (Playwright): + +```javascript +const { chromium } = require('playwright'); +const testableUtils = require('testable-utils'); +const describe = testableUtils.describe; +const it = testableUtils.it; + +(async () => { + const browser = await chromium.launch({ headless: false }); + const page = await browser.newPage(); + + await describe('Google Related', async function() { + await it('Open google home page', async function() { + // Instructs the blank page to navigate a URL + await page.goto('https://www.google.com'); + await page.screenshot({path: 'homepage.png'}); + + // Fetches page's title + const title = await page.title(); + console.info(`The title is: ${title}`); + }); + + await it('Open google news page', async function() { + await page.goto('https://news.google.com'); + await page.screenshot({path: 'newspage.png'}); + + // Fetches page's title + const title = await page.title(); + console.info(`The News title is: ${title}`); + }); + }); + + await browser.close(); +})(); +``` + ### Wait For Finish Use this function to wait for the remainder of the test duration before the script finishes. Returns a Promise so that you can run some cleanup code before the script exits. diff --git a/lib/events-watcher.js b/lib/events-watcher.js index 480ff2c..8d7f8e0 100644 --- a/lib/events-watcher.js +++ b/lib/events-watcher.js @@ -4,26 +4,26 @@ const TailIntervalMs = 100; const TailBlockSize = 10485760; function watchForEvents(fileName, events, log) { - const tail = new Tail(fileName, '\n', { start: 0, interval: TailIntervalMs, blockSize: TailBlockSize }); - tail.on('line', function(data) { - if (!data) - return; - try { - const event = JSON.parse(data); - if (event.name) { - log.debug(`Received event ${event.name} with contents ${event.contents || ''}`); - events.emit(event.name, event.contents); - } - } catch(err) { - log.error(`Error processing live event ${data}`, helper.toErrorMessage(null, err)); - } - }); - tail.on('error', function(data) { - log.error('Error tailing live event', data); - }); - tail.watch(); + const tail = new Tail(fileName, '\n', { start: 0, interval: TailIntervalMs, blockSize: TailBlockSize }); + tail.on('line', function (data) { + if ( !data ) + return; + try { + const event = JSON.parse(data); + if ( event.name ) { + log.debug(`Received event ${event.name} with contents ${event.contents || ''}`); + events.emit(event.name, event.contents); + } + } catch (err) { + log.error(`Error processing live event ${data}`, helper.toErrorMessage(null, err)); + } + }); + tail.on('error', function (data) { + log.error('Error tailing live event', data); + }); + tail.watch(); events.finish = () => { tail.unwatch(); } - return tail; + return tail; } module.exports = watchForEvents; diff --git a/lib/main.js b/lib/main.js index 57fe24f..e865df2 100644 --- a/lib/main.js +++ b/lib/main.js @@ -135,21 +135,7 @@ if (registerCommands) { }); } -let steps; -function testSteps(){ - const StepsClass = new TestSteps(); - - const stepsObj = {}; - stepsObj.describe = StepsClass.describe.bind(StepsClass); - stepsObj.it = StepsClass.it.bind(StepsClass); - stepsObj.before = StepsClass.before.bind(StepsClass); - stepsObj.after = StepsClass.after.bind(StepsClass); - stepsObj.beforeEach = StepsClass.beforeEach.bind(StepsClass); - stepsObj.afterEach = StepsClass.afterEach.bind(StepsClass); - - steps = stepsObj; -} -testSteps(); +const testSteps = new TestSteps(); module.exports.isLocal = isLocal; module.exports.isSmokeTest = isSmokeTest; @@ -162,10 +148,9 @@ module.exports.events = events; module.exports.dataTable = csv; module.exports.waitForFinish = waitForFinish; - -module.exports.describe = steps.describe; -module.exports.it = steps.it; -module.exports.before = steps.before; -module.exports.after = steps.after; -module.exports.beforeEach = steps.beforeEach; -module.exports.afterEach = steps.afterEach; +module.exports.describe = testSteps.describe.bind(testSteps); +module.exports.it = testSteps.it.bind(testSteps); +module.exports.before = testSteps.before.bind(testSteps); +module.exports.after = testSteps.after.bind(testSteps); +module.exports.beforeEach = testSteps.beforeEach.bind(testSteps); +module.exports.afterEach = testSteps.afterEach.bind(testSteps); diff --git a/lib/testable-test.js b/lib/testable-test.js index f37c459..6ea9b6f 100644 --- a/lib/testable-test.js +++ b/lib/testable-test.js @@ -231,16 +231,6 @@ class TestSteps { } toErrorContent(error) { - if (_.isUndefined(error) || error === null) - return ""; - if (_.isString(error)) - return error; - if (!_.isError(error) && _.isBuffer(error)) - return error.toString(); - if (!_.isError(error) && _.isObject(error)) - return util.inspect(error); - if (!_.isError(error)) - return '' + error; if (_.isUndefined(error.message)) return "Unknown error"; switch (error.message) { From 2a917067ff0afc0f2b388e525eb7486cc155867a Mon Sep 17 00:00:00 2001 From: Aamir Mahmood Date: Wed, 23 Jun 2021 01:27:42 +0500 Subject: [PATCH 60/70] PR Feedback --- README.md | 89 +++++++++++-------------------------------------------- 1 file changed, 18 insertions(+), 71 deletions(-) diff --git a/README.md b/README.md index 7d9de35..e0d3e41 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ A set of utility APIs for use while running [Testable](https://testable.io) scen * [Iterate CSV](#iterate-csv) * [Async code](#async-code) * [Manual live event](#manual-live-event) -* [Suite and Tests](#suite-and-tests) +* [Test Framework Syntax](#test-framework-syntax) * [Wait for finish](#wait-for-finish) * [Webdriver.io custom commands](#webdriverio-commands) * [Screenshots](#screenshots) @@ -372,87 +372,34 @@ describe('Load Url Requested in Event', function() { }); ``` -### Suite and Tests -You can run your tests in with same Webdriver.io API and can have multiple test suites. +### Test Framework Syntax -Example (Selenium Webdriver): +Structure your tests using the familiar Mocha.js test case syntax. When run on the Testable platform you will be able to see a test case report of all test steps including pass/fail status, duration, and error details on failure. -```javascript -const webdriver = require('selenium-webdriver'); -const util = require('util'); -const fs = require('fs'); -const writeFile = util.promisify(fs.writeFile); -const path = require('path'); - -const testableUtils = require('testable-utils'); -const describe = testableUtils.describe; -const it = testableUtils.it; - -async function takeScreenshot(driver, file){ - let image = await driver.takeScreenshot(); - await writeFile(file, image, 'base64'); -} - -(async function example() { - global.driver = await new webdriver.Builder() - .withCapabilities(webdriver.Capabilities.chrome()) - .build(); - - try { - await describe('Google Related', async function() { - await it('Open google home page', async function() { - await driver.get('http://www.google.com'); - await takeScreenshot(driver, path.join(process.env.OUTPUT_DIR || '.', 'HomePage.png')); - await driver.wait(webdriver.until.titleIs('Google'), 10000); - }); - - await it('Open google home page', async function() { - await driver.get("https://news.google.com"); - await takeScreenshot(driver, path.join(process.env.OUTPUT_DIR || '.', 'News.png')); - await driver.wait(webdriver.until.titleIs('Google News'), 10000); - }); - }); - } finally { - await driver.quit(); - } -})(); -``` -Example (Playwright): +For Example: ```javascript -const { chromium } = require('playwright'); const testableUtils = require('testable-utils'); const describe = testableUtils.describe; const it = testableUtils.it; - -(async () => { - const browser = await chromium.launch({ headless: false }); - const page = await browser.newPage(); - - await describe('Google Related', async function() { - await it('Open google home page', async function() { - // Instructs the blank page to navigate a URL - await page.goto('https://www.google.com'); - await page.screenshot({path: 'homepage.png'}); - - // Fetches page's title - const title = await page.title(); - console.info(`The title is: ${title}`); +// await if there is any async code in your tests +await describe('My example test suite', function() { + it('First test step', async function() { + await driver.get('http://www.google.com'); // Selenium javascript example code }); +}); +``` - await it('Open google news page', async function() { - await page.goto('https://news.google.com'); - await page.screenshot({path: 'newspage.png'}); - - // Fetches page's title - const title = await page.title(); - console.info(`The News title is: ${title}`); - }); - }); +Full API: - await browser.close(); -})(); +```javascript +describe(suite, fn); // fn should be a function that contains a sequence of it() blocks +it(test, fn); // fn executes a single test step +beforeEach(fn); // runs before each test step (it block) +afterEach(fn); // runs after each test step (it block) +before(fn); // runs before each suite (describe block) +after(fn); // runs after each suite (describe block) ``` ### Wait For Finish From 98d44c4a1076d2fa77917c01ee95803b4f3012fd Mon Sep 17 00:00:00 2001 From: Aamir Mahmood Date: Wed, 23 Jun 2021 13:14:09 +0500 Subject: [PATCH 61/70] to errorTrace --- lib/testable-test.js | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/lib/testable-test.js b/lib/testable-test.js index 6ea9b6f..d8a203f 100644 --- a/lib/testable-test.js +++ b/lib/testable-test.js @@ -8,16 +8,16 @@ class TestSteps { constructor() { this.cb = { startSuite: (suite) => { - this.reportTestSuiteActions('StartSuite', suite ); + this.reportTestSuiteActions('StartSuite', suite); }, finishSuite: (suite) => { - this.reportTestSuiteActions('FinishSuite', suite ); + this.reportTestSuiteActions('FinishSuite', suite); }, startTest: (test) => { - this.reportTestSuiteActions('StartSuiteTest', test ); + this.reportTestSuiteActions('StartSuiteTest', test); }, finishTest: (test) => { - this.reportTestSuiteActions('FinishSuiteTest', test ); + this.reportTestSuiteActions('FinishSuiteTest', test); } }; @@ -184,7 +184,7 @@ class TestSteps { if ( err.message ) test.error = err.message; if ( err.stack ) - test.errorTrace = this.toErrorContent(err); + test.errorTrace = this.toErrorTrace(err); } test.finished = Date.now(); test.duration = Date.now() - test.started; @@ -231,7 +231,7 @@ class TestSteps { } toErrorContent(error) { - if (_.isUndefined(error.message)) + if ( _.isUndefined(error.message) ) return "Unknown error"; switch (error.message) { case "Error: read ECONNRESET": @@ -243,6 +243,15 @@ class TestSteps { return error.message; } } + + toErrorTrace(exception) { + let answer = (exception.message || exception.errorType) + '\n'; + _.forEach(exception.stackTrace, (traceLine) => { + answer += ' at ' + traceLine.declaringClass + '.' + traceLine.methodName + + '(' + traceLine.fileName + ':' + traceLine.lineNumber + ')\n'; + }); + return answer; + } } module.exports = TestSteps; From dccee8cf63e514f2f1baf0e0c61c93092ecacfa3 Mon Sep 17 00:00:00 2001 From: Aamir Mahmood Date: Wed, 23 Jun 2021 13:22:36 +0500 Subject: [PATCH 62/70] one small test --- lib/testable-test.js | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/lib/testable-test.js b/lib/testable-test.js index d8a203f..bd91b89 100644 --- a/lib/testable-test.js +++ b/lib/testable-test.js @@ -178,6 +178,8 @@ class TestSteps { await this._executeFn(fn); test.state = 'passed'; } catch (err) { + + console.log(JSON.stringify(err)); suite.hasError = true; test.state = 'failed'; test.errorType = err.name; @@ -230,20 +232,6 @@ class TestSteps { }); } - toErrorContent(error) { - if ( _.isUndefined(error.message) ) - return "Unknown error"; - switch (error.message) { - case "Error: read ECONNRESET": - case "Error: socket hang up": - return "Connection closed unexpectedly"; - case "connect ETIMEDOUT": - return "Connect timed out"; - default: - return error.message; - } - } - toErrorTrace(exception) { let answer = (exception.message || exception.errorType) + '\n'; _.forEach(exception.stackTrace, (traceLine) => { From 58cdce5ec5b292a632ae7a68db943c5fdc2384d5 Mon Sep 17 00:00:00 2001 From: Aamir Mahmood Date: Wed, 23 Jun 2021 13:27:34 +0500 Subject: [PATCH 63/70] console added --- lib/testable-test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/testable-test.js b/lib/testable-test.js index bd91b89..2ba38f9 100644 --- a/lib/testable-test.js +++ b/lib/testable-test.js @@ -178,7 +178,7 @@ class TestSteps { await this._executeFn(fn); test.state = 'passed'; } catch (err) { - + console.log('------ ERROR REPORTING CHECK'); console.log(JSON.stringify(err)); suite.hasError = true; test.state = 'failed'; From bd7f0033bccd063a1366a698ee4f8a88c9780a82 Mon Sep 17 00:00:00 2001 From: Aamir Mahmood Date: Wed, 23 Jun 2021 13:29:39 +0500 Subject: [PATCH 64/70] console added --- lib/testable-test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/testable-test.js b/lib/testable-test.js index 2ba38f9..bccd19c 100644 --- a/lib/testable-test.js +++ b/lib/testable-test.js @@ -179,7 +179,7 @@ class TestSteps { test.state = 'passed'; } catch (err) { console.log('------ ERROR REPORTING CHECK'); - console.log(JSON.stringify(err)); + console.log(err); suite.hasError = true; test.state = 'failed'; test.errorType = err.name; From 31bc741516af279d8b44815c3e667c0407fb7457 Mon Sep 17 00:00:00 2001 From: Aamir Mahmood Date: Wed, 23 Jun 2021 14:56:48 +0500 Subject: [PATCH 65/70] console removed --- lib/testable-test.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/testable-test.js b/lib/testable-test.js index bccd19c..51c57c2 100644 --- a/lib/testable-test.js +++ b/lib/testable-test.js @@ -178,8 +178,6 @@ class TestSteps { await this._executeFn(fn); test.state = 'passed'; } catch (err) { - console.log('------ ERROR REPORTING CHECK'); - console.log(err); suite.hasError = true; test.state = 'failed'; test.errorType = err.name; From 0bec00948afc3fd6480b9d195c4656551d6ee647 Mon Sep 17 00:00:00 2001 From: Aamir Mahmood Date: Wed, 23 Jun 2021 15:00:01 +0500 Subject: [PATCH 66/70] removed util require --- lib/testable-test.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/testable-test.js b/lib/testable-test.js index 51c57c2..fae671b 100644 --- a/lib/testable-test.js +++ b/lib/testable-test.js @@ -1,6 +1,5 @@ const { v4: uuidv4 } = require('uuid'); const fs = require('fs'); -const util = require('util'); var _ = require('lodash'); class TestSteps { From 8c0ae420f4ac323075d80718b832d23db2294008 Mon Sep 17 00:00:00 2001 From: Aamir Mahmood Date: Wed, 23 Jun 2021 17:07:35 +0500 Subject: [PATCH 67/70] Types updated --- index.d.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/index.d.ts b/index.d.ts index 503e063..9ace5a9 100644 --- a/index.d.ts +++ b/index.d.ts @@ -12,6 +12,14 @@ declare namespace testableUtils { function waitForFinish(): Promise + function describe(suiteName: string, fn: Function) : Promise; + function it(testName: string, fn: Function) : Promise; + function before(fn: Function) : void; + function after(fn: Function) : void; + function beforeEach(fn: Function) : void; + function afterEach(fn: Function) : void; + + interface Log { debug(message?: any); error(message?: any); From 32025360b8b8a0e17061e973fb059e623bb051be Mon Sep 17 00:00:00 2001 From: Aamir Mahmood Date: Wed, 23 Jun 2021 21:13:53 +0500 Subject: [PATCH 68/70] Types updated --- index.d.ts | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/index.d.ts b/index.d.ts index 9ace5a9..f631555 100644 --- a/index.d.ts +++ b/index.d.ts @@ -11,13 +11,17 @@ declare namespace testableUtils { function waitForFinish(): Promise + function describe(suiteName: string, fn: Function): Promise; - function describe(suiteName: string, fn: Function) : Promise; - function it(testName: string, fn: Function) : Promise; - function before(fn: Function) : void; - function after(fn: Function) : void; - function beforeEach(fn: Function) : void; - function afterEach(fn: Function) : void; + function it(testName: string, fn: Function): Promise; + + function before(fn: Function): void; + + function after(fn: Function): void; + + function beforeEach(fn: Function): void; + + function afterEach(fn: Function): void; interface Log { @@ -45,7 +49,7 @@ declare namespace testableUtils { }; - interface Chunk{ + interface Chunk { id: number, executionType: string, agent: string, @@ -54,7 +58,7 @@ declare namespace testableUtils { startedAt: Date, concurrentClients: number } - interface Execution{ + interface Execution { id: number, createdAt: Date, updatedAt: Date, @@ -109,17 +113,17 @@ declare namespace testableUtils { markAsSuccess(): void; markAsFailure(): void; - data:{resource: string, url: string}, + data: { resource: string, url: string }, } interface ResultOptions { - namespace?: string; + namespace?: string; name: string; key?: string; val?: number; units?: string; } interface GetOptions { - namespace?: string; + namespace?: string; name: string; key?: string; } From e38072a0158f2eec4a13fd6ed9cecf03c45ae079 Mon Sep 17 00:00:00 2001 From: Aamir Mahmood Date: Wed, 23 Jun 2021 23:10:27 +0500 Subject: [PATCH 69/70] version bumped --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 37d7ae2..70e2958 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "testable-utils", - "version": "0.5.9", + "version": "0.5.10", "description": "Utilities for Testable scripts", "author": "Avi Stramer", "keywords": [ From 24f62818e2fc6fdd083c87516095f8a09a3c2d7a Mon Sep 17 00:00:00 2001 From: Aamir Mahmood Date: Thu, 24 Jun 2021 00:46:44 +0500 Subject: [PATCH 70/70] function names re updated --- lib/testable-test.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/testable-test.js b/lib/testable-test.js index fae671b..5bf7315 100644 --- a/lib/testable-test.js +++ b/lib/testable-test.js @@ -7,16 +7,16 @@ class TestSteps { constructor() { this.cb = { startSuite: (suite) => { - this.reportTestSuiteActions('StartSuite', suite); + this._reportTestSuiteActions('StartSuite', suite); }, finishSuite: (suite) => { - this.reportTestSuiteActions('FinishSuite', suite); + this._reportTestSuiteActions('FinishSuite', suite); }, startTest: (test) => { - this.reportTestSuiteActions('StartSuiteTest', test); + this._reportTestSuiteActions('StartSuiteTest', test); }, finishTest: (test) => { - this.reportTestSuiteActions('FinishSuiteTest', test); + this._reportTestSuiteActions('FinishSuiteTest', test); } }; @@ -183,7 +183,7 @@ class TestSteps { if ( err.message ) test.error = err.message; if ( err.stack ) - test.errorTrace = this.toErrorTrace(err); + test.errorTrace = this._toErrorTrace(err); } test.finished = Date.now(); test.duration = Date.now() - test.started; @@ -210,7 +210,7 @@ class TestSteps { } } - reportTestSuiteActions(type, contents) { + _reportTestSuiteActions(type, contents) { const currentSuite = this.currentSuite; if ( currentSuite && type === 'FinishSuiteTest' && contents && contents.state === 'failed' ) currentSuite.hasError = true; @@ -229,7 +229,7 @@ class TestSteps { }); } - toErrorTrace(exception) { + _toErrorTrace(exception) { let answer = (exception.message || exception.errorType) + '\n'; _.forEach(exception.stackTrace, (traceLine) => { answer += ' at ' + traceLine.declaringClass + '.' + traceLine.methodName +