refactor: update imports to use ES module syntax and improve test structure (#1350)

- Changed import statements across multiple files to use the .js extension for ES module compatibility.
- Refactored test files to utilize jest's unstable_mockModule for mocking core actions.
- Removed unnecessary spy instances in tests, replacing them with direct mocked function calls.
- Updated TypeScript configuration to target ES2022 and use NodeNext module resolution.
- Removed the tsconfig.spec.json file and adjusted the main tsconfig.json to exclude test files.
This commit is contained in:
Chiranjib Swain
2026-07-24 02:09:34 +05:30
committed by GitHub
parent 1e223db275
commit eaf9131fae
122 changed files with 67910 additions and 55239 deletions

View File

@@ -1,8 +1,17 @@
import {Logger} from './logger';
import * as core from '@actions/core';
import {jest, beforeEach, describe, expect, it} from '@jest/globals';
import type {Logger as LoggerType} from './logger.js';
jest.unstable_mockModule('@actions/core', () => ({
warning: jest.fn(),
info: jest.fn(),
error: jest.fn()
}));
const {Logger} = await import('./logger.js');
const core = await import('@actions/core');
describe('Logger', (): void => {
let logger: Logger;
let logger: LoggerType;
beforeEach((): void => {
logger = new Logger();
@@ -11,12 +20,8 @@ describe('Logger', (): void => {
describe('warning()', (): void => {
let message: string;
let coreWarningSpy: jest.SpyInstance;
beforeEach((): void => {
message = 'dummy-message';
coreWarningSpy = jest.spyOn(core, 'warning').mockImplementation();
});
it('should log a warning with the given message', (): void => {
@@ -24,8 +29,8 @@ describe('Logger', (): void => {
logger.warning(message);
expect(coreWarningSpy).toHaveBeenCalledTimes(1);
expect(coreWarningSpy).toHaveBeenCalledWith(
expect(jest.mocked(core.warning)).toHaveBeenCalledTimes(1);
expect(jest.mocked(core.warning)).toHaveBeenCalledWith(
expect.stringContaining('dummy-message')
);
});
@@ -34,12 +39,8 @@ describe('Logger', (): void => {
describe('info()', (): void => {
let message: string;
let coreInfoSpy: jest.SpyInstance;
beforeEach((): void => {
message = 'dummy-message';
coreInfoSpy = jest.spyOn(core, 'info').mockImplementation();
});
it('should log an information with the given message', (): void => {
@@ -47,8 +48,8 @@ describe('Logger', (): void => {
logger.info(message);
expect(coreInfoSpy).toHaveBeenCalledTimes(1);
expect(coreInfoSpy).toHaveBeenCalledWith(
expect(jest.mocked(core.info)).toHaveBeenCalledTimes(1);
expect(jest.mocked(core.info)).toHaveBeenCalledWith(
expect.stringContaining('dummy-message')
);
});
@@ -57,12 +58,8 @@ describe('Logger', (): void => {
describe('error()', (): void => {
let message: string;
let coreErrorSpy: jest.SpyInstance;
beforeEach((): void => {
message = 'dummy-message';
coreErrorSpy = jest.spyOn(core, 'error').mockImplementation();
});
it('should log an error with the given message', (): void => {
@@ -70,8 +67,8 @@ describe('Logger', (): void => {
logger.error(message);
expect(coreErrorSpy).toHaveBeenCalledTimes(1);
expect(coreErrorSpy).toHaveBeenCalledWith(
expect(jest.mocked(core.error)).toHaveBeenCalledTimes(1);
expect(jest.mocked(core.error)).toHaveBeenCalledWith(
expect.stringContaining('dummy-message')
);
});