Skip to content

Commit 168c7e8

Browse files
Added tests for the new "tag" and "scope" options
1 parent d91b4fc commit 168c7e8

File tree

3 files changed

+538
-3
lines changed

3 files changed

+538
-3
lines changed

test/specs/action/success.spec.js

Lines changed: 223 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,60 @@ describe("GitHub Action - success tests", () => {
4848
expect(cli).stdout.to.include("::set-output name=type::major");
4949
expect(cli).stdout.to.include("::set-output name=version::2.0.0");
5050
expect(cli).stdout.to.include("::set-output name=old-version::1.0.0");
51+
expect(cli).stdout.to.include("::set-output name=tag::latest");
52+
expect(cli).stdout.to.include("::set-output name=access::public");
53+
expect(cli).stdout.to.include("::set-output name=dry-run::false");
54+
expect(cli).to.have.exitCode(0);
55+
56+
files.assert.contents("home/.npmrc",
57+
`//registry.npmjs.org/:_authToken=\${INPUT_TOKEN}${EOL}` +
58+
`registry=https://registry.npmjs.org/${EOL}`
59+
);
60+
61+
npm.assert.ran(4);
62+
});
63+
64+
it("should publish a new version to NPM if no package exists", async () => {
65+
files.create([
66+
{ path: "workspace/package.json", contents: { name: "my-lib", version: "1.0.0" }},
67+
]);
68+
69+
npm.mock({
70+
args: ["config", "get", "userconfig"],
71+
stdout: `${paths.npmrc}${EOL}`,
72+
});
73+
74+
npm.mock({
75+
args: ["view", "my-lib", "version"],
76+
stdout: `${EOL}`,
77+
stderr: `npm ERR! code E404${EOL}`
78+
});
79+
80+
npm.mock({
81+
args: ["config", "get", "userconfig"],
82+
stdout: `${paths.npmrc}${EOL}`,
83+
});
84+
85+
npm.mock({
86+
args: ["publish"],
87+
stdout: `my-lib 1.0.0${EOL}`,
88+
});
89+
90+
let cli = exec.action({
91+
env: {
92+
INPUT_TOKEN: "my-secret-token",
93+
}
94+
});
95+
96+
expect(cli).to.have.stderr("");
97+
expect(cli).stdout.to.include("my-lib 1.0.0");
98+
expect(cli).stdout.to.include("Successfully published my-lib v1.0.0 to NPM");
99+
expect(cli).stdout.to.include("::set-output name=type::major");
100+
expect(cli).stdout.to.include("::set-output name=version::1.0.0");
101+
expect(cli).stdout.to.include("::set-output name=old-version::0.0.0");
102+
expect(cli).stdout.to.include("::set-output name=tag::latest");
103+
expect(cli).stdout.to.include("::set-output name=access::public");
104+
expect(cli).stdout.to.include("::set-output name=dry-run::false");
51105
expect(cli).to.have.exitCode(0);
52106

53107
files.assert.contents("home/.npmrc",
@@ -84,6 +138,9 @@ describe("GitHub Action - success tests", () => {
84138
expect(cli).stdout.to.include("::set-output name=type::none");
85139
expect(cli).stdout.to.include("::set-output name=version::1.0.0");
86140
expect(cli).stdout.to.include("::set-output name=old-version::1.0.0");
141+
expect(cli).stdout.to.include("::set-output name=tag::latest");
142+
expect(cli).stdout.to.include("::set-output name=access::public");
143+
expect(cli).stdout.to.include("::set-output name=dry-run::false");
87144
expect(cli).to.have.exitCode(0);
88145

89146
files.assert.contents("home/.npmrc",
@@ -133,6 +190,9 @@ describe("GitHub Action - success tests", () => {
133190
expect(cli).stdout.to.include("::set-output name=type::minor");
134191
expect(cli).stdout.to.include("::set-output name=version::1.1.0");
135192
expect(cli).stdout.to.include("::set-output name=old-version::1.0.0");
193+
expect(cli).stdout.to.include("::set-output name=tag::latest");
194+
expect(cli).stdout.to.include("::set-output name=access::public");
195+
expect(cli).stdout.to.include("::set-output name=dry-run::false");
136196
expect(cli).to.have.exitCode(0);
137197

138198
files.assert.contents("home/.npmrc",
@@ -198,6 +258,9 @@ describe("GitHub Action - success tests", () => {
198258
expect(cli).stdout.to.include("::set-output name=type::patch");
199259
expect(cli).stdout.to.include("::set-output name=version::1.0.1");
200260
expect(cli).stdout.to.include("::set-output name=old-version::1.0.0");
261+
expect(cli).stdout.to.include("::set-output name=tag::latest");
262+
expect(cli).stdout.to.include("::set-output name=access::public");
263+
expect(cli).stdout.to.include("::set-output name=dry-run::false");
201264
expect(cli).to.have.exitCode(0);
202265

203266
files.assert.contents("home/.npmrc",
@@ -255,6 +318,164 @@ describe("GitHub Action - success tests", () => {
255318
expect(cli).stdout.to.include("::set-output name=type::prerelease");
256319
expect(cli).stdout.to.include("::set-output name=version::1.0.0-beta");
257320
expect(cli).stdout.to.include("::set-output name=old-version::1.0.0");
321+
expect(cli).stdout.to.include("::set-output name=tag::latest");
322+
expect(cli).stdout.to.include("::set-output name=access::public");
323+
expect(cli).stdout.to.include("::set-output name=dry-run::false");
324+
expect(cli).to.have.exitCode(0);
325+
326+
files.assert.contents("home/.npmrc",
327+
`//registry.npmjs.org/:_authToken=\${INPUT_TOKEN}${EOL}` +
328+
`registry=https://registry.npmjs.org/${EOL}`
329+
);
330+
331+
npm.assert.ran(4);
332+
});
333+
334+
it("should publish a scoped package", () => {
335+
files.create([
336+
{ path: "workspace/package.json", contents: { name: "@my-scope/my-lib", version: "2.0.0" }},
337+
]);
338+
339+
npm.mock({
340+
args: ["config", "get", "userconfig"],
341+
stdout: `${paths.npmrc}${EOL}`,
342+
});
343+
344+
npm.mock({
345+
args: ["view", "@my-scope/my-lib", "version"],
346+
stdout: `1.0.0${EOL}`,
347+
});
348+
349+
npm.mock({
350+
args: ["config", "get", "userconfig"],
351+
stdout: `${paths.npmrc}${EOL}`,
352+
});
353+
354+
npm.mock({
355+
args: ["publish"],
356+
env: { INPUT_TOKEN: "my-secret-token" },
357+
stdout: `@my-scope/my-lib 2.0.0${EOL}`,
358+
});
359+
360+
let cli = exec.action({
361+
env: {
362+
INPUT_TOKEN: "my-secret-token",
363+
}
364+
});
365+
366+
expect(cli).to.have.stderr("");
367+
expect(cli).stdout.to.include("@my-scope/my-lib 2.0.0");
368+
expect(cli).stdout.to.include("Successfully published @my-scope/my-lib v2.0.0 to NPM");
369+
expect(cli).stdout.to.include("::set-output name=type::major");
370+
expect(cli).stdout.to.include("::set-output name=version::2.0.0");
371+
expect(cli).stdout.to.include("::set-output name=old-version::1.0.0");
372+
expect(cli).stdout.to.include("::set-output name=tag::latest");
373+
expect(cli).stdout.to.include("::set-output name=access::restricted");
374+
expect(cli).stdout.to.include("::set-output name=dry-run::false");
375+
expect(cli).to.have.exitCode(0);
376+
377+
files.assert.contents("home/.npmrc",
378+
`//registry.npmjs.org/:_authToken=\${INPUT_TOKEN}${EOL}` +
379+
`registry=https://registry.npmjs.org/${EOL}`
380+
);
381+
382+
npm.assert.ran(4);
383+
});
384+
385+
it("should publish to a specific tag", () => {
386+
files.create([
387+
{ path: "workspace/package.json", contents: { name: "my-lib", version: "2.0.0" }},
388+
]);
389+
390+
npm.mock({
391+
args: ["config", "get", "userconfig"],
392+
stdout: `${paths.npmrc}${EOL}`,
393+
});
394+
395+
npm.mock({
396+
args: ["view", "my-lib@next", "version"],
397+
stdout: `1.0.0${EOL}`,
398+
});
399+
400+
npm.mock({
401+
args: ["config", "get", "userconfig"],
402+
stdout: `${paths.npmrc}${EOL}`,
403+
});
404+
405+
npm.mock({
406+
args: ["publish", "--tag", "next"],
407+
env: { INPUT_TOKEN: "my-secret-token" },
408+
stdout: `my-lib 2.0.0${EOL}`,
409+
});
410+
411+
let cli = exec.action({
412+
env: {
413+
INPUT_TOKEN: "my-secret-token",
414+
INPUT_TAG: "next",
415+
}
416+
});
417+
418+
expect(cli).to.have.stderr("");
419+
expect(cli).stdout.to.include("my-lib 2.0.0");
420+
expect(cli).stdout.to.include("Successfully published my-lib v2.0.0 to NPM");
421+
expect(cli).stdout.to.include("::set-output name=type::major");
422+
expect(cli).stdout.to.include("::set-output name=version::2.0.0");
423+
expect(cli).stdout.to.include("::set-output name=old-version::1.0.0");
424+
expect(cli).stdout.to.include("::set-output name=tag::next");
425+
expect(cli).stdout.to.include("::set-output name=access::public");
426+
expect(cli).stdout.to.include("::set-output name=dry-run::false");
427+
expect(cli).to.have.exitCode(0);
428+
429+
files.assert.contents("home/.npmrc",
430+
`//registry.npmjs.org/:_authToken=\${INPUT_TOKEN}${EOL}` +
431+
`registry=https://registry.npmjs.org/${EOL}`
432+
);
433+
434+
npm.assert.ran(4);
435+
});
436+
437+
it("should publish a scoped package with public access", () => {
438+
files.create([
439+
{ path: "workspace/package.json", contents: { name: "@my-scope/my-lib", version: "2.0.0" }},
440+
]);
441+
442+
npm.mock({
443+
args: ["config", "get", "userconfig"],
444+
stdout: `${paths.npmrc}${EOL}`,
445+
});
446+
447+
npm.mock({
448+
args: ["view", "@my-scope/my-lib", "version"],
449+
stdout: `1.0.0${EOL}`,
450+
});
451+
452+
npm.mock({
453+
args: ["config", "get", "userconfig"],
454+
stdout: `${paths.npmrc}${EOL}`,
455+
});
456+
457+
npm.mock({
458+
args: ["publish", "--access", "public"],
459+
env: { INPUT_TOKEN: "my-secret-token" },
460+
stdout: `@my-scope/my-lib 2.0.0${EOL}`,
461+
});
462+
463+
let cli = exec.action({
464+
env: {
465+
INPUT_TOKEN: "my-secret-token",
466+
INPUT_ACCESS: "public"
467+
}
468+
});
469+
470+
expect(cli).to.have.stderr("");
471+
expect(cli).stdout.to.include("@my-scope/my-lib 2.0.0");
472+
expect(cli).stdout.to.include("Successfully published @my-scope/my-lib v2.0.0 to NPM");
473+
expect(cli).stdout.to.include("::set-output name=type::major");
474+
expect(cli).stdout.to.include("::set-output name=version::2.0.0");
475+
expect(cli).stdout.to.include("::set-output name=old-version::1.0.0");
476+
expect(cli).stdout.to.include("::set-output name=tag::latest");
477+
expect(cli).stdout.to.include("::set-output name=access::public");
478+
expect(cli).stdout.to.include("::set-output name=dry-run::false");
258479
expect(cli).to.have.exitCode(0);
259480

260481
files.assert.contents("home/.npmrc",
@@ -302,6 +523,8 @@ describe("GitHub Action - success tests", () => {
302523
expect(cli).stdout.to.include("::set-output name=type::minor");
303524
expect(cli).stdout.to.include("::set-output name=version::1.1.0");
304525
expect(cli).stdout.to.include("::set-output name=old-version::1.0.0");
526+
expect(cli).stdout.to.include("::set-output name=tag::latest");
527+
expect(cli).stdout.to.include("::set-output name=access::public");
305528
expect(cli).stdout.to.include("::set-output name=dry-run::true");
306529
expect(cli).stdout.to.include("my-lib 1.1.0");
307530
expect(cli).stdout.to.include("📦 my-lib v1.1.0 was NOT actually published to NPM (dry run)");

0 commit comments

Comments
 (0)