Use glob for path param

This was done such that multiple files
can be loaded that match given glob
patterns. Existing behaviour is preserved
for exact match.
This commit is contained in:
Sam 2022-10-25 00:49:33 +00:00
parent 437c49a57c
commit 1d46172340
10 changed files with 2660 additions and 55 deletions

View file

@ -29,12 +29,11 @@ afterEach(() => {
delete process.env["INPUT_PATH"]
})
test("repo", () => {
test("repo", async () => {
process.env["INPUT_REPO"] = "other"
expect(require("../src/config")).toMatchObject({
pullRequestNumber: expect.any(Number),
repo: {owner: "marocchino", repo: "other"},
body: "",
header: "",
append: false,
recreate: false,
@ -45,13 +44,13 @@ test("repo", () => {
hideDetails: false,
githubToken: "some-token"
})
expect(await require("../src/config").getBody()).toEqual("")
})
test("header", () => {
test("header", async () => {
process.env["INPUT_HEADER"] = "header"
expect(require("../src/config")).toMatchObject({
pullRequestNumber: expect.any(Number),
repo: {owner: "marocchino", repo: "stick-pull-request-comment"},
body: "",
header: "header",
append: false,
recreate: false,
@ -62,13 +61,13 @@ test("header", () => {
hideDetails: false,
githubToken: "some-token"
})
expect(await require("../src/config").getBody()).toEqual("")
})
test("append", () => {
test("append", async () => {
process.env["INPUT_APPEND"] = "true"
expect(require("../src/config")).toMatchObject({
pullRequestNumber: expect.any(Number),
repo: {owner: "marocchino", repo: "stick-pull-request-comment"},
body: "",
header: "",
append: true,
recreate: false,
@ -79,13 +78,13 @@ test("append", () => {
hideDetails: false,
githubToken: "some-token"
})
expect(await require("../src/config").getBody()).toEqual("")
})
test("recreate", () => {
test("recreate", async () => {
process.env["INPUT_RECREATE"] = "true"
expect(require("../src/config")).toMatchObject({
pullRequestNumber: expect.any(Number),
repo: {owner: "marocchino", repo: "stick-pull-request-comment"},
body: "",
header: "",
append: false,
recreate: true,
@ -96,13 +95,13 @@ test("recreate", () => {
hideDetails: false,
githubToken: "some-token"
})
expect(await require("../src/config").getBody()).toEqual("")
})
test("delete", () => {
test("delete", async () => {
process.env["INPUT_DELETE"] = "true"
expect(require("../src/config")).toMatchObject({
pullRequestNumber: expect.any(Number),
repo: {owner: "marocchino", repo: "stick-pull-request-comment"},
body: "",
header: "",
append: false,
recreate: false,
@ -113,13 +112,13 @@ test("delete", () => {
hideDetails: false,
githubToken: "some-token"
})
expect(await require("../src/config").getBody()).toEqual("")
})
test("hideOldComment", () => {
test("hideOldComment", async () => {
process.env["INPUT_HIDE"] = "true"
expect(require("../src/config")).toMatchObject({
pullRequestNumber: expect.any(Number),
repo: {owner: "marocchino", repo: "stick-pull-request-comment"},
body: "",
header: "",
append: false,
recreate: false,
@ -130,13 +129,13 @@ test("hideOldComment", () => {
hideDetails: false,
githubToken: "some-token"
})
expect(await require("../src/config").getBody()).toEqual("")
})
test("hideAndRecreate", () => {
test("hideAndRecreate", async () => {
process.env["INPUT_HIDE_AND_RECREATE"] = "true"
expect(require("../src/config")).toMatchObject({
pullRequestNumber: expect.any(Number),
repo: {owner: "marocchino", repo: "stick-pull-request-comment"},
body: "",
header: "",
append: false,
recreate: false,
@ -147,13 +146,13 @@ test("hideAndRecreate", () => {
hideDetails: false,
githubToken: "some-token"
})
expect(await require("../src/config").getBody()).toEqual("")
})
test("hideClassify", () => {
test("hideClassify", async () => {
process.env["INPUT_HIDE_CLASSIFY"] = "OFF_TOPIC"
expect(require("../src/config")).toMatchObject({
pullRequestNumber: expect.any(Number),
repo: {owner: "marocchino", repo: "stick-pull-request-comment"},
body: "",
header: "",
append: false,
recreate: false,
@ -164,13 +163,13 @@ test("hideClassify", () => {
hideDetails: false,
githubToken: "some-token"
})
expect(await require("../src/config").getBody()).toEqual("")
})
test("hideDetails", () => {
test("hideDetails", async () => {
process.env["INPUT_HIDE_DETAILS"] = "true"
expect(require("../src/config")).toMatchObject({
pullRequestNumber: expect.any(Number),
repo: {owner: "marocchino", repo: "stick-pull-request-comment"},
body: "",
header: "",
append: false,
recreate: false,
@ -181,14 +180,14 @@ test("hideDetails", () => {
hideDetails: true,
githubToken: "some-token"
})
expect(await require("../src/config").getBody()).toEqual("")
})
describe("path", () => {
test("when exists return content of a file", () => {
test("when exists return content of a file", async () => {
process.env["INPUT_PATH"] = "./__tests__/assets/result"
expect(require("../src/config")).toMatchObject({
pullRequestNumber: expect.any(Number),
repo: {owner: "marocchino", repo: "stick-pull-request-comment"},
body: "hi there\n",
header: "",
append: false,
recreate: false,
@ -199,14 +198,34 @@ describe("path", () => {
hideDetails: false,
githubToken: "some-token"
})
expect(await require("../src/config").getBody()).toEqual("hi there\n")
})
test("when not exists return null string", () => {
test("glob match files", async () => {
process.env["INPUT_PATH"] = "./__tests__/assets/*"
expect(require("../src/config")).toMatchObject({
pullRequestNumber: expect.any(Number),
repo: {owner: "marocchino", repo: "stick-pull-request-comment"},
header: "",
append: false,
recreate: false,
deleteOldComment: false,
hideOldComment: false,
hideAndRecreate: false,
hideClassify: "OUTDATED",
hideDetails: false,
githubToken: "some-token"
})
expect(await require("../src/config").getBody()).toEqual(
"hi there\n\nhey there\n"
)
})
test("when not exists return null string", async () => {
process.env["INPUT_PATH"] = "./__tests__/assets/not_exists"
expect(require("../src/config")).toMatchObject({
pullRequestNumber: expect.any(Number),
repo: {owner: "marocchino", repo: "stick-pull-request-comment"},
body: "",
header: "",
append: false,
recreate: false,
@ -217,15 +236,15 @@ describe("path", () => {
hideDetails: false,
githubToken: "some-token"
})
expect(await require("../src/config").getBody()).toEqual("")
})
})
test("message", () => {
test("message", async () => {
process.env["INPUT_MESSAGE"] = "hello there"
expect(require("../src/config")).toMatchObject({
pullRequestNumber: expect.any(Number),
repo: {owner: "marocchino", repo: "stick-pull-request-comment"},
body: "hello there",
header: "",
append: false,
recreate: false,
@ -236,4 +255,5 @@ test("message", () => {
hideDetails: false,
githubToken: "some-token"
})
expect(await require("../src/config").getBody()).toEqual("hello there")
})