Skip to content

Commit

Permalink
refactor: pull side effect out of action bundle import (#115)
Browse files Browse the repository at this point in the history
  • Loading branch information
mcous authored Jul 3, 2023
1 parent c139f4f commit 7ae2800
Show file tree
Hide file tree
Showing 14 changed files with 308 additions and 384 deletions.
6 changes: 6 additions & 0 deletions action.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* eslint-disable @typescript-eslint/no-floating-promises, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call */
"use strict";

const { main } = require("./dist/main.js");

main();
2 changes: 1 addition & 1 deletion action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,4 @@ outputs:
runs:
using: node16
main: dist/main.js
main: action.js
19 changes: 18 additions & 1 deletion dist/main.js

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

6 changes: 3 additions & 3 deletions dist/main.js.map

Large diffs are not rendered by default.

156 changes: 19 additions & 137 deletions package-lock.json

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

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"type": "git",
"url": "https://github.com/JS-DevTools/npm-publish.git"
},
"type": "commonjs",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"bin": {
Expand Down Expand Up @@ -72,10 +73,9 @@
"prettier": "^2.8.8",
"prettier-plugin-jsdoc": "^0.4.2",
"rimraf": "^5.0.0",
"testdouble": "^3.17.2",
"testdouble-vitest": "^0.1.2",
"typescript": "^5.0.4",
"vitest": "^0.32.4"
"vitest": "^0.32.4",
"vitest-when": "^0.1.2"
},
"dependencies": {
"@types/semver": "^7.5.0",
Expand Down
29 changes: 13 additions & 16 deletions src/__tests__/npm-publish.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { vi, describe, it, afterEach, expect } from "vitest";
import { imitateEsm, reset } from "testdouble-vitest";
import * as td from "testdouble";
import { vi, describe, it, expect } from "vitest";
import { when } from "vitest-when";

import * as subject from "../npm-publish.js";
import { readManifest, type PackageManifest } from "../read-manifest.js";
Expand All @@ -15,16 +14,12 @@ import {
} from "../compare-and-publish/index.js";
import type { Logger, Options } from "../options.js";

vi.mock("../read-manifest", () => imitateEsm("../read-manifest"));
vi.mock("../normalize-options", () => imitateEsm("../normalize-options"));
vi.mock("../npm", () => imitateEsm("../npm"));
vi.mock("../compare-and-publish", () => imitateEsm("../compare-and-publish"));
vi.mock("../read-manifest");
vi.mock("../normalize-options");
vi.mock("../npm");
vi.mock("../compare-and-publish");

describe("npmPublish", () => {
afterEach(() => {
reset();
});

it("should read the manifest, get publish config, compare, and publish", async () => {
const options: Options = { package: "./cool-package", token: "abc123" };

Expand All @@ -46,11 +41,13 @@ describe("npmPublish", () => {
oldVersion: "0.1.2",
};

td.when(readManifest("./cool-package")).thenResolve(manifest);
td.when(normalizeOptions(manifest, options)).thenReturn(normalizedOptions);
td.when(
useNpmEnvironment(manifest, normalizedOptions, compareAndPublish)
).thenResolve(publishResult);
when(readManifest).calledWith("./cool-package").thenResolve(manifest);
when(normalizeOptions)
.calledWith(manifest, options)
.thenReturn(normalizedOptions);
when(useNpmEnvironment<PublishResult>)
.calledWith(manifest, normalizedOptions, compareAndPublish)
.thenResolve(publishResult);

const result = await subject.npmPublish(options);

Expand Down
Loading

0 comments on commit 7ae2800

Please sign in to comment.