diff --git a/lib/planner/write-plans-to-disk.js b/lib/planner/write-plans-to-disk.js index 2af1d9ea..324947af 100644 --- a/lib/planner/write-plans-to-disk.js +++ b/lib/planner/write-plans-to-disk.js @@ -3,15 +3,14 @@ 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) { - 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`); - // fs.writeFileSync(filePath, JSON.stringify(plan.testCase)); + 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`); 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..2ad903a5 100644 --- a/test/unit/lib/planner/write-plan-to-disk-tests.js +++ b/test/unit/lib/planner/write-plan-to-disk-tests.js @@ -14,7 +14,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 +24,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 +63,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.json'], ]); });