Skip to content

Commit 8aaed03

Browse files
committed
Fix tests
1 parent 16f8b42 commit 8aaed03

File tree

8 files changed

+2609
-678
lines changed

8 files changed

+2609
-678
lines changed

dist/index.js

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

dist/licenses.txt

Lines changed: 2484 additions & 568 deletions
Large diffs are not rendered by default.

src/download-artifact.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { mkdirP } from "@actions/io";
66
import { Octokit } from "@octokit/core";
77
import AdmZip from "adm-zip";
88
import { filesize } from "filesize";
9-
import tar from "tar";
9+
import * as tar from "tar";
1010

1111
import { extendPaths, extendDependencies } from "./env-functions";
1212
import { isError } from "./helper-functions";

src/download-repository.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as core from "@actions/core";
44
import { mkdirP } from "@actions/io";
55
import { Octokit } from "@octokit/core";
66
import { filesize } from "filesize";
7-
import tar from "tar";
7+
import * as tar from "tar";
88

99
import downloadFile from "./download-file";
1010
import { extendDependencies } from "./env-functions";

src/upload-artifact.ts

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import fs from "fs";
22
import path from "path";
33
import * as core from "@actions/core";
44
import * as artifact from "@actions/artifact";
5-
import tar from "tar";
5+
import * as tar from "tar";
66
import { filesize } from "filesize";
77

88
import { isError } from "./helper-functions";
@@ -131,7 +131,7 @@ const uploadArtifact = async (
131131
uploadPaths.push(dependenciesPath);
132132
}
133133

134-
const artifactClient = artifact.create();
134+
const artifactClient = new artifact.DefaultArtifactClient();
135135

136136
let uploadResult;
137137

