mirror of
https://github.com/actions/stale.git
synced 2026-10-08 15:33:06 +01:00
- 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.
77 lines
1.8 KiB
TypeScript
77 lines
1.8 KiB
TypeScript
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: LoggerType;
|
|
|
|
beforeEach((): void => {
|
|
logger = new Logger();
|
|
});
|
|
|
|
describe('warning()', (): void => {
|
|
let message: string;
|
|
|
|
beforeEach((): void => {
|
|
message = 'dummy-message';
|
|
});
|
|
|
|
it('should log a warning with the given message', (): void => {
|
|
expect.assertions(2);
|
|
|
|
logger.warning(message);
|
|
|
|
expect(jest.mocked(core.warning)).toHaveBeenCalledTimes(1);
|
|
expect(jest.mocked(core.warning)).toHaveBeenCalledWith(
|
|
expect.stringContaining('dummy-message')
|
|
);
|
|
});
|
|
});
|
|
|
|
describe('info()', (): void => {
|
|
let message: string;
|
|
|
|
beforeEach((): void => {
|
|
message = 'dummy-message';
|
|
});
|
|
|
|
it('should log an information with the given message', (): void => {
|
|
expect.assertions(2);
|
|
|
|
logger.info(message);
|
|
|
|
expect(jest.mocked(core.info)).toHaveBeenCalledTimes(1);
|
|
expect(jest.mocked(core.info)).toHaveBeenCalledWith(
|
|
expect.stringContaining('dummy-message')
|
|
);
|
|
});
|
|
});
|
|
|
|
describe('error()', (): void => {
|
|
let message: string;
|
|
|
|
beforeEach((): void => {
|
|
message = 'dummy-message';
|
|
});
|
|
|
|
it('should log an error with the given message', (): void => {
|
|
expect.assertions(2);
|
|
|
|
logger.error(message);
|
|
|
|
expect(jest.mocked(core.error)).toHaveBeenCalledTimes(1);
|
|
expect(jest.mocked(core.error)).toHaveBeenCalledWith(
|
|
expect.stringContaining('dummy-message')
|
|
);
|
|
});
|
|
});
|
|
});
|