From 021344e1bdce47cdb7b70b0f6c86079900fd16ee Mon Sep 17 00:00:00 2001 From: dalejo96 Date: Wed, 20 Dec 2023 18:16:20 -0500 Subject: [PATCH] requested changes --- .eslintrc.json | 1 - .mocharc.json | 2 +- package.json | 2 +- src/prepare.ts | 4 ++-- src/publish.ts | 6 ++--- test/{utils.ts => helpers/context.ts} | 0 test/integration/prepare.test.ts | 5 ++--- test/integration/verifyConditions.test.ts | 4 ++-- test/unit/EnvVarError.test.ts | 2 +- test/unit/prepare.test.ts | 10 ++++----- .../{publish.test..ts => publish.test.ts} | 12 ++++------ yarn.lock | 22 +++++++++---------- 12 files changed, 32 insertions(+), 38 deletions(-) rename test/{utils.ts => helpers/context.ts} (100%) rename test/unit/{publish.test..ts => publish.test.ts} (71%) diff --git a/.eslintrc.json b/.eslintrc.json index f06f1b7..aeca304 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -188,7 +188,6 @@ ], "import/no-duplicates": "error", "import/no-import-module-exports": "error", - "import/no-namespace": "error", "import/no-relative-packages": "error", "import/no-unresolved": "error", "import/no-useless-path-segments": "error", diff --git a/.mocharc.json b/.mocharc.json index a4ebbae..8c03047 100644 --- a/.mocharc.json +++ b/.mocharc.json @@ -3,7 +3,7 @@ "exit": true, "extension": ["ts"], "recursive": true, - "require": ["ts-node/register","test/hooks.ts"], + "require": ["ts-node/register", "test/hooks.ts"], "slow": 1000, "spec": ["test/**/*.test.*"], "timeout": 5000 diff --git a/package.json b/package.json index 3d50493..21fc481 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,7 @@ "axios": "^1.6.0" }, "devDependencies": { - "@stackbuilders/assertive-ts": "^1.4.0", + "@assertive-ts/core": "^2.0.0", "@types/mocha": "^10.0.1", "@types/semantic-release": "^20.0.1", "@types/sinon": "^17.0.2", diff --git a/src/prepare.ts b/src/prepare.ts index a19c010..406a485 100644 --- a/src/prepare.ts +++ b/src/prepare.ts @@ -7,11 +7,11 @@ import { getCabalFilename } from "./utils/prepare"; import { readFile, writeFile } from "fs/promises"; import { resolve } from "path"; -export const versionPattern = /version:\s+(\S+)/; +export const VERSION_PATTERN = /version:\s+(\S+)/; export const readAndWriteNewCabal = async (fullCabalPath: string, newVersion: string): Promise => { const versionContents = await readFile(fullCabalPath, "utf8"); - const newContents = versionContents.replace(versionPattern, `version: ${newVersion}`); + const newContents = versionContents.replace(VERSION_PATTERN, `version: ${newVersion}`); await writeFile(fullCabalPath, newContents, "utf8"); }; diff --git a/src/publish.ts b/src/publish.ts index 3dbded0..022f63c 100644 --- a/src/publish.ts +++ b/src/publish.ts @@ -5,14 +5,14 @@ import { PluginConfig } from "./types/pluginConfig"; import { runExecCommand } from "./utils/exec"; export const HACKAGE_PACKAGES_URL = "https://hackage.haskell.org/package"; -export const CANDIDATES = "candidates/"; +export const CANDIDATES_PATH = "candidates/"; export const postReleaseCandidate = async ( sdistPath: string, packageName: string, hackageToken?: string, ): Promise => { - const url = `${HACKAGE_PACKAGES_URL}/${packageName}/${CANDIDATES}`; + const url = `${HACKAGE_PACKAGES_URL}/${packageName}/${CANDIDATES_PATH}`; try { const headers = { Accept: "text/plain", @@ -26,7 +26,7 @@ export const postReleaseCandidate = async ( return req.status; } catch (e: unknown) { - throw new Error(`You do not have access to POST a file to ${url}, ${String((e as Error).message)}`); + throw e instanceof Error ? new Error(`You do not have access to POST a file to ${url}, ${e.message}`) : e; } }; diff --git a/test/utils.ts b/test/helpers/context.ts similarity index 100% rename from test/utils.ts rename to test/helpers/context.ts diff --git a/test/integration/prepare.test.ts b/test/integration/prepare.test.ts index c58fe3e..2c025a2 100644 --- a/test/integration/prepare.test.ts +++ b/test/integration/prepare.test.ts @@ -1,11 +1,10 @@ -import { expect } from "@stackbuilders/assertive-ts"; +import { expect } from "@assertive-ts/core"; import Sinon from "sinon"; import { prepare } from "../../src/prepare"; import { PluginConfig } from "../../src/types/pluginConfig"; -// eslint-disable-next-line import/no-namespace import * as exec from "../../src/utils/exec"; -import { semanticContext, contextWithoutRelease } from "../utils"; +import { semanticContext, contextWithoutRelease } from "../helpers/context"; const pluginConfig: PluginConfig = { cabalFile: "test/fixtures/test-1-package.cabal", diff --git a/test/integration/verifyConditions.test.ts b/test/integration/verifyConditions.test.ts index ee7c773..c7b188c 100644 --- a/test/integration/verifyConditions.test.ts +++ b/test/integration/verifyConditions.test.ts @@ -1,9 +1,9 @@ -import { expect } from "@stackbuilders/assertive-ts"; +import { expect } from "@assertive-ts/core"; import { PluginConfig } from "../../src/types/pluginConfig"; import { EnvVarError } from "../../src/utils/EnvVarError"; import { verifyConditions } from "../../src/verifyConditions"; -import { semanticContext } from "../utils"; +import { semanticContext } from "../helpers/context"; const pluginConfig: PluginConfig = { cabalFile: "test-1-package.cabal", diff --git a/test/unit/EnvVarError.test.ts b/test/unit/EnvVarError.test.ts index 3f4eee1..51381b3 100644 --- a/test/unit/EnvVarError.test.ts +++ b/test/unit/EnvVarError.test.ts @@ -1,4 +1,4 @@ -import { expect } from "@stackbuilders/assertive-ts"; +import { expect } from "@assertive-ts/core"; import { EnvVarError } from "../../src/utils/EnvVarError"; diff --git a/test/unit/prepare.test.ts b/test/unit/prepare.test.ts index 12a885a..bc4f7c9 100644 --- a/test/unit/prepare.test.ts +++ b/test/unit/prepare.test.ts @@ -1,14 +1,14 @@ -import { expect } from "@stackbuilders/assertive-ts"; +import { expect } from "@assertive-ts/core"; import { readAndWriteNewCabal } from "../../src/prepare"; import { readFile, writeFile } from "fs/promises"; -describe("readAndWriteNewCabal", () => { - const fakeCabalPath = "./test/fixtures/test-1-package.cabal"; - const fakeNewVersion = "0.0.7"; - const cabalContent = "name: test-1-package\nversion: 0.0.1"; +const fakeCabalPath = "./test/fixtures/test-1-package.cabal"; +const fakeNewVersion = "0.0.7"; +const cabalContent = "name: test-1-package\nversion: 0.0.1"; +describe("readAndWriteNewCabal", () => { afterEach(async () => { await writeFile(fakeCabalPath, cabalContent, "utf8"); }); diff --git a/test/unit/publish.test..ts b/test/unit/publish.test.ts similarity index 71% rename from test/unit/publish.test..ts rename to test/unit/publish.test.ts index 001c94d..dc145d0 100644 --- a/test/unit/publish.test..ts +++ b/test/unit/publish.test.ts @@ -1,8 +1,8 @@ -import { expect } from "@stackbuilders/assertive-ts"; +import { expect } from "@assertive-ts/core"; import axios from "axios"; import sinon from "sinon"; -import { CANDIDATES, HACKAGE_PACKAGES_URL, postReleaseCandidate } from "../../src/publish"; +import { CANDIDATES_PATH, HACKAGE_PACKAGES_URL, postReleaseCandidate } from "../../src/publish"; const sdistPath = "sdist/path"; const packageName = "my-hackage-package"; @@ -16,7 +16,7 @@ describe("postReleaseCandidate", () => { expect(statusCode).toBeEqual(200); expect(axiosPostStub.calledOnce).toBeTruthy(); - expect(axiosPostStub.firstCall.args[0]).toBeEqual(`${HACKAGE_PACKAGES_URL}/${packageName}/${CANDIDATES}`); + expect(axiosPostStub.firstCall.args[0]).toBeEqual(`${HACKAGE_PACKAGES_URL}/${packageName}/${CANDIDATES_PATH}`); }); it("throws an error on unsuccessful request", async () => { @@ -25,11 +25,7 @@ describe("postReleaseCandidate", () => { const request = postReleaseCandidate(sdistPath, packageName, hackageToken); - await expect(request).toBeRejectedWith( - new Error( - `You do not have access to POST a file to ${HACKAGE_PACKAGES_URL}/${packageName}/${CANDIDATES}, ${errorMsg}`, - ), - ); + await expect(request).toBeRejected(); expect(axiosPostStub.calledOnce).toBeTruthy(); }); }); diff --git a/yarn.lock b/yarn.lock index 32f5cfe..db28b9c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -12,6 +12,16 @@ __metadata: languageName: node linkType: hard +"@assertive-ts/core@npm:^2.0.0": + version: 2.0.0 + resolution: "@assertive-ts/core@npm:2.0.0" + dependencies: + "@cometlib/dedent": ^0.8.0-es.10 + fast-deep-equal: ^3.1.3 + checksum: 93b76098dbbf919af486c8be7a2ef96a9493499070e5431fe41dc79849c3fb309df14565b2f4903b657620198c38fc776b6a53b2907a53b0260fdaba7397b0b5 + languageName: node + linkType: hard + "@babel/code-frame@npm:^7.0.0, @babel/code-frame@npm:^7.21.4": version: 7.22.5 resolution: "@babel/code-frame@npm:7.22.5" @@ -764,21 +774,11 @@ __metadata: languageName: node linkType: hard -"@stackbuilders/assertive-ts@npm:^1.4.0": - version: 1.4.0 - resolution: "@stackbuilders/assertive-ts@npm:1.4.0" - dependencies: - "@cometlib/dedent": ^0.8.0-es.10 - fast-deep-equal: ^3.1.3 - checksum: 89d787a9f55f57e0baf164a08b2210266dbd483be284cf4d2f4d20e1403aced432abbe786c7f439b4ecdd4bd7ba2410bfedf2240162203b36860572736c4c591 - languageName: node - linkType: hard - "@stackbuilders/semantic-release-hackage@workspace:.": version: 0.0.0-use.local resolution: "@stackbuilders/semantic-release-hackage@workspace:." dependencies: - "@stackbuilders/assertive-ts": ^1.4.0 + "@assertive-ts/core": ^2.0.0 "@types/mocha": ^10.0.1 "@types/semantic-release": ^20.0.1 "@types/sinon": ^17.0.2