|
| 1 | +import * as fs from 'src/utils/fs'; |
| 2 | +import * as npm from 'src/utils/npm'; |
| 3 | +import * as config from 'src/categories/js/standard-version/standard-version.config'; |
| 4 | +import { defaultConfig } from 'src/categories/js/standard-version/config/default.config'; |
| 5 | +import { standardVersion } from 'src/categories/js/standard-version/standard-version.entrypoint'; |
| 6 | + |
| 7 | +jest.mock('src/utils/fs'); |
| 8 | +const fsMocked = jest.mocked(fs); |
| 9 | + |
| 10 | +jest.mock('src/utils/npm'); |
| 11 | +const npmMocked = jest.mocked(npm); |
| 12 | + |
| 13 | +jest.mock('src/categories/js/standard-version/standard-version.config'); |
| 14 | +const configMocked = jest.mocked(config); |
| 15 | + |
| 16 | +describe('standardVersion', () => { |
| 17 | + beforeEach(() => { |
| 18 | + configMocked.getConfig.mockReturnValueOnce(defaultConfig); |
| 19 | + npmMocked.getPackageJson.mockResolvedValue({}); |
| 20 | + }); |
| 21 | + |
| 22 | + test('should get config from getConfig', async () => { |
| 23 | + await standardVersion(); |
| 24 | + |
| 25 | + expect(configMocked.getConfig).toBeCalled(); |
| 26 | + }); |
| 27 | + |
| 28 | + test('should install standard-version package', async () => { |
| 29 | + await standardVersion(); |
| 30 | + |
| 31 | + expect(npmMocked.installDevelopmentDependencies).toBeCalledWith('standard-version'); |
| 32 | + }); |
| 33 | + |
| 34 | + test('should create config with repository url and set it', async () => { |
| 35 | + const withoutReadme = 'https://github.com/Allohamora/cli'; |
| 36 | + const homepage = `${withoutReadme}#readme`; |
| 37 | + |
| 38 | + npmMocked.getPackageJson.mockResolvedValueOnce({ homepage }); |
| 39 | + |
| 40 | + await standardVersion(); |
| 41 | + |
| 42 | + expect(fsMocked.addJsonFileToRoot).toBeCalledWith('.versionrc.json', defaultConfig.createConfig(withoutReadme)); |
| 43 | + }); |
| 44 | + |
| 45 | + test('should add config to package.json', async () => { |
| 46 | + await standardVersion(); |
| 47 | + |
| 48 | + expect(npmMocked.addToPackageJson).toBeCalledWith('standard-version', defaultConfig.packageJsonConfig); |
| 49 | + }); |
| 50 | + |
| 51 | + test('should add release scripts', async () => { |
| 52 | + await standardVersion(); |
| 53 | + |
| 54 | + expect(npmMocked.addScripts).toBeCalledWith(...defaultConfig.scripts); |
| 55 | + }); |
| 56 | +}); |
0 commit comments