Skip to content

Commit 06cdb94

Browse files
authored
Merge pull request #961 from crazy-max/esm
switch to ESM and update config/test wiring
2 parents f64486a + 2617546 commit 06cdb94

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+283
-232
lines changed
Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2023 actions-toolkit authors
2+
* Copyright 2025 actions-toolkit authors
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -14,6 +14,17 @@
1414
* limitations under the License.
1515
*/
1616

17-
import {Context as GitHubContext} from '@actions/github/lib/context';
17+
import {jest} from '@jest/globals';
18+
import os from 'os';
1819

19-
export type Context = GitHubContext;
20+
export const mockPlatform = (platform: NodeJS.Platform) => {
21+
return jest.spyOn(os, 'platform').mockImplementation(() => platform);
22+
};
23+
24+
export const mockArch = (arch: string) => {
25+
return jest.spyOn(os, 'arch').mockImplementation(() => arch);
26+
};
27+
28+
export const mockHomedir = (dir: string) => {
29+
return jest.spyOn(os, 'homedir').mockImplementation(() => dir);
30+
};

__tests__/buildx/install.test.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@
1414
* limitations under the License.
1515
*/
1616

17-
import {describe, expect, it, jest, test, afterEach} from '@jest/globals';
17+
import {describe, expect, it, test, afterEach} from '@jest/globals';
1818
import fs from 'fs';
1919
import os from 'os';
2020
import path from 'path';
2121
import * as rimraf from 'rimraf';
22-
import osm = require('os');
22+
23+
import {mockArch, mockPlatform} from '../.helpers/os';
2324

2425
import {Install} from '../../src/buildx/install';
2526

