Skip to content

Commit

Permalink
feat: add impl and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
antongolub committed Nov 18, 2021
1 parent ab46b05 commit 29599f1
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# @semrel-extra/npm
Drop-in-repl npm plugin to handle `npm-whoami` throttling issue for monorepos: https://github.com/semantic-release/npm/issues/414
Drop-in-repl for standard npm plugin to handle `npm-whoami` throttling issue for monorepos: [semantic-release/npm/issues/414](https://github.com/semantic-release/npm/issues/414)

### Install
```shell
Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
"scripts": {
"test": "uvu ./src/test/*"
},
"files": [
"src/main",
"LICENSE",
"README.md"
],
"repository": {
"type": "git",
"url": "git+https://github.com/semrel-extra/npm.git"
Expand Down
22 changes: 22 additions & 0 deletions src/main/js/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const plugin = require('@semantic-release/npm')

let verified
let result

async function verifyConditionsHooked(...args) {
if (verified) {
return result
}

return plugin.verifyConditions(...args).then(r => {
result = r
verified = true
})
}

verifyConditionsHooked._reset = () => {
result = undefined
verified = undefined
}

module.exports = { ...plugin, verifyConditions: verifyConditionsHooked }
36 changes: 36 additions & 0 deletions src/test/js/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
const sinon = require('sinon')
const { test } = require('uvu')
const assert = require('uvu/assert')
const plugin = require('../../main/js')
const realNpmPlugin = require('@semantic-release/npm')

test('prepare, publish, addChannel are re-exported as is', () => {
assert.is(realNpmPlugin.addChannel, plugin.addChannel)
assert.is(realNpmPlugin.publish, plugin.publish)
assert.is(realNpmPlugin.prepare, plugin.prepare)
})

test('verifyConditions passes args down to `semrel/npm`', async () => {
const mock = sinon.mock(realNpmPlugin)
mock.expects('verifyConditions').once().withArgs('test').returns(Promise.resolve())

await plugin.verifyConditions('test')

mock.verify()
mock.restore()
plugin.verifyConditions._reset()
})

test('prevents multiple `verifyConditions` invocations', async () => {
const mock = sinon.mock(realNpmPlugin)
mock.expects('verifyConditions').once().withArgs('test').returns(Promise.resolve())

await plugin.verifyConditions('test')
await plugin.verifyConditions('test')

mock.verify()
mock.restore()
plugin.verifyConditions._reset()
})

test.run()

0 comments on commit 29599f1

Please sign in to comment.