-
Notifications
You must be signed in to change notification settings - Fork 25
/
TestPublishToNpm.groovy
57 lines (50 loc) · 2.19 KB
/
TestPublishToNpm.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/
package jenkins.tests
import jenkins.tests.BuildPipelineTest
import static com.lesfurets.jenkins.unit.MethodCall.callArgsToString
import static org.hamcrest.CoreMatchers.hasItem
import static org.hamcrest.MatcherAssert.assertThat
import org.junit.Before
import org.junit.Test
class TestPublishToNpm extends BuildPipelineTest {
@Override
@Before
void setUp() {
super.setUp()
}
@Test
void testWithTarball() {
this.registerLibTester(new PublishToNpmLibTester('artifact', '/tmp/workspace/example.tgz'))
super.testPipeline('tests/jenkins/jobs/PublishToNpmUsingTarball_JenkinsFile')
assertThat(getShellCommands('npm'), hasItem(
'\n npm set registry \"https://registry.npmjs.org\"\n npm set //registry.npmjs.org/:_authToken NPM_TOKEN\n npm publish /tmp/workspace/example.tgz --dry-run && npm publish /tmp/workspace/example.tgz --access public --tag beta\n '
))
assertThat(getShellCommands('nvmrc'), hasItem('rm -rf /tmp/workspace/.nvmrc && rm -rf ~/.nvmrc'))
}
@Test
void testWithRepoTag() {
this.registerLibTester(new PublishToNpmLibTester('github'))
super.testPipeline('tests/jenkins/jobs/PublishToNpm_Jenkinsfile')
assertThat(getShellCommands('npm'), hasItem(
'\n npm set registry \"https://registry.npmjs.org\"\n npm set //registry.npmjs.org/:_authToken NPM_TOKEN\n npm publish --dry-run && npm publish --access public --tag latest\n '
))
assertThat(getShellCommands('nvmrc'), hasItem('rm -rf /tmp/workspace/.nvmrc && rm -rf ~/.nvmrc'))
}
def getShellCommands(searchtext) {
def shCommands = helper.callStack.findAll { call ->
call.methodName == 'sh'
}.collect { call ->
callArgsToString(call)
}.findAll { npmCommand ->
npmCommand.contains(searchtext)
}
return shCommands
}
}