-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: set Eufemia.version during release
- Loading branch information
1 parent
2c09399
commit e74d441
Showing
2 changed files
with
101 additions
and
1 deletion.
There are no files selected for viewing
100 changes: 100 additions & 0 deletions
100
packages/dnb-eufemia/scripts/prepub/tasks/__tests__/makeReleaseVersion.test.js
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,100 @@ | ||
/** | ||
* Scripts test | ||
* | ||
*/ | ||
|
||
import fs from 'fs-extra' | ||
import { makeReleaseVersion } from '../makeReleaseVersion' | ||
import * as getBranchName from 'current-git-branch' | ||
import * as getNextReleaseVersion from '../../../release/getNextReleaseVersion' | ||
|
||
jest.mock('../../../release/getNextReleaseVersion', () => { | ||
return { | ||
...jest.requireActual('../../../release/getNextReleaseVersion'), | ||
getNextReleaseVersion: jest.fn().mockResolvedValue(), | ||
} | ||
}) | ||
|
||
jest.mock('fs-extra', () => { | ||
return { | ||
...jest.requireActual('fs-extra'), | ||
writeFile: jest.fn().mockResolvedValue(), | ||
} | ||
}) | ||
|
||
jest.mock('repo-utils', () => { | ||
return { | ||
...jest.requireActual('repo-utils'), | ||
isCI: true, | ||
} | ||
}) | ||
|
||
jest.mock('current-git-branch', () => { | ||
return jest.fn().mockReturnValue('release') | ||
}) | ||
|
||
beforeEach(() => { | ||
jest.resetAllMocks() | ||
}) | ||
|
||
describe('makeReleaseVersion', () => { | ||
it('should only run when on release branches', async () => { | ||
jest | ||
.spyOn(getBranchName, 'default') | ||
.mockImplementationOnce(() => 'release') | ||
jest | ||
.spyOn(getNextReleaseVersion, 'getNextReleaseVersion') | ||
.mockImplementationOnce(async () => '123456789') | ||
|
||
await makeReleaseVersion() | ||
|
||
expect(fs.writeFile).toHaveBeenCalledTimes(1) | ||
}) | ||
|
||
it('should not run when not on release branches', async () => { | ||
jest | ||
.spyOn(getBranchName, 'default') | ||
.mockImplementationOnce(() => 'not-valid') | ||
jest | ||
.spyOn(getNextReleaseVersion, 'getNextReleaseVersion') | ||
.mockImplementationOnce(async () => '123456789') | ||
|
||
await makeReleaseVersion() | ||
|
||
expect(fs.writeFile).toHaveBeenCalledTimes(0) | ||
}) | ||
|
||
it('write version in Eufemia file', async () => { | ||
jest | ||
.spyOn(getBranchName, 'default') | ||
.mockImplementationOnce(() => 'release') | ||
jest | ||
.spyOn(getNextReleaseVersion, 'getNextReleaseVersion') | ||
.mockImplementationOnce(async () => '123456789') | ||
|
||
await makeReleaseVersion() | ||
|
||
expect(fs.writeFile).toHaveBeenCalledTimes(1) | ||
expect(fs.writeFile).toHaveBeenLastCalledWith( | ||
expect.stringContaining('src/shared/Eufemia.js'), | ||
expect.stringContaining(`return '123456789'`) | ||
) | ||
}) | ||
|
||
it('write branch in Eufemia file', async () => { | ||
jest | ||
.spyOn(getBranchName, 'default') | ||
.mockImplementationOnce(() => 'release') | ||
jest | ||
.spyOn(getNextReleaseVersion, 'getNextReleaseVersion') | ||
.mockImplementationOnce(async () => null) | ||
|
||
await makeReleaseVersion() | ||
|
||
expect(fs.writeFile).toHaveBeenCalledTimes(1) | ||
expect(fs.writeFile).toHaveBeenLastCalledWith( | ||
expect.stringContaining('src/shared/Eufemia.js'), | ||
expect.stringContaining(`return 'release'`) | ||
) | ||
}) | ||
}) |
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