Skip to content

Commit

Permalink
Add updated test for setOutput
Browse files Browse the repository at this point in the history
  • Loading branch information
razor-x committed Jan 2, 2023
1 parent cfaedeb commit 1e230fb
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 87 deletions.
22 changes: 16 additions & 6 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"build:ncc": "ncc build src/action/index.ts --source-map --external semver",
"build:node_modules": "shx mkdir -p dist/node_modules && shx cp -r node_modules/semver dist/node_modules",
"watch": "tsc --watch",
"test": "mocha && npm run lint",
"test": "NODE_ENV=test mocha && npm run lint",
"coverage": "nyc -x test -x dist/sourcemap-register.js node_modules/mocha/bin/mocha",
"upgrade": "npm-check -u && npm audit fix",
"release": "npm run clean && npm run build && npm test && npm run bump"
Expand Down
13 changes: 12 additions & 1 deletion src/action/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { debug, getInput, setFailed, setOutput } from "@actions/core";
import { debug, getInput, setFailed, setOutput as setOutputActionsCore } from "@actions/core";
import { npmPublish } from "../npm-publish";
import { Access, Options } from "../options";

Expand Down Expand Up @@ -64,6 +64,17 @@ async function main(): Promise<void> {
}
}

/**
* Set output with logging to stdout for test support
*/
function setOutput(...args: Parameters<typeof setOutputActionsCore>) {
if (process.env.NODE_ENV === "test") {
console.log(`TEST-set-output name=${args[0]}::${args[1]}`);
return;
}
return setOutputActionsCore(...args);
}

