Skip to content

Commit

Permalink
chore: move to swc/jest (#7739)
Browse files Browse the repository at this point in the history
* chore: move to swc

* chore: fix tax rate tests

* chore: undo failed test

* chore: fix unit tests script

* chore: use node 20

* Update scripts/run-workspace-unit-tests-in-chunks.sh
  • Loading branch information
riqwan authored Jun 20, 2024
1 parent f615577 commit 03924a4
Show file tree
Hide file tree
Showing 137 changed files with 386 additions and 419 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"lint:path": "eslint --ignore-path .eslintignore --ext .js,.ts,.tsx",
"prettier": "prettier",
"jest": "jest",
"test": "turbo run test --concurrency=50% --no-daemon --no-cache --force --filter='./packages/*' --filter='./packages/core/*' --filter='./packages/cli/*' --filter='./packages/modules/*' --filter='./packages/modules/providers/*'",
"test": "turbo run test --concurrency=50% --no-daemon --no-cache --force",
"test:chunk": "./scripts/run-workspace-unit-tests-in-chunks.sh",
"test:integration:packages": "turbo run test:integration --concurrency=50% --no-daemon --no-cache --force --filter='./packages/*' --filter='./packages/core/*' --filter='./packages/cli/*' --filter='./packages/modules/*' --filter='./packages/modules/providers/*'",
"test:integration:api": "turbo run test:integration:chunk --concurrency=50% --no-daemon --no-cache --force --filter=integration-tests-api",
Expand Down
10 changes: 1 addition & 9 deletions packages/core/modules-sdk/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
module.exports = {
transform: {
"^.+\\.[jt]s?$": [
"ts-jest",
{
tsconfig: "tsconfig.json",
isolatedModules: true,
},
],
},
transform: { "^.+\\.[jt]s?$": "@swc/jest" },
testEnvironment: `node`,
moduleFileExtensions: [`js`, `ts`],
}
1 change: 0 additions & 1 deletion packages/core/modules-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
"cross-env": "^5.2.1",
"jest": "^29.7.0",
"rimraf": "^5.0.1",
"ts-jest": "^29.1.1",
"typescript": "^5.1.6"
},
"dependencies": {
Expand Down
6 changes: 4 additions & 2 deletions packages/core/modules-sdk/src/medusa-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export type RegisterModuleJoinerConfig =
| ModuleJoinerConfig
| ((modules: ModuleJoinerConfig[]) => ModuleJoinerConfig)

export class MedusaModule {
class MedusaModule {
private static instances_: Map<string, { [key: string]: IModuleService }> =
new Map()
private static modules_: Map<string, ModuleAlias[]> = new Map()
Expand Down Expand Up @@ -589,4 +589,6 @@ export class MedusaModule {
}

global.MedusaModule ??= MedusaModule
exports.MedusaModule = global.MedusaModule
const GlobalMedusaModule = global.MedusaModule as typeof MedusaModule

export { GlobalMedusaModule as MedusaModule }
2 changes: 1 addition & 1 deletion packages/core/modules-sdk/src/remote-link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export class RemoteLink {
)
}

for (const mod of modulesLoaded) {
for (const mod of modulesLoaded || []) {
this.addModule(mod)
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/modules-sdk/src/remote-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class RemoteQuery {
)
}

for (const mod of modulesLoaded) {
for (const mod of modulesLoaded || []) {
if (!mod.__definition.isQueryable) {
continue
}
Expand Down
10 changes: 1 addition & 9 deletions packages/core/orchestration/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
module.exports = {
transform: {
"^.+\\.[jt]s?$": [
"ts-jest",
{
tsconfig: "tsconfig.json",
isolatedModules: true,
},
],
},
transform: { "^.+\\.[jt]s?$": "@swc/jest" },
testEnvironment: `node`,
moduleFileExtensions: [`js`, `ts`],
}
1 change: 0 additions & 1 deletion packages/core/orchestration/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
"cross-env": "^5.2.1",
"jest": "^29.7.0",
"rimraf": "^5.0.1",
"ts-jest": "^29.1.1",
"typescript": "^5.1.6"
},
"dependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class GlobalWorkflow extends WorkflowManager {
} else if (Array.isArray(modulesLoaded) && modulesLoaded.length) {
container = createMedusaContainer()

for (const mod of modulesLoaded) {
for (const mod of modulesLoaded || []) {
const registrationName = mod.__definition.registrationName
container.register(registrationName, asValue(mod))
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/orchestration/src/workflow/local-workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export class LocalWorkflow {
} else if (Array.isArray(modulesLoaded) && modulesLoaded.length) {
container = createMedusaContainer()

for (const mod of modulesLoaded) {
for (const mod of modulesLoaded || []) {
const registrationName = mod.__definition.registrationName
container.register(registrationName, asValue(mod))
}
Expand Down
12 changes: 5 additions & 7 deletions packages/core/orchestration/src/workflow/workflow-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
TransactionStepsDefinition,
} from "../transaction"
import { WorkflowScheduler } from "./scheduler"
import { MedusaError } from "@medusajs/utils"

export interface WorkflowDefinition {
id: string
Expand Down Expand Up @@ -51,7 +50,7 @@ export type WorkflowStepHandler = (
args: WorkflowStepHandlerArguments
) => Promise<unknown>

export class WorkflowManager {
class WorkflowManager {
protected static workflows: Map<string, WorkflowDefinition> = new Map()
protected static scheduler = new WorkflowScheduler()

Expand Down Expand Up @@ -79,10 +78,7 @@ export class WorkflowManager {

static getTransactionDefinition(workflowId): OrchestratorBuilder {
if (!WorkflowManager.workflows.has(workflowId)) {
throw new MedusaError(
MedusaError.Types.NOT_FOUND,
`Workflow with id "${workflowId}" not found.`
)
throw new Error(`Workflow with id "${workflowId}" not found.`)
}

const workflow = WorkflowManager.workflows.get(workflowId)!
Expand Down Expand Up @@ -232,4 +228,6 @@ export class WorkflowManager {
}

global.WorkflowManager ??= WorkflowManager
exports.WorkflowManager = global.WorkflowManager
const GlobalWorkflowManager = global.WorkflowManager

export { GlobalWorkflowManager as WorkflowManager }
10 changes: 1 addition & 9 deletions packages/core/workflows-sdk/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
module.exports = {
transform: {
"^.+\\.[jt]s?$": [
"ts-jest",
{
tsconfig: "tsconfig.json",
isolatedModules: true,
},
],
},
transform: { "^.+\\.[jt]s?$": "@swc/jest" },
testEnvironment: `node`,
moduleFileExtensions: [`js`, `ts`],
}
1 change: 0 additions & 1 deletion packages/core/workflows-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
"cross-env": "^5.2.1",
"jest": "^29.7.0",
"rimraf": "^5.0.1",
"ts-jest": "^29.1.1",
"typescript": "^5.1.6"
},
"dependencies": {
Expand Down
6 changes: 4 additions & 2 deletions packages/core/workflows-sdk/src/medusa-workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { LocalWorkflow } from "@medusajs/orchestration"
import { LoadedModule, MedusaContainer } from "@medusajs/types"
import { ExportedWorkflow } from "./helper"

export class MedusaWorkflow {
class MedusaWorkflow {
static workflows: Record<
string,
(
Expand All @@ -28,4 +28,6 @@ export class MedusaWorkflow {
}

global.MedusaWorkflow ??= MedusaWorkflow
exports.MedusaWorkflow = global.MedusaWorkflow
const GlobalMedusaWorkflow = global.MedusaWorkflow

export { GlobalMedusaWorkflow as MedusaWorkflow }
1 change: 0 additions & 1 deletion packages/medusa/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
"jest": "^29.7.0",
"rimraf": "^5.0.1",
"supertest": "^4.0.2",
"ts-jest": "^29.1.1",
"typescript": "^5.3.3"
},
"scripts": {
Expand Down
10 changes: 6 additions & 4 deletions packages/modules/api-key/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ module.exports = {
"^@types": "<rootDir>/src/types",
},
transform: {
"^.+\\.[jt]s?$": [
"ts-jest",
"^.+\\.[jt]s$": [
"@swc/jest",
{
tsconfig: "tsconfig.spec.json",
isolatedModules: true,
jsc: {
parser: { syntax: "typescript", decorators: true },
transform: { decoratorMetadata: true },
},
},
],
},
Expand Down
1 change: 0 additions & 1 deletion packages/modules/api-key/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
"jest": "^29.7.0",
"medusa-test-utils": "^1.1.44",
"rimraf": "^3.0.2",
"ts-jest": "^29.1.1",
"ts-node": "^10.9.1",
"tsc-alias": "^1.8.6",
"typescript": "^5.1.6"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { IAuthModuleService } from "@medusajs/types"
import { Modules } from "@medusajs/modules-sdk"
import { createAuthIdentities } from "../../__fixtures__/auth-identity"
import { IAuthModuleService } from "@medusajs/types"
import { moduleIntegrationTestRunner, SuiteOptions } from "medusa-test-utils"
import { createAuthIdentities } from "../../__fixtures__/auth-identity"

jest.setTimeout(30000)

Expand Down
10 changes: 6 additions & 4 deletions packages/modules/auth/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ module.exports = {
"^@types": "<rootDir>/src/types",
},
transform: {
"^.+\\.[jt]s?$": [
"ts-jest",
"^.+\\.[jt]s$": [
"@swc/jest",
{
tsconfig: "tsconfig.spec.json",
isolatedModules: true,
jsc: {
parser: { syntax: "typescript", decorators: true },
transform: { decoratorMetadata: true },
},
},
],
},
Expand Down
2 changes: 0 additions & 2 deletions packages/modules/auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@
"jest": "^29.7.0",
"medusa-test-utils": "^1.1.42",
"rimraf": "^3.0.2",
"ts-jest": "^29.1.1",
"ts-node": "^10.9.1",
"tsc-alias": "^1.8.6",
"typescript": "^5.1.6"
},
Expand Down
3 changes: 2 additions & 1 deletion packages/modules/auth/src/models/provider-identity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
OnInit,
PrimaryKey,
Property,
Rel,
} from "@mikro-orm/core"

import {
Expand Down Expand Up @@ -52,7 +53,7 @@ export default class ProviderIdentity {
@ManyToOne(() => AuthIdentity, {
persist: false,
})
auth_identity: AuthIdentity
auth_identity: Rel<AuthIdentity>

@Property({ columnType: "jsonb", nullable: true })
user_metadata: Record<string, unknown> | null
Expand Down
1 change: 0 additions & 1 deletion packages/modules/cache-inmemory/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
"cross-env": "^5.2.1",
"jest": "^29.7.0",
"rimraf": "^5.0.1",
"ts-jest": "^29.1.1",
"typescript": "^5.1.6"
},
"scripts": {
Expand Down
10 changes: 1 addition & 9 deletions packages/modules/cache-redis/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
module.exports = {
transform: {
"^.+\\.[jt]s?$": [
"ts-jest",
{
tsconfig: "tsconfig.json",
isolatedModules: true,
},
],
},
transform: { "^.+\\.[jt]s$": "@swc/jest" },
testEnvironment: `node`,
moduleFileExtensions: [`js`, `ts`],
}
1 change: 0 additions & 1 deletion packages/modules/cache-redis/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
"cross-env": "^5.2.1",
"jest": "^29.7.0",
"rimraf": "^5.0.1",
"ts-jest": "^29.1.1",
"typescript": "^5.1.6"
},
"scripts": {
Expand Down
10 changes: 6 additions & 4 deletions packages/modules/cart/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ module.exports = {
"^@utils": "<rootDir>/src/utils",
},
transform: {
"^.+\\.[jt]s?$": [
"ts-jest",
"^.+\\.[jt]s$": [
"@swc/jest",
{
tsconfig: "tsconfig.spec.json",
isolatedModules: true,
jsc: {
parser: { syntax: "typescript", decorators: true },
transform: { decoratorMetadata: true },
},
},
],
},
Expand Down
1 change: 0 additions & 1 deletion packages/modules/cart/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
"jest": "^29.7.0",
"medusa-test-utils": "^1.1.44",
"rimraf": "^3.0.2",
"ts-jest": "^29.1.1",
"ts-node": "^10.9.1",
"tsc-alias": "^1.8.6",
"typescript": "^5.1.6"
Expand Down
9 changes: 5 additions & 4 deletions packages/modules/cart/src/models/cart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
OptionalProps,
PrimaryKey,
Property,
Rel,
} from "@mikro-orm/core"
import Address from "./address"
import LineItem from "./line-item"
Expand Down Expand Up @@ -115,7 +116,7 @@ export default class Cart {
cascade: [Cascade.PERSIST],
nullable: true,
})
shipping_address: Address | null
shipping_address: Rel<Address> | null

@BillingAddressIdIndex()
@ManyToOne({
Expand All @@ -131,20 +132,20 @@ export default class Cart {
cascade: [Cascade.PERSIST],
nullable: true,
})
billing_address: Address | null
billing_address: Rel<Address> | null

@Property({ columnType: "jsonb", nullable: true })
metadata: Record<string, unknown> | null = null

@OneToMany(() => LineItem, (lineItem) => lineItem.cart, {
cascade: [Cascade.PERSIST, "soft-remove"] as any,
})
items = new Collection<LineItem>(this)
items = new Collection<Rel<LineItem>>(this)

@OneToMany(() => ShippingMethod, (shippingMethod) => shippingMethod.cart, {
cascade: [Cascade.PERSIST, "soft-remove"] as any,
})
shipping_methods = new Collection<ShippingMethod>(this)
shipping_methods = new Collection<Rel<ShippingMethod>>(this)

@Property({
onCreate: () => new Date(),
Expand Down
3 changes: 2 additions & 1 deletion packages/modules/cart/src/models/line-item-adjustment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
ManyToOne,
OnInit,
Property,
Rel,
} from "@mikro-orm/core"
import AdjustmentLine from "./adjustment-line"
import LineItem from "./line-item"
Expand Down Expand Up @@ -42,7 +43,7 @@ const DeletedAtIndex = createPsqlIndexStatementHelper({
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
export default class LineItemAdjustment extends AdjustmentLine {
@ManyToOne({ entity: () => LineItem, persist: false })
item: LineItem
item: Rel<LineItem>

@LineItemIdIndex()
@ManyToOne({
Expand Down
Loading

0 comments on commit 03924a4

Please sign in to comment.