Skip to content

Commit

Permalink
Add setupReportFolder unit test in Reporter class
Browse files Browse the repository at this point in the history
  • Loading branch information
silversonicaxel committed Jan 16, 2019
1 parent 175775e commit 2936822
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion src/class/reporter.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import * as chai from 'chai';
import { spy, assert, sandbox, createSandbox } from 'sinon';
import { spy, assert, createSandbox } from 'sinon';
import * as sinonChai from 'sinon-chai';
import { Reporter } from './reporter';
import { Analyzer } from './analyzer';
import { Reader } from './reader';
import * as fs from 'fs';
import * as del from 'del';

const expect = chai.expect;
chai.use(sinonChai);
Expand Down Expand Up @@ -47,6 +49,38 @@ describe('#Reporter', () => {
});
});

describe('#setupReportFolder', () => {
it('should delete an old report folder if it exists', () => {
const existsSyncReturn = true;
const fsExistsSyncStub = sandboxSet.stub(fs, 'existsSync').returns(existsSyncReturn);
const delSyncStub = sandboxSet.stub(del, 'sync').returns(existsSyncReturn);
const fsMkdirSyncStub = sandboxSet.stub(fs, 'mkdirSync').returns(existsSyncReturn);
const fsCopyFileSyncStub = sandboxSet.stub(fs, 'copyFileSync').returns(existsSyncReturn);

reporter['setupReportFolder']();

assert.called(fsExistsSyncStub);
assert.called(delSyncStub);
assert.called(fsMkdirSyncStub);
assert.called(fsCopyFileSyncStub);
});

it('should delete any report folder if it does not exists', () => {
const existsSyncReturn = false;
const fsExistsSyncStub = sandboxSet.stub(fs, 'existsSync').returns(existsSyncReturn);
const delSyncStub = sandboxSet.stub(del, 'sync').returns(existsSyncReturn);
const fsMkdirSyncStub = sandboxSet.stub(fs, 'mkdirSync').returns(existsSyncReturn);
const fsCopyFileSyncStub = sandboxSet.stub(fs, 'copyFileSync').returns(existsSyncReturn);

reporter['setupReportFolder']();

assert.called(fsExistsSyncStub);
assert.notCalled(delSyncStub);
assert.called(fsMkdirSyncStub);
assert.called(fsCopyFileSyncStub);
});
});

describe('#reportFeaturesFiles', () => {
it('should not read the provided empty folders', () => {
const readContentFeatureFileSpy = spy(reader, 'readContentFeatureFile');
Expand Down

0 comments on commit 2936822

Please sign in to comment.