From 34f8ee5247e7978365259c49c5a8640566bb40f4 Mon Sep 17 00:00:00 2001 From: Dantuluri Date: Tue, 27 Aug 2019 11:28:04 -0400 Subject: [PATCH 1/7] added more descriptive file names, names are breaking file length requirements --- lib/planner/write-plans-to-disk.js | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/lib/planner/write-plans-to-disk.js b/lib/planner/write-plans-to-disk.js index 2af1d9ea..1cec0b10 100644 --- a/lib/planner/write-plans-to-disk.js +++ b/lib/planner/write-plans-to-disk.js @@ -2,16 +2,34 @@ const fs = require('fs'); const path = require('path'); +const _ = require('lodash'); const configHandler = require('../util/config/config-handler.js'); module.exports = function writePlansToDisk(plans) { - let date = Date.now(); - let fileCount = 1; + // let date = Date.now(); + // let fileCount = 1; const outputPath = configHandler.get('outputPath'); for (let plan of plans) { let filePath = path.resolve(outputPath, - `${date}-simulato-${fileCount++}_${plans.length}.json`); + (function generateTestName(plan) { + let filteredPlan = _.filter(plan, function(o) { + return ( + (!o.name.toLowerCase().includes('navigateToPresto'.toLowerCase())) && + (!o.name.toLowerCase().includes('NAVIGATE_TO_PRESTO'.toLowerCase()))); + }); + const crypto = require('crypto'); + const sha256 = (x) => crypto.createHash('sha256').update(x, 'utf8').digest('hex'); + + return `simulato + ---${filteredPlan[0].name} + --${filteredPlan[filteredPlan.length-1].name} + --${sha256(plan.toString())}`; + })(plan)); + + // `${date}-simulato-${fileCount++}_${plans.length}.json`); + // fs.writeFileSync(filePath, JSON.stringify(plan.testCase)); + console.log(filePath.length) fs.writeFileSync(filePath, JSON.stringify(plan)); } console.log(`Generated and wrote ${plans.length} test(s) to disk`); From 3c2e6d6fe72be629945dece894ba021b53aa49d8 Mon Sep 17 00:00:00 2001 From: Dantuluri Date: Fri, 30 Aug 2019 10:12:48 -0400 Subject: [PATCH 2/7] removed actions from test names --- lib/planner/write-plans-to-disk.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/planner/write-plans-to-disk.js b/lib/planner/write-plans-to-disk.js index 1cec0b10..d152033e 100644 --- a/lib/planner/write-plans-to-disk.js +++ b/lib/planner/write-plans-to-disk.js @@ -12,24 +12,24 @@ module.exports = function writePlansToDisk(plans) { for (let plan of plans) { let filePath = path.resolve(outputPath, (function generateTestName(plan) { - let filteredPlan = _.filter(plan, function(o) { - return ( - (!o.name.toLowerCase().includes('navigateToPresto'.toLowerCase())) && - (!o.name.toLowerCase().includes('NAVIGATE_TO_PRESTO'.toLowerCase()))); - }); + // let filteredPlan = _.filter(plan, function(o) { + // return ( + // (!o.name.toLowerCase().includes('navigateToPresto'.toLowerCase())) && + // (!o.name.toLowerCase().includes('NAVIGATE_TO_PRESTO'.toLowerCase()))); + // }); const crypto = require('crypto'); const sha256 = (x) => crypto.createHash('sha256').update(x, 'utf8').digest('hex'); - return `simulato - ---${filteredPlan[0].name} - --${filteredPlan[filteredPlan.length-1].name} - --${sha256(plan.toString())}`; + return `simulato` + + // `---${filteredPlan[0].name}`+ + // `-->${filteredPlan[filteredPlan.length-1].name}`+ + `--${sha256(plan.toString())}`; })(plan)); // `${date}-simulato-${fileCount++}_${plans.length}.json`); // fs.writeFileSync(filePath, JSON.stringify(plan.testCase)); - console.log(filePath.length) + console.log(filePath.length); fs.writeFileSync(filePath, JSON.stringify(plan)); } console.log(`Generated and wrote ${plans.length} test(s) to disk`); From 8bac9eed02443f2bf141a2c67593e5b4ee462a94 Mon Sep 17 00:00:00 2001 From: Dantuluri Date: Thu, 12 Sep 2019 10:32:23 -0400 Subject: [PATCH 3/7] changed output test file names to be generated from plan --- lib/planner/write-plans-to-disk.js | 19 +------------------ .../lib/planner/write-plan-to-disk-tests.js | 19 +++++++++++++++---- 2 files changed, 16 insertions(+), 22 deletions(-) diff --git a/lib/planner/write-plans-to-disk.js b/lib/planner/write-plans-to-disk.js index d152033e..ce6d62c1 100644 --- a/lib/planner/write-plans-to-disk.js +++ b/lib/planner/write-plans-to-disk.js @@ -2,34 +2,17 @@ const fs = require('fs'); const path = require('path'); -const _ = require('lodash'); const configHandler = require('../util/config/config-handler.js'); module.exports = function writePlansToDisk(plans) { - // let date = Date.now(); - // let fileCount = 1; const outputPath = configHandler.get('outputPath'); for (let plan of plans) { let filePath = path.resolve(outputPath, (function generateTestName(plan) { - // let filteredPlan = _.filter(plan, function(o) { - // return ( - // (!o.name.toLowerCase().includes('navigateToPresto'.toLowerCase())) && - // (!o.name.toLowerCase().includes('NAVIGATE_TO_PRESTO'.toLowerCase()))); - // }); const crypto = require('crypto'); const sha256 = (x) => crypto.createHash('sha256').update(x, 'utf8').digest('hex'); - - return `simulato` + - // `---${filteredPlan[0].name}`+ - // `-->${filteredPlan[filteredPlan.length-1].name}`+ - `--${sha256(plan.toString())}`; + return `simulato`+`--${sha256(plan.toString())}`; })(plan)); - - // `${date}-simulato-${fileCount++}_${plans.length}.json`); - - // fs.writeFileSync(filePath, JSON.stringify(plan.testCase)); - console.log(filePath.length); fs.writeFileSync(filePath, JSON.stringify(plan)); } console.log(`Generated and wrote ${plans.length} test(s) to disk`); diff --git a/test/unit/lib/planner/write-plan-to-disk-tests.js b/test/unit/lib/planner/write-plan-to-disk-tests.js index 9ababf15..3236b68b 100644 --- a/test/unit/lib/planner/write-plan-to-disk-tests.js +++ b/test/unit/lib/planner/write-plan-to-disk-tests.js @@ -7,6 +7,7 @@ const expect = require('chai').expect; describe('lib/planner/write-plans-to-disk.js', function() { let fs; let path; + let crypto_stub; let configHandler; let clock; let writePlansToDisk; @@ -14,7 +15,7 @@ describe('lib/planner/write-plans-to-disk.js', function() { beforeEach(function() { mockery.enable({useCleanCache: true}); mockery.registerAllowable('../../../../lib/planner/write-plans-to-disk.js'); - + let crypto; fs = { writeFileSync: sinon.stub(), }; @@ -24,12 +25,22 @@ describe('lib/planner/write-plans-to-disk.js', function() { configHandler = { get: sinon.stub(), }; + crypto = { + createHash: sinon.stub().returns({ + update: sinon.stub().returns({ + digest: sinon.stub().returns( + 'hashedPlan' + ), + }), + }), + }; clock = sinon.useFakeTimers(12345); sinon.spy(console, 'log'); mockery.registerMock('fs', fs); mockery.registerMock('path', path); + mockery.registerMock('crypto', crypto); mockery.registerMock('../util/config/config-handler.js', configHandler); writePlansToDisk = require('../../../../lib/planner/write-plans-to-disk.js'); @@ -53,14 +64,14 @@ describe('lib/planner/write-plans-to-disk.js', function() { describe('for each plan of the passed in plans', function() { it('should call path.resolve with the outputPath and the constructed file name', function() { - let plans = ['plan1', 'plan2']; + let plans = ['plan1']; + configHandler.get.returns('outputPath/'); writePlansToDisk(plans); expect(path.resolve.args).to.deep.equal([ - [`outputPath/`, '12345-simulato-1_2.json'], - [`outputPath/`, '12345-simulato-2_2.json'], + [`outputPath/`, 'simulato--hashedPlan'], ]); }); From 3456393ca7bf73beb15ef2be01b97674680a9ed1 Mon Sep 17 00:00:00 2001 From: Dantuluri Date: Thu, 12 Sep 2019 10:36:12 -0400 Subject: [PATCH 4/7] removed unused var --- test/unit/lib/planner/write-plan-to-disk-tests.js | 1 - 1 file changed, 1 deletion(-) diff --git a/test/unit/lib/planner/write-plan-to-disk-tests.js b/test/unit/lib/planner/write-plan-to-disk-tests.js index 3236b68b..7431a1c5 100644 --- a/test/unit/lib/planner/write-plan-to-disk-tests.js +++ b/test/unit/lib/planner/write-plan-to-disk-tests.js @@ -7,7 +7,6 @@ const expect = require('chai').expect; describe('lib/planner/write-plans-to-disk.js', function() { let fs; let path; - let crypto_stub; let configHandler; let clock; let writePlansToDisk; From 83623e7b07186dc5abe48ffab323a9027cabf072 Mon Sep 17 00:00:00 2001 From: Dantuluri Date: Thu, 12 Sep 2019 10:47:18 -0400 Subject: [PATCH 5/7] apending file extention to the test name --- lib/planner/write-plans-to-disk.js | 2 +- test/unit/lib/planner/write-plan-to-disk-tests.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/planner/write-plans-to-disk.js b/lib/planner/write-plans-to-disk.js index ce6d62c1..f9666eec 100644 --- a/lib/planner/write-plans-to-disk.js +++ b/lib/planner/write-plans-to-disk.js @@ -11,7 +11,7 @@ module.exports = function writePlansToDisk(plans) { (function generateTestName(plan) { const crypto = require('crypto'); const sha256 = (x) => crypto.createHash('sha256').update(x, 'utf8').digest('hex'); - return `simulato`+`--${sha256(plan.toString())}`; + return `simulato`+`--${sha256(plan.toString())}.json`; })(plan)); fs.writeFileSync(filePath, JSON.stringify(plan)); } diff --git a/test/unit/lib/planner/write-plan-to-disk-tests.js b/test/unit/lib/planner/write-plan-to-disk-tests.js index 7431a1c5..2ad903a5 100644 --- a/test/unit/lib/planner/write-plan-to-disk-tests.js +++ b/test/unit/lib/planner/write-plan-to-disk-tests.js @@ -70,7 +70,7 @@ describe('lib/planner/write-plans-to-disk.js', function() { writePlansToDisk(plans); expect(path.resolve.args).to.deep.equal([ - [`outputPath/`, 'simulato--hashedPlan'], + [`outputPath/`, 'simulato--hashedPlan.json'], ]); }); From f17346904932a7f827a7924af036187d2db08966 Mon Sep 17 00:00:00 2001 From: Dantuluri Date: Tue, 17 Sep 2019 13:12:58 -0400 Subject: [PATCH 6/7] removed IIFE write-plan-to-disk --- lib/planner/write-plans-to-disk.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/planner/write-plans-to-disk.js b/lib/planner/write-plans-to-disk.js index f9666eec..31156c22 100644 --- a/lib/planner/write-plans-to-disk.js +++ b/lib/planner/write-plans-to-disk.js @@ -4,15 +4,14 @@ const fs = require('fs'); const path = require('path'); const configHandler = require('../util/config/config-handler.js'); + module.exports = function writePlansToDisk(plans) { const outputPath = configHandler.get('outputPath'); for (let plan of plans) { - let filePath = path.resolve(outputPath, - (function generateTestName(plan) { - const crypto = require('crypto'); - const sha256 = (x) => crypto.createHash('sha256').update(x, 'utf8').digest('hex'); - return `simulato`+`--${sha256(plan.toString())}.json`; - })(plan)); + const crypto = require('crypto'); + const sha256 = (x) => crypto.createHash('sha256').update(x, 'utf8').digest('hex'); + let testName = `simulato`+`--${sha256(plan.toString())}.json`; + let filePath = path.resolve(outputPath, testName); fs.writeFileSync(filePath, JSON.stringify(plan)); } console.log(`Generated and wrote ${plans.length} test(s) to disk`); From 085cca03f6de490175665d5835a238daa214367c Mon Sep 17 00:00:00 2001 From: Dantuluri Date: Wed, 18 Sep 2019 10:52:22 -0400 Subject: [PATCH 7/7] moved require statemnt to meet style guides --- lib/planner/write-plans-to-disk.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/planner/write-plans-to-disk.js b/lib/planner/write-plans-to-disk.js index 31156c22..324947af 100644 --- a/lib/planner/write-plans-to-disk.js +++ b/lib/planner/write-plans-to-disk.js @@ -3,12 +3,11 @@ const fs = require('fs'); const path = require('path'); const configHandler = require('../util/config/config-handler.js'); - +const crypto = require('crypto'); module.exports = function writePlansToDisk(plans) { const outputPath = configHandler.get('outputPath'); for (let plan of plans) { - const crypto = require('crypto'); const sha256 = (x) => crypto.createHash('sha256').update(x, 'utf8').digest('hex'); let testName = `simulato`+`--${sha256(plan.toString())}.json`; let filePath = path.resolve(outputPath, testName);