diff --git a/jest.config.js b/jest.config.js index 64928b8..e8dbe2d 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,10 +1,8 @@ /** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ module.exports = { transform: { - '^.+\\.jsx?$': 'babel-jest', '^.+\\.tsx?$': 'ts-jest', }, - preset: 'ts-jest', moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'], testEnvironment: 'node', testPathIgnorePatterns: [ diff --git a/package.json b/package.json index 2665b6d..1c51a32 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@artus/core", - "version": "2.1.1", + "version": "2.2.0", "description": "Core package of Artus", "main": "./lib/index.js", "types": "./lib/index.d.ts", @@ -44,19 +44,20 @@ "@artus/eslint-config-artus": "0.0.1", "@artus/tsconfig": "1.0.1", "@babel/core": "^7.18.6", - "@types/jest": "^27.4.1", + "@types/jest": "^29.5.11", "@types/js-yaml": "^4.0.5", "@types/koa": "^2.13.4", "@types/minimatch": "^3.0.5", + "@types/node": "^20.10.5", "axios": "^0.26.1", - "babel-jest": "^27.5.1", + "babel-jest": "^29.7.0", "egg-ci": "^2.1.0", "eslint": "^8.19.0", "eslint-plugin-import": "^2.26.0", - "jest": "^27.5.1", + "jest": "^29.7.0", "koa": "^2.13.4", "reflect-metadata": "^0.1.13", - "ts-jest": "^27.1.3", + "ts-jest": "^29.1.1", "typescript": "^4.8.0" }, "dependencies": { @@ -71,4 +72,4 @@ "ci": { "version": "16, 18" } -} +} \ No newline at end of file diff --git a/src/configuration/index.ts b/src/configuration/index.ts index 7f89bb2..eb04a8c 100644 --- a/src/configuration/index.ts +++ b/src/configuration/index.ts @@ -44,7 +44,7 @@ export default class ConfigurationHandler { } async setConfigByFile(fileItem: ManifestItem) { - const configContent: ConfigObject = await compatibleRequire(fileItem.path); + const configContent: ConfigObject = await compatibleRequire(fileItem.path + fileItem.extname); if (configContent) { const env = ConfigurationHandler.getEnvFromFilename(fileItem.filename); this.setConfig(env, configContent); diff --git a/src/loader/impl/config.ts b/src/loader/impl/config.ts index b0c1575..ae3560f 100644 --- a/src/loader/impl/config.ts +++ b/src/loader/impl/config.ts @@ -56,7 +56,7 @@ class ConfigLoader implements Loader { } protected async loadConfigFile(item: ManifestItem): Promise> { - const originConfigObj = await compatibleRequire(item.path); + const originConfigObj = await compatibleRequire(item.path + item.extname); let configObj = originConfigObj; if (typeof originConfigObj === 'function') { const app = this.container.get(ArtusInjectEnum.Application); diff --git a/src/loader/impl/lifecycle.ts b/src/loader/impl/lifecycle.ts index 128110d..2cc27cf 100644 --- a/src/loader/impl/lifecycle.ts +++ b/src/loader/impl/lifecycle.ts @@ -18,7 +18,7 @@ class LifecycleLoader implements Loader { } async load(item: ManifestItem) { - const origin: Constructable[] = await compatibleRequire(item.path, true); + const origin: Constructable[] = await compatibleRequire(item.path + item.extname, true); item.loaderState = Object.assign({ exportNames: ['default'] }, item.loaderState); const { loaderState: state } = item as { loaderState: { exportNames: string[] } }; diff --git a/src/loader/impl/module.ts b/src/loader/impl/module.ts index 860ce55..8efcbb0 100644 --- a/src/loader/impl/module.ts +++ b/src/loader/impl/module.ts @@ -13,7 +13,7 @@ class ModuleLoader implements Loader { } async load(item: ManifestItem): Promise { - const origin = await compatibleRequire(item.path, true); + const origin = await compatibleRequire(item.path + item.extname, true); item.loaderState = Object.assign({ exportNames: ['default'] }, item.loaderState); const { loaderState: state } = item as { loaderState: { exportNames: string[] } }; diff --git a/src/utils/compatible_require.ts b/src/utils/compatible_require.ts index 87960f3..c33337b 100644 --- a/src/utils/compatible_require.ts +++ b/src/utils/compatible_require.ts @@ -1,13 +1,25 @@ import assert from 'assert'; +import * as tslib from 'tslib'; /** * compatible esModule require * @param path */ export default async function compatibleRequire(path: string, origin = false): Promise { - const requiredModule = await import(path); + if (path.endsWith('.json')) { + return require(path); + } - assert(requiredModule, `module '${path}' exports is undefined`); + let requiredModule; + try { + /* eslint-disable-next-line @typescript-eslint/no-var-requires */ + requiredModule = tslib.__importStar(require(path)); + assert(requiredModule, `module '${path}' exports is undefined`); + } catch { + requiredModule = await import(path); + assert(requiredModule, `module '${path}' exports is undefined`); + requiredModule = requiredModule.__esModule ? requiredModule.default ?? requiredModule : requiredModule; + } return origin ? requiredModule : (requiredModule.default || requiredModule); } \ No newline at end of file diff --git a/test/__snapshots__/scanner.test.ts.snap b/test/__snapshots__/scanner.test.ts.snap index c18bca0..87519b8 100644 --- a/test/__snapshots__/scanner.test.ts.snap +++ b/test/__snapshots__/scanner.test.ts.snap @@ -1,87 +1,87 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`test/scanner.test.ts should be scan application 1`] = ` -Object { - "pluginConfig": Object { - "default": Object { - "mysql": Object { +{ + "pluginConfig": { + "default": { + "mysql": { "enable": false, "refName": "src/mysql_plugin", }, - "redis": Object { + "redis": { "enable": true, "refName": "src/redis_plugin", }, - "testDuplicate": Object { + "testDuplicate": { "enable": false, "refName": "@artus/injection", }, }, - "dev": Object { - "testDuplicate": Object { + "dev": { + "testDuplicate": { "enable": true, "refName": "src/test_duplicate_plugin", }, }, }, - "refMap": Object { - "@artus/injection": Object { - "items": Array [], + "refMap": { + "@artus/injection": { + "items": [], "packageVersion": undefined, "relativedPath": "../../../node_modules/@artus/injection/lib", }, - "_app": Object { - "items": Array [ - Object { + "_app": { + "items": [ + { "extname": ".ts", "filename": "config.default.ts", "loader": "config", - "loaderState": Object { - "exportNames": Array [], + "loaderState": { + "exportNames": [], }, "path": "src/config/config.default", "source": "app", "unitName": "_app", }, - Object { + { "extname": ".ts", "filename": "config.dev.ts", "loader": "config", - "loaderState": Object { - "exportNames": Array [], + "loaderState": { + "exportNames": [], }, "path": "src/config/config.dev", "source": "app", "unitName": "_app", }, - Object { + { "extname": ".ts", "filename": "plugin.default.ts", "loader": "config", - "loaderState": Object { - "exportNames": Array [], + "loaderState": { + "exportNames": [], }, "path": "src/config/plugin.default", "source": "app", "unitName": "_app", }, - Object { + { "extname": ".ts", "filename": "plugin.dev.ts", "loader": "config", - "loaderState": Object { - "exportNames": Array [], + "loaderState": { + "exportNames": [], }, "path": "src/config/plugin.dev", "source": "app", "unitName": "_app", }, - Object { + { "extname": ".ts", "filename": "hello.ts", "loader": "module", - "loaderState": Object { - "exportNames": Array [ + "loaderState": { + "exportNames": [ "default", ], }, @@ -89,23 +89,23 @@ Object { "source": "app", "unitName": "_app", }, - Object { + { "extname": ".json", "filename": "exception.json", "loader": "exception", - "loaderState": Object { - "exportNames": Array [], + "loaderState": { + "exportNames": [], }, "path": "src/exception", "source": "app", "unitName": "_app", }, - Object { + { "extname": ".ts", "filename": "default.ts", "loader": "exception-filter", - "loaderState": Object { - "exportNames": Array [ + "loaderState": { + "exportNames": [ "MockExceptionFilter", ], }, @@ -113,12 +113,12 @@ Object { "source": "app", "unitName": "_app", }, - Object { + { "extname": ".ts", "filename": "koa_app.ts", "loader": "module", - "loaderState": Object { - "exportNames": Array [ + "loaderState": { + "exportNames": [ "default", ], }, @@ -126,12 +126,12 @@ Object { "source": "app", "unitName": "_app", }, - Object { + { "extname": ".ts", "filename": "lifecycle.ts", "loader": "lifecycle-hook-unit", - "loaderState": Object { - "exportNames": Array [ + "loaderState": { + "exportNames": [ "default", ], }, @@ -139,12 +139,12 @@ Object { "source": "app", "unitName": "_app", }, - Object { + { "extname": ".ts", "filename": "hello.ts", "loader": "module", - "loaderState": Object { - "exportNames": Array [ + "loaderState": { + "exportNames": [ "default", ], }, @@ -156,14 +156,14 @@ Object { "packageVersion": undefined, "relativedPath": "", }, - "src/redis_plugin": Object { - "items": Array [ - Object { + "src/redis_plugin": { + "items": [ + { "extname": ".ts", "filename": "app.ts", "loader": "lifecycle-hook-unit", - "loaderState": Object { - "exportNames": Array [ + "loaderState": { + "exportNames": [ "default", ], }, @@ -173,8 +173,8 @@ Object { }, ], "packageVersion": undefined, - "pluginMetadata": Object { - "exclude": Array [ + "pluginMetadata": { + "exclude": [ "not_to_be_scanned_dir", "not_to_be_scanned_file.ts", ], @@ -182,10 +182,10 @@ Object { }, "relativedPath": "src/redis_plugin", }, - "src/test_duplicate_plugin": Object { - "items": Array [], + "src/test_duplicate_plugin": { + "items": [], "packageVersion": undefined, - "pluginMetadata": Object { + "pluginMetadata": { "name": "testDuplicate", }, "relativedPath": "src/test_duplicate_plugin", @@ -196,61 +196,61 @@ Object { `; exports[`test/scanner.test.ts should scan application with nesting preset a which defined in options 1`] = ` -Object { - "pluginConfig": Object { - "default": Object { - "a": Object { +{ + "pluginConfig": { + "default": { + "a": { "enable": false, "refName": "../plugins/plugin_a", }, - "b": Object { + "b": { "enable": false, "refName": "../plugins/plugin_b", }, - "c": Object { + "c": { "enable": false, "refName": "../plugins/plugin_c", }, - "d": Object { + "d": { "enable": true, "refName": "../plugins/plugin_d", }, - "plugin-with-entry-a": Object { + "plugin-with-entry-a": { "enable": true, "refName": "../plugins/plugin_with_entry_a", }, - "plugin-with-entry-b": Object { + "plugin-with-entry-b": { "enable": true, "refName": "../plugins/plugin_with_entry_b", }, - "plugin-with-entry-c": Object { + "plugin-with-entry-c": { "enable": false, "refName": "../plugins/plugin_with_entry_c", }, - "preset_a": Object { + "preset_a": { "enable": true, "refName": "../plugins/preset_a", }, - "preset_b": Object { + "preset_b": { "enable": true, "refName": "../plugins/preset_b", }, - "preset_c": Object { + "preset_c": { "enable": true, "refName": "../plugins/preset_c", }, }, }, - "refMap": Object { - "../plugins/plugin_a": Object { - "items": Array [], + "refMap": { + "../plugins/plugin_a": { + "items": [], "packageVersion": "0.0.1", - "pluginMetadata": Object { - "dependencies": Array [ - Object { + "pluginMetadata": { + "dependencies": [ + { "name": "plugin-b", }, - Object { + { "name": "plugin-c", "optional": true, }, @@ -259,12 +259,12 @@ Object { }, "relativedPath": "../plugins/plugin_a", }, - "../plugins/plugin_b": Object { - "items": Array [], + "../plugins/plugin_b": { + "items": [], "packageVersion": undefined, - "pluginMetadata": Object { - "dependencies": Array [ - Object { + "pluginMetadata": { + "dependencies": [ + { "name": "plugin-c", }, ], @@ -272,12 +272,12 @@ Object { }, "relativedPath": "../plugins/plugin_b", }, - "../plugins/plugin_d": Object { - "items": Array [], + "../plugins/plugin_d": { + "items": [], "packageVersion": undefined, - "pluginMetadata": Object { - "dependencies": Array [ - Object { + "pluginMetadata": { + "dependencies": [ + { "name": "plugin-c", "optional": true, }, @@ -286,30 +286,30 @@ Object { }, "relativedPath": "../plugins/plugin_d", }, - "../plugins/plugin_with_entry_a": Object { - "items": Array [], + "../plugins/plugin_with_entry_a": { + "items": [], "packageVersion": undefined, - "pluginMetadata": Object { + "pluginMetadata": { "name": "plugin-with-entry-a", }, "relativedPath": "../plugins/plugin_with_entry_a/mock_lib", }, - "../plugins/plugin_with_entry_b": Object { - "items": Array [], + "../plugins/plugin_with_entry_b": { + "items": [], "packageVersion": undefined, - "pluginMetadata": Object { + "pluginMetadata": { "name": "plugin-with-entry-b", }, "relativedPath": "../plugins/plugin_with_entry_b/mock_lib", }, - "../plugins/preset_a": Object { - "items": Array [ - Object { + "../plugins/preset_a": { + "items": [ + { "extname": ".ts", "filename": "plugin.default.ts", "loader": "config", - "loaderState": Object { - "exportNames": Array [], + "loaderState": { + "exportNames": [], }, "path": "../plugins/preset_a/config/plugin.default", "source": "plugin", @@ -317,19 +317,19 @@ Object { }, ], "packageVersion": undefined, - "pluginMetadata": Object { + "pluginMetadata": { "name": "preset_a", }, "relativedPath": "../plugins/preset_a", }, - "../plugins/preset_b": Object { - "items": Array [ - Object { + "../plugins/preset_b": { + "items": [ + { "extname": ".ts", "filename": "plugin.default.ts", "loader": "config", - "loaderState": Object { - "exportNames": Array [], + "loaderState": { + "exportNames": [], }, "path": "../plugins/preset_b/config/plugin.default", "source": "plugin", @@ -337,19 +337,19 @@ Object { }, ], "packageVersion": undefined, - "pluginMetadata": Object { + "pluginMetadata": { "name": "preset_b", }, "relativedPath": "../plugins/preset_b", }, - "../plugins/preset_c": Object { - "items": Array [ - Object { + "../plugins/preset_c": { + "items": [ + { "extname": ".ts", "filename": "plugin.default.ts", "loader": "config", - "loaderState": Object { - "exportNames": Array [], + "loaderState": { + "exportNames": [], }, "path": "../plugins/preset_c/config/plugin.default", "source": "plugin", @@ -357,13 +357,13 @@ Object { }, ], "packageVersion": undefined, - "pluginMetadata": Object { + "pluginMetadata": { "name": "preset_c", }, "relativedPath": "../plugins/preset_c", }, - "_app": Object { - "items": Array [], + "_app": { + "items": [], "packageVersion": undefined, "relativedPath": "", }, @@ -373,37 +373,37 @@ Object { `; exports[`test/scanner.test.ts should scan application with single preset b which defined in config 1`] = ` -Object { - "pluginConfig": Object { - "default": Object { - "a": Object { +{ + "pluginConfig": { + "default": { + "a": { "enable": true, "refName": "../plugins/plugin_a", }, - "b": Object { + "b": { "enable": true, "refName": "../plugins/plugin_b", }, - "plugin-with-entry-b": Object { + "plugin-with-entry-b": { "enable": true, "refName": "../plugins/plugin_with_entry_b", }, - "preset_b": Object { + "preset_b": { "enable": true, "refName": "../plugins/preset_b", }, }, }, - "refMap": Object { - "../plugins/plugin_a": Object { - "items": Array [], + "refMap": { + "../plugins/plugin_a": { + "items": [], "packageVersion": "0.0.1", - "pluginMetadata": Object { - "dependencies": Array [ - Object { + "pluginMetadata": { + "dependencies": [ + { "name": "plugin-b", }, - Object { + { "name": "plugin-c", "optional": true, }, @@ -412,12 +412,12 @@ Object { }, "relativedPath": "../plugins/plugin_a", }, - "../plugins/plugin_b": Object { - "items": Array [], + "../plugins/plugin_b": { + "items": [], "packageVersion": undefined, - "pluginMetadata": Object { - "dependencies": Array [ - Object { + "pluginMetadata": { + "dependencies": [ + { "name": "plugin-c", }, ], @@ -425,22 +425,22 @@ Object { }, "relativedPath": "../plugins/plugin_b", }, - "../plugins/plugin_with_entry_b": Object { - "items": Array [], + "../plugins/plugin_with_entry_b": { + "items": [], "packageVersion": undefined, - "pluginMetadata": Object { + "pluginMetadata": { "name": "plugin-with-entry-b", }, "relativedPath": "../plugins/plugin_with_entry_b/mock_lib", }, - "../plugins/preset_b": Object { - "items": Array [ - Object { + "../plugins/preset_b": { + "items": [ + { "extname": ".ts", "filename": "plugin.default.ts", "loader": "config", - "loaderState": Object { - "exportNames": Array [], + "loaderState": { + "exportNames": [], }, "path": "../plugins/preset_b/config/plugin.default", "source": "plugin", @@ -448,19 +448,19 @@ Object { }, ], "packageVersion": undefined, - "pluginMetadata": Object { + "pluginMetadata": { "name": "preset_b", }, "relativedPath": "../plugins/preset_b", }, - "_app": Object { - "items": Array [ - Object { + "_app": { + "items": [ + { "extname": ".ts", "filename": "plugin.default.ts", "loader": "config", - "loaderState": Object { - "exportNames": Array [], + "loaderState": { + "exportNames": [], }, "path": "config/plugin.default", "source": "app", @@ -476,38 +476,38 @@ Object { `; exports[`test/scanner.test.ts should scan application with single preset c which defined in options 1`] = ` -Object { - "pluginConfig": Object { - "default": Object { - "b": Object { +{ + "pluginConfig": { + "default": { + "b": { "enable": false, "refName": "../plugins/plugin_b", }, - "c": Object { + "c": { "enable": false, "refName": "../plugins/plugin_c", }, - "d": Object { + "d": { "enable": true, "refName": "../plugins/plugin_d", }, - "plugin-with-entry-c": Object { + "plugin-with-entry-c": { "enable": false, "refName": "../plugins/plugin_with_entry_c", }, - "preset_c": Object { + "preset_c": { "enable": true, "refName": "../plugins/preset_c", }, }, }, - "refMap": Object { - "../plugins/plugin_d": Object { - "items": Array [], + "refMap": { + "../plugins/plugin_d": { + "items": [], "packageVersion": undefined, - "pluginMetadata": Object { - "dependencies": Array [ - Object { + "pluginMetadata": { + "dependencies": [ + { "name": "plugin-c", "optional": true, }, @@ -516,14 +516,14 @@ Object { }, "relativedPath": "../plugins/plugin_d", }, - "../plugins/preset_c": Object { - "items": Array [ - Object { + "../plugins/preset_c": { + "items": [ + { "extname": ".ts", "filename": "plugin.default.ts", "loader": "config", - "loaderState": Object { - "exportNames": Array [], + "loaderState": { + "exportNames": [], }, "path": "../plugins/preset_c/config/plugin.default", "source": "plugin", @@ -531,13 +531,13 @@ Object { }, ], "packageVersion": undefined, - "pluginMetadata": Object { + "pluginMetadata": { "name": "preset_c", }, "relativedPath": "../plugins/preset_c", }, - "_app": Object { - "items": Array [], + "_app": { + "items": [], "packageVersion": undefined, "relativedPath": "", }, diff --git a/test/app.test.ts b/test/app.test.ts index 6677d75..a4dd157 100644 --- a/test/app.test.ts +++ b/test/app.test.ts @@ -7,7 +7,7 @@ describe('test/app.test.ts', () => { describe('app koa with ts', () => { it('should run app', async () => { // Skip Controller - const HelloController = await import('./fixtures/app_koa_with_ts/src/controllers/hello'); + const HelloController = require('./fixtures/app_koa_with_ts/src/controllers/hello'); assert(HelloController); expect(await new HelloController.default().index()).toStrictEqual({ content: 'Hello Artus', @@ -20,7 +20,7 @@ describe('test/app.test.ts', () => { app, main, isListening, - } = await import('./fixtures/app_koa_with_ts/src/bootstrap'); + } = require('./fixtures/app_koa_with_ts/src/bootstrap'); // Check Artus Default Class Inject to Contianer expect(app.container.get(ArtusInjectEnum.Application)).toBeInstanceOf(ArtusApplication); @@ -29,7 +29,7 @@ describe('test/app.test.ts', () => { expect(app.container.get(ConfigurationHandler)).toBeInstanceOf(ConfigurationHandler); await main(); - + const testResponse = await axios.get('http://127.0.0.1:3000', { headers: { 'x-hello-artus': 'true', diff --git a/test/config.test.ts b/test/config.test.ts index 9fa648e..f75f9f6 100644 --- a/test/config.test.ts +++ b/test/config.test.ts @@ -5,7 +5,7 @@ describe("test/config.test.ts", () => { describe("app with config", () => { it("should config load on application", async () => { process.env[ARTUS_SERVER_ENV] = "production"; - const { main } = await import("./fixtures/app_with_config/bootstrap"); + const { main } = require("./fixtures/app_with_config/bootstrap"); const app = await main(); expect(app.config).toEqual({ name: "test-for-config", diff --git a/test/exception.test.ts b/test/exception.test.ts index 19a2dcd..9e12d7e 100644 --- a/test/exception.test.ts +++ b/test/exception.test.ts @@ -75,7 +75,7 @@ describe('test/app.test.ts', () => { try { const { main, - } = await import('./fixtures/exception_with_ts_yaml/bootstrap'); + } = require('./fixtures/exception_with_ts_yaml/bootstrap'); const app = await main(); try { diff --git a/test/exception_filter.test.ts b/test/exception_filter.test.ts index 5059bba..be680e1 100644 --- a/test/exception_filter.test.ts +++ b/test/exception_filter.test.ts @@ -18,7 +18,7 @@ describe('test/exception_filter.test.ts', () => { try { const { main, - } = await import('./fixtures/exception_filter/bootstrap'); + } = require('./fixtures/exception_filter/bootstrap'); const app = await main(); const mockSet: Set = app.container.get('mock_exception_set'); @@ -47,7 +47,7 @@ describe('test/exception_filter.test.ts', () => { try { const { main, - } = await import('./fixtures/exception_invalid_filter/bootstrap'); + } = require('./fixtures/exception_invalid_filter/bootstrap'); expect(() => main()).rejects.toThrow(new Error(`invalid ExceptionFilter TestInvalidFilter`)); } catch (error) { diff --git a/test/fixtures/logger/src/index.ts b/test/fixtures/logger/src/index.ts index f2061c8..aeec49d 100644 --- a/test/fixtures/logger/src/index.ts +++ b/test/fixtures/logger/src/index.ts @@ -10,7 +10,7 @@ const defaultManifest: Manifest = { _app: { items: [ { - path: path.resolve(rootDir, "./test_clazz.ts"), + path: path.resolve(rootDir, "./test_clazz"), extname: ".ts", filename: "test_clazz.ts", }, @@ -27,12 +27,12 @@ export const manifestWithCustomLogger: Manifest = { items: [ ...defaultManifest.refMap._app.items, { - path: path.resolve(rootDir, "./test_custom_clazz.ts"), + path: path.resolve(rootDir, "./test_custom_clazz"), extname: ".ts", filename: "test_custom_clazz.ts", }, { - path: path.resolve(rootDir, "./custom_logger.ts"), + path: path.resolve(rootDir, "./custom_logger"), extname: ".ts", filename: "custom_logger.ts", }, diff --git a/test/fixtures/module_with_custom_loader/src/index.ts b/test/fixtures/module_with_custom_loader/src/index.ts index 7c27ecc..306f0af 100644 --- a/test/fixtures/module_with_custom_loader/src/index.ts +++ b/test/fixtures/module_with_custom_loader/src/index.ts @@ -10,7 +10,7 @@ export default { _app: { items: [ { - path: path.resolve(rootDir, "./test_clazz.ts"), + path: path.resolve(rootDir, "./test_clazz"), extname: ".ts", filename: "test_clazz.ts", loader: "test-custom-loader", diff --git a/test/fixtures/module_with_js/src/index.js b/test/fixtures/module_with_js/src/index.js index 7716d36..4e5ef33 100644 --- a/test/fixtures/module_with_js/src/index.js +++ b/test/fixtures/module_with_js/src/index.js @@ -10,14 +10,14 @@ module.exports = { items: [ { id: "testServiceA", - path: path.resolve(rootDir, "./test_service_a.js"), + path: path.resolve(rootDir, "./test_service_a"), extname: ".js", filename: "test_service_a.js", }, { id: "testServiceB", scope: "Execution", - path: path.resolve(rootDir, "./test_service_b.js"), + path: path.resolve(rootDir, "./test_service_b"), extname: ".js", filename: "test_service_b.js", }, diff --git a/test/fixtures/module_with_ts/src/index.ts b/test/fixtures/module_with_ts/src/index.ts index e7a8c8f..09687ea 100644 --- a/test/fixtures/module_with_ts/src/index.ts +++ b/test/fixtures/module_with_ts/src/index.ts @@ -10,12 +10,12 @@ export default { _app: { items: [ { - path: path.resolve(rootDir, "./test_service_a.ts"), + path: path.resolve(rootDir, "./test_service_a"), extname: ".ts", filename: "test_service_a.ts", }, { - path: path.resolve(rootDir, "./test_service_b.ts"), + path: path.resolve(rootDir, "./test_service_b"), extname: ".ts", filename: "test_service_b.ts", }, diff --git a/test/logger.test.ts b/test/logger.test.ts index 374ff75..db2656c 100644 --- a/test/logger.test.ts +++ b/test/logger.test.ts @@ -33,7 +33,7 @@ describe('test/logger.test.ts', () => { describe('log message with default level (INFO)', () => { it('should log message with Logger from Contianer', async () => { - const { default: manifest } = await import('./fixtures/logger/src'); + const { default: manifest } = require('./fixtures/logger/src'); const app = await _getAppWithConfig({}, manifest); const testClazz = app.container.get(TestLoggerClazz); @@ -60,7 +60,7 @@ describe('test/logger.test.ts', () => { }); it('should log message with Logger from Contianer and log method', async () => { - const { default: manifest } = await import('./fixtures/logger/src'); + const { default: manifest } = require('./fixtures/logger/src'); const app = await _getAppWithConfig({}, manifest); const testClazz = app.container.get(TestLoggerClazz); @@ -89,7 +89,7 @@ describe('test/logger.test.ts', () => { describe('log message with custom level (TRACE)', () => { it('should log message with Logger from Contianer', async () => { - const { default: manifest } = await import('./fixtures/logger/src'); + const { default: manifest } = require('./fixtures/logger/src'); const app = await _getAppWithConfig({ logger: { level: LoggerLevel.TRACE, @@ -122,7 +122,7 @@ describe('test/logger.test.ts', () => { }); it('should log message with Logger from Contianer and log method', async () => { - const { default: manifest } = await import('./fixtures/logger/src'); + const { default: manifest } = require('./fixtures/logger/src'); const app = await _getAppWithConfig({ logger: { level: LoggerLevel.TRACE, @@ -157,7 +157,7 @@ describe('test/logger.test.ts', () => { describe('log message with custom Logger', () => { it('should log message with custom method', async () => { - const { manifestWithCustomLogger: manifest } = await import('./fixtures/logger/src'); + const { manifestWithCustomLogger: manifest } = require('./fixtures/logger/src'); const app = await _getAppWithConfig({}, manifest); const testClazz = app.container.get(TestCustomLoggerClazz); diff --git a/tsconfig.build.json b/tsconfig.build.json index 21d10a3..45cfa69 100644 --- a/tsconfig.build.json +++ b/tsconfig.build.json @@ -3,5 +3,9 @@ "compilerOptions": { "rootDir": "./src" }, - "exclude": ["lib", "test", "**/*.test.ts"] -} + "exclude": [ + "lib", + "test", + "**/*.test.ts" + ] +} \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index 4c5a8d0..8b3cec6 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -7,8 +7,10 @@ "jest", "reflect-metadata" ], + "module": "NodeNext", + "moduleResolution": "NodeNext" }, "exclude": [ "lib", ], -} +} \ No newline at end of file