Skip to content

Commit 7ae2800

Browse files
authored
refactor: pull side effect out of action bundle import (#115)
1 parent c139f4f commit 7ae2800

File tree

14 files changed

+308
-384
lines changed

14 files changed

+308
-384
lines changed

action.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/* eslint-disable @typescript-eslint/no-floating-promises, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call */
2+
"use strict";
3+
4+
const { main } = require("./dist/main.js");
5+
6+
main();

action.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,4 @@ outputs:
9393
9494
runs:
9595
using: node16
96-
main: dist/main.js
96+
main: action.js

dist/main.js

Lines changed: 18 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/main.js.map

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

Lines changed: 19 additions & 137 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"type": "git",
2020
"url": "https://github.com/JS-DevTools/npm-publish.git"
2121
},
22+
"type": "commonjs",
2223
"main": "lib/index.js",
2324
"types": "lib/index.d.ts",
2425
"bin": {
@@ -72,10 +73,9 @@
7273
"prettier": "^2.8.8",
7374
"prettier-plugin-jsdoc": "^0.4.2",
7475
"rimraf": "^5.0.0",
75-
"testdouble": "^3.17.2",
76-
"testdouble-vitest": "^0.1.2",
7776
"typescript": "^5.0.4",
78-
"vitest": "^0.32.4"
77+
"vitest": "^0.32.4",
78+
"vitest-when": "^0.1.2"
7979
},
8080
"dependencies": {
8181
"@types/semver": "^7.5.0",

src/__tests__/npm-publish.test.ts

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import { vi, describe, it, afterEach, expect } from "vitest";
2-
import { imitateEsm, reset } from "testdouble-vitest";
3-
import * as td from "testdouble";
1+
import { vi, describe, it, expect } from "vitest";
2+
import { when } from "vitest-when";
43

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

18-
vi.mock("../read-manifest", () => imitateEsm("../read-manifest"));
19-
vi.mock("../normalize-options", () => imitateEsm("../normalize-options"));
20-
vi.mock("../npm", () => imitateEsm("../npm"));
21-
vi.mock("../compare-and-publish", () => imitateEsm("../compare-and-publish"));
17+
vi.mock("../read-manifest");
18+
vi.mock("../normalize-options");
19+
vi.mock("../npm");
20+
vi.mock("../compare-and-publish");
2221

2322
describe("npmPublish", () => {
24-
afterEach(() => {
25-
reset();
26-
});
27-
2823
it("should read the manifest, get publish config, compare, and publish", async () => {
2924
const options: Options = { package: "./cool-package", token: "abc123" };
3025

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

49-
td.when(readManifest("./cool-package")).thenResolve(manifest);
50-
td.when(normalizeOptions(manifest, options)).thenReturn(normalizedOptions);
51-
td.when(
52-
useNpmEnvironment(manifest, normalizedOptions, compareAndPublish)
53-
).thenResolve(publishResult);
44+
when(readManifest).calledWith("./cool-package").thenResolve(manifest);
45+
when(normalizeOptions)
46+
.calledWith(manifest, options)
47+
.thenReturn(normalizedOptions);
48+
when(useNpmEnvironment<PublishResult>)
49+
.calledWith(manifest, normalizedOptions, compareAndPublish)
50+
.thenResolve(publishResult);
5451

5552
const result = await subject.npmPublish(options);
5653

0 commit comments

Comments
 (0)