test: use node test runner to assert expected cases (#538)
This commit is contained in:
@@ -1,7 +0,0 @@
|
||||
{
|
||||
"include": ["src/*.js"],
|
||||
"exclude": ["**/*.spec.js"],
|
||||
"reporter": ["lcov", "text"],
|
||||
"all": false,
|
||||
"cache": true
|
||||
}
|
||||
@@ -42,7 +42,7 @@ jobs:
|
||||
- name: "unit(test): upload coverage to CodeCov"
|
||||
uses: codecov/codecov-action@671740ac38dd9b0130fbe1cec585b89eea48d3de # v5.5.2
|
||||
with:
|
||||
directory: ./coverage
|
||||
files: test/coverage.xml
|
||||
token: ${{ secrets.CODECOV_TOKEN }}
|
||||
|
||||
- name: "build: package code for distribution"
|
||||
|
||||
+1
-1
@@ -8,4 +8,4 @@ node_modules
|
||||
.DS_Store
|
||||
|
||||
# Testing remnants
|
||||
coverage
|
||||
coverage.xml
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
{
|
||||
"require": [
|
||||
"@actions/core",
|
||||
"@actions/github",
|
||||
"@slack/web-api",
|
||||
"axios",
|
||||
"axios-retry",
|
||||
"flat",
|
||||
"https-proxy-agent",
|
||||
"markup-js",
|
||||
"mocha-suppress-logs"
|
||||
],
|
||||
"recursive": true,
|
||||
"timeout": 3000
|
||||
}
|
||||
Generated
+7
-1213
File diff suppressed because it is too large
Load Diff
+1
-7
@@ -10,7 +10,7 @@
|
||||
"dev": "act public --eventpath .github/resources/.actions/event.json --secret-file .github/resources/.env --platform ubuntu-latest=node:20-buster --container-architecture linux/amd64",
|
||||
"lint:fix": "biome check --write",
|
||||
"lint": "biome check",
|
||||
"test": "c8 mocha test/*.spec.js",
|
||||
"test": "node --test --experimental-test-coverage --test-reporter=spec --test-reporter-destination=stdout --test-reporter=junit --test-reporter-destination=test/coverage.xml test/*.spec.js",
|
||||
"postversion": "TAG=\"v$(npm pkg get version | jq -r)\" && grep -rl 'slackapi/slack-github-action@v' ./docs ./example-workflows | xargs sed -i \"s|slackapi/slack-github-action@v.*|slackapi/slack-github-action@${TAG}|g\""
|
||||
},
|
||||
"repository": {
|
||||
@@ -47,18 +47,12 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@biomejs/biome": "^2.3.11",
|
||||
"@types/chai": "^5.0.1",
|
||||
"@types/flat": "^5.0.5",
|
||||
"@types/js-yaml": "^4.0.9",
|
||||
"@types/markup-js": "^1.5.0",
|
||||
"@types/mocha": "^10.0.10",
|
||||
"@types/node": "^20.19.28",
|
||||
"@types/sinon": "^21.0.0",
|
||||
"@vercel/ncc": "^0.38.4",
|
||||
"c8": "^10.1.3",
|
||||
"chai": "^6.2.0",
|
||||
"mocha": "^11.7.4",
|
||||
"mocha-suppress-logs": "^0.6.0",
|
||||
"sinon": "^21.0.1",
|
||||
"typescript": "^5.9.3"
|
||||
}
|
||||
|
||||
+27
-24
@@ -1,7 +1,8 @@
|
||||
import assert from "node:assert";
|
||||
import { beforeEach, describe, it } from "node:test";
|
||||
import core from "@actions/core";
|
||||
import webapi from "@slack/web-api";
|
||||
import errors from "@slack/web-api/dist/errors.js";
|
||||
import { assert } from "chai";
|
||||
import sinon from "sinon";
|
||||
import Client from "../src/client.js";
|
||||
import Config from "../src/config.js";
|
||||
@@ -31,9 +32,9 @@ describe("client", () => {
|
||||
assert.fail("Failed to throw for missing input");
|
||||
} catch (err) {
|
||||
if (err instanceof SlackError) {
|
||||
assert.include(err.message, "No API method was provided for use");
|
||||
assert.ok(err.message.includes("No API method was provided for use"));
|
||||
} else {
|
||||
assert.fail("Failed to throw a SlackError", err);
|
||||
assert.fail(err);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -54,9 +55,9 @@ describe("client", () => {
|
||||
assert.fail("Failed to throw for missing input");
|
||||
} catch (err) {
|
||||
if (err instanceof SlackError) {
|
||||
assert.include(err.message, "No token was provided to post with");
|
||||
assert.ok(err.message.includes("No token was provided to post with"));
|
||||
} else {
|
||||
assert.fail("Failed to throw a SlackError", err);
|
||||
assert.fail(err);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -87,8 +88,8 @@ describe("client", () => {
|
||||
webapi: mocks.webapi,
|
||||
};
|
||||
await new Client().post(config);
|
||||
assert.isTrue(constructors.calledWithNew());
|
||||
assert.isTrue(
|
||||
assert.ok(constructors.calledWithNew());
|
||||
assert.ok(
|
||||
constructors.calledWith("xoxb-example-002", {
|
||||
agent: undefined,
|
||||
allowAbsoluteUrls: false,
|
||||
@@ -97,14 +98,14 @@ describe("client", () => {
|
||||
slackApiUrl: undefined,
|
||||
}),
|
||||
);
|
||||
assert.isTrue(apis.calledOnce);
|
||||
assert.isTrue(
|
||||
assert.ok(apis.calledOnce);
|
||||
assert.ok(
|
||||
apis.calledWith("pins.add", {
|
||||
channel: "CHANNELHERE",
|
||||
timestamp: "1234567890.000000",
|
||||
}),
|
||||
);
|
||||
assert.isTrue(config.core.setOutput.calledWith("ok", true));
|
||||
assert.ok(config.core.setOutput.calledWith("ok", true));
|
||||
});
|
||||
|
||||
it("uses arguments to send to a custom api method", async () => {
|
||||
@@ -134,8 +135,8 @@ describe("client", () => {
|
||||
webapi: mocks.webapi,
|
||||
};
|
||||
await new Client().post(config);
|
||||
assert.isTrue(constructors.calledWithNew());
|
||||
assert.isTrue(
|
||||
assert.ok(constructors.calledWithNew());
|
||||
assert.ok(
|
||||
constructors.calledWith("ollamapassword", {
|
||||
agent: undefined,
|
||||
allowAbsoluteUrls: false,
|
||||
@@ -144,16 +145,16 @@ describe("client", () => {
|
||||
slackApiUrl: "http://localhost:11434/api/",
|
||||
}),
|
||||
);
|
||||
assert.isTrue(apis.calledOnce);
|
||||
assert.isTrue(
|
||||
assert.ok(apis.calledOnce);
|
||||
assert.ok(
|
||||
apis.calledWith("generate", {
|
||||
model: "llama3.2",
|
||||
prompt: "How many sides does a circle have?",
|
||||
stream: false,
|
||||
}),
|
||||
);
|
||||
assert.isTrue(config.core.setOutput.calledWith("ok", undefined));
|
||||
assert.isTrue(
|
||||
assert.ok(config.core.setOutput.calledWith("ok", undefined));
|
||||
assert.ok(
|
||||
config.core.setOutput.calledWith(
|
||||
"response",
|
||||
JSON.stringify({ done: true, response: "Infinite" }),
|
||||
@@ -306,7 +307,7 @@ describe("client", () => {
|
||||
await send(mocks.core);
|
||||
assert.fail("Expected an error but none was found");
|
||||
} catch (_err) {
|
||||
assert.isTrue(mocks.core.setFailed.called);
|
||||
assert.ok(mocks.core.setFailed.called);
|
||||
assert.equal(mocks.core.setOutput.getCall(0).firstArg, "ok");
|
||||
assert.equal(mocks.core.setOutput.getCall(0).lastArg, false);
|
||||
assert.equal(mocks.core.setOutput.getCall(1).firstArg, "response");
|
||||
@@ -341,7 +342,7 @@ describe("client", () => {
|
||||
await send(mocks.core);
|
||||
assert.fail("Expected an error but none was found");
|
||||
} catch (_err) {
|
||||
assert.isFalse(mocks.core.setFailed.called);
|
||||
assert.strictEqual(mocks.core.setFailed.called, false);
|
||||
assert.equal(mocks.core.setOutput.getCall(0).firstArg, "ok");
|
||||
assert.equal(mocks.core.setOutput.getCall(0).lastArg, false);
|
||||
assert.equal(mocks.core.setOutput.getCall(1).firstArg, "response");
|
||||
@@ -377,7 +378,7 @@ describe("client", () => {
|
||||
await send(mocks.core);
|
||||
assert.fail("Expected an error but none was found");
|
||||
} catch (_err) {
|
||||
assert.isTrue(mocks.core.setFailed.called);
|
||||
assert.ok(mocks.core.setFailed.called);
|
||||
assert.equal(mocks.core.setOutput.getCall(0).firstArg, "ok");
|
||||
assert.equal(mocks.core.setOutput.getCall(0).lastArg, false);
|
||||
assert.equal(mocks.core.setOutput.getCall(1).firstArg, "response");
|
||||
@@ -406,7 +407,7 @@ describe("client", () => {
|
||||
await send(mocks.core);
|
||||
assert.fail("Expected an error but none was found");
|
||||
} catch (_err) {
|
||||
assert.isFalse(mocks.core.setFailed.called);
|
||||
assert.strictEqual(mocks.core.setFailed.called, false);
|
||||
assert.equal(mocks.core.setOutput.getCall(0).firstArg, "ok");
|
||||
assert.equal(mocks.core.setOutput.getCall(0).lastArg, false);
|
||||
assert.equal(mocks.core.setOutput.getCall(1).firstArg, "response");
|
||||
@@ -432,7 +433,7 @@ describe("client", () => {
|
||||
await send(mocks.core);
|
||||
assert.fail("Expected an error but none was found");
|
||||
} catch (_err) {
|
||||
assert.isFalse(mocks.core.setFailed.called);
|
||||
assert.strictEqual(mocks.core.setFailed.called, false);
|
||||
assert.equal(mocks.core.setOutput.getCall(0).firstArg, "ok");
|
||||
assert.equal(mocks.core.setOutput.getCall(0).lastArg, false);
|
||||
assert.equal(mocks.core.setOutput.getCall(1).firstArg, "response");
|
||||
@@ -456,7 +457,7 @@ describe("client", () => {
|
||||
const client = new Client();
|
||||
const { httpsAgent, proxy: proxying } = client.proxies(config);
|
||||
assert.deepEqual(httpsAgent.proxy, new URL(proxy));
|
||||
assert.isNotFalse(proxying);
|
||||
assert.notStrictEqual(proxying, false);
|
||||
});
|
||||
|
||||
it("fails to configure proxies with an invalid proxied url", async () => {
|
||||
@@ -471,9 +472,11 @@ describe("client", () => {
|
||||
assert.fail("An invalid proxy URL was not thrown as error!");
|
||||
} catch (err) {
|
||||
if (err instanceof SlackError) {
|
||||
assert.include(err.message, "Failed to configure the HTTPS proxy");
|
||||
assert.ok(
|
||||
err.message.includes("Failed to configure the HTTPS proxy"),
|
||||
);
|
||||
} else {
|
||||
assert.fail("Failed to throw a SlackError", err);
|
||||
assert.fail(err);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
+46
-44
@@ -1,4 +1,5 @@
|
||||
import { assert } from "chai";
|
||||
import assert from "node:assert";
|
||||
import { beforeEach, describe, it } from "node:test";
|
||||
import Config from "../src/config.js";
|
||||
import SlackError from "../src/errors.js";
|
||||
import send from "../src/send.js";
|
||||
@@ -34,7 +35,7 @@ describe("config", () => {
|
||||
assert.equal(config.inputs.proxy, "https://example.com");
|
||||
assert.equal(config.inputs.retries, config.Retries.ZERO);
|
||||
assert.equal(config.inputs.token, "xoxb-example");
|
||||
assert.isTrue(mocks.core.setSecret.withArgs("xoxb-example").called);
|
||||
assert.ok(mocks.core.setSecret.withArgs("xoxb-example").called);
|
||||
});
|
||||
|
||||
it("allows token environment variables with a webhook", async () => {
|
||||
@@ -45,10 +46,8 @@ describe("config", () => {
|
||||
assert.equal(config.inputs.token, "xoxb-example");
|
||||
assert.equal(config.inputs.webhook, "https://example.com");
|
||||
assert.equal(config.inputs.webhookType, "incoming-webhook");
|
||||
assert.isTrue(mocks.core.setSecret.withArgs("xoxb-example").called);
|
||||
assert.isTrue(
|
||||
mocks.core.setSecret.withArgs("https://example.com").called,
|
||||
);
|
||||
assert.ok(mocks.core.setSecret.withArgs("xoxb-example").called);
|
||||
assert.ok(mocks.core.setSecret.withArgs("https://example.com").called);
|
||||
});
|
||||
|
||||
it("allows webhook environment variables with a token", async () => {
|
||||
@@ -59,10 +58,8 @@ describe("config", () => {
|
||||
assert.equal(config.inputs.method, "chat.postMessage");
|
||||
assert.equal(config.inputs.token, "xoxb-example");
|
||||
assert.equal(config.inputs.webhook, "https://example.com");
|
||||
assert.isTrue(mocks.core.setSecret.withArgs("xoxb-example").called);
|
||||
assert.isTrue(
|
||||
mocks.core.setSecret.withArgs("https://example.com").called,
|
||||
);
|
||||
assert.ok(mocks.core.setSecret.withArgs("xoxb-example").called);
|
||||
assert.ok(mocks.core.setSecret.withArgs("https://example.com").called);
|
||||
});
|
||||
|
||||
it("errors when both the token and webhook is provided", async () => {
|
||||
@@ -73,16 +70,17 @@ describe("config", () => {
|
||||
assert.fail("Failed to error when invalid inputs are provided");
|
||||
} catch (err) {
|
||||
if (err instanceof SlackError) {
|
||||
assert.include(
|
||||
err.message,
|
||||
"Invalid input! Either the token or webhook is required - not both.",
|
||||
assert.ok(
|
||||
err.message.includes(
|
||||
"Invalid input! Either the token or webhook is required - not both.",
|
||||
),
|
||||
);
|
||||
assert.isTrue(mocks.core.setSecret.withArgs("xoxb-example").called);
|
||||
assert.isTrue(
|
||||
assert.ok(mocks.core.setSecret.withArgs("xoxb-example").called);
|
||||
assert.ok(
|
||||
mocks.core.setSecret.withArgs("https://example.com").called,
|
||||
);
|
||||
} else {
|
||||
assert.fail("Failed to throw a SlackError", err);
|
||||
assert.fail(err);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -94,12 +92,13 @@ describe("config", () => {
|
||||
assert.fail("Failed to error when invalid inputs are provided");
|
||||
} catch (err) {
|
||||
if (err instanceof SlackError) {
|
||||
assert.include(
|
||||
err.message,
|
||||
"Missing input! A token must be provided to use the method decided.",
|
||||
assert.ok(
|
||||
err.message.includes(
|
||||
"Missing input! A token must be provided to use the method decided.",
|
||||
),
|
||||
);
|
||||
} else {
|
||||
assert.fail("Failed to throw a SlackError", err);
|
||||
assert.fail(err);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -110,12 +109,13 @@ describe("config", () => {
|
||||
assert.fail("Failed to error when invalid inputs are provided");
|
||||
} catch (err) {
|
||||
if (err instanceof SlackError) {
|
||||
assert.include(
|
||||
err.message,
|
||||
"Missing input! Either a method or webhook is required to take action.",
|
||||
assert.ok(
|
||||
err.message.includes(
|
||||
"Missing input! Either a method or webhook is required to take action.",
|
||||
),
|
||||
);
|
||||
} else {
|
||||
assert.fail("Failed to throw a SlackError", err);
|
||||
assert.fail(err);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -127,12 +127,13 @@ describe("config", () => {
|
||||
assert.fail("Failed to error when invalid inputs are provided");
|
||||
} catch (err) {
|
||||
if (err instanceof SlackError) {
|
||||
assert.include(
|
||||
err.message,
|
||||
"Missing input! The webhook type must be 'incoming-webhook' or 'webhook-trigger'.",
|
||||
assert.ok(
|
||||
err.message.includes(
|
||||
"Missing input! The webhook type must be 'incoming-webhook' or 'webhook-trigger'.",
|
||||
),
|
||||
);
|
||||
} else {
|
||||
assert.fail("Failed to throw a SlackError", err);
|
||||
assert.fail(err);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -145,12 +146,13 @@ describe("config", () => {
|
||||
assert.fail("Failed to error when invalid inputs are provided");
|
||||
} catch (err) {
|
||||
if (err instanceof SlackError) {
|
||||
assert.include(
|
||||
err.message,
|
||||
"Invalid input! The webhook type must be 'incoming-webhook' or 'webhook-trigger'.",
|
||||
assert.ok(
|
||||
err.message.includes(
|
||||
"Invalid input! The webhook type must be 'incoming-webhook' or 'webhook-trigger'.",
|
||||
),
|
||||
);
|
||||
} else {
|
||||
assert.fail("Failed to throw a SlackError", err);
|
||||
assert.fail(err);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -163,7 +165,7 @@ describe("config", () => {
|
||||
await send(mocks.core);
|
||||
assert.fail("Failed to error for incomplete inputs while testing");
|
||||
} catch {
|
||||
assert.isTrue(mocks.core.setSecret.withArgs("xoxb-example").called);
|
||||
assert.ok(mocks.core.setSecret.withArgs("xoxb-example").called);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -174,9 +176,7 @@ describe("config", () => {
|
||||
await send(mocks.core);
|
||||
assert.fail("Failed to error for incomplete inputs while testing");
|
||||
} catch {
|
||||
assert.isTrue(
|
||||
mocks.core.setSecret.withArgs("https://slack.com").called,
|
||||
);
|
||||
assert.ok(mocks.core.setSecret.withArgs("https://slack.com").called);
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -193,12 +193,13 @@ describe("config", () => {
|
||||
await send(mocks.core);
|
||||
} catch (err) {
|
||||
if (err instanceof SlackError) {
|
||||
assert.include(
|
||||
err.message,
|
||||
'Invalid input! An unknown "retries" value was used: FOREVER',
|
||||
assert.ok(
|
||||
err.message.includes(
|
||||
'Invalid input! An unknown "retries" value was used: FOREVER',
|
||||
),
|
||||
);
|
||||
} else {
|
||||
assert.fail("Failed to throw a SlackError", err);
|
||||
assert.fail(err);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -214,12 +215,13 @@ describe("config", () => {
|
||||
await send(mocks.core);
|
||||
} catch (err) {
|
||||
if (err instanceof SlackError) {
|
||||
assert.include(
|
||||
err.message,
|
||||
'Invalid input! An unknown "retries" value was used: FOREVER',
|
||||
assert.ok(
|
||||
err.message.includes(
|
||||
'Invalid input! An unknown "retries" value was used: FOREVER',
|
||||
),
|
||||
);
|
||||
} else {
|
||||
assert.fail("Failed to throw a SlackError", err);
|
||||
assert.fail(err);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
+53
-45
@@ -1,6 +1,7 @@
|
||||
import assert from "node:assert";
|
||||
import path from "node:path";
|
||||
import { beforeEach, describe, it } from "node:test";
|
||||
import core from "@actions/core";
|
||||
import { assert } from "chai";
|
||||
import { YAMLException } from "js-yaml";
|
||||
import Config from "../src/config.js";
|
||||
import Content from "../src/content.js";
|
||||
@@ -45,12 +46,13 @@ describe("content", () => {
|
||||
assert.fail("Failed to throw for invalid input");
|
||||
} catch (err) {
|
||||
if (err instanceof SlackError) {
|
||||
assert.include(
|
||||
err.message,
|
||||
"Invalid input! Just the payload or payload file path is required.",
|
||||
assert.ok(
|
||||
err.message.includes(
|
||||
"Invalid input! Just the payload or payload file path is required.",
|
||||
),
|
||||
);
|
||||
} else {
|
||||
assert.fail("Failed to throw a SlackError", err);
|
||||
assert.fail(err);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -278,12 +280,13 @@ describe("content", () => {
|
||||
assert.fail("Failed to throw for missing payload content");
|
||||
} catch (err) {
|
||||
if (err instanceof SlackError) {
|
||||
assert.include(
|
||||
err.message,
|
||||
"Invalid input! No payload content was provided",
|
||||
assert.ok(
|
||||
err.message.includes(
|
||||
"Invalid input! No payload content was provided",
|
||||
),
|
||||
);
|
||||
} else {
|
||||
assert.fail("Failed to throw a SlackError", err);
|
||||
assert.fail(err);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -295,17 +298,18 @@ describe("content", () => {
|
||||
assert.fail("Failed to throw for invalid JSON");
|
||||
} catch (err) {
|
||||
if (err instanceof SlackError) {
|
||||
assert.include(
|
||||
err.message,
|
||||
"Invalid input! Failed to parse contents of the provided payload",
|
||||
assert.ok(
|
||||
err.message.includes(
|
||||
"Invalid input! Failed to parse contents of the provided payload",
|
||||
),
|
||||
);
|
||||
assert.isDefined(err.cause?.values);
|
||||
assert.notStrictEqual(err.cause?.values, undefined);
|
||||
assert.equal(err.cause.values.length, 2);
|
||||
const [jsonError, yamlError] = err.cause.values;
|
||||
assert.isTrue(jsonError instanceof SyntaxError);
|
||||
assert.isTrue(yamlError instanceof YAMLException);
|
||||
assert.ok(jsonError instanceof SyntaxError);
|
||||
assert.ok(yamlError instanceof YAMLException);
|
||||
} else {
|
||||
assert.fail("Failed to throw a SlackError", err);
|
||||
assert.fail(err);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -515,7 +519,7 @@ describe("content", () => {
|
||||
mocks.fs.readFileSync
|
||||
.withArgs(path.resolve("example.json"), "utf-8")
|
||||
.returns(`{
|
||||
"message": "What makes $\{\{ env.TREASURE }} a secret"
|
||||
"message": "What makes $\{{ env.TREASURE }} a secret"
|
||||
}`);
|
||||
mocks.core.getBooleanInput.withArgs("payload-templated").returns(true);
|
||||
const config = new Config(mocks.core);
|
||||
@@ -540,12 +544,11 @@ describe("content", () => {
|
||||
assert.fail("Failed to throw for the wrong payload type");
|
||||
} catch (err) {
|
||||
if (err instanceof SlackError) {
|
||||
assert.include(
|
||||
err.message,
|
||||
"Invalid input! No payload found for content",
|
||||
assert.ok(
|
||||
err.message.includes("Invalid input! No payload found for content"),
|
||||
);
|
||||
} else {
|
||||
assert.fail("Failed to throw a SlackError", err);
|
||||
assert.fail(err);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -557,12 +560,13 @@ describe("content", () => {
|
||||
assert.fail("Failed to throw for nonexistent files");
|
||||
} catch (err) {
|
||||
if (err instanceof SlackError) {
|
||||
assert.include(
|
||||
err.message,
|
||||
"Invalid input! Failed to parse contents of the provided payload file",
|
||||
assert.ok(
|
||||
err.message.includes(
|
||||
"Invalid input! Failed to parse contents of the provided payload file",
|
||||
),
|
||||
);
|
||||
} else {
|
||||
assert.fail("Failed to throw a SlackError", err);
|
||||
assert.fail(err);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -574,18 +578,20 @@ describe("content", () => {
|
||||
assert.fail("Failed to throw for an unknown extension");
|
||||
} catch (err) {
|
||||
if (err instanceof SlackError) {
|
||||
assert.include(
|
||||
err.message,
|
||||
"Invalid input! Failed to parse contents of the provided payload file",
|
||||
assert.ok(
|
||||
err.message.includes(
|
||||
"Invalid input! Failed to parse contents of the provided payload file",
|
||||
),
|
||||
);
|
||||
assert.isDefined(err.cause?.values);
|
||||
assert.notStrictEqual(err.cause?.values, undefined);
|
||||
assert.equal(err.cause.values.length, 1);
|
||||
assert.include(
|
||||
err.cause.values[0].message,
|
||||
"Invalid input! Failed to parse file extension unknown.md",
|
||||
assert.ok(
|
||||
err.cause.values[0].message.includes(
|
||||
"Invalid input! Failed to parse file extension unknown.md",
|
||||
),
|
||||
);
|
||||
} else {
|
||||
assert.fail("Failed to throw a SlackError", err);
|
||||
assert.fail(err);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -601,15 +607,16 @@ describe("content", () => {
|
||||
assert.fail("Failed to throw for invalid JSON");
|
||||
} catch (err) {
|
||||
if (err instanceof SlackError) {
|
||||
assert.include(
|
||||
err.message,
|
||||
"Invalid input! Failed to parse contents of the provided payload file",
|
||||
assert.ok(
|
||||
err.message.includes(
|
||||
"Invalid input! Failed to parse contents of the provided payload file",
|
||||
),
|
||||
);
|
||||
assert.isDefined(err.cause?.values);
|
||||
assert.notStrictEqual(err.cause?.values, undefined);
|
||||
assert.equal(err.cause.values.length, 1);
|
||||
assert.isTrue(err.cause.values[0] instanceof SyntaxError);
|
||||
assert.ok(err.cause.values[0] instanceof SyntaxError);
|
||||
} else {
|
||||
assert.fail("Failed to throw a SlackError", err);
|
||||
assert.fail(err);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -624,15 +631,16 @@ describe("content", () => {
|
||||
assert.fail("Failed to throw for invalid YAML");
|
||||
} catch (err) {
|
||||
if (err instanceof SlackError) {
|
||||
assert.include(
|
||||
err.message,
|
||||
"Invalid input! Failed to parse contents of the provided payload file",
|
||||
assert.ok(
|
||||
err.message.includes(
|
||||
"Invalid input! Failed to parse contents of the provided payload file",
|
||||
),
|
||||
);
|
||||
assert.isDefined(err.cause?.values);
|
||||
assert.notStrictEqual(err.cause?.values, undefined);
|
||||
assert.equal(err.cause.values.length, 1);
|
||||
assert.isTrue(err.cause.values[0] instanceof YAMLException);
|
||||
assert.ok(err.cause.values[0] instanceof YAMLException);
|
||||
} else {
|
||||
assert.fail("Failed to throw a SlackError", err);
|
||||
assert.fail(err);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
+4
-3
@@ -1,6 +1,7 @@
|
||||
import assert from "node:assert";
|
||||
import { beforeEach, describe, it } from "node:test";
|
||||
import core from "@actions/core";
|
||||
import { LogLevel } from "@slack/logger";
|
||||
import { assert } from "chai";
|
||||
import Logger from "../src/logger.js";
|
||||
import { mocks } from "./index.spec.js";
|
||||
|
||||
@@ -15,7 +16,7 @@ describe("logger", () => {
|
||||
const { logger } = new Logger(core);
|
||||
const actual = logger.getLevel();
|
||||
const expected = LogLevel.DEBUG;
|
||||
assert.equal(actual, expected);
|
||||
assert.strictEqual(actual, expected);
|
||||
});
|
||||
|
||||
it("info", () => {
|
||||
@@ -23,7 +24,7 @@ describe("logger", () => {
|
||||
const { logger } = new Logger(core);
|
||||
const actual = logger.getLevel();
|
||||
const expected = LogLevel.INFO;
|
||||
assert.equal(actual, expected);
|
||||
assert.strictEqual(actual, expected);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
+5
-4
@@ -1,4 +1,5 @@
|
||||
import { assert } from "chai";
|
||||
import assert from "node:assert";
|
||||
import { beforeEach, describe, it } from "node:test";
|
||||
import send from "../src/send.js";
|
||||
import { mocks } from "./index.spec.js";
|
||||
|
||||
@@ -35,7 +36,7 @@ describe("send", () => {
|
||||
JSON.stringify({ ok: true }),
|
||||
);
|
||||
assert.equal(mocks.core.setOutput.getCall(2).firstArg, "time");
|
||||
assert.isAtLeast(mocks.core.setOutput.getCall(2).lastArg, 0);
|
||||
assert.ok(mocks.core.setOutput.getCall(2).lastArg >= 0);
|
||||
});
|
||||
|
||||
it("token", async () => {
|
||||
@@ -53,7 +54,7 @@ describe("send", () => {
|
||||
JSON.stringify({ ok: true }),
|
||||
);
|
||||
assert.equal(mocks.core.setOutput.getCall(2).firstArg, "time");
|
||||
assert.isAtLeast(mocks.core.setOutput.getCall(2).lastArg, 0);
|
||||
assert.ok(mocks.core.setOutput.getCall(2).lastArg >= 0);
|
||||
});
|
||||
|
||||
it("incoming webhook", async () => {
|
||||
@@ -73,7 +74,7 @@ describe("send", () => {
|
||||
JSON.stringify("ok"),
|
||||
);
|
||||
assert.equal(mocks.core.setOutput.getCall(2).firstArg, "time");
|
||||
assert.isAtLeast(mocks.core.setOutput.getCall(2).lastArg, 0);
|
||||
assert.ok(mocks.core.setOutput.getCall(2).lastArg >= 0);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
+32
-23
@@ -1,6 +1,7 @@
|
||||
import assert from "node:assert";
|
||||
import { beforeEach, describe, it } from "node:test";
|
||||
import core from "@actions/core";
|
||||
import { AxiosError } from "axios";
|
||||
import { assert } from "chai";
|
||||
import Config from "../src/config.js";
|
||||
import SlackError from "../src/errors.js";
|
||||
import send from "../src/send.js";
|
||||
@@ -84,9 +85,9 @@ describe("webhook", () => {
|
||||
assert.fail("Failed to throw for missing input");
|
||||
} catch (err) {
|
||||
if (err instanceof SlackError) {
|
||||
assert.include(err.message, "No webhook was provided to post to");
|
||||
assert.ok(err.message.includes("No webhook was provided to post to"));
|
||||
} else {
|
||||
assert.fail("Failed to throw a SlackError", err);
|
||||
assert.fail(err);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -109,9 +110,11 @@ describe("webhook", () => {
|
||||
await send(mocks.core);
|
||||
} catch (err) {
|
||||
if (err instanceof SlackError) {
|
||||
assert.include(err.message, "Request failed with status code 400");
|
||||
assert.ok(
|
||||
err.message.includes("Request failed with status code 400"),
|
||||
);
|
||||
} else {
|
||||
assert.fail("Failed to throw a SlackError", err);
|
||||
assert.fail(err);
|
||||
}
|
||||
}
|
||||
assert.equal(mocks.axios.post.getCalls().length, 1);
|
||||
@@ -142,9 +145,11 @@ describe("webhook", () => {
|
||||
await send(mocks.core);
|
||||
} catch (err) {
|
||||
if (err instanceof SlackError) {
|
||||
assert.include(err.message, "Request failed with status code 400");
|
||||
assert.ok(
|
||||
err.message.includes("Request failed with status code 400"),
|
||||
);
|
||||
} else {
|
||||
assert.fail("Failed to throw a SlackError", err);
|
||||
assert.fail(err);
|
||||
}
|
||||
}
|
||||
assert.equal(mocks.axios.post.getCalls().length, 1);
|
||||
@@ -172,9 +177,11 @@ describe("webhook", () => {
|
||||
assert.fail("Failed to throw for missing input");
|
||||
} catch (err) {
|
||||
if (err instanceof SlackError) {
|
||||
assert.include(err.message, "No webhook was provided to proxy to");
|
||||
assert.ok(
|
||||
err.message.includes("No webhook was provided to proxy to"),
|
||||
);
|
||||
} else {
|
||||
assert.fail("Failed to throw a SlackError", err);
|
||||
assert.fail(err);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -186,7 +193,7 @@ describe("webhook", () => {
|
||||
const config = new Config(mocks.core);
|
||||
const webhook = new Webhook();
|
||||
const request = webhook.proxies(config);
|
||||
assert.isUndefined(request);
|
||||
assert.strictEqual(request, undefined);
|
||||
});
|
||||
|
||||
it("sets up the proxy agent for the provided https proxy", async () => {
|
||||
@@ -200,7 +207,7 @@ describe("webhook", () => {
|
||||
const webhook = new Webhook();
|
||||
const { httpsAgent, proxy: proxying } = webhook.proxies(config);
|
||||
assert.deepEqual(httpsAgent.proxy, new URL(proxy));
|
||||
assert.isNotFalse(proxying);
|
||||
assert.notStrictEqual(proxying, false);
|
||||
});
|
||||
|
||||
it("sets up the agent without proxy for http proxies", async () => {
|
||||
@@ -214,7 +221,7 @@ describe("webhook", () => {
|
||||
const webhook = new Webhook();
|
||||
const { httpsAgent, proxy: proxying } = webhook.proxies(config);
|
||||
assert.deepEqual(httpsAgent.proxy, new URL(proxy));
|
||||
assert.isFalse(proxying);
|
||||
assert.strictEqual(proxying, false);
|
||||
});
|
||||
|
||||
it("fails to configure proxies with an invalid proxied url", async () => {
|
||||
@@ -231,9 +238,11 @@ describe("webhook", () => {
|
||||
assert.fail("An invalid proxy URL was not thrown as error!");
|
||||
} catch (err) {
|
||||
if (err instanceof SlackError) {
|
||||
assert.include(err.message, "Failed to configure the HTTPS proxy");
|
||||
assert.ok(
|
||||
err.message.includes("Failed to configure the HTTPS proxy"),
|
||||
);
|
||||
} else {
|
||||
assert.fail("Failed to throw a SlackError", err);
|
||||
assert.fail(err);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -252,10 +261,12 @@ describe("webhook", () => {
|
||||
assert.fail("An unknown URL protocol was not thrown as error!");
|
||||
} catch (err) {
|
||||
if (err instanceof SlackError) {
|
||||
assert.include(err.message, "Failed to configure the HTTPS proxy");
|
||||
assert.include(err.cause.message, "Unsupported URL protocol");
|
||||
assert.ok(
|
||||
err.message.includes("Failed to configure the HTTPS proxy"),
|
||||
);
|
||||
assert.ok(err.cause.message.includes("Unsupported URL protocol"));
|
||||
} else {
|
||||
assert.fail("Failed to throw a SlackError", err);
|
||||
assert.fail(err);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -295,14 +306,12 @@ describe("webhook", () => {
|
||||
if (!result.retryDelay) {
|
||||
assert.fail("No retry delay found!");
|
||||
}
|
||||
assert.isAtLeast(
|
||||
result.retryDelay(10, mocks.errors.axios.network_failed),
|
||||
1800000,
|
||||
assert.ok(
|
||||
result.retryDelay(10, mocks.errors.axios.network_failed) > 1800000,
|
||||
"last attempt is around 30 minutes after starting",
|
||||
);
|
||||
assert.isAtMost(
|
||||
result.retryDelay(10, mocks.errors.axios.network_failed),
|
||||
3600000,
|
||||
assert.ok(
|
||||
result.retryDelay(10, mocks.errors.axios.network_failed) < 3600000,
|
||||
"last attempt is no more than an hour later",
|
||||
);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user