Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(medusa): migrate medusa unit tests / plugins integration tests to swc jest #6820

Merged
merged 29 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
47a9d0b
chore: shard unit tests
riqwan Mar 23, 2024
b6bf776
chore: move paypal and stripe to swc
riqwan Mar 25, 2024
e4b1510
Merge branch 'develop' into feat/unit-tests
riqwan Mar 25, 2024
1cc9114
chore: update actions
riqwan Mar 25, 2024
0beffc1
Merge branch 'develop' into feat/unit-tests
riqwan Mar 25, 2024
31ba232
Merge branch 'develop' into feat/unit-tests
riqwan Mar 25, 2024
8839919
chore: refactor http paypal client
riqwan Mar 25, 2024
23c873a
chore: added changeset
riqwan Mar 25, 2024
4dc19ff
chore: remove medusa changes
riqwan Mar 25, 2024
930d135
Merge branch 'develop' into feat/unit-tests
riqwan Mar 25, 2024
c79ac93
feat(medusa): migrate medusa unit tests to run with swc jest
riqwan Mar 24, 2024
fb7edfe
chore: skip broken tests
riqwan Mar 25, 2024
b0c4c98
chore: paralelize payment plugins
riqwan Mar 25, 2024
b914445
chore: update yarn lock
riqwan Mar 25, 2024
a7be1d1
chore: migrate plugins to swc
riqwan Mar 25, 2024
30f975b
Merge branch 'develop' into feat/medusa-swc
riqwan Mar 25, 2024
bbdbc54
chore: ignore node modules
riqwan Mar 25, 2024
49728b7
Merge branch 'develop' into feat/medusa-swc
riqwan Mar 25, 2024
2d262fd
chore: use detect handles
riqwan Mar 25, 2024
05a26e7
Merge branch 'develop' into feat/medusa-swc
riqwan Mar 25, 2024
5cae26a
Merge branch 'develop' into feat/medusa-swc
riqwan Mar 25, 2024
8f7fc94
undo node modules
riqwan Mar 25, 2024
0e0a388
improve decorator
adrien2p Mar 25, 2024
b20f88f
fix
adrien2p Mar 25, 2024
fb48a4d
Merge branch 'feat/medusa-swc' of github.com:medusajs/medusa into fea…
adrien2p Mar 25, 2024
d809159
chore: remove obselete snapshot
riqwan Mar 25, 2024
19c444d
chore: remove constructors in payload classes
riqwan Mar 25, 2024
77e4449
chore: resets
riqwan Mar 25, 2024
360071d
Merge branch 'develop' into feat/medusa-swc
riqwan Mar 25, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/polite-houses-nail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@medusajs/medusa": patch
---

feat(medusa): migrate medusa unit tests to run with swc jest

This file was deleted.

