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:
1 parent
8fa43a6db3
commit
ae6dbc06be
20 files changed
+202
-52
No files matched your search
@@ -16,7 +16,17 @@ module.exports = {
|
|||||||
`.cache`,
|
`.cache`,
|
||||||
],
|
],
|
||||||
transformIgnorePatterns: ["/dist", "/node_modules/"],
|
transformIgnorePatterns: ["/dist", "/node_modules/"],
|
||||||
transform: { "^.+\\.[jt]s$": ["@swc/jest"] },
|
transform: {
|
||||||
|
"^.+\\.[jt]s$": [
|
||||||
|
"@swc/jest",
|
||||||
|
{
|
||||||
|
jsc: {
|
||||||
|
parser: { syntax: "typescript", decorators: true },
|
||||||
|
transform: { decoratorMetadata: true },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
setupFiles: ["../setup-env.js"],
|
setupFiles: ["../setup-env.js"],
|
||||||
setupFilesAfterEnv: ["../setup.js"],
|
setupFilesAfterEnv: ["../setup.js"],
|
||||||
globalSetup: "../globalSetup.js",
|
globalSetup: "../globalSetup.js",
|
||||||
|
|||||||
@@ -5,7 +5,15 @@ module.exports = {
|
|||||||
rootDir: "./",
|
rootDir: "./",
|
||||||
transformIgnorePatterns: ["/dist", "/node_modules/"],
|
transformIgnorePatterns: ["/dist", "/node_modules/"],
|
||||||
transform: {
|
transform: {
|
||||||
"^.+\\.[jt]s$": ["@swc/jest"],
|
"^.+\\.[jt]s$": [
|
||||||
|
"@swc/jest",
|
||||||
|
{
|
||||||
|
jsc: {
|
||||||
|
parser: { syntax: "typescript", decorators: true },
|
||||||
|
transform: { decoratorMetadata: true },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
},
|
},
|
||||||
setupFiles: ["../setup-env.js"],
|
setupFiles: ["../setup-env.js"],
|
||||||
}
|
}
|
||||||
@@ -26,7 +26,17 @@ module.exports = {
|
|||||||
`__testfixtures__`,
|
`__testfixtures__`,
|
||||||
`.cache`,
|
`.cache`,
|
||||||
],
|
],
|
||||||
transform: { "^.+\\.[jt]s$": ["@swc/jest"] },
|
transform: {
|
||||||
|
"^.+\\.[jt]s$": [
|
||||||
|
"@swc/jest",
|
||||||
|
{
|
||||||
|
jsc: {
|
||||||
|
parser: { syntax: "typescript", decorators: true },
|
||||||
|
transform: { decoratorMetadata: true },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
setupFiles: ["<rootDir>/integration-tests/setup-env.js"],
|
setupFiles: ["<rootDir>/integration-tests/setup-env.js"],
|
||||||
setupFilesAfterEnv: ["<rootDir>/integration-tests/setup.js"],
|
setupFilesAfterEnv: ["<rootDir>/integration-tests/setup.js"],
|
||||||
}
|
}
|
||||||
@@ -15,7 +15,15 @@ module.exports = {
|
|||||||
],
|
],
|
||||||
transformIgnorePatterns: ["/dist", "/node_modules/"],
|
transformIgnorePatterns: ["/dist", "/node_modules/"],
|
||||||
transform: {
|
transform: {
|
||||||
"^.+\\.[jt]s$": ["@swc/jest"],
|
"^.+\\.[jt]s$": [
|
||||||
|
"@swc/jest",
|
||||||
|
{
|
||||||
|
jsc: {
|
||||||
|
parser: { syntax: "typescript", decorators: true },
|
||||||
|
transform: { decoratorMetadata: true },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
},
|
},
|
||||||
setupFiles: ["../setup-env.js"],
|
setupFiles: ["../setup-env.js"],
|
||||||
/*setupFilesAfterEnv: ["../setup.js"],
|
/*setupFilesAfterEnv: ["../setup.js"],
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"lib": ["es5", "es6", "es2019"],
|
"lib": ["es5", "es6", "es2019"],
|
||||||
"target": "es5",
|
"target": "es2022",
|
||||||
"outDir": "./dist",
|
"outDir": "./dist",
|
||||||
"esModuleInterop": true,
|
"esModuleInterop": true,
|
||||||
"declaration": true,
|
"declaration": true,
|
||||||
|
|||||||
@@ -1,5 +1,15 @@
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
transform: { "^.+\\.[jt]s$": ["@swc/jest"] },
|
transform: {
|
||||||
|
"^.+\\.[jt]s$": [
|
||||||
|
"@swc/jest",
|
||||||
|
{
|
||||||
|
jsc: {
|
||||||
|
parser: { syntax: "typescript", decorators: true },
|
||||||
|
transform: { decoratorMetadata: true },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
testEnvironment: `node`,
|
testEnvironment: `node`,
|
||||||
moduleFileExtensions: [`js`, `ts`],
|
moduleFileExtensions: [`js`, `ts`],
|
||||||
}
|
}
|
||||||
@@ -3,6 +3,7 @@ import { initModules, InitModulesOptions } from "./init-modules"
|
|||||||
|
|
||||||
import { ContainerRegistrationKeys, ModulesSdkUtils } from "@medusajs/utils"
|
import { ContainerRegistrationKeys, ModulesSdkUtils } from "@medusajs/utils"
|
||||||
import { MockEventBusService } from "."
|
import { MockEventBusService } from "."
|
||||||
|
import { toMikroOrmEntities } from "@medusajs/utils/src"
|
||||||
|
|
||||||
export interface SuiteOptions<TService = unknown> {
|
export interface SuiteOptions<TService = unknown> {
|
||||||
MikroOrmWrapper: TestDatabase
|
MikroOrmWrapper: TestDatabase
|
||||||
@@ -41,7 +42,7 @@ export function moduleIntegrationTestRunner<TService = any>({
|
|||||||
process.env.LOG_LEVEL = "error"
|
process.env.LOG_LEVEL = "error"
|
||||||
|
|
||||||
moduleModels ??= Object.values(require(`${process.cwd()}/src/models`))
|
moduleModels ??= Object.values(require(`${process.cwd()}/src/models`))
|
||||||
// migrationPath ??= process.cwd() + "/src/migrations/!(*.d).{js,ts,cjs}"
|
moduleModels = toMikroOrmEntities(moduleModels)
|
||||||
|
|
||||||
const tempName = parseInt(process.env.JEST_WORKER_ID || "1")
|
const tempName = parseInt(process.env.JEST_WORKER_ID || "1")
|
||||||
const dbName = `medusa-${moduleName.toLowerCase()}-integration-${tempName}`
|
const dbName = `medusa-${moduleName.toLowerCase()}-integration-${tempName}`
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"lib": ["es5", "es6", "es2019"],
|
"lib": ["es5", "es6", "es2019"],
|
||||||
"target": "es5",
|
"target": "es2022",
|
||||||
"outDir": "./dist",
|
"outDir": "./dist",
|
||||||
"esModuleInterop": true,
|
"esModuleInterop": true,
|
||||||
"declaration": true,
|
"declaration": true,
|
||||||
|
|||||||
@@ -632,4 +632,24 @@ export function createMikrORMEntity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const toMikroORMEntity = createMikrORMEntity()
|
/**
|
||||||
|
* Takes a DML entity and returns a Mikro ORM entity otherwise
|
||||||
|
* return the input idempotently
|
||||||
|
* @param entity
|
||||||
|
*/
|
||||||
|
export const toMikroORMEntity = (entity: any) => {
|
||||||
|
if (DmlEntity.isDmlEntity(entity)) {
|
||||||
|
return createMikrORMEntity()(entity)
|
||||||
|
}
|
||||||
|
|
||||||
|
return entity
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Takes any DmlEntity or mikro orm entities and return mikro orm entities only.
|
||||||
|
* This action is idempotent if non of the entities are DmlEntity
|
||||||
|
* @param entities
|
||||||
|
*/
|
||||||
|
export const toMikroOrmEntities = function (entities: any[]) {
|
||||||
|
return entities.map(toMikroORMEntity)
|
||||||
|
}
|
||||||
@@ -11,3 +11,4 @@ export * from "./medusa-service"
|
|||||||
export * from "./definition"
|
export * from "./definition"
|
||||||
export * from "./event-builder-factory"
|
export * from "./event-builder-factory"
|
||||||
export * from "./joiner-config-builder"
|
export * from "./joiner-config-builder"
|
||||||
|
export * from "./loaders/load-models"
|
||||||
@@ -8,7 +8,7 @@ import {
|
|||||||
upperCaseFirst,
|
upperCaseFirst,
|
||||||
} from "../common"
|
} from "../common"
|
||||||
import { join } from "path"
|
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
|
* 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
|
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 }[]
|
|
||||||
}
|
|
||||||
@@ -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 }[]
|
||||||
|
}
|
||||||
@@ -1,6 +1,14 @@
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
transform: {
|
transform: {
|
||||||
"^.+\\.[jt]s$": ["@swc/jest"],
|
"^.+\\.[jt]s$": [
|
||||||
|
"@swc/jest",
|
||||||
|
{
|
||||||
|
jsc: {
|
||||||
|
parser: { syntax: "typescript", decorators: true },
|
||||||
|
transform: { decoratorMetadata: true },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
},
|
},
|
||||||
testEnvironment: `node`,
|
testEnvironment: `node`,
|
||||||
moduleFileExtensions: [`js`, `ts`],
|
moduleFileExtensions: [`js`, `ts`],
|
||||||
|
|||||||
@@ -1,5 +1,15 @@
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
transform: { "^.+\\.[jt]s$": "@swc/jest" },
|
transform: {
|
||||||
|
"^.+\\.[jt]s$": [
|
||||||
|
"@swc/jest",
|
||||||
|
{
|
||||||
|
jsc: {
|
||||||
|
parser: { syntax: "typescript", decorators: true },
|
||||||
|
transform: { decoratorMetadata: true },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
testEnvironment: `node`,
|
testEnvironment: `node`,
|
||||||
moduleFileExtensions: [`js`, `ts`],
|
moduleFileExtensions: [`js`, `ts`],
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,14 @@
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
transform: {
|
transform: {
|
||||||
"^.+\\.[jt]s$": ["@swc/jest"],
|
"^.+\\.[jt]s$": [
|
||||||
|
"@swc/jest",
|
||||||
|
{
|
||||||
|
jsc: {
|
||||||
|
parser: { syntax: "typescript", decorators: true },
|
||||||
|
transform: { decoratorMetadata: true },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
},
|
},
|
||||||
testEnvironment: `node`,
|
testEnvironment: `node`,
|
||||||
moduleFileExtensions: [`js`, `ts`],
|
moduleFileExtensions: [`js`, `ts`],
|
||||||
|
|||||||
@@ -1,5 +1,15 @@
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
transform: { "^.+\\.[jt]s$": ["@swc/jest"] },
|
transform: {
|
||||||
|
"^.+\\.[jt]s$": [
|
||||||
|
"@swc/jest",
|
||||||
|
{
|
||||||
|
jsc: {
|
||||||
|
parser: { syntax: "typescript", decorators: true },
|
||||||
|
transform: { decoratorMetadata: true },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
testEnvironment: `node`,
|
testEnvironment: `node`,
|
||||||
moduleFileExtensions: [`js`, `ts`],
|
moduleFileExtensions: [`js`, `ts`],
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,15 @@
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
transform: { "^.+\\.[jt]s$": ["@swc/jest"] },
|
transform: {
|
||||||
|
"^.+\\.[jt]s$": [
|
||||||
|
"@swc/jest",
|
||||||
|
{
|
||||||
|
jsc: {
|
||||||
|
parser: { syntax: "typescript", decorators: true },
|
||||||
|
transform: { decoratorMetadata: true },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
testEnvironment: `node`,
|
testEnvironment: `node`,
|
||||||
moduleFileExtensions: [`js`, `jsx`, `ts`, `tsx`, `json`],
|
moduleFileExtensions: [`js`, `jsx`, `ts`, `tsx`, `json`],
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,15 @@
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
transform: { "^.+\\.[jt]s$": ["@swc/jest"] },
|
transform: {
|
||||||
|
"^.+\\.[jt]s$": [
|
||||||
|
"@swc/jest",
|
||||||
|
{
|
||||||
|
jsc: {
|
||||||
|
parser: { syntax: "typescript", decorators: true },
|
||||||
|
transform: { decoratorMetadata: true },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
testEnvironment: `node`,
|
testEnvironment: `node`,
|
||||||
moduleFileExtensions: [`js`, `jsx`, `ts`, `tsx`, `json`],
|
moduleFileExtensions: [`js`, `jsx`, `ts`, `tsx`, `json`],
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,15 @@
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
transform: { "^.+\\.[jt]s$": ["@swc/jest"] },
|
transform: {
|
||||||
|
"^.+\\.[jt]s$": [
|
||||||
|
"@swc/jest",
|
||||||
|
{
|
||||||
|
jsc: {
|
||||||
|
parser: { syntax: "typescript", decorators: true },
|
||||||
|
transform: { decoratorMetadata: true },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
testEnvironment: `node`,
|
testEnvironment: `node`,
|
||||||
moduleFileExtensions: [`js`, `jsx`, `ts`, `tsx`, `json`],
|
moduleFileExtensions: [`js`, `jsx`, `ts`, `tsx`, `json`],
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,15 @@
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
transform: { "^.+\\.[jt]s$": ["@swc/jest"] },
|
transform: {
|
||||||
|
"^.+\\.[jt]s$": [
|
||||||
|
"@swc/jest",
|
||||||
|
{
|
||||||
|
jsc: {
|
||||||
|
parser: { syntax: "typescript", decorators: true },
|
||||||
|
transform: { decoratorMetadata: true },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
testEnvironment: `node`,
|
testEnvironment: `node`,
|
||||||
moduleFileExtensions: [`js`, `jsx`, `ts`, `tsx`, `json`],
|
moduleFileExtensions: [`js`, `jsx`, `ts`, `tsx`, `json`],
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user