diff --git a/src/app/jimpex.ts b/src/app/jimpex.ts index d8d42f7..b2bb508 100644 --- a/src/app/jimpex.ts +++ b/src/app/jimpex.ts @@ -8,6 +8,7 @@ import { envUtilsProvider } from '@homer0/env-utils'; import { packageInfoProvider } from '@homer0/package-info'; import { pathUtilsProvider } from '@homer0/path-utils'; import { rootFileProvider } from '@homer0/root-file'; +import { tsAsyncImport } from '@homer0/ts-async-import'; import { EventsHub } from '@homer0/events-hub'; import { simpleConfigProvider } from '@homer0/simple-config'; import compression from 'compression'; @@ -613,8 +614,9 @@ export class Jimpex extends Jimple { * the application so they'll be available for all the services. */ protected async _loadESMModules(): Promise { - const { default: nodeFetch } = await import('node-fetch'); - const { default: mime } = await import('mime'); + const { default: nodeFetch } = + await tsAsyncImport('node-fetch'); + const { default: mime } = await tsAsyncImport('mime'); this.set('node-fetch', () => nodeFetch); this.set('mime', () => mime); diff --git a/tests/app/jimpex.test.ts b/tests/app/jimpex.test.ts index 0b0cfdb..fba3d54 100644 --- a/tests/app/jimpex.test.ts +++ b/tests/app/jimpex.test.ts @@ -1,8 +1,8 @@ /* eslint-disable no-process-env, dot-notation */ -jest.mock('node-fetch', () => 'node-fetch'); -jest.mock('mime', () => 'mime'); +jest.mock('@homer0/ts-async-import'); import fs from 'fs/promises'; import * as path from 'path'; +import { tsAsyncImport } from '@homer0/ts-async-import'; import { https, spdy, @@ -28,7 +28,14 @@ import type { ExpressMiddleware, } from '@src/types'; +const tsAsyncImportMock = tsAsyncImport as jest.MockedFunction; + describe('Jimpex', () => { + beforeEach(() => { + tsAsyncImportMock.mockClear(); + tsAsyncImportMock.mockImplementation((name) => Promise.resolve({ default: name })); + }); + describe('class', () => { beforeEach(() => { delete process.env['NODE_TLS_REJECT_UNAUTHORIZED'];