Skip to content

Commit

Permalink
cgx tests and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
farisT committed Apr 8, 2020
1 parent 58a0d96 commit 75da92e
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 12 deletions.
3 changes: 2 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
"docs": "typedoc --out docs ./src"
},
"dependencies": {
"bluebird": "^3.7.2",
"figlet": "^1.3.0",
"fs-extra": "^9.0.0",
"inquirer": "^7.1.0",
Expand All @@ -55,6 +54,7 @@
"@types/node": "^13.11.0",
"@types/sinon": "^9.0.0",
"@types/sinon-chai": "^3.2.4",
"bluebird": "^3.7.2",
"chai": "^4.2.0",
"mocha": "^7.1.1",
"mocha-junit-reporter": "^1.23.3",
Expand Down
5 changes: 2 additions & 3 deletions src/actions/bitbucket.actions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Bluebird from 'bluebird';
import * as logger from '../utils/logger.util';
import { ConsoleMessage } from '../models/console-message';

describe('src/bitbucket.actions', () => {
describe('src/actions/bitbucket.actions', () => {

let sandbox: sinon.SinonSandbox;
let bitBucketFileQuestionStub: sinon.SinonStub;
Expand Down Expand Up @@ -41,7 +41,6 @@ describe('src/bitbucket.actions', () => {
files: UniversalChoiceValue.README,
stub: sinon.stub(templates, 'readme'),
function: templates.readme,

},
{
name: 'todo',
Expand Down Expand Up @@ -90,7 +89,7 @@ describe('src/bitbucket.actions', () => {
sandbox = sinon.createSandbox();
mockAnswer.files = caseItem.files;
bitBucketFileQuestionStub = sandbox.stub(questions, 'bitbucketFileQuestion').resolves(mockAnswer);
const bitBucket = await bitbucketActions()
const bitBucket: Promise<any> = await bitbucketActions()
expect(caseItem.stub).to.be.calledOnce;
expect(bitBucket).to.equal(caseItem.function());
sandbox.restore();
Expand Down
1 change: 1 addition & 0 deletions src/actions/bitbucket.actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { showInfo } from '../utils/logger.util';

export async function bitbucketActions(): Promise<any> {
const bitbucketFileAnswer: Answer = await bitbucketFileQuestion();

switch (bitbucketFileAnswer.files) {
case UniversalChoiceValue.ALL: {
showInfo(ConsoleMessage.START_GENERATING);
Expand Down
75 changes: 75 additions & 0 deletions src/cgx.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import sinon from 'sinon';
import { expect } from 'chai';
import { CGX } from './cgx';
import * as logger from './utils/logger.util';
import * as questions from './questions';
import { ProviderValue, Answer, LicenseValue } from './models/choice';
import * as actions from './actions';
import Bluebird from 'bluebird';

describe('src/cgx', () => {
let sandbox: sinon.SinonSandbox;
let showTitleAndBannerStub: sinon.SinonStub;
let providerQuestionStub: sinon.SinonStub;

const mockAnswer: Answer = {
files: {},
userName: 'someUser',
licenses: LicenseValue.MIT,
provider: ProviderValue.GITHUB,
overwrite: false,
}
beforeEach(() => {
sandbox = sinon.createSandbox();
showTitleAndBannerStub = sandbox.stub(logger, 'showTitleAndBanner');
});

afterEach(() => {
sandbox.restore();
});

it('should always call showTitleAndBanner and providerQuestion', async () => {
providerQuestionStub = sandbox.stub(questions, 'providerQuestion').resolves(mockAnswer);
await CGX();
expect(showTitleAndBannerStub).to.be.calledOnce;
expect(providerQuestionStub).to.be.calledOnce;
});
const cases = [
{
name: 'gitlab',
provider: ProviderValue.GITLAB,
stub: sinon.stub(actions, 'gitlabActions'),
function: actions.gitlabActions,
},
{
name: 'github',
provider: ProviderValue.GITHUB,
stub: sinon.stub(actions, 'githubActions'),
function: actions.githubActions,
},
{
name: 'bitbucket',
provider: ProviderValue.BITBUCKET,
stub: sinon.stub(actions, 'bitbucketActions'),
function: actions.bitbucketActions,
},
{
name: 'codecommit',
provider: ProviderValue.CODECOMMIT,
stub: sinon.stub(actions, 'codecommitActions'),
function: actions.codecommitActions,
},
];
Bluebird.each(cases, (caseItem) => {
it(`should return ${caseItem.name} actions if the choice is made for it`, async () => {
sandbox = sinon.createSandbox();
mockAnswer.provider = caseItem.provider;
showTitleAndBannerStub = sandbox.stub(logger, 'showTitleAndBanner');
providerQuestionStub = sandbox.stub(questions, 'providerQuestion').resolves(mockAnswer);
const cgx: Promise<any> = await CGX();
expect(caseItem.stub).to.be.calledOnce;
expect(cgx).to.be.equal(caseItem.function())
sandbox.restore();
})
});
});
9 changes: 4 additions & 5 deletions src/templates/universal/changelog.template.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import { FileName } from '../../models/file';
import { CommitData } from '../../models/commit-data';
import * as childProcess from 'child_process';
Expand All @@ -19,11 +18,11 @@ export function changelog() {
const newLine: string = '\n';
const json = gitLogToJSON(gitLog);

return `# Changelog
return `# Changelog
` + json.map((commit: CommitData) => {
return `__Commit:__ [${commit.hash}](${commit.hash}):
__Message:__ ${commit.message}
return `__Commit:__ [${commit.hash}](${commit.hash}):
__Message:__ ${commit.message}
__Author:__ ${commit.author} on ${commit.date} ${newLine} ${newLine}`;
})
};
Expand Down
1 change: 0 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"target": "ESNext",
"module": "commonjs",
"lib": ["es6", "es2015", "dom"],
"declaration": true,
"experimentalDecorators": true,
"outDir": "lib",
"rootDir": "src",
Expand Down
1 change: 0 additions & 1 deletion tslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@
"trailing-comma": [true, {"multiline": "always", "singleline": "never"}]
}
}

0 comments on commit 75da92e

Please sign in to comment.