-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: adding more migrated test cases
- Loading branch information
Showing
3 changed files
with
117 additions
and
85 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,64 @@ | ||
'use strict' | ||
|
||
const tap = require('tap') | ||
const { test } = require('node:test') | ||
const sinon = require('sinon') | ||
const proxyquire = require('proxyquire') | ||
const core = require('@actions/core') | ||
|
||
const setup = () => { | ||
const setup = ({ t }) => { | ||
const coreStub = sinon.stub(core) | ||
const logger = proxyquire('../src/log', { | ||
'@actions/core': coreStub, | ||
const coreMock = t.mock.module('@actions/core', { | ||
namedExports: coreStub, | ||
}) | ||
|
||
return { coreStub, logger } | ||
const logger = require('../src/log') | ||
return { coreStub, logger, coreMock } | ||
} | ||
|
||
tap.afterEach(() => { | ||
sinon.restore() | ||
}) | ||
|
||
tap.test('calling log with an array will stringify it', async () => { | ||
const { logger, coreStub } = setup() | ||
logger.logDebug([1, 2, 3]) | ||
sinon.assert.calledWithExactly(coreStub.debug, '1,2,3') | ||
}) | ||
test('logger tests', async t => { | ||
t.beforeEach(() => { | ||
delete require.cache[require.resolve('../src/log')] | ||
}) | ||
|
||
tap.test('logDebug calls @actions/core/debug', async () => { | ||
const { logger, coreStub } = setup() | ||
logger.logDebug('Debug') | ||
sinon.assert.calledOnce(coreStub.debug) | ||
sinon.assert.notCalled(coreStub.error) | ||
}) | ||
t.afterEach(() => { | ||
sinon.restore() | ||
}) | ||
|
||
tap.test('logError calls @actions/core/error', async () => { | ||
const { logger, coreStub } = setup() | ||
logger.logError(new Error('not a string')) | ||
sinon.assert.calledOnce(coreStub.error) | ||
sinon.assert.notCalled(coreStub.debug) | ||
}) | ||
await t.test('calling log with an array will stringify it', async t => { | ||
const { logger, coreStub, coreMock } = setup({ t }) | ||
logger.logDebug([1, 2, 3]) | ||
sinon.assert.calledWithExactly(coreStub.debug, '1,2,3') | ||
coreMock.restore() | ||
}) | ||
|
||
tap.test('logInfo calls @actions/core/info', async () => { | ||
const { logger, coreStub } = setup() | ||
logger.logInfo('Debug') | ||
await t.test('logDebug calls @actions/core/debug', async t => { | ||
const { logger, coreStub, coreMock } = setup({ t }) | ||
logger.logDebug('Debug') | ||
sinon.assert.calledOnce(coreStub.debug) | ||
sinon.assert.notCalled(coreStub.error) | ||
coreMock.restore() | ||
}) | ||
|
||
sinon.assert.calledOnce(coreStub.info) | ||
sinon.assert.notCalled(coreStub.debug) | ||
}) | ||
await t.test('logError calls @actions/core/error', async t => { | ||
const { logger, coreStub, coreMock } = setup({ t }) | ||
logger.logError(new Error('not a string')) | ||
sinon.assert.calledOnce(coreStub.error) | ||
sinon.assert.notCalled(coreStub.debug) | ||
coreMock.restore() | ||
}) | ||
|
||
tap.test('logWarning calls @actions/core/warning', async () => { | ||
const { logger, coreStub } = setup() | ||
logger.logWarning('warning') | ||
await t.test('logInfo calls @actions/core/info', async t => { | ||
const { logger, coreStub, coreMock } = setup({ t }) | ||
logger.logInfo('Debug') | ||
sinon.assert.calledOnce(coreStub.info) | ||
sinon.assert.notCalled(coreStub.debug) | ||
coreMock.restore() | ||
}) | ||
|
||
sinon.assert.calledOnce(coreStub.warning) | ||
sinon.assert.notCalled(coreStub.debug) | ||
await t.test('logWarning calls @actions/core/warning', async t => { | ||
const { logger, coreStub, coreMock } = setup({ t }) | ||
logger.logWarning('warning') | ||
sinon.assert.calledOnce(coreStub.warning) | ||
sinon.assert.notCalled(coreStub.debug) | ||
coreMock.restore() | ||
}) | ||
}) |
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,33 +1,46 @@ | ||
'use strict' | ||
|
||
const tap = require('tap') | ||
const { test } = require('node:test') | ||
const assert = require('node:assert') | ||
const sinon = require('sinon') | ||
const proxyquire = require('proxyquire') | ||
|
||
const setup = () => { | ||
const setup = ({ t }) => { | ||
const execWithOutputStub = sinon.stub() | ||
const revertCommitProxy = proxyquire('../src/utils/revertCommit', { | ||
'./execWithOutput': { execWithOutput: execWithOutputStub }, | ||
const execMock = t.mock.module('../src/utils/execWithOutput.js', { | ||
namedExports: { | ||
execWithOutput: execWithOutputStub, | ||
}, | ||
}) | ||
|
||
return { execWithOutputStub, revertCommitProxy } | ||
const revertCommitProxy = require('../src/utils/revertCommit') | ||
return { execWithOutputStub, revertCommitProxy, execMock } | ||
} | ||
|
||
tap.afterEach(() => { | ||
sinon.restore() | ||
}) | ||
test('revertCommit tests', async t => { | ||
t.beforeEach(() => { | ||
delete require.cache[require.resolve('../src/utils/revertCommit')] | ||
}) | ||
|
||
tap.test('Revert commit', async t => { | ||
const { revertCommitProxy, execWithOutputStub } = setup() | ||
const baseRef = 'master' | ||
await revertCommitProxy.revertCommit(baseRef) | ||
t.afterEach(() => { | ||
sinon.restore() | ||
}) | ||
|
||
t.ok(execWithOutputStub.callCount === 2) | ||
await t.test('Revert commit', async t => { | ||
const { revertCommitProxy, execWithOutputStub, execMock } = setup({ t }) | ||
const baseRef = 'master' | ||
await revertCommitProxy.revertCommit(baseRef) | ||
|
||
sinon.assert.calledWithExactly(execWithOutputStub, 'git', ['revert', 'HEAD']) | ||
sinon.assert.calledWithExactly(execWithOutputStub, 'git', [ | ||
'push', | ||
'origin', | ||
`${baseRef}`, | ||
]) | ||
assert.equal(execWithOutputStub.callCount, 2) | ||
|
||
sinon.assert.calledWithExactly(execWithOutputStub, 'git', [ | ||
'revert', | ||
'HEAD', | ||
]) | ||
sinon.assert.calledWithExactly(execWithOutputStub, 'git', [ | ||
'push', | ||
'origin', | ||
`${baseRef}`, | ||
]) | ||
execMock.restore() | ||
}) | ||
}) |
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,38 +1,48 @@ | ||
'use strict' | ||
|
||
const tap = require('tap') | ||
const { test } = require('node:test') | ||
const assert = require('node:assert') | ||
const sinon = require('sinon') | ||
const proxyquire = require('proxyquire') | ||
|
||
const setup = () => { | ||
const setup = ({ t }) => { | ||
const execWithOutputStub = sinon.stub() | ||
const tagVersionProxy = proxyquire('../src/utils/tagVersion', { | ||
'./execWithOutput': { execWithOutput: execWithOutputStub }, | ||
const execMock = t.mock.module('../src/utils/execWithOutput.js', { | ||
namedExports: { | ||
execWithOutput: execWithOutputStub, | ||
}, | ||
}) | ||
|
||
return { execWithOutputStub, tagVersionProxy } | ||
const tagVersionProxy = require('../src/utils/tagVersion') | ||
return { execWithOutputStub, tagVersionProxy, execMock } | ||
} | ||
|
||
tap.afterEach(() => { | ||
sinon.restore() | ||
}) | ||
test('tagVersion tests', async t => { | ||
t.beforeEach(() => { | ||
delete require.cache[require.resolve('../src/utils/tagVersion')] | ||
}) | ||
|
||
t.afterEach(() => { | ||
sinon.restore() | ||
}) | ||
|
||
tap.test('Tag version in git', async t => { | ||
const { tagVersionProxy, execWithOutputStub } = setup() | ||
const version = 'v3.0.0' | ||
await tagVersionProxy.tagVersionInGit(version) | ||
|
||
t.ok(execWithOutputStub.callCount === 2) | ||
|
||
sinon.assert.calledWithExactly(execWithOutputStub, 'git', [ | ||
'tag', | ||
'-f', | ||
`${version}`, | ||
]) | ||
sinon.assert.calledWithExactly(execWithOutputStub, 'git', [ | ||
'push', | ||
'origin', | ||
'-f', | ||
`v3.0.0`, | ||
]) | ||
await t.test('Tag version in git', async t => { | ||
const { tagVersionProxy, execWithOutputStub, execMock } = setup({ t }) | ||
const version = 'v3.0.0' | ||
await tagVersionProxy.tagVersionInGit(version) | ||
|
||
assert.equal(execWithOutputStub.callCount, 2) | ||
|
||
sinon.assert.calledWithExactly(execWithOutputStub, 'git', [ | ||
'tag', | ||
'-f', | ||
`${version}`, | ||
]) | ||
sinon.assert.calledWithExactly(execWithOutputStub, 'git', [ | ||
'push', | ||
'origin', | ||
'-f', | ||
`v3.0.0`, | ||
]) | ||
execMock.restore() | ||
}) | ||
}) |