Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setup test suite and cleaned up dependencies #8

Merged
merged 2 commits into from
Apr 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
root = true
[*]
indent_style = space
indent_size = 4
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
end_of_line = lf
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,5 @@ lib/
# Other
docs/
.nyc_output
demo/
demo/
test/
farisT marked this conversation as resolved.
Show resolved Hide resolved
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ lib/**/*.spec.js
lib/**/**.d.ts
*.gif
*.md
test/
2,483 changes: 2,296 additions & 187 deletions package-lock.json

Large diffs are not rendered by default.

17 changes: 16 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
],
"scripts": {
"start": "npm run build && npm run global",
"test": "npm run lint && npm run test:unit",
"test:unit": "mocha",
"lint": "tslint -p . --fix",
"build": "npm run clean:some && tsc -p .",
"global": "npm i -g && cgx",
"clean:some": "rm -rf ./lib ./docs",
Expand All @@ -34,7 +37,6 @@
"docs": "typedoc --out docs ./src"
},
"dependencies": {
"@types/fs-extra": "^8.1.0",
"figlet": "^1.3.0",
"fs-extra": "^9.0.0",
"inquirer": "^7.1.0",
Expand All @@ -43,9 +45,22 @@
},
"devDependencies": {
"@liftr/tscov": "^1.4.4",
"@types/bluebird": "^3.5.30",
"@types/chai": "^4.2.11",
"@types/figlet": "^1.2.0",
"@types/fs-extra": "^8.1.0",
"@types/inquirer": "^6.5.0",
"@types/mocha": "^7.0.2",
"@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",
"nyc": "^15.0.1",
"sinon": "^9.0.1",
"sinon-chai": "^3.5.0",
"ts-node": "^8.8.2",
"tslint": "^6.1.1",
"typedoc": "^0.17.3",
Expand Down
100 changes: 100 additions & 0 deletions src/actions/bitbucket.actions.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import sinon from 'sinon';
import { expect } from 'chai';
import * as questions from '../questions';
import { bitbucketActions } from './bitbucket.actions';
import { Answer, ProviderValue, LicenseValue, UniversalChoiceValue } from '../models/choice';
import * as templates from '../templates/universal';
import Bluebird from 'bluebird';
import * as logger from '../utils/logger.util';
import { ConsoleMessage } from '../models/console-message';

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

let sandbox: sinon.SinonSandbox;
let bitBucketFileQuestionStub: sinon.SinonStub;

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

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

it('should always call bitBucketFunction', async () => {
bitBucketFileQuestionStub = sandbox.stub(questions, 'bitbucketFileQuestion').resolves(mockAnswer);
await bitbucketActions();
expect(bitBucketFileQuestionStub).to.be.called;
});

context('actions', () => {
const cases = [
{
name: 'readme',
files: UniversalChoiceValue.README,
stub: sinon.stub(templates, 'readme'),
function: templates.readme,
},
{
name: 'todo',
files: UniversalChoiceValue.TODO,
stub: sinon.stub(templates, 'toDo'),
function: templates.toDo,

},
{
name: 'contributing',
files: UniversalChoiceValue.CONTRIBUTING,
stub: sinon.stub(templates, 'contributing'),
function: templates.contributing,

},
{
name: 'changelog',
files: UniversalChoiceValue.CHANGELOG,
stub: sinon.stub(templates, 'changelog'),
function: templates.changelog,

},
{
name: 'code of conduct',
files: UniversalChoiceValue.CODE_OF_CONDUCT,
stub: sinon.stub(templates, 'codeOfConduct'),
function: templates.codeOfConduct,

},
{
name: 'license',
files: UniversalChoiceValue.LICENSE,
stub: sinon.stub(templates, 'license'),
function: templates.license,
},
];
it(`should call showInfo, contributing and return code of conduct template if all choice is made`, async () => {
mockAnswer.files = UniversalChoiceValue.ALL;
const showInfoStub = sandbox.stub(logger, 'showInfo')
bitBucketFileQuestionStub = sandbox.stub(questions, 'bitbucketFileQuestion').resolves(mockAnswer);
await bitbucketActions()
expect(showInfoStub).to.be.calledOnceWithExactly(ConsoleMessage.START_GENERATING);
})
Bluebird.each(cases, (caseItem) => {
it(`should return ${caseItem.name} template if the choice is made for it`, async () => {
sandbox = sinon.createSandbox();
mockAnswer.files = caseItem.files;
bitBucketFileQuestionStub = sandbox.stub(questions, 'bitbucketFileQuestion').resolves(mockAnswer);
const bitBucket: Promise<any> = await bitbucketActions()
expect(caseItem.stub).to.be.calledOnce;
expect(bitBucket).to.equal(caseItem.function());
sandbox.restore();
})
})
})
});

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();
})
});
});
2 changes: 1 addition & 1 deletion src/questions/bitbucket-file.question.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ export async function bitbucketFileQuestion(): Promise<Answer> {
name: 'files',
type: 'list',
message: 'Which Bitbucket files do you want to generate?',
choices: listOfFiles
choices: listOfFiles,
}]);
}
2 changes: 1 addition & 1 deletion src/questions/codecommit-file.question.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ export async function codecommitFileQuestion(): Promise<Answer> {
name: 'files',
type: 'list',
message: 'Which CodeCommit files do you want to generate?',
choices: listOfFiles
choices: listOfFiles,
}]);
}
2 changes: 1 addition & 1 deletion src/questions/github-file.question.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ export async function githubFileQuestion(): Promise<Answer> {
name: 'files',
type: 'list',
message: 'Which Github files do you want to generate?',
choices: listOfFiles
choices: listOfFiles,
}]);
}
2 changes: 1 addition & 1 deletion src/questions/gitlab-file.question.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ export async function gitlabFileQuestion(): Promise<Answer> {
name: 'files',
type: 'list',
message: 'Which Gitlab files do you want to generate?',
choices: listOfFiles
choices: listOfFiles,
}]);
}
2 changes: 1 addition & 1 deletion src/questions/license.question.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ export async function licenseQuestion(): Promise<Answer> {
name: 'licenses',
type: 'list',
message: 'Which type of license do you want to generate?',
choices: listOfLicenses
choices: listOfLicenses,
}]);
}
2 changes: 1 addition & 1 deletion src/questions/overwrite-file.question.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ export async function overwriteFileQuestion(): Promise<Answer> {
name: 'overwrite',
type: 'confirm',
message: 'This file already exists. Do you want to overwrite it?',
default: false
default: false,
}]);
}
2 changes: 1 addition & 1 deletion src/questions/provider.question.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ export async function providerQuestion(): Promise<Answer> {
name: 'provider',
type: 'list',
message: 'Select a Git hosting provider:',
choices: listOfFiles
choices: listOfFiles,
}]);
}
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
10 changes: 5 additions & 5 deletions src/templates/universal/license.template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export async function license() {
}

