Skip to content

Commit 15db037

Browse files
authored
test: fix test file extensions and inputs for repositories (#161)
This pull request fixes the file extension for two test files that were incorrectly named. This caused them not to be tested. A new test has been added to ensure all test files have the correct extension. This also fixes a bug in some tests where `repositories` inputs included the repository owner. The owner has been removed from these inputs and the snapshots have been updated.
1 parent 9ccc6db commit 15db037

12 files changed

+80
-23
lines changed

package-lock.json

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

tests/index.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
11
import { readdirSync } from "node:fs";
22

3-
import { execa } from "execa";
43
import test from "ava";
4+
import { execa } from "execa";
5+
6+
// Get all files in tests directory
7+
const files = readdirSync("tests");
8+
9+
// Files to ignore
10+
const ignore = ["index.js", "main.js", "README.md", "snapshots"];
511

6-
const tests = readdirSync("tests").filter((file) => file.endsWith(".test.js"));
12+
const testFiles = files.filter((file) => !ignore.includes(file));
713

8-
for (const file of tests) {
14+
// Throw an error if there is a file that does not end with test.js in the tests directory
15+
for (const file of testFiles) {
16+
if (!file.endsWith(".test.js")) {
17+
throw new Error(`File ${file} does not end with .test.js`);
18+
}
919
test(file, async (t) => {
1020
// Override Actions environment variables that change `core`’s behavior
1121
const env = {

tests/main-custom-github-api-url.test.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
import { test, DEFAULT_ENV } from "./main.js";
1+
import { DEFAULT_ENV, test } from "./main.js";
22

33
// Verify that main works with a custom GitHub API URL passed as `github-api-url` input
44
await test(
55
() => {
66
process.env.INPUT_OWNER = process.env.GITHUB_REPOSITORY_OWNER;
7-
process.env.INPUT_REPOSITORIES = process.env.GITHUB_REPOSITORY;
7+
const currentRepoName = process.env.GITHUB_REPOSITORY.split("/")[1];
8+
process.env.INPUT_REPOSITORIES = currentRepoName;
89
},
910
{
1011
...DEFAULT_ENV,

tests/main-private-key-with-escaped-newlines.js

Lines changed: 0 additions & 6 deletions
This file was deleted.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { DEFAULT_ENV, test } from "./main.js";
2+
3+
// Verify `main` works correctly when `private-key` input has escaped newlines
4+
await test(() => {
5+
process.env["INPUT_PRIVATE-KEY"] = DEFAULT_ENV["INPUT_PRIVATE-KEY"].replace(
6+
/\n/g,
7+
"\\n"
8+
);
9+
});
File renamed without changes.

tests/main-token-get-owner-set-repo-set-to-many.test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ import { test } from "./main.js";
33
// Verify `main` successfully obtains a token when the `owner` and `repositories` inputs are set (and the latter is a list of repos).
44
await test(() => {
55
process.env.INPUT_OWNER = process.env.GITHUB_REPOSITORY_OWNER;
6-
process.env.INPUT_REPOSITORIES = `${process.env.GITHUB_REPOSITORY},actions/toolkit`;
6+
const currentRepoName = process.env.GITHUB_REPOSITORY.split("/")[1];
7+
process.env.INPUT_REPOSITORIES = `${currentRepoName},toolkit`;
78
});

tests/main-token-get-owner-set-repo-set-to-one.test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ import { test } from "./main.js";
33
// Verify `main` successfully obtains a token when the `owner` and `repositories` inputs are set (and the latter is a single repo).
44
await test(() => {
55
process.env.INPUT_OWNER = process.env.GITHUB_REPOSITORY_OWNER;
6-
process.env.INPUT_REPOSITORIES = process.env.GITHUB_REPOSITORY;
6+
const currentRepoName = process.env.GITHUB_REPOSITORY.split("/")[1];
7+
process.env.INPUT_REPOSITORIES = currentRepoName;
78
});

tests/main-token-get-owner-unset-repo-set.test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ import { test } from "./main.js";
33
// Verify `main` successfully obtains a token when the `owner` input is not set, but the `repositories` input is set.
44
await test(() => {
55
delete process.env.INPUT_OWNER;
6-
process.env.INPUT_REPOSITORIES = process.env.GITHUB_REPOSITORY;
6+
const currentRepoName = process.env.GITHUB_REPOSITORY.split("/")[1];
7+
process.env.INPUT_REPOSITORIES = currentRepoName;
78
});

tests/main.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export async function test(cb = (_mockPool) => {}, env = DEFAULT_ENV) {
4646

4747
// Set up mocking
4848
const baseUrl = new URL(env["INPUT_GITHUB-API-URL"]);
49-
const basePath = baseUrl.pathname === '/' ? '' : baseUrl.pathname;
49+
const basePath = baseUrl.pathname === "/" ? "" : baseUrl.pathname;
5050
const mockAgent = new MockAgent();
5151
mockAgent.disableNetConnect();
5252
setGlobalDispatcher(mockAgent);
@@ -58,8 +58,9 @@ export async function test(cb = (_mockPool) => {}, env = DEFAULT_ENV) {
5858
const mockInstallationId = "123456";
5959
const mockAppSlug = "github-actions";
6060
const owner = env.INPUT_OWNER ?? env.GITHUB_REPOSITORY_OWNER;
61+
const currentRepoName = env.GITHUB_REPOSITORY.split("/")[1];
6162
const repo = encodeURIComponent(
62-
(env.INPUT_REPOSITORIES ?? env.GITHUB_REPOSITORY).split(",")[0]
63+
(env.INPUT_REPOSITORIES ?? currentRepoName).split(",")[0]
6364
);
6465
mockPool
6566
.intercept({
@@ -73,7 +74,7 @@ export async function test(cb = (_mockPool) => {}, env = DEFAULT_ENV) {
7374
})
7475
.reply(
7576
200,
76-
{ id: mockInstallationId, "app_slug": mockAppSlug },
77+
{ id: mockInstallationId, app_slug: mockAppSlug },
7778
{ headers: { "content-type": "application/json" } }
7879
);
7980

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy