import { describe, beforeEach, test, expect, jest } from '@jest/globals'; import { Knifecycle, constant } from 'knifecycle'; import initResolve from './resolve.js'; import { type LogService } from './log.js'; import { type JsonValue } from 'type-fest'; describe('initResolve', () => { const MAIN_FILE_URL = import.meta.url; const log = jest.fn(); beforeEach(() => { log.mockReset(); }); test('should work', async () => { const resolve = await initResolve({ MAIN_FILE_URL, log, }); expect('function' === typeof resolve).toBeTruthy(); expect(filterLogs(log.mock.calls)).toMatchInlineSnapshot(` [ [ "debug", "🛂 - Initializing the resolve service (resolving from file://.../src/services/resolve.test.ts)!", ], ] `); }); // TODO: enable it when Jest will fully support `import` describe.skip('resolve', () => { test('should work', async () => { const resolve = await initResolve({ MAIN_FILE_URL, log, }); log.mockClear(); const result = resolve('./services/random.js'); expect({ result, logCalls: filterLogs(log.mock.calls), }).toMatchInlineSnapshot(); }); }); test('should work with Knifecycle', async () => { const { resolve } = await new Knifecycle() .register(initResolve) .register(constant('log', log)) .register(constant('MAIN_FILE_URL', import.meta.url)) .run(['resolve']); expect(resolve).toBeDefined(); expect(filterLogs(log.mock.calls)).toMatchInlineSnapshot(` [ [ "debug", "🛂 - Initializing the resolve service (resolving from file://.../src/services/resolve.test.ts)!", ], ] `); }); }); function filterLogs(calls: JsonValue[][]) { return calls.map((args) => args.map((s) => s ?.toString() .replace(/"file:\/\/.*\/common-services\/(.+)"/g, 'file://.../$1'), ), ); }