Skip to content

Commit

Permalink
fix: set Eufemia.version during release
Browse files Browse the repository at this point in the history
  • Loading branch information
tujoworker committed Feb 9, 2022
1 parent 2c09399 commit e74d441
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 1 deletion.
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'`)
)
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
export async function makeReleaseVersion() {
const branchName = getBranchName()

if (releaseBranches.includes(branchName)) {
if (!releaseBranches.includes(branchName)) {
return // stop here
}

Expand Down

0 comments on commit e74d441

Please sign in to comment.