function createFile(filepath: string, fileContent: string, fileName: string): void {
fs.writeFile(filepath, fileContent, (err) => {
fs.writeFile(filepath, fileContent, (err: Error) => {
showCreate(fileName, filepath);
if (err) {throw err};
});
Expand Down Expand Up @@ -111,11 +111,11 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.`
function ISCfileContent(userName: string): string {
return `Copyright (c) ${currentYear} ${userName}

Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted,
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted,
provided that the above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.`
}

Expand Down
18 changes: 9 additions & 9 deletions src/utils/logger.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,31 @@ export const showTitleAndBanner = (): void => {
console.log(cyan(figlet.textSync(ConsoleMessage.TITLE, { horizontalLayout: 'full' })));
console.info(cyan(ConsoleMessage.BANNER));
}

export const showError = (message: string | Error): void => {
console.error(red(ConsoleMessage.ERROR) + message);
}

export const showSuccess = (message: string): void => {
console.log(green(ConsoleMessage.SUCCESS) + message + newLine);
}

export const showInfo = (message: string): void => {
console.info(cyan(ConsoleMessage.INFO) + message + newLine);
}

export const showGenerate= (fileName: string): void => {
console.log(cyan(ConsoleMessage.GENERATE) + `${fileName}...`);
}

export const showCreate= (fileName: string, filePath: string): void => {
filePath
? console.log(green(ConsoleMessage.CREATE) + `${fileName} in ${filePath}`)
filePath
? console.log(green(ConsoleMessage.CREATE) + `${fileName} in ${filePath}`)
: console.log(green(ConsoleMessage.CREATE) + `${fileName}`);
}

export const showUpdate = (fileName: string, filePath: string): void => {
filePath
? console.log(green(ConsoleMessage.UPDATE) + `${fileName} in ${filePath}`)
filePath
? console.log(green(ConsoleMessage.UPDATE) + `${fileName} in ${filePath}`)
: console.log(green(ConsoleMessage.UPDATE) + `${fileName}`);
}
Loading