-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✅ Add tests for project infos module
- Loading branch information
Franck
committed
Jun 10, 2019
1 parent
34d475c
commit aae1bc6
Showing
4 changed files
with
290 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
module.exports = { | ||
collectCoverageFrom: ['./src/**/*.js', '!**/node_modules/**', '!**/vendor/**'] | ||
collectCoverageFrom: [ | ||
'./src/**/*.js', | ||
'!./src/index.js', | ||
'!**/node_modules/**', | ||
'!**/vendor/**' | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,257 @@ | ||
const ora = require('ora') | ||
const childProcess = require('child_process') | ||
|
||
const utils = require('./utils') | ||
const { getProjectInfos } = require('./project-infos') | ||
|
||
jest.mock('ora') | ||
jest.mock('child_process', () => ({ | ||
execSync: jest.fn() | ||
})) | ||
jest.mock('./utils', () => ({ | ||
getPackageJson: jest.fn() | ||
})) | ||
|
||
const succeed = jest.fn() | ||
const fail = jest.fn() | ||
|
||
ora.mockReturnValue({ | ||
start: () => ({ | ||
succeed, | ||
fail | ||
}) | ||
}) | ||
|
||
describe('projectInfos', () => { | ||
describe('getProjectInfos', () => { | ||
it('should call ora with correct parameters', async () => { | ||
await getProjectInfos() | ||
|
||
expect(ora).toHaveBeenCalledTimes(1) | ||
expect(ora).toHaveBeenCalledWith('Gathering project infos') | ||
expect(succeed).toHaveBeenCalledTimes(1) | ||
expect(succeed).toHaveBeenCalledWith('Project infos gathered') | ||
}) | ||
|
||
it('should return correct infos', async () => { | ||
const packgeJsonInfos = { | ||
name: 'readme-md-generator', | ||
version: '0.1.3', | ||
description: 'CLI that generates beautiful README.md files.', | ||
author: 'Franck Abgrall', | ||
license: 'MIT', | ||
homepage: 'https://github.com/kefranabg/readme-md-generator#readme', | ||
repository: { | ||
type: 'git', | ||
url: 'git+https://github.com/kefranabg/readme-md-generator.git' | ||
}, | ||
bugs: { | ||
url: 'https://github.com/kefranabg/readme-md-generator/issues' | ||
}, | ||
engines: { | ||
npm: '>=5.5.0', | ||
node: '>=9.3.0' | ||
} | ||
} | ||
utils.getPackageJson.mockReturnValueOnce(Promise.resolve(packgeJsonInfos)) | ||
childProcess.execSync.mockReturnValue( | ||
'https://github.com/kefranabg/readme-md-generator.git' | ||
) | ||
|
||
const projectInfos = await getProjectInfos() | ||
|
||
expect(projectInfos).toEqual({ | ||
name: 'readme-md-generator', | ||
description: 'CLI that generates beautiful README.md files.', | ||
version: '0.1.3', | ||
author: 'Franck Abgrall', | ||
repositoryUrl: 'https://github.com/kefranabg/readme-md-generator', | ||
contributingUrl: | ||
'https://github.com/kefranabg/readme-md-generator/issues', | ||
githubUsername: 'kefranabg', | ||
engines: { | ||
npm: '>=5.5.0', | ||
node: '>=9.3.0' | ||
}, | ||
licenseName: 'MIT', | ||
licenseUrl: | ||
'https://github.com/kefranabg/readme-md-generator/blob/master/LICENSE', | ||
documentationUrl: | ||
'https://github.com/kefranabg/readme-md-generator#readme', | ||
isGithubRepos: true | ||
}) | ||
}) | ||
|
||
it('should return correct infos when repos is not github', async () => { | ||
const packgeJsonInfos = { | ||
name: 'readme-md-generator', | ||
version: '0.1.3', | ||
description: 'CLI that generates beautiful README.md files.', | ||
author: 'Franck Abgrall', | ||
license: 'MIT', | ||
homepage: 'https://gitlab.com/kefranabg/readme-md-generator#readme', | ||
repository: { | ||
type: 'git', | ||
url: 'git+https://gitlab.com/kefranabg/readme-md-generator.git' | ||
}, | ||
bugs: { | ||
url: 'https://gitlab.com/kefranabg/readme-md-generator/issues' | ||
}, | ||
engines: { | ||
npm: '>=5.5.0', | ||
node: '>=9.3.0' | ||
} | ||
} | ||
utils.getPackageJson.mockReturnValueOnce(Promise.resolve(packgeJsonInfos)) | ||
childProcess.execSync.mockReturnValue( | ||
'https://github.com/kefranabg/readme-md-generator.git' | ||
) | ||
|
||
const projectInfos = await getProjectInfos() | ||
|
||
expect(projectInfos).toEqual({ | ||
name: 'readme-md-generator', | ||
description: 'CLI that generates beautiful README.md files.', | ||
version: '0.1.3', | ||
author: 'Franck Abgrall', | ||
repositoryUrl: 'https://gitlab.com/kefranabg/readme-md-generator', | ||
contributingUrl: | ||
'https://gitlab.com/kefranabg/readme-md-generator/issues', | ||
githubUsername: undefined, | ||
engines: { | ||
npm: '>=5.5.0', | ||
node: '>=9.3.0' | ||
}, | ||
licenseName: 'MIT', | ||
licenseUrl: undefined, | ||
documentationUrl: | ||
'https://gitlab.com/kefranabg/readme-md-generator#readme', | ||
isGithubRepos: false | ||
}) | ||
}) | ||
|
||
it('should return correct infos when package.json is not defined', async () => { | ||
utils.getPackageJson.mockReturnValueOnce(Promise.resolve(undefined)) | ||
childProcess.execSync.mockReturnValue( | ||
'https://github.com/kefranabg/readme-md-generator.git' | ||
) | ||
|
||
const projectInfos = await getProjectInfos() | ||
|
||
expect(projectInfos).toEqual({ | ||
name: 'readme-md-generator', | ||
description: undefined, | ||
version: undefined, | ||
author: undefined, | ||
repositoryUrl: 'https://github.com/kefranabg/readme-md-generator', | ||
contributingUrl: | ||
'https://github.com/kefranabg/readme-md-generator/issues', | ||
githubUsername: 'kefranabg', | ||
engines: undefined, | ||
licenseName: undefined, | ||
licenseUrl: | ||
'https://github.com/kefranabg/readme-md-generator/blob/master/LICENSE', | ||
documentationUrl: undefined, | ||
isGithubRepos: true | ||
}) | ||
}) | ||
|
||
it('should return correct infos when repos is not github and package.json are not defined', async () => { | ||
utils.getPackageJson.mockReturnValueOnce(Promise.resolve(undefined)) | ||
childProcess.execSync.mockReturnValue( | ||
'https://gitlab.com/kefranabg/readme-md-generator.git' | ||
) | ||
|
||
const projectInfos = await getProjectInfos() | ||
|
||
expect(projectInfos).toEqual({ | ||
name: 'readme-md-generator', | ||
description: undefined, | ||
version: undefined, | ||
author: undefined, | ||
repositoryUrl: 'https://gitlab.com/kefranabg/readme-md-generator', | ||
contributingUrl: | ||
'https://gitlab.com/kefranabg/readme-md-generator/issues', | ||
githubUsername: undefined, | ||
engines: undefined, | ||
licenseName: undefined, | ||
licenseUrl: undefined, | ||
documentationUrl: undefined, | ||
isGithubRepos: false | ||
}) | ||
}) | ||
|
||
it('should return correct infos when git config and package.json are not defined', async () => { | ||
utils.getPackageJson.mockReturnValueOnce(Promise.resolve(undefined)) | ||
childProcess.execSync.mockImplementation(() => { | ||
throw new Error('error') | ||
}) | ||
|
||
const projectInfos = await getProjectInfos() | ||
|
||
expect(projectInfos).toEqual({ | ||
name: 'readme-md-generator', | ||
description: undefined, | ||
version: undefined, | ||
author: undefined, | ||
repositoryUrl: undefined, | ||
contributingUrl: undefined, | ||
githubUsername: undefined, | ||
engines: undefined, | ||
licenseName: undefined, | ||
licenseUrl: undefined, | ||
documentationUrl: undefined, | ||
isGithubRepos: false | ||
}) | ||
}) | ||
|
||
it('should return correct infos when git config is not defined', async () => { | ||
const packgeJsonInfos = { | ||
name: 'readme-md-generator', | ||
version: '0.1.3', | ||
description: 'CLI that generates beautiful README.md files.', | ||
author: 'Franck Abgrall', | ||
license: 'MIT', | ||
homepage: 'https://github.com/kefranabg/readme-md-generator#readme', | ||
repository: { | ||
type: 'git', | ||
url: 'git+https://github.com/kefranabg/readme-md-generator.git' | ||
}, | ||
bugs: { | ||
url: 'https://github.com/kefranabg/readme-md-generator/issues' | ||
}, | ||
engines: { | ||
npm: '>=5.5.0', | ||
node: '>=9.3.0' | ||
} | ||
} | ||
utils.getPackageJson.mockReturnValueOnce(Promise.resolve(packgeJsonInfos)) | ||
childProcess.execSync.mockImplementation(() => { | ||
throw new Error('error') | ||
}) | ||
|
||
const projectInfos = await getProjectInfos() | ||
|
||
expect(projectInfos).toEqual({ | ||
name: 'readme-md-generator', | ||
description: 'CLI that generates beautiful README.md files.', | ||
version: '0.1.3', | ||
author: 'Franck Abgrall', | ||
repositoryUrl: 'https://github.com/kefranabg/readme-md-generator', | ||
contributingUrl: | ||
'https://github.com/kefranabg/readme-md-generator/issues', | ||
githubUsername: 'kefranabg', | ||
engines: { | ||
npm: '>=5.5.0', | ||
node: '>=9.3.0' | ||
}, | ||
licenseName: 'MIT', | ||
licenseUrl: | ||
'https://github.com/kefranabg/readme-md-generator/blob/master/LICENSE', | ||
documentationUrl: | ||
'https://github.com/kefranabg/readme-md-generator#readme', | ||
isGithubRepos: true | ||
}) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
const questions = require('./') | ||
|
||
describe('questions', () => { | ||
it('should export questions in the correct order', () => { | ||
const questionsNameOrder = Object.keys(questions) | ||
|
||
expect(questionsNameOrder).toEqual([ | ||
'askProjectName', | ||
'askProjectVersion', | ||
'askProjectDescription', | ||
'askProjectDocumentationUrl', | ||
'askAuhtorName', | ||
'askAuthorGithub', | ||
'askAuthorTwitter', | ||
'askProjectPrerequisites', | ||
'askLicenseName', | ||
'askLicenseUrl', | ||
'askContributing' | ||
]) | ||
}) | ||
}) |