Skip to content

Commit

Permalink
Merge pull request #198 from GannettDigital/plan_based_test_names
Browse files Browse the repository at this point in the history
Plan based test names
  • Loading branch information
scottgunther authored Sep 18, 2019
2 parents 12d5276 + 085cca0 commit 80774f8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
9 changes: 4 additions & 5 deletions lib/planner/write-plans-to-disk.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`);
Expand Down
18 changes: 14 additions & 4 deletions test/unit/lib/planner/write-plan-to-disk-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
};
Expand All @@ -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');
Expand All @@ -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'],
]);
});

Expand Down

0 comments on commit 80774f8

Please sign in to comment.