This repository was archived by the owner on Jun 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
298 additions
and
186 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
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,69 +1,102 @@ | ||
// import { pascalCase } from 'change-case'; | ||
// import faker from 'faker'; | ||
// /* eslint-disable import/first */ | ||
import { pascalCase, paramCase } from 'change-case'; | ||
import faker from 'faker'; | ||
|
||
// // import { getEnvironment } from '../utils'; | ||
import { getCurrentBranch, getEnvironment, getPackageName } from '../utils'; | ||
|
||
// // import { getStackName } from './stackName'; | ||
import { getStackName, setPreDefinedStackName } from './stackName'; | ||
|
||
// const branchName = [ | ||
// faker.random.words(1), | ||
// faker.random.words(1), | ||
// faker.random.words(1), | ||
// faker.random.words(1), | ||
// ].join('/'); | ||
const mockMath = Object.create(global.Math); | ||
const randomNumber = 0.12345; | ||
mockMath.random = () => randomNumber; | ||
global.Math = mockMath; | ||
|
||
// const packageName = `@${faker.random.words(1)}/${faker.random.words(1)}`; | ||
const branchName = [ | ||
faker.random.words(1), | ||
faker.random.words(1), | ||
faker.random.words(1), | ||
faker.random.words(1), | ||
].join('/'); | ||
|
||
// const packageNamePascalCase = pascalCase(packageName); | ||
const environment = faker.random.word(); | ||
|
||
// jest.mock('../utils', () => ({ | ||
// getCurrentBranch: jest.fn(() => branchName), | ||
// getEnvironment: jest.fn(), | ||
// getPackageName: jest.fn(() => packageName), | ||
// })); | ||
const packageName = `@${faker.random.word()}/${faker.random.word()}`; | ||
|
||
jest.mock('../utils', () => ({ | ||
getCurrentBranch: jest.fn(), | ||
getEnvironment: jest.fn(), | ||
getPackageName: jest.fn(), | ||
})); | ||
|
||
describe('testing getStackName', () => { | ||
test('should return correct name for testing environment', async () => { | ||
// (getEnvironment as jest.Mock).mockReturnValueOnce('Testing'); | ||
// const stackName = await getStackName(); | ||
// expect(stackName).toEqual( | ||
// `Test${pascalCase(branchName)}-${packageNamePascalCase}` | ||
// ); | ||
expect(1).toEqual(1); | ||
test('documentation case #1', async () => { | ||
(getCurrentBranch as jest.Mock).mockReturnValueOnce(branchName); | ||
(getEnvironment as jest.Mock).mockReturnValueOnce(environment); | ||
(getPackageName as jest.Mock).mockReturnValueOnce(packageName); | ||
const preDefinedStackName = faker.random.word(); | ||
setPreDefinedStackName(preDefinedStackName); | ||
const stackName = await getStackName(); | ||
expect(stackName).toEqual(preDefinedStackName); | ||
}); | ||
|
||
// test('should return correct name for development environment', () => { | ||
// (getEnvironment as jest.Mock).mockReturnValueOnce('Development'); | ||
// return expect(getStackName()).resolves.toEqual( | ||
// `Dev${packageNamePascalCase}` | ||
// ); | ||
// }); | ||
describe('pre-defined stack name not defined', () => { | ||
beforeEach(() => { | ||
jest.resetAllMocks(); | ||
setPreDefinedStackName(''); | ||
}); | ||
|
||
test('documentation case #2', async () => { | ||
(getCurrentBranch as jest.Mock).mockReturnValueOnce(branchName); | ||
(getEnvironment as jest.Mock).mockReturnValueOnce(environment); | ||
(getPackageName as jest.Mock).mockReturnValueOnce(packageName); | ||
const stackName = await getStackName(); | ||
expect(stackName).toEqual(`${pascalCase(packageName)}-${environment}`); | ||
}); | ||
|
||
// test('should return correct name for staging environment', () => { | ||
// (getEnvironment as jest.Mock).mockReturnValueOnce('Staging'); | ||
// return expect(getStackName()).resolves.toEqual(packageNamePascalCase); | ||
// }); | ||
test('documentation case #3', async () => { | ||
(getCurrentBranch as jest.Mock).mockReturnValueOnce(branchName); | ||
(getEnvironment as jest.Mock).mockReturnValueOnce(undefined); | ||
(getPackageName as jest.Mock).mockReturnValueOnce(packageName); | ||
const stackName = await getStackName(); | ||
expect(stackName).toEqual( | ||
`${pascalCase(packageName)}-${paramCase(branchName)}`, | ||
); | ||
}); | ||
|
||
// test('should return correct name for production environment', () => { | ||
// (getEnvironment as jest.Mock).mockReturnValueOnce('Production'); | ||
// return expect(getStackName()).resolves.toEqual(packageNamePascalCase); | ||
// }); | ||
test('documentation case #4', async () => { | ||
(getCurrentBranch as jest.Mock).mockReturnValueOnce(undefined); | ||
(getEnvironment as jest.Mock).mockReturnValueOnce(undefined); | ||
(getPackageName as jest.Mock).mockReturnValueOnce(packageName); | ||
const stackName = await getStackName(); | ||
expect(stackName).toEqual(`${pascalCase(packageName)}`); | ||
}); | ||
|
||
// describe('should return correct name when pre defined stack name is provided', () => { | ||
// const preDefinedStackName = faker.random.word(); | ||
test('documentation case #5', async () => { | ||
(getCurrentBranch as jest.Mock).mockReturnValueOnce(branchName); | ||
(getEnvironment as jest.Mock).mockReturnValueOnce(environment); | ||
(getPackageName as jest.Mock).mockReturnValueOnce(undefined); | ||
const stackName = await getStackName(); | ||
expect(stackName).toEqual( | ||
`Stack-${randomNumber * 100000}-${environment}`, | ||
); | ||
}); | ||
|
||
// test('Testing environment', () => { | ||
// (getEnvironment as jest.Mock).mockReturnValueOnce('Testing'); | ||
// return expect(getStackName({ preDefinedStackName })).resolves.toEqual( | ||
// `Test${preDefinedStackName}` | ||
// ); | ||
// }); | ||
test('documentation case #6', async () => { | ||
(getCurrentBranch as jest.Mock).mockReturnValueOnce(branchName); | ||
(getEnvironment as jest.Mock).mockReturnValueOnce(undefined); | ||
(getPackageName as jest.Mock).mockReturnValueOnce(undefined); | ||
const stackName = await getStackName(); | ||
expect(stackName).toEqual( | ||
`Stack-${randomNumber * 100000}-${paramCase(branchName)}`, | ||
); | ||
}); | ||
|
||
// test('Development environment', () => { | ||
// (getEnvironment as jest.Mock).mockReturnValueOnce('Development'); | ||
// return expect(getStackName({ preDefinedStackName })).resolves.toEqual( | ||
// `Dev${preDefinedStackName}` | ||
// ); | ||
// }); | ||
// }); | ||
test('documentation case #6', async () => { | ||
(getCurrentBranch as jest.Mock).mockReturnValueOnce(undefined); | ||
(getEnvironment as jest.Mock).mockReturnValueOnce(undefined); | ||
(getPackageName as jest.Mock).mockReturnValueOnce(undefined); | ||
const stackName = await getStackName(); | ||
expect(stackName).toEqual(`Stack-${randomNumber * 100000}`); | ||
}); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -1,3 +1,9 @@ | ||
module.exports = { | ||
extends: '../../config/eslintrc.react', | ||
rules: { | ||
'no-use-before-define': 'off', | ||
'react/jsx-filename-extension': 'off', | ||
'react/jsx-one-expression-per-line': 'off', | ||
'react/no-danger': 'off', | ||
}, | ||
}; |
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
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
Oops, something went wrong.