Skip to content

Commit

Permalink
fix: use ts-async-import
Browse files Browse the repository at this point in the history
  • Loading branch information
homer0 committed Apr 7, 2024
1 parent 809d54b commit 95cf29b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/app/jimpex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -613,8 +614,9 @@ export class Jimpex extends Jimple {
* the application so they'll be available for all the services.
*/
protected async _loadESMModules(): Promise<void> {
const { default: nodeFetch } = await import('node-fetch');
const { default: mime } = await import('mime');
const { default: nodeFetch } =
await tsAsyncImport<typeof import('node-fetch')>('node-fetch');
const { default: mime } = await tsAsyncImport<typeof import('mime')>('mime');

this.set('node-fetch', () => nodeFetch);
this.set('mime', () => mime);
Expand Down
11 changes: 9 additions & 2 deletions tests/app/jimpex.test.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -28,7 +28,14 @@ import type {
ExpressMiddleware,
} from '@src/types';

const tsAsyncImportMock = tsAsyncImport as jest.MockedFunction<typeof tsAsyncImport>;

describe('Jimpex', () => {
beforeEach(() => {
tsAsyncImportMock.mockClear();
tsAsyncImportMock.mockImplementation((name) => Promise.resolve({ default: name }));
});

describe('class', () => {
beforeEach(() => {
delete process.env['NODE_TLS_REJECT_UNAUTHORIZED'];
Expand Down

0 comments on commit 95cf29b

Please sign in to comment.