2 changes: 1 addition & 1 deletion integration-tests/api/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module.exports = {
`__testfixtures__`,
`.cache`,
],
transformIgnorePatterns: [`/dist`],
transformIgnorePatterns: ["/dist", "/node_modules/"],
transform: { "^.+\\.[jt]s$": ["@swc/jest"] },
setupFiles: ["../setup-env.js"],
setupFilesAfterEnv: ["../setup.js"],
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"private": true,
"scripts": {
"test:integration": "jest --silent=false --maxWorkers=50% --bail --detectOpenHandles --forceExit --logHeapUsage",
"test:integration:chunk": "jest --silent --bail --maxWorkers=50% --forceExit --testPathPattern=$(echo $CHUNKS | jq -r \".[${CHUNK}] | .[]\")",
"test:integration:chunk": "jest --silent --bail --maxWorkers=50% --forceExit --detectOpenHandles --testPathPattern=$(echo $CHUNKS | jq -r \".[${CHUNK}] | .[]\")",
"build": "babel src -d dist --extensions \".ts,.js\""
},
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/modules/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module.exports = {
`__testfixtures__`,
`.cache`,
],
transformIgnorePatterns: [`/dist`],
transformIgnorePatterns: ["/dist", "/node_modules/"],
transform: {
"^.+\\.[jt]s$": ["@swc/jest"],
},
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/modules/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"license": "MIT",
"private": true,
"scripts": {
"test:integration": "jest --silent=false --maxWorkers=50% --bail --detectOpenHandles --forceExit --logHeapUsage",
"test:integration": "jest --silent --maxWorkers=50% --bail --detectOpenHandles --forceExit --logHeapUsage",
"test:integration:chunk": "jest --silent --bail --maxWorkers=50% --forceExit --testPathPattern=$(echo $CHUNKS | jq -r \".[${CHUNK}] | .[]\")",
"build": "babel src -d dist --extensions \".ts,.js\""
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ describe("/store/carts", () => {
})

const customer = await simpleCustomerFactory(dbConnection, {}, 100)

const items = []
const cart = await simpleCartFactory(dbConnection, {
email: "[email protected]",
region: regionId,
Expand All @@ -194,7 +194,6 @@ describe("/store/carts", () => {
],
})

const items = []
for (let i = 0; i < 13; i++) {
const product = await simpleProductFactory(dbConnection, {})
await prodVarInventoryService.attachInventoryItem(
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/plugins/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ module.exports = {
`__testfixtures__`,
`.cache`,
],
transformIgnorePatterns: [`/dist`],
transform: { "^.+\\.[jt]s$": `../../jest-transformer.js` },
transformIgnorePatterns: ["/dist", "/node_modules/"],
transform: { "^.+\\.[jt]s$": `@swc/jest` },
setupFiles: ["../setup-env.js"],
setupFilesAfterEnv: ["../setup.js"],
globalSetup: "../globalSetup.js",
Expand Down
4 changes: 3 additions & 1 deletion integration-tests/plugins/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"license": "MIT",
"private": true,
"scripts": {
"test:integration": "node --expose-gc ./../../node_modules/.bin/jest --silent=false --runInBand --bail --detectOpenHandles --logHeapUsage --clearMocks --forceExit",
"test:integration": "jest --silent=false --maxWorkers=50% --bail --detectOpenHandles --clearMocks --forceExit",
adrien2p marked this conversation as resolved.
Show resolved Hide resolved
"build": "babel src -d dist --extensions \".ts,.js\""
},
"dependencies": {
Expand Down Expand Up @@ -40,6 +40,8 @@
"@babel/core": "^7.12.10",
"@babel/node": "^7.12.10",
"@medusajs/types": "workspace:^",
"@swc/core": "^1.4.8",
"@swc/jest": "^0.2.36",
"babel-preset-medusa-package": "*",
"jest": "^26.6.3",
"jest-environment-node": "26.6.2"
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/repositories/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module.exports = {
`__testfixtures__`,
`.cache`,
],
transformIgnorePatterns: [`/dist`],
transformIgnorePatterns: ["/dist", "/node_modules/"],
transform: { "^.+\\.[jt]s$": `../../jest-transformer.js` },
setupFiles: ["../setup-env.js"],
setupFilesAfterEnv: ["../setup.js"],
Expand Down
2 changes: 1 addition & 1 deletion packages/event-bus-redis/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"watch": "tsc --build --watch",
"prepublishOnly": "cross-env NODE_ENV=production tsc --build",
"build": "rimraf dist && tsc --build",
"test": "jest --passWithNoTests"
"test": "jest --silent --bail --maxWorkers=50% --forceExit"
},
"dependencies": {
"@medusajs/modules-sdk": "^1.12.8",
Expand Down
2 changes: 1 addition & 1 deletion packages/medusa-payment-paypal/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module.exports = {
transform: {
"^.+\\.[jt]s?$": "@swc/jest",
},
transformIgnorePatterns: ["/node_modules/(?!(axios)/).*", "dist"],
transformIgnorePatterns: ["/node_modules/(?!(axios)/).*", "/dist"],
testEnvironment: `node`,
moduleFileExtensions: [`js`, `ts`],
}
2 changes: 1 addition & 1 deletion packages/medusa-payment-paypal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"license": "MIT",
"scripts": {
"prepublishOnly": "cross-env NODE_ENV=production tsc --build",
"test": "jest --runInBand --bail --forceExit",
"test": "jest --silent --bail --maxWorkers=50% --forceExit",
riqwan marked this conversation as resolved.
Show resolved Hide resolved
"build": "rimraf dist && tsc",
"watch": "tsc --watch"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/medusa-payment-stripe/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"license": "MIT",
"scripts": {
"prepublishOnly": "cross-env NODE_ENV=production tsc --build",
"test": "jest --runInBand --bail --forceExit",
"test": "jest --silent --bail --maxWorkers=50% --forceExit",
"build": "rimraf dist && tsc -p ./tsconfig.server.json && medusa-admin bundle",
"watch": "tsc --watch"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/medusa-plugin-brightpearl/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
},
"scripts": {
"prepare": "cross-env NODE_ENV=production yarn run build",
"test": "jest --passWithNoTests src",
"test": "jest --silent --bail --maxWorkers=50% --forceExit",
"build": "babel src --out-dir . --ignore '**/__tests__','**/__mocks__'",
"watch": "babel -w src --out-dir . --ignore '**/__tests__','**/__mocks__'"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/medusa-plugin-restock-notification/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
},
"scripts": {
"prepare": "cross-env NODE_ENV=production yarn run build",
"test": "jest --passWithNoTests src",
"test": "jest --silent --bail --maxWorkers=50% --forceExit",
"build": "babel src --out-dir . --ignore '**/__tests__','**/__mocks__'",
"watch": "babel -w src --out-dir . --ignore '**/__tests__','**/__mocks__'"
},
Expand Down
22 changes: 22 additions & 0 deletions packages/medusa/.swcrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"$schema": "https://json.schemastore.org/swcrc",
"jsc": {
"parser": {
"syntax": "typescript",
"tsx": false,
"decorators": true,
"dynamicImport": true
},
"transform": {
"legacyDecorator": true,
"decoratorMetadata": true
},
"target": "es5"
},
"module": {
"type": "commonjs",
"noInterop": false
},
"minify": false,
"sourceMaps": true
}
12 changes: 3 additions & 9 deletions packages/medusa/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,11 @@ module.exports = {
// useCoverage ? `jest-junit` : []
// )
// : [`default`].concat(useCoverage ? `jest-junit` : []),
globals: {
"ts-jest": {
tsConfig: "tsconfig.spec.json",
isolatedModules: false,
},
},
transform: {
"^.+\\.[jt]s?$": "ts-jest",
"^.+\\.[jt]s?$": "@swc/jest",
},
modulePathIgnorePatterns: ["__fixtures__"],
modulePathIgnorePatterns: ["__fixtures__", "node_modules", "dist"],
testEnvironment: `node`,
moduleFileExtensions: [`js`, `jsx`, `ts`, `tsx`, `json`],
moduleFileExtensions: [`js`, `ts`],
setupFilesAfterEnv: ["<rootDir>/setupTests.js"],
}
4 changes: 3 additions & 1 deletion packages/medusa/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
"license": "MIT",
"devDependencies": {
"@medusajs/types": "^1.11.14",
"@swc/core": "^1.4.8",
"@swc/jest": "^0.2.36",
"@types/express": "^4.17.17",
"@types/ioredis": "^4.28.10",
"@types/jsonwebtoken": "^8.5.9",
Expand All @@ -43,7 +45,7 @@
"prepublishOnly": "cross-env NODE_ENV=production tsc --build",
"build": "rimraf dist && tsc --build",
"serve": "node dist/app.js",
"test": "jest --runInBand --bail --detectOpenHandles --forceExit"
"test": "jest --silent --bail --maxWorkers=50% --forceExit"
},
"peerDependencies": {
"medusa-interfaces": "^1.3.7",
Expand Down
106 changes: 53 additions & 53 deletions packages/medusa/src/api/routes/admin/discounts/create-discount.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import {
AllocationType,
DiscountConditionOperator,
DiscountRuleType,
} from "../../../../models"
import { Type } from "class-transformer"
import {
IsArray,
IsBoolean,
Expand All @@ -16,14 +12,18 @@ import {
IsString,
ValidateNested,
} from "class-validator"
import { AdminUpsertConditionsReq } from "../../../../types/discount"
import DiscountService from "../../../../services/discount"
import { Request, Response } from "express"
import { EntityManager } from "typeorm"
import {
AllocationType,
DiscountConditionOperator,
DiscountRuleType,
} from "../../../../models"
import DiscountService from "../../../../services/discount"
import { FindParams } from "../../../../types/common"
import { AdminUpsertConditionsReq } from "../../../../types/discount"
import { IsGreaterThan } from "../../../../utils/validators/greater-than"
import { IsISO8601Duration } from "../../../../utils/validators/iso8601-duration"
import { Type } from "class-transformer"
import { Request, Response } from "express"
import { FindParams } from "../../../../types/common"

/**
* @oas [post] /admin/discounts
Expand Down Expand Up @@ -164,6 +164,49 @@ export default async (req: Request, res: Response) => {
res.status(200).json({ discount })
}

/**
* Details of the discount rule to create.
*/
export class AdminPostDiscountsDiscountRule {
/**
* The discount rule's description.
*/
@IsString()
@IsOptional()
description?: string

/**
* The discount rule's type.
*/
@IsEnum(DiscountRuleType, {
message: `Invalid rule type, must be one of "fixed", "percentage" or "free_shipping"`,
})
type: DiscountRuleType

/**
* The discount rule's value.
*/
@IsNumber()
value: number

/**
* The discount rule's allocation.
*/
@IsEnum(AllocationType, {
message: `Invalid allocation type, must be one of "total" or "item"`,
})
allocation: AllocationType

/**
* The discount rule's conditions.
*/
@IsOptional()
@IsArray()
@ValidateNested({ each: true })
@Type(() => AdminCreateCondition)
conditions?: AdminCreateCondition[]
}

/**
* @schema AdminPostDiscountsReq
* type: object
Expand Down Expand Up @@ -322,49 +365,6 @@ export class AdminPostDiscountsReq {
metadata?: Record<string, unknown>
}

/**
* Details of the discount rule to create.
*/
export class AdminPostDiscountsDiscountRule {
/**
* The discount rule's description.
*/
@IsString()
@IsOptional()
description?: string

/**
* The discount rule's type.
*/
@IsEnum(DiscountRuleType, {
message: `Invalid rule type, must be one of "fixed", "percentage" or "free_shipping"`,
})
type: DiscountRuleType

/**
* The discount rule's value.
*/
@IsNumber()
value: number

/**
* The discount rule's allocation.
*/
@IsEnum(AllocationType, {
message: `Invalid allocation type, must be one of "total" or "item"`,
})
allocation: AllocationType

/**
* The discount rule's conditions.
*/
@IsOptional()
@IsArray()
@ValidateNested({ each: true })
@Type(() => AdminCreateCondition)
conditions?: AdminCreateCondition[]
}

/**
* Details of the discount condition to create.
*/
Expand Down
Loading
Loading