GeezerVison is showing github.com — switch to ESM and update config/test wiring by crazy-max · Pull Request #961 · docker/actions-toolkit
switch to ESM and update config/test wiring
#961
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and
privacy statement . We’ll occasionally send you account related emails.
Already on GitHub?
Sign in
to your account
Uh oh!
There was an error while loading. Please reload this page.
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter
Filter by extension
.cjs
(2)
.json
(1)
.ts
(9)
All 3 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Hide whitespace
Diff view
Hide whitespace
add ESM-safe os test helpers and tsconfig for tests
Loading branch information
Uh oh!
There was an error while loading. Please reload this page.
commit 3f7be6d97d121ef2bdaf3e9135a3082a1c285c20
There are no files selected for viewing
Original file line number
Diff line number
Diff line change
@@ -0,0 +1,30 @@
/**
* Copyright 2025 actions-toolkit authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {jest} from '@jest/globals';
import os from 'os';
export const mockPlatform = (platform: NodeJS.Platform) => {
return jest.spyOn(os, 'platform').mockImplementation(() => platform);
};
export const mockArch = (arch: string) => {
return jest.spyOn(os, 'arch').mockImplementation(() => arch);
};
export const mockHomedir = (dir: string) => {
return jest.spyOn(os, 'homedir').mockImplementation(() => dir);
};
Original file line number
Diff line number
Diff line change
Expand Up
@@ -14,12 +14,13 @@
* limitations under the License.
*/
import {describe, expect, it, jest, test, afterEach} from '@jest/globals';
import {describe, expect, it, test, afterEach} from '@jest/globals';
import fs from 'fs';
import os from 'os';
import path from 'path';
import * as rimraf from 'rimraf';
import osm = require('os');
import {mockArch, mockPlatform} from '../.helpers/os';
import {Install} from '../../src/buildx/install';
Expand Down
Expand Up
@@ -85,8 +86,8 @@ describe('download', () => {
['linux', 's390x'],
])(
'acquires buildx for %s/%s', async (os, arch) => {
jest.spyOn(osm, 'platform').mockImplementation(() => os as NodeJS.Platform);
jest.spyOn(osm, 'arch').mockImplementation(() => arch);
mockPlatform( os as NodeJS.Platform);
mockArch( arch);
const install = new Install();
const buildxBin = await install.download('latest');
expect(fs.existsSync(buildxBin)).toBe(true);
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -14,12 +14,13 @@
* limitations under the License.
*/
import {describe, expect, it, jest, test, afterEach} from '@jest/globals';
import {describe, expect, it, test, afterEach} from '@jest/globals';
import fs from 'fs';
import os from 'os';
import path from 'path';
import * as rimraf from 'rimraf';
import osm = require('os');
import {mockArch, mockPlatform} from '../.helpers/os';
import {Install} from '../../src/compose/install';
Expand Down
Expand Up
@@ -85,8 +86,8 @@ describe('download', () => {
['linux', 's390x'],
])(
'acquires compose for %s/%s', async (os, arch) => {
jest.spyOn(osm, 'platform').mockImplementation(() => os as NodeJS.Platform);
jest.spyOn(osm, 'arch').mockImplementation(() => arch);
mockPlatform( os as NodeJS.Platform);
mockArch( arch);
const install = new Install();
const composeBin = await install.download('latest');
expect(fs.existsSync(composeBin)).toBe(true);
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -14,12 +14,13 @@
* limitations under the License.
*/
import {describe, expect, it, jest, test, afterEach} from '@jest/globals';
import {describe, expect, it, test, afterEach} from '@jest/globals';
import fs from 'fs';
import os from 'os';
import path from 'path';
import * as rimraf from 'rimraf';
import osm = require('os');
import {mockArch, mockPlatform} from '../.helpers/os';
import {Install} from '../../src/cosign/install';
Expand Down
Expand Up
@@ -80,8 +81,8 @@ describe('download', () => {
['linux', 'arm64']
])(
'acquires undock for %s/%s', async (os, arch) => {
jest.spyOn(osm, 'platform').mockImplementation(() => os as NodeJS.Platform);
jest.spyOn(osm, 'arch').mockImplementation(() => arch);
mockPlatform( os as NodeJS.Platform);
mockArch( arch);
const install = new Install();
const cosignBin = await install.download({
version: 'latest'
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -19,9 +19,10 @@ import fs from 'fs';
import os from 'os';
import path from 'path';
import * as io from '@actions/io';
import osm = require('os');
import * as rimraf from 'rimraf';
import {mockHomedir} from '../.helpers/os';
import {Docker} from '../../src/docker/docker';
import {ConfigFile} from '../../src/types/docker/docker';
Expand All
@@ -47,7 +48,7 @@ describe('configDir', () => {
});
it('returns default', async () => {
process.env.DOCKER_CONFIG = '';
jest.spyOn(osm, 'homedir').mockImplementation(() => path.join('/tmp', 'home'));
mockHomedir( path.join('/tmp', 'home'));
expect(Docker.configDir).toEqual(path.join('/tmp', 'home', '.docker'));
});
it('returns from env', async () => {
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -19,7 +19,8 @@ import fs from 'fs';
import os from 'os';
import path from 'path';
import * as rimraf from 'rimraf';
import osm = require('os');
import {mockArch, mockPlatform} from '../.helpers/os';
import {Install, InstallSourceArchive, InstallSourceImage} from '../../src/docker/install';
Expand Down
Expand Up
@@ -60,8 +61,8 @@ describe('download', () => {
[image('27.3.1'), 'win32'],
])(
'acquires %p of docker (%s)', async (source, platformOS) => {
jest.spyOn(osm, 'platform').mockImplementation(() => platformOS as NodeJS.Platform);
jest.spyOn(osm, 'arch').mockImplementation(() => 'x64');
mockPlatform( platformOS as NodeJS.Platform);
mockArch( 'x64');
const install = new Install({
source: source,
runDir: tmpDir
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -14,12 +14,13 @@
* limitations under the License.
*/
import {afterEach, describe, expect, jest, test} from '@jest/globals';
import {afterEach, describe, expect, test} from '@jest/globals';
import fs from 'fs';
import os from 'os';
import path from 'path';
import * as rimraf from 'rimraf';
import osm = require('os');
import {mockArch, mockPlatform} from '../.helpers/os';
import {OCI} from '../../src/oci/oci';
Expand All
@@ -44,8 +45,8 @@ describe('defaultPlatform', () => {
['linux', 'ppc64', {architecture: 'ppc64le', os: 'linux'}],
['linux', 's390x', {architecture: 's390x', os: 'linux'}]
])('default platform for %s/%s', async (os: string, arch: string, expected: Platform) => {
jest.spyOn(osm, 'platform').mockImplementation(() => os as NodeJS.Platform);
jest.spyOn(osm, 'arch').mockImplementation(() => arch);
mockPlatform( os as NodeJS.Platform);
mockArch( arch);
const res = OCI.defaultPlatform();
expect(res).toEqual(expected);
});
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -14,12 +14,13 @@
* limitations under the License.
*/
import {describe, expect, it, jest, test, afterEach} from '@jest/globals';
import {describe, expect, it, test, afterEach} from '@jest/globals';
import fs from 'fs';
import os from 'os';
import path from 'path';
import * as rimraf from 'rimraf';
import osm = require('os');
import {mockArch, mockPlatform} from '../.helpers/os';
import {Install} from '../../src/regclient/install';
Expand Down
Expand Up
@@ -75,8 +76,8 @@ describe('download', () => {
['linux', 's390x'],
])(
'acquires regclient for %s/%s', async (os, arch) => {
jest.spyOn(osm, 'platform').mockImplementation(() => os as NodeJS.Platform);
jest.spyOn(osm, 'arch').mockImplementation(() => arch);
mockPlatform( os as NodeJS.Platform);
mockArch( arch);
const install = new Install();
const regclientBin = await install.download('latest');
expect(fs.existsSync(regclientBin)).toBe(true);
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -14,12 +14,13 @@
* limitations under the License.
*/
import {describe, expect, it, jest, test, afterEach} from '@jest/globals';
import {describe, expect, it, test, afterEach} from '@jest/globals';
import fs from 'fs';
import os from 'os';
import path from 'path';
import * as rimraf from 'rimraf';
import osm = require('os');
import {mockArch, mockPlatform} from '../.helpers/os';
import {Install} from '../../src/undock/install';
Expand Down
Expand Up
@@ -80,8 +81,8 @@ describe('download', () => {
['linux', 's390x'],
])(
'acquires undock for %s/%s', async (os, arch) => {
jest.spyOn(osm, 'platform').mockImplementation(() => os as NodeJS.Platform);
jest.spyOn(osm, 'arch').mockImplementation(() => arch);
mockPlatform( os as NodeJS.Platform);
mockArch( arch);
const install = new Install();
const undockBin = await install.download('latest');
expect(fs.existsSync(undockBin)).toBe(true);
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -41,7 +41,8 @@ module.exports = {
'^.+\\.ts$': [
'ts-jest',
{
useESM: true
useESM: true,
tsconfig: '<rootDir>/tsconfig.test.json'
}
]
},
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -24,7 +24,8 @@ module.exports = {
'^.+\\.ts$': [
'ts-jest',
{
useESM: true
useESM: true,
tsconfig: '<rootDir>/tsconfig.test.json'
}
]
},
Expand Down
Original file line number
Diff line number
Diff line change
@@ -0,0 +1,15 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"rootDir": ".",
"noEmit": true
},
"include": [
"src/**/*.ts",
"__tests__/**/*.ts"
],
"exclude": [
"lib",
"node_modules"
]
}
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.