@@ -85,8 +86,8 @@ describe('download', () => {
8586
['linux', 's390x'],
8687
])(
8788
'acquires buildx for %s/%s', async (os, arch) => {
88-
jest.spyOn(osm, 'platform').mockImplementation(() => os as NodeJS.Platform);
89-
jest.spyOn(osm, 'arch').mockImplementation(() => arch);
89+
mockPlatform(os as NodeJS.Platform);
90+
mockArch(arch);
9091
const install = new Install();
9192
const buildxBin = await install.download('latest');
9293
expect(fs.existsSync(buildxBin)).toBe(true);

__tests__/compose/install.test.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@
1414
* limitations under the License.
1515
*/
1616

17-
import {describe, expect, it, jest, test, afterEach} from '@jest/globals';
17+
import {describe, expect, it, test, afterEach} from '@jest/globals';
1818
import fs from 'fs';
1919
import os from 'os';
2020
import path from 'path';
2121
import * as rimraf from 'rimraf';
22-
import osm = require('os');
22+
23+
import {mockArch, mockPlatform} from '../.helpers/os';
2324

2425
import {Install} from '../../src/compose/install';
2526

@@ -85,8 +86,8 @@ describe('download', () => {
8586
['linux', 's390x'],
8687
])(
8788
'acquires compose for %s/%s', async (os, arch) => {
88-
jest.spyOn(osm, 'platform').mockImplementation(() => os as NodeJS.Platform);
89-
jest.spyOn(osm, 'arch').mockImplementation(() => arch);
89+
mockPlatform(os as NodeJS.Platform);
90+
mockArch(arch);
9091
const install = new Install();
9192
const composeBin = await install.download('latest');
9293
expect(fs.existsSync(composeBin)).toBe(true);

__tests__/cosign/install.test.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@
1414
* limitations under the License.
1515
*/
1616

17-
import {describe, expect, it, jest, test, afterEach} from '@jest/globals';
17+
import {describe, expect, it, test, afterEach} from '@jest/globals';
1818
import fs from 'fs';
1919
import os from 'os';
2020
import path from 'path';
2121
import * as rimraf from 'rimraf';
22-
import osm = require('os');
22+
23+
import {mockArch, mockPlatform} from '../.helpers/os';
2324

2425
import {Install} from '../../src/cosign/install';
2526

@@ -80,8 +81,8 @@ describe('download', () => {
8081
['linux', 'arm64']
8182
])(
8283
'acquires undock for %s/%s', async (os, arch) => {
83-
jest.spyOn(osm, 'platform').mockImplementation(() => os as NodeJS.Platform);
84-
jest.spyOn(osm, 'arch').mockImplementation(() => arch);
84+
mockPlatform(os as NodeJS.Platform);
85+
mockArch(arch);
8586
const install = new Install();
8687
const cosignBin = await install.download({
8788
version: 'latest'

__tests__/docker/docker.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ import fs from 'fs';
1919
import os from 'os';
2020
import path from 'path';
2121
import * as io from '@actions/io';
22-
import osm = require('os');
2322
import * as rimraf from 'rimraf';
2423

24+
import {mockHomedir} from '../.helpers/os';
25+
2526
import {Docker} from '../../src/docker/docker';
2627

2728
import {ConfigFile} from '../../src/types/docker/docker';
@@ -47,7 +48,7 @@ describe('configDir', () => {
4748
});
4849
it('returns default', async () => {
4950
process.env.DOCKER_CONFIG = '';
50-
jest.spyOn(osm, 'homedir').mockImplementation(() => path.join('/tmp', 'home'));
51+
mockHomedir(path.join('/tmp', 'home'));
5152
expect(Docker.configDir).toEqual(path.join('/tmp', 'home', '.docker'));
5253
});
5354
it('returns from env', async () => {

__tests__/docker/install.test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ import fs from 'fs';
1919
import os from 'os';
2020
import path from 'path';
2121
import * as rimraf from 'rimraf';
22-
import osm = require('os');
22+
23+
import {mockArch, mockPlatform} from '../.helpers/os';
2324

2425
import {Install, InstallSourceArchive, InstallSourceImage} from '../../src/docker/install';
2526

@@ -60,8 +61,8 @@ describe('download', () => {
6061
[image('27.3.1'), 'win32'],
6162
])(
6263
'acquires %p of docker (%s)', async (source, platformOS) => {
63-
jest.spyOn(osm, 'platform').mockImplementation(() => platformOS as NodeJS.Platform);
64-
jest.spyOn(osm, 'arch').mockImplementation(() => 'x64');
64+
mockPlatform(platformOS as NodeJS.Platform);
65+
mockArch('x64');
6566
const install = new Install({
6667
source: source,
6768
runDir: tmpDir

__tests__/oci/oci.test.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@
1414
* limitations under the License.
1515
*/
1616

17-
import {afterEach, describe, expect, jest, test} from '@jest/globals';
17+
import {afterEach, describe, expect, test} from '@jest/globals';
1818
import fs from 'fs';
1919
import os from 'os';
2020
import path from 'path';
2121
import * as rimraf from 'rimraf';
22-
import osm = require('os');
22+
23+
import {mockArch, mockPlatform} from '../.helpers/os';
2324

2425
import {OCI} from '../../src/oci/oci';
2526

@@ -44,8 +45,8 @@ describe('defaultPlatform', () => {
4445
['linux', 'ppc64', {architecture: 'ppc64le', os: 'linux'}],
4546
['linux', 's390x', {architecture: 's390x', os: 'linux'}]
4647
])('default platform for %s/%s', async (os: string, arch: string, expected: Platform) => {
47-
jest.spyOn(osm, 'platform').mockImplementation(() => os as NodeJS.Platform);
48-
jest.spyOn(osm, 'arch').mockImplementation(() => arch);
48+
mockPlatform(os as NodeJS.Platform);
49+
mockArch(arch);
4950
const res = OCI.defaultPlatform();
5051
expect(res).toEqual(expected);
5152
});

__tests__/regclient/install.test.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@
1414
* limitations under the License.
1515
*/
1616

17-
import {describe, expect, it, jest, test, afterEach} from '@jest/globals';
17+
import {describe, expect, it, test, afterEach} from '@jest/globals';
1818
import fs from 'fs';
1919
import os from 'os';
2020
import path from 'path';
2121
import * as rimraf from 'rimraf';
22-
import osm = require('os');
22+
23+
import {mockArch, mockPlatform} from '../.helpers/os';
2324

2425
import {Install} from '../../src/regclient/install';
2526

@@ -75,8 +76,8 @@ describe('download', () => {
7576
['linux', 's390x'],
7677
])(
7778
'acquires regclient for %s/%s', async (os, arch) => {
78-
jest.spyOn(osm, 'platform').mockImplementation(() => os as NodeJS.Platform);
79-
jest.spyOn(osm, 'arch').mockImplementation(() => arch);
79+
mockPlatform(os as NodeJS.Platform);
80+
mockArch(arch);
8081
const install = new Install();
8182
const regclientBin = await install.download('latest');
8283
expect(fs.existsSync(regclientBin)).toBe(true);

__tests__/undock/install.test.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@
1414
* limitations under the License.
1515
*/
1616

17-
import {describe, expect, it, jest, test, afterEach} from '@jest/globals';
17+
import {describe, expect, it, test, afterEach} from '@jest/globals';
1818
import fs from 'fs';
1919
import os from 'os';
2020
import path from 'path';
2121
import * as rimraf from 'rimraf';
22-
import osm = require('os');
22+
23+
import {mockArch, mockPlatform} from '../.helpers/os';
2324

2425
import {Install} from '../../src/undock/install';
2526

@@ -80,8 +81,8 @@ describe('download', () => {
8081
['linux', 's390x'],
8182
])(
8283
'acquires undock for %s/%s', async (os, arch) => {
83-
jest.spyOn(osm, 'platform').mockImplementation(() => os as NodeJS.Platform);
84-
jest.spyOn(osm, 'arch').mockImplementation(() => arch);
84+
mockPlatform(os as NodeJS.Platform);
85+
mockArch(arch);
8586
const install = new Install();
8687
const undockBin = await install.download('latest');
8788
expect(fs.existsSync(undockBin)).toBe(true);

0 commit comments

Comments
 (0)