parent
df78eaf547
commit
3ef11caa59
@ -1 +1,2 @@
|
|||||||
|
/coverage
|
||||||
/node_modules
|
/node_modules
|
||||||
|
@ -0,0 +1,65 @@
|
|||||||
|
import {beforeEach, describe, expect, test} from '@jest/globals';
|
||||||
|
|
||||||
|
import * as context from '../src/context';
|
||||||
|
|
||||||
|
describe('getInputs', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
process.env = Object.keys(process.env).reduce((object, key) => {
|
||||||
|
if (!key.startsWith('INPUT_')) {
|
||||||
|
object[key] = process.env[key];
|
||||||
|
}
|
||||||
|
return object;
|
||||||
|
}, {});
|
||||||
|
});
|
||||||
|
|
||||||
|
// prettier-ignore
|
||||||
|
test.each([
|
||||||
|
[
|
||||||
|
0,
|
||||||
|
new Map<string, string>([]),
|
||||||
|
{
|
||||||
|
image: 'tonistiigi/binfmt:latest',
|
||||||
|
platforms: 'all',
|
||||||
|
} as context.Inputs
|
||||||
|
],
|
||||||
|
[
|
||||||
|
1,
|
||||||
|
new Map<string, string>([
|
||||||
|
['image', 'docker/binfmt:latest'],
|
||||||
|
['platforms', 'arm64,riscv64,arm'],
|
||||||
|
]),
|
||||||
|
{
|
||||||
|
image: 'docker/binfmt:latest',
|
||||||
|
platforms: 'arm64,riscv64,arm',
|
||||||
|
} as context.Inputs
|
||||||
|
],
|
||||||
|
[
|
||||||
|
2,
|
||||||
|
new Map<string, string>([
|
||||||
|
['platforms', 'arm64, riscv64, arm '],
|
||||||
|
]),
|
||||||
|
{
|
||||||
|
image: 'tonistiigi/binfmt:latest',
|
||||||
|
platforms: 'arm64,riscv64,arm',
|
||||||
|
} as context.Inputs
|
||||||
|
]
|
||||||
|
])(
|
||||||
|
'[%d] given %p as inputs, returns %p',
|
||||||
|
async (num: number, inputs: Map<string, string>, expected: context.Inputs) => {
|
||||||
|
inputs.forEach((value: string, name: string) => {
|
||||||
|
setInput(name, value);
|
||||||
|
});
|
||||||
|
const res = await context.getInputs();
|
||||||
|
expect(res).toEqual(expected);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
// See: https://github.com/actions/toolkit/blob/master/packages/core/src/core.ts#L67
|
||||||
|
function getInputName(name: string): string {
|
||||||
|
return `INPUT_${name.replace(/ /g, '_').toUpperCase()}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function setInput(name: string, value: string): void {
|
||||||
|
process.env[getInputName(name)] = value;
|
||||||
|
}
|
@ -0,0 +1,29 @@
|
|||||||
|
import fs from 'fs';
|
||||||
|
import os from 'os';
|
||||||
|
import path from 'path';
|
||||||
|
|
||||||
|
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'docker-setup-qemu-action-'));
|
||||||
|
|
||||||
|
process.env = Object.assign({}, process.env, {
|
||||||
|
TEMP: tmpDir,
|
||||||
|
GITHUB_REPOSITORY: 'docker/setup-qemu-action',
|
||||||
|
RUNNER_TEMP: path.join(tmpDir, 'runner-temp'),
|
||||||
|
RUNNER_TOOL_CACHE: path.join(tmpDir, 'runner-tool-cache')
|
||||||
|
}) as {
|
||||||
|
[key: string]: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
clearMocks: true,
|
||||||
|
moduleFileExtensions: ['js', 'ts'],
|
||||||
|
testMatch: ['**/*.test.ts'],
|
||||||
|
transform: {
|
||||||
|
'^.+\\.ts$': 'ts-jest'
|
||||||
|
},
|
||||||
|
moduleNameMapper: {
|
||||||
|
'^csv-parse/sync': '<rootDir>/node_modules/csv-parse/dist/cjs/sync.cjs'
|
||||||
|
},
|
||||||
|
collectCoverageFrom: ['src/**/{!(main.ts),}.ts'],
|
||||||
|
coveragePathIgnorePatterns: ['lib/', 'node_modules/', '__mocks__/', '__tests__/'],
|
||||||
|
verbose: true
|
||||||
|
};
|
@ -1,17 +1,21 @@
|
|||||||
{
|
{
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
|
"esModuleInterop": true,
|
||||||
"target": "es6",
|
"target": "es6",
|
||||||
"module": "commonjs",
|
"module": "commonjs",
|
||||||
|
"strict": true,
|
||||||
"newLine": "lf",
|
"newLine": "lf",
|
||||||
"outDir": "./lib",
|
"outDir": "./lib",
|
||||||
"rootDir": "./src",
|
"rootDir": "./src",
|
||||||
"esModuleInterop": true,
|
|
||||||
"forceConsistentCasingInFileNames": true,
|
"forceConsistentCasingInFileNames": true,
|
||||||
"strict": true,
|
|
||||||
"noImplicitAny": false,
|
"noImplicitAny": false,
|
||||||
|
"resolveJsonModule": true,
|
||||||
"useUnknownInCatchVariables": false,
|
"useUnknownInCatchVariables": false,
|
||||||
},
|
},
|
||||||
"exclude": [
|
"exclude": [
|
||||||
"node_modules"
|
"./__tests__/**/*",
|
||||||
|
"./lib/**/*",
|
||||||
|
"node_modules",
|
||||||
|
"jest.config.ts"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue