Skip to content

Commit

Permalink
fix: add test
Browse files Browse the repository at this point in the history
  • Loading branch information
akijoey committed Sep 17, 2021
1 parent 5b95b11 commit 4b89890
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function castArray(arr) {

module.exports = async function publish(pluginConfig, context) {
const { logger, nextRelease } = context
logger.log('Deploying version %s with maven', nextRelease.version)
logger.log(`Deploying version ${nextRelease.version} with maven`)

const mvn = await findMaven()
const settings = path.join(__dirname, '../settings.xml')
Expand Down
23 changes: 23 additions & 0 deletions test/prepare.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const prepare = require('../lib/prepare')
const { exec, findMaven } = require('../lib/util')

jest.mock('../lib/util')
findMaven.mockReturnValue('mvn')

describe('prepare', () => {
const context = {
logger: { log: jest.fn() },
nextRelease: { version: '1.0.0' }
}

it('update version', async () => {
await prepare({}, context)
expect(exec).toHaveBeenCalledWith('mvn', [
'versions:set',
'-B',
'-ntp',
'-DgenerateBackupPoms=false',
`-DnewVersion=1.0.0`
])
})
})
31 changes: 31 additions & 0 deletions test/publish.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const path = require('path')

const publish = require('../lib/publish')
const { exec, findMaven } = require('../lib/util')

jest.mock('../lib/util')
findMaven.mockReturnValue('mvn')

describe('publish', () => {
const context = {
logger: { log: jest.fn() },
nextRelease: { version: '1.0.0' }
}
const settings = path.join(__dirname, '../settings.xml')
const args = ['deploy', '-B', '-ntp', '-DskipTests', '-s', settings]

it('publish without profile', async () => {
await publish({}, context)
expect(exec).toHaveBeenCalledWith('mvn', args)
})

it('pubish with single profile', async () => {
await publish({ profiles: 'release' }, context)
expect(exec).toHaveBeenCalledWith('mvn', args.concat('-P', 'release'))
})

it('pubish with multiple profiles', async () => {
await publish({ profiles: ['test', 'release'] }, context)
expect(exec).toHaveBeenCalledWith('mvn', args.concat('-P', 'test,release'))
})
})
31 changes: 31 additions & 0 deletions test/verify.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const path = require('path')

const verify = require('../lib/verify')
const { exec, getEnv, parsePom } = require('../lib/util')

jest.mock('fs-extra')
jest.mock('../lib/util')
getEnv.mockReturnValue(true)
parsePom.mockResolvedValue({
project: {
groupId: 'com.akijoey',
artifactId: 'test',
version: '1.0.0'
}
})

describe('verify', () => {
const context = {
logger: { log: jest.fn() },
nextRelease: { version: '1.0.0' }
}

it('import gpg secret', async () => {
await verify({}, context)
expect(exec).toHaveBeenCalledWith('gpg', [
'--import',
'--batch',
path.join(__dirname, '../secret.asc')
])
})
})

0 comments on commit 4b89890

Please sign in to comment.