Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions dist/index.js

Large diffs are not rendered by default.

13 changes: 12 additions & 1 deletion jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,18 @@ const config: Config = {
statements: 100,
},
},
preset: 'ts-jest',
extensionsToTreatAsEsm: ['.ts'],
moduleNameMapper: {
'^(\\.{1,2}/.*)\\.js$': '$1',
},
transform: {
'^.+\\.tsx?$': [
'ts-jest',
{
useESM: true,
},
],
},
testEnvironment: 'node',
};

Expand Down
56 changes: 46 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@
"lint:fix": "npm run lint -- --fix",
"lint:tsc": "tsc --noEmit",
"prepare": "husky",
"test": "jest",
"test:ci": "CI=true jest --ci --colors --coverage",
"test:watch": "jest --watch"
"test": "NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" jest",
"test:ci": "CI=true npm test -- --ci --colors --coverage",
"test:watch": "npm test -- --watch"
},
"dependencies": {
"@actions/core": "2.0.3",
"@actions/core": "3.0.0",
"@actions/exec": "3.0.0",
"@actions/tool-cache": "3.0.1"
},
"devDependencies": {
Expand Down
74 changes: 57 additions & 17 deletions src/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,60 @@
import os from 'node:os';

import * as core from '@actions/core';
import * as exec from '@actions/exec';
import * as tc from '@actions/tool-cache';

import { run } from '.';

jest.mock('@actions/core');
jest.mock('@actions/exec');
jest.mock('@actions/tool-cache');
jest.mock('node:os');

const mockedCore = jest.mocked(core);
const mockedExec = jest.mocked(exec);
const mockedTc = jest.mocked(tc);
const mockedOs = jest.mocked(os);
import type { arch, platform } from 'node:os';

import type { addPath, getInput, setFailed } from '@actions/core';
import type { exec } from '@actions/exec';
import type {
cacheFile,
downloadTool,
extractTar,
extractZip,
find,
} from '@actions/tool-cache';
import { jest } from '@jest/globals';

const mockedCore: {
getInput: jest.MockedFunction<typeof getInput>;
addPath: jest.MockedFunction<typeof addPath>;
setFailed: jest.MockedFunction<typeof setFailed>;
} = {
getInput: jest.fn(),
addPath: jest.fn(),
setFailed: jest.fn(),
};

const mockedExec: {
exec: jest.MockedFunction<typeof exec>;
} = {
exec: jest.fn(),
};

const mockedTc: {
downloadTool: jest.MockedFunction<typeof downloadTool>;
extractTar: jest.MockedFunction<typeof extractTar>;
extractZip: jest.MockedFunction<typeof extractZip>;
cacheFile: jest.MockedFunction<typeof cacheFile>;
find: jest.MockedFunction<typeof find>;
} = {
downloadTool: jest.fn(),
extractTar: jest.fn(),
extractZip: jest.fn(),
cacheFile: jest.fn(),
find: jest.fn(),
};

const mockedOs: {
platform: jest.MockedFunction<typeof platform>;
arch: jest.MockedFunction<typeof arch>;
} = {
platform: jest.fn(),
arch: jest.fn(),
};

jest.unstable_mockModule('@actions/core', () => mockedCore);
jest.unstable_mockModule('@actions/exec', () => mockedExec);
jest.unstable_mockModule('@actions/tool-cache', () => mockedTc);
jest.unstable_mockModule('node:os', () => mockedOs);

const { run } = await import('./index.js');

beforeEach(() => {
jest.resetAllMocks();
Expand Down
12 changes: 8 additions & 4 deletions src/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import os from 'node:os';
import { jest } from '@jest/globals';

import { getBinaryPath, getDownloadObject } from './utils';
const mockedOs = {
platform: jest.fn(),
arch: jest.fn(),
};

jest.mock('node:os');
const mockedOs = jest.mocked(os);
jest.unstable_mockModule('node:os', () => mockedOs);

const { getBinaryPath, getDownloadObject } = await import('./utils.js');

const platforms: NodeJS.Platform[] = ['darwin', 'linux', 'win32'];
const architectures = ['arm', 'x32', 'x64'] as NodeJS.Architecture[];
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"compilerOptions": {
"target": "es2021",
"target": "es2022",
"module": "esnext",
"moduleResolution": "node",
"esModuleInterop": true,
"strict": true
Expand Down