@@ -141,9 +141,6 @@ const uploadArtifact = async (
141141
artifactName,
142142
uploadPaths,
143143
rootDirectory,
144-
{
145-
continueOnError: true,
146-
},
147144
);
148145
} catch (error) {
149146
if (error instanceof Error)
@@ -157,20 +154,9 @@ const uploadArtifact = async (
157154
if (isError(!uploadResult, `Error uploading artifact for ${packageName}`))
158155
return false;
159156

160-
if (
161-
isError(
162-
uploadResult &&
163-
uploadResult.failedItems &&
164-
uploadResult.failedItems.length,
165-
`Error uploading artifact for ${packageName}: ${uploadResult.failedItems}`,
166-
)
167-
) {
168-
return false;
169-
}
170-
171157
core.info(
172-
`==> Uploaded artifact: ${uploadResult.artifactName} (${filesize(
173-
uploadResult.size,
158+
`==> Uploaded artifact: ${artifactName} (${filesize(
159+
uploadResult?.size || 0,
174160
)})`,
175161
);
176162

tests/download-artifact.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import * as core from "@actions/core";
55
import { Octokit } from "@octokit/core";
66
import AdmZip from "adm-zip";
77
import { filesize } from "filesize";
8-
import tar from "tar";
8+
import * as tar from "tar";
99
import { describe, it, expect, vi } from "vitest";
1010

1111
import downloadArtifact from "../src/download-artifact";

tests/download-repository.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import fs from "fs";
22
import * as core from "@actions/core";
33
import { Octokit } from "@octokit/core";
44
import { filesize } from "filesize";
5-
import tar from "tar";
5+
import * as tar from "tar";
66
import { describe, it, expect, vi } from "vitest";
77

88
import downloadFile from "../src/download-file";

tests/upload-artifact.spec.ts

Lines changed: 33 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,19 @@ import path from "path";
33
import * as core from "@actions/core";
44
import * as artifact from "@actions/artifact";
55
import { filesize } from "filesize";
6-
import tar from "tar";
6+
import * as tar from "tar";
77
import { describe, it, expect, vi } from "vitest";
88

99
import uploadArtifact from "../src/upload-artifact";
1010
import { getCacheKeyHash } from "../src/cache-functions";
1111
import { EnvironmentVariables } from "../src/types/env-functions";
1212

1313
vi.mock("@actions/core");
14-
vi.mock("@actions/artifact");
14+
vi.mock("@actions/artifact", () => ({
15+
DefaultArtifactClient: vi.fn().mockImplementation(() => ({
16+
uploadArtifact: vi.fn(),
17+
})),
18+
}));
1519
vi.mock("tar");
1620

1721
const getArtifactName = (
@@ -80,9 +84,7 @@ const emptyObject = {};
8084

8185
const uploadResult = () =>
8286
Promise.resolve({
83-
artifactName,
8487
size,
85-
failedItems: [],
8688
});
8789

8890
describe("uploadArtifact", () => {
@@ -93,7 +95,7 @@ describe("uploadArtifact", () => {
9395
...env,
9496
};
9597

96-
(artifact.create as vi.Mock).mockImplementationOnce(() => ({
98+
(artifact.DefaultArtifactClient as vi.Mock).mockImplementation(() => ({
9799
uploadArtifact: uploadResult,
98100
}));
99101

@@ -146,14 +148,21 @@ describe("uploadArtifact", () => {
146148
...env,
147149
};
148150

149-
const coverageArtifactName = `coverage-${repo}-${os}-${compiler}`;
151+
const cacheKeySha = getCacheKeyHash(
152+
`coverage-${repo}`,
153+
cacheSuffix,
154+
env,
155+
{},
156+
cmakeOptions,
157+
sha,
158+
);
159+
160+
const coverageArtifactName = `${os}-${compiler}-coverage-${repo}-${cacheKeySha}`;
150161

151-
(artifact.create as vi.Mock).mockImplementationOnce(() => ({
162+
(artifact.DefaultArtifactClient as vi.Mock).mockImplementation(() => ({
152163
uploadArtifact: () =>
153164
Promise.resolve({
154-
artifactName: coverageArtifactName,
155165
size,
156-
failedItems: [],
157166
}),
158167
}));
159168

@@ -169,7 +178,7 @@ describe("uploadArtifact", () => {
169178

170179
const isUploaded = await uploadArtifact(
171180
`coverage-${packageName}`,
172-
packageName,
181+
`coverage-${packageName}`,
173182
sha,
174183
installDir,
175184
null,
@@ -197,12 +206,10 @@ describe("uploadArtifact", () => {
197206

198207
const ecbuildArtifactName = `ecbuild-${os}-cmake-${testEnv.CMAKE_VERSION}-${sha}`;
199208

200-
(artifact.create as vi.Mock).mockImplementationOnce(() => ({
209+
(artifact.DefaultArtifactClient as vi.Mock).mockImplementation(() => ({
201210
uploadArtifact: () =>
202211
Promise.resolve({
203-
artifactName: ecbuildArtifactName,
204212
size,
205-
failedItems: [],
206213
}),
207214
}));
208215

@@ -290,7 +297,7 @@ describe("uploadArtifact", () => {
290297
...env,
291298
};
292299

293-
(artifact.create as vi.Mock).mockImplementation(() => ({
300+
(artifact.DefaultArtifactClient as vi.Mock).mockImplementation(() => ({
294301
uploadArtifact: uploadResult,
295302
}));
296303

@@ -333,9 +340,11 @@ describe("uploadArtifact", () => {
333340
...env,
334341
};
335342

336-
(artifact.create as vi.Mock).mockImplementationOnce(() => ({
337-
uploadArtifact: uploadResult,
338-
}));
343+
(artifact.DefaultArtifactClient as vi.Mock).mockImplementation(
344+
() => ({
345+
uploadArtifact: uploadResult,
346+
}),
347+
);
339348

340349
const statSync = vi.spyOn(fs, "statSync");
341350
(statSync as vi.Mock).mockImplementationOnce(() => ({
@@ -369,7 +378,7 @@ describe("uploadArtifact", () => {
369378

370379
expect(isUploaded).toBe(false);
371380

372-
(artifact.create as vi.Mock).mockReset();
381+
(artifact.DefaultArtifactClient as vi.Mock).mockReset();
373382

374383
if (!(error instanceof Error)) return;
375384
expect(core.warning).toHaveBeenCalledWith(
@@ -378,61 +387,14 @@ describe("uploadArtifact", () => {
378387
},
379388
);
380389

381-
it("returns false if artifact item upload has some failures", async () => {
382-
expect.assertions(2);
383-
384-
const testEnv = {
385-
...env,
386-
};
387-
388-
(artifact.create as vi.Mock).mockImplementationOnce(() => ({
389-
uploadArtifact: () =>
390-
Promise.resolve({
391-
artifactName,
392-
size,
393-
failedItems: [artifactName],
394-
}),
395-
}));
396-
397-
const statSync = vi.spyOn(fs, "statSync");
398-
(statSync as vi.Mock).mockImplementationOnce(() => ({
399-
size,
400-
}));
401-
402-
const writeFileSync = vi.spyOn(fs, "writeFileSync");
403-
writeFileSync.mockImplementationOnce((path: string) => {
404-
if (path === dependenciesPath) return true;
405-
});
406-
407-
const isUploaded = await uploadArtifact(
408-
repository,
409-
packageName,
410-
sha,
411-
installDir,
412-
dependencies,
413-
os,
414-
compiler,
415-
testEnv,
416-
{},
417-
githubToken,
418-
cacheSuffix,
419-
cmakeOptions,
420-
);
421-
422-
expect(isUploaded).toBe(false);
423-
expect(core.warning).toHaveBeenCalledWith(
424-
`Error uploading artifact for ${repo}: ${artifactName}`,
425-
);
426-
});
427-
428390
it("returns false if artifact item upload returns empty result", async () => {
429391
expect.assertions(2);
430392

431393
const testEnv = {
432394
...env,
433395
};
434396

435-
(artifact.create as vi.Mock).mockImplementationOnce(() => ({
397+
(artifact.DefaultArtifactClient as vi.Mock).mockImplementation(() => ({
436398
uploadArtifact: () => Promise.resolve(),
437399
}));
438400

@@ -480,9 +442,11 @@ describe("uploadArtifact", () => {
480442
...env,
481443
};
482444

483-
(artifact.create as vi.Mock).mockImplementationOnce(() => ({
484-
uploadArtifact: () => Promise.reject(error),
485-
}));
445+
(artifact.DefaultArtifactClient as vi.Mock).mockImplementation(
446+
() => ({
447+
uploadArtifact: () => Promise.reject(error),
448+
}),
449+
);
486450

487451
const statSync = vi.spyOn(fs, "statSync");
488452
(statSync as vi.Mock).mockImplementationOnce(() => ({

0 commit comments

Comments
 (0)