Skip to content

Commit 29599f1

Browse files
committed
feat: add impl and tests
1 parent ab46b05 commit 29599f1

File tree

4 files changed

+64
-1
lines changed

4 files changed

+64
-1
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# @semrel-extra/npm
2-
Drop-in-repl npm plugin to handle `npm-whoami` throttling issue for monorepos: https://github.com/semantic-release/npm/issues/414
2+
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)
33

44
### Install
55
```shell

package.json

+5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
"scripts": {
77
"test": "uvu ./src/test/*"
88
},
9+
"files": [
10+
"src/main",
11+
"LICENSE",
12+
"README.md"
13+
],
914
"repository": {
1015
"type": "git",
1116
"url": "git+https://github.com/semrel-extra/npm.git"

src/main/js/index.js

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
const plugin = require('@semantic-release/npm')
2+
3+
let verified
4+
let result
5+
6+
async function verifyConditionsHooked(...args) {
7+
if (verified) {
8+
return result
9+
}
10+
11+
return plugin.verifyConditions(...args).then(r => {
12+
result = r
13+
verified = true
14+
})
15+
}
16+
17+
verifyConditionsHooked._reset = () => {
18+
result = undefined
19+
verified = undefined
20+
}
21+
22+
module.exports = { ...plugin, verifyConditions: verifyConditionsHooked }

src/test/js/index.js

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
const sinon = require('sinon')
2+
const { test } = require('uvu')
3+
const assert = require('uvu/assert')
4+
const plugin = require('../../main/js')
5+
const realNpmPlugin = require('@semantic-release/npm')
6+
7+
test('prepare, publish, addChannel are re-exported as is', () => {
8+
assert.is(realNpmPlugin.addChannel, plugin.addChannel)
9+
assert.is(realNpmPlugin.publish, plugin.publish)
10+
assert.is(realNpmPlugin.prepare, plugin.prepare)
11+
})
12+
13+
test('verifyConditions passes args down to `semrel/npm`', async () => {
14+
const mock = sinon.mock(realNpmPlugin)
15+
mock.expects('verifyConditions').once().withArgs('test').returns(Promise.resolve())
16+
17+
await plugin.verifyConditions('test')
18+
19+
mock.verify()
20+
mock.restore()
21+
plugin.verifyConditions._reset()
22+
})
23+
24+
test('prevents multiple `verifyConditions` invocations', async () => {
25+
const mock = sinon.mock(realNpmPlugin)
26+
mock.expects('verifyConditions').once().withArgs('test').returns(Promise.resolve())
27+
28+
await plugin.verifyConditions('test')
29+
await plugin.verifyConditions('test')
30+
31+
mock.verify()
32+
mock.restore()
33+
plugin.verifyConditions._reset()
34+
})
35+
36+
test.run()

0 commit comments

Comments
 (0)