/**
* Prints errors to the GitHub Actions console
*/
Expand Down
156 changes: 78 additions & 78 deletions test/specs/action/success.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ describe("GitHub Action - success tests", () => {
expect(cli).stdout.to.include(
"Successfully published my-lib v2.0.0 to https://registry.npmjs.org/"
);
expect(cli).stdout.to.include("::set-output name=type::major");
expect(cli).stdout.to.include("::set-output name=version::2.0.0");
expect(cli).stdout.to.include("::set-output name=old-version::1.0.0");
expect(cli).stdout.to.include("::set-output name=tag::latest");
expect(cli).stdout.to.include("::set-output name=access::public");
expect(cli).stdout.to.include("::set-output name=dry-run::false");
expect(cli).stdout.to.include("TEST-set-output name=type::major");
expect(cli).stdout.to.include("TEST-set-output name=version::2.0.0");
expect(cli).stdout.to.include("TEST-set-output name=old-version::1.0.0");
expect(cli).stdout.to.include("TEST-set-output name=tag::latest");
expect(cli).stdout.to.include("TEST-set-output name=access::public");
expect(cli).stdout.to.include("TEST-set-output name=dry-run::false");
expect(cli).to.have.exitCode(0);

files.assert.contents(
Expand Down Expand Up @@ -106,12 +106,12 @@ describe("GitHub Action - success tests", () => {
expect(cli).stdout.to.include(
"Successfully published my-lib v0.1.0 to https://registry.npmjs.org/"
);
expect(cli).stdout.to.include("::set-output name=type::major");
expect(cli).stdout.to.include("::set-output name=version::0.1.0");
expect(cli).stdout.to.include("::set-output name=old-version::1.0.0");
expect(cli).stdout.to.include("::set-output name=tag::latest");
expect(cli).stdout.to.include("::set-output name=access::public");
expect(cli).stdout.to.include("::set-output name=dry-run::false");
expect(cli).stdout.to.include("TEST-set-output name=type::major");
expect(cli).stdout.to.include("TEST-set-output name=version::0.1.0");
expect(cli).stdout.to.include("TEST-set-output name=old-version::1.0.0");
expect(cli).stdout.to.include("TEST-set-output name=tag::latest");
expect(cli).stdout.to.include("TEST-set-output name=access::public");
expect(cli).stdout.to.include("TEST-set-output name=dry-run::false");
expect(cli).to.have.exitCode(0);

files.assert.contents(
Expand Down Expand Up @@ -163,12 +163,12 @@ describe("GitHub Action - success tests", () => {
expect(cli).stdout.to.include(
"my-lib v0.1.0 is lower than the version published to https://registry.npmjs.org/"
);
expect(cli).stdout.to.include("::set-output name=type::lower");
expect(cli).stdout.to.include("::set-output name=version::0.1.0");
expect(cli).stdout.to.include("::set-output name=old-version::1.0.0");
expect(cli).stdout.to.include("::set-output name=tag::latest");
expect(cli).stdout.to.include("::set-output name=access::public");
expect(cli).stdout.to.include("::set-output name=dry-run::false");
expect(cli).stdout.to.include("TEST-set-output name=type::lower");
expect(cli).stdout.to.include("TEST-set-output name=version::0.1.0");
expect(cli).stdout.to.include("TEST-set-output name=old-version::1.0.0");
expect(cli).stdout.to.include("TEST-set-output name=tag::latest");
expect(cli).stdout.to.include("TEST-set-output name=access::public");
expect(cli).stdout.to.include("TEST-set-output name=dry-run::false");
expect(cli).to.have.exitCode(0);

files.assert.contents(
Expand Down Expand Up @@ -221,12 +221,12 @@ describe("GitHub Action - success tests", () => {
expect(cli).stdout.to.include(
"Successfully published my-lib v1.0.0 to https://registry.npmjs.org/"
);
expect(cli).stdout.to.include("::set-output name=type::major");
expect(cli).stdout.to.include("::set-output name=version::1.0.0");
expect(cli).stdout.to.include("::set-output name=old-version::0.0.0");
expect(cli).stdout.to.include("::set-output name=tag::latest");
expect(cli).stdout.to.include("::set-output name=access::public");
expect(cli).stdout.to.include("::set-output name=dry-run::false");
expect(cli).stdout.to.include("TEST-set-output name=type::major");
expect(cli).stdout.to.include("TEST-set-output name=version::1.0.0");
expect(cli).stdout.to.include("TEST-set-output name=old-version::0.0.0");
expect(cli).stdout.to.include("TEST-set-output name=tag::latest");
expect(cli).stdout.to.include("TEST-set-output name=access::public");
expect(cli).stdout.to.include("TEST-set-output name=dry-run::false");
expect(cli).to.have.exitCode(0);

files.assert.contents(
Expand Down Expand Up @@ -278,12 +278,12 @@ describe("GitHub Action - success tests", () => {
expect(cli).stdout.to.include(
"Successfully published my-lib v1.0.0 to https://registry.npmjs.org/"
);
expect(cli).stdout.to.include("::set-output name=type::major");
expect(cli).stdout.to.include("::set-output name=version::1.0.0");
expect(cli).stdout.to.include("::set-output name=old-version::0.0.0");
expect(cli).stdout.to.include("::set-output name=tag::my-tag");
expect(cli).stdout.to.include("::set-output name=access::public");
expect(cli).stdout.to.include("::set-output name=dry-run::false");
expect(cli).stdout.to.include("TEST-set-output name=type::major");
expect(cli).stdout.to.include("TEST-set-output name=version::1.0.0");
expect(cli).stdout.to.include("TEST-set-output name=old-version::0.0.0");
expect(cli).stdout.to.include("TEST-set-output name=tag::my-tag");
expect(cli).stdout.to.include("TEST-set-output name=access::public");
expect(cli).stdout.to.include("TEST-set-output name=dry-run::false");
expect(cli).to.have.exitCode(0);

files.assert.contents(
Expand Down Expand Up @@ -323,12 +323,12 @@ describe("GitHub Action - success tests", () => {
expect(cli).stdout.to.include(
"📦 my-lib v1.0.0 is already published to https://registry.npmjs.org/"
);
expect(cli).stdout.to.include("::set-output name=type::none");
expect(cli).stdout.to.include("::set-output name=version::1.0.0");
expect(cli).stdout.to.include("::set-output name=old-version::1.0.0");
expect(cli).stdout.to.include("::set-output name=tag::latest");
expect(cli).stdout.to.include("::set-output name=access::public");
expect(cli).stdout.to.include("::set-output name=dry-run::false");
expect(cli).stdout.to.include("TEST-set-output name=type::none");
expect(cli).stdout.to.include("TEST-set-output name=version::1.0.0");
expect(cli).stdout.to.include("TEST-set-output name=old-version::1.0.0");
expect(cli).stdout.to.include("TEST-set-output name=tag::latest");
expect(cli).stdout.to.include("TEST-set-output name=access::public");
expect(cli).stdout.to.include("TEST-set-output name=dry-run::false");
expect(cli).to.have.exitCode(0);

files.assert.contents(
Expand Down Expand Up @@ -385,12 +385,12 @@ describe("GitHub Action - success tests", () => {
expect(cli).stdout.to.include(
"📦 Successfully published my-lib v1.1.0 to https://registry.npmjs.org/"
);
expect(cli).stdout.to.include("::set-output name=type::minor");
expect(cli).stdout.to.include("::set-output name=version::1.1.0");
expect(cli).stdout.to.include("::set-output name=old-version::1.0.0");
expect(cli).stdout.to.include("::set-output name=tag::latest");
expect(cli).stdout.to.include("::set-output name=access::public");
expect(cli).stdout.to.include("::set-output name=dry-run::false");
expect(cli).stdout.to.include("TEST-set-output name=type::minor");
expect(cli).stdout.to.include("TEST-set-output name=version::1.1.0");
expect(cli).stdout.to.include("TEST-set-output name=old-version::1.0.0");
expect(cli).stdout.to.include("TEST-set-output name=tag::latest");
expect(cli).stdout.to.include("TEST-set-output name=access::public");
expect(cli).stdout.to.include("TEST-set-output name=dry-run::false");
expect(cli).to.have.exitCode(0);

files.assert.contents(
Expand Down Expand Up @@ -459,12 +459,12 @@ describe("GitHub Action - success tests", () => {
expect(cli).stdout.to.include(
"📦 Successfully published my-lib v1.0.1 to https://registry.npmjs.org/"
);
expect(cli).stdout.to.include("::set-output name=type::patch");
expect(cli).stdout.to.include("::set-output name=version::1.0.1");
expect(cli).stdout.to.include("::set-output name=old-version::1.0.0");
expect(cli).stdout.to.include("::set-output name=tag::latest");
expect(cli).stdout.to.include("::set-output name=access::public");
expect(cli).stdout.to.include("::set-output name=dry-run::false");
expect(cli).stdout.to.include("TEST-set-output name=type::patch");
expect(cli).stdout.to.include("TEST-set-output name=version::1.0.1");
expect(cli).stdout.to.include("TEST-set-output name=old-version::1.0.0");
expect(cli).stdout.to.include("TEST-set-output name=tag::latest");
expect(cli).stdout.to.include("TEST-set-output name=access::public");
expect(cli).stdout.to.include("TEST-set-output name=dry-run::false");
expect(cli).to.have.exitCode(0);

files.assert.contents(
Expand Down Expand Up @@ -525,12 +525,12 @@ describe("GitHub Action - success tests", () => {
expect(cli).stdout.to.include(
"📦 Successfully published my-lib v1.0.0-beta to https://registry.npmjs.org/"
);
expect(cli).stdout.to.include("::set-output name=type::prerelease");
expect(cli).stdout.to.include("::set-output name=version::1.0.0-beta");
expect(cli).stdout.to.include("::set-output name=old-version::1.0.0");
expect(cli).stdout.to.include("::set-output name=tag::latest");
expect(cli).stdout.to.include("::set-output name=access::public");
expect(cli).stdout.to.include("::set-output name=dry-run::false");
expect(cli).stdout.to.include("TEST-set-output name=type::prerelease");
expect(cli).stdout.to.include("TEST-set-output name=version::1.0.0-beta");
expect(cli).stdout.to.include("TEST-set-output name=old-version::1.0.0");
expect(cli).stdout.to.include("TEST-set-output name=tag::latest");
expect(cli).stdout.to.include("TEST-set-output name=access::public");
expect(cli).stdout.to.include("TEST-set-output name=dry-run::false");
expect(cli).to.have.exitCode(0);

files.assert.contents(
Expand Down Expand Up @@ -582,12 +582,12 @@ describe("GitHub Action - success tests", () => {
expect(cli).stdout.to.include(
"Successfully published @my-scope/my-lib v2.0.0 to https://registry.npmjs.org/"
);
expect(cli).stdout.to.include("::set-output name=type::major");
expect(cli).stdout.to.include("::set-output name=version::2.0.0");
expect(cli).stdout.to.include("::set-output name=old-version::1.0.0");
expect(cli).stdout.to.include("::set-output name=tag::latest");
expect(cli).stdout.to.include("::set-output name=access::restricted");
expect(cli).stdout.to.include("::set-output name=dry-run::false");
expect(cli).stdout.to.include("TEST-set-output name=type::major");
expect(cli).stdout.to.include("TEST-set-output name=version::2.0.0");
expect(cli).stdout.to.include("TEST-set-output name=old-version::1.0.0");
expect(cli).stdout.to.include("TEST-set-output name=tag::latest");
expect(cli).stdout.to.include("TEST-set-output name=access::restricted");
expect(cli).stdout.to.include("TEST-set-output name=dry-run::false");
expect(cli).to.have.exitCode(0);

files.assert.contents(
Expand Down Expand Up @@ -640,12 +640,12 @@ describe("GitHub Action - success tests", () => {
expect(cli).stdout.to.include(
"Successfully published my-lib v2.0.0 to https://registry.npmjs.org/"
);
expect(cli).stdout.to.include("::set-output name=type::major");
expect(cli).stdout.to.include("::set-output name=version::2.0.0");
expect(cli).stdout.to.include("::set-output name=old-version::1.0.0");
expect(cli).stdout.to.include("::set-output name=tag::next");
expect(cli).stdout.to.include("::set-output name=access::public");
expect(cli).stdout.to.include("::set-output name=dry-run::false");
expect(cli).stdout.to.include("TEST-set-output name=type::major");
expect(cli).stdout.to.include("TEST-set-output name=version::2.0.0");
expect(cli).stdout.to.include("TEST-set-output name=old-version::1.0.0");
expect(cli).stdout.to.include("TEST-set-output name=tag::next");
expect(cli).stdout.to.include("TEST-set-output name=access::public");
expect(cli).stdout.to.include("TEST-set-output name=dry-run::false");
expect(cli).to.have.exitCode(0);

files.assert.contents(
Expand Down Expand Up @@ -698,12 +698,12 @@ describe("GitHub Action - success tests", () => {
expect(cli).stdout.to.include(
"Successfully published @my-scope/my-lib v2.0.0 to https://registry.npmjs.org/"
);
expect(cli).stdout.to.include("::set-output name=type::major");
expect(cli).stdout.to.include("::set-output name=version::2.0.0");
expect(cli).stdout.to.include("::set-output name=old-version::1.0.0");
expect(cli).stdout.to.include("::set-output name=tag::latest");
expect(cli).stdout.to.include("::set-output name=access::public");
expect(cli).stdout.to.include("::set-output name=dry-run::false");
expect(cli).stdout.to.include("TEST-set-output name=type::major");
expect(cli).stdout.to.include("TEST-set-output name=version::2.0.0");
expect(cli).stdout.to.include("TEST-set-output name=old-version::1.0.0");
expect(cli).stdout.to.include("TEST-set-output name=tag::latest");
expect(cli).stdout.to.include("TEST-set-output name=access::public");
expect(cli).stdout.to.include("TEST-set-output name=dry-run::false");
expect(cli).to.have.exitCode(0);

files.assert.contents(
Expand Down Expand Up @@ -752,12 +752,12 @@ describe("GitHub Action - success tests", () => {
});

expect(cli).to.have.stderr("");
expect(cli).stdout.to.include("::set-output name=type::minor");
expect(cli).stdout.to.include("::set-output name=version::1.1.0");
expect(cli).stdout.to.include("::set-output name=old-version::1.0.0");
expect(cli).stdout.to.include("::set-output name=tag::latest");
expect(cli).stdout.to.include("::set-output name=access::public");
expect(cli).stdout.to.include("::set-output name=dry-run::true");
expect(cli).stdout.to.include("TEST-set-output name=type::minor");
expect(cli).stdout.to.include("TEST-set-output name=version::1.1.0");
expect(cli).stdout.to.include("TEST-set-output name=old-version::1.0.0");
expect(cli).stdout.to.include("TEST-set-output name=tag::latest");
expect(cli).stdout.to.include("TEST-set-output name=access::public");
expect(cli).stdout.to.include("TEST-set-output name=dry-run::true");
expect(cli).stdout.to.include("my-lib 1.1.0");
expect(cli).stdout.to.include(
"📦 my-lib v1.1.0 was NOT actually published to https://registry.npmjs.org/ (dry run)"
Expand Down

0 comments on commit 1e230fb

Please sign in to comment.