chore: Update module test runner to support DmlEntities when needed (#7799)

* chore: Update module test runner to support DmlEntities when needed

* update es version for core test utils

* fix test

* update swc config
This commit is contained in:
Adrien de Peretti
2024-06-24 09:44:01 +02:00
committed by GitHub
parent 8fa43a6db3
commit ae6dbc06be
20 changed files with 202 additions and 52 deletions

View File

@@ -11,3 +11,4 @@ export * from "./medusa-service"
export * from "./definition"
export * from "./event-builder-factory"
export * from "./joiner-config-builder"
export * from "./loaders/load-models"

View File

@@ -8,7 +8,7 @@ import {
upperCaseFirst,
} from "../common"
import { join } from "path"
import { readdirSync, statSync } from "fs"
import { loadModels } from "./loaders/load-models"
/**
* Define joiner config for a module based on the models (object representation or entities) present in the models directory. This action will be sync until
@@ -111,37 +111,3 @@ export function buildEntitiesNameToLinkableKeysMap(
return entityLinkableKeysMap
}
function loadModels(basePath: string) {
const excludedExtensions = [".ts.map", ".js.map", ".d.ts"]
let modelsFiles: any[] = []
try {
modelsFiles = readdirSync(basePath)
} catch (e) {}
return modelsFiles
.flatMap((file) => {
if (
file.startsWith("index.") ||
excludedExtensions.some((ext) => file.endsWith(ext))
) {
return
}
const filePath = join(basePath, file)
const stats = statSync(filePath)
if (stats.isFile()) {
try {
const required = require(filePath)
return Object.values(required).filter(
(resource) => typeof resource === "function" && !!resource.name
)
} catch (e) {}
}
return
})
.filter(Boolean) as { name: string }[]
}

View File

@@ -0,0 +1,40 @@
import { readdirSync, statSync } from "fs"
import { join } from "path"
/**
* Load all the models from the given path
* @param basePath
*/
export function loadModels(basePath: string) {
const excludedExtensions = [".ts.map", ".js.map", ".d.ts"]
let modelsFiles: any[] = []
try {
modelsFiles = readdirSync(basePath)
} catch (e) {}
return modelsFiles
.flatMap((file) => {
if (
file.startsWith("index.") ||
excludedExtensions.some((ext) => file.endsWith(ext))
) {
return
}
const filePath = join(basePath, file)
const stats = statSync(filePath)
if (stats.isFile()) {
try {
const required = require(filePath)
return Object.values(required).filter(
(resource) => typeof resource === "function" && !!resource.name
)
} catch (e) {}
}
return
})
.filter(Boolean) as { name: string }[]
}