feature: bundle all modules (#9324)
This commit is contained in:
@@ -34,9 +34,6 @@
|
||||
"@swc/core": "^1.7.28",
|
||||
"@swc/jest": "^0.2.36",
|
||||
"awilix": "^8.0.1",
|
||||
"bignumber.js": "^9.1.2",
|
||||
"cross-env": "^5.2.1",
|
||||
"ioredis": "^5.4.1",
|
||||
"jest": "^29.7.0",
|
||||
"pg": "^8.13.0",
|
||||
"rimraf": "^5.0.1",
|
||||
|
||||
@@ -49,6 +49,7 @@
|
||||
"test": "jest --runInBand --bail --passWithNoTests --forceExit"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@medusajs/medusa-cli": "^1.3.22",
|
||||
"@mikro-orm/core": "5.9.7",
|
||||
"@mikro-orm/knex": "5.9.7",
|
||||
"@mikro-orm/migrations": "5.9.7",
|
||||
@@ -58,7 +59,6 @@
|
||||
"@types/express": "^4.17.17",
|
||||
"@types/jsonwebtoken": "^8.5.9",
|
||||
"awilix": "^8.0.1",
|
||||
"bignumber.js": "^9.1.2",
|
||||
"ioredis": "^5.4.1",
|
||||
"jest": "^29.7.0",
|
||||
"pg": "^8.13.0",
|
||||
@@ -68,7 +68,6 @@
|
||||
"vite": "^5.2.11"
|
||||
},
|
||||
"dependencies": {
|
||||
"@medusajs/medusa-cli": "^1.3.22",
|
||||
"@medusajs/modules-sdk": "^1.12.11",
|
||||
"@medusajs/orchestration": "^0.5.7",
|
||||
"@medusajs/types": "^1.11.16",
|
||||
@@ -78,23 +77,30 @@
|
||||
"connect-redis": "5.2.0",
|
||||
"cookie-parser": "^1.4.6",
|
||||
"cors": "^2.8.5",
|
||||
"express": "^4.18.2",
|
||||
"express": "^4.21.0",
|
||||
"express-session": "^1.17.3",
|
||||
"ioredis": "^5.4.1",
|
||||
"jsonwebtoken": "^9.0.2",
|
||||
"medusa-telemetry": "^0.0.17",
|
||||
"morgan": "^1.9.1",
|
||||
"zod": "3.22.4"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@medusajs/medusa-cli": "^1.3.22",
|
||||
"@mikro-orm/core": "5.9.7",
|
||||
"@mikro-orm/knex": "5.9.7",
|
||||
"@mikro-orm/migrations": "5.9.7",
|
||||
"@mikro-orm/postgresql": "5.9.7",
|
||||
"awilix": "^8.0.1",
|
||||
"bignumber.js": "^9.1.2",
|
||||
"ioredis": "^5.4.1",
|
||||
"pg": "^8.13.0",
|
||||
"vite": "^5.2.11"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"ioredis": {
|
||||
"optional": true
|
||||
},
|
||||
"vite": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
dist/
|
||||
node_modules/
|
||||
@@ -1,340 +0,0 @@
|
||||
# Change Log
|
||||
|
||||
## 1.1.44
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- [#6864](https://github.com/medusajs/medusa/pull/6864) [`e944a627f0`](https://github.com/medusajs/medusa/commit/e944a627f074fb39a56f4bc7b3d6d315736ebf7c) Thanks [@adrien2p](https://github.com/adrien2p)! - feat: region payment providers management workflows/api
|
||||
|
||||
- [#6919](https://github.com/medusajs/medusa/pull/6919) [`56c04f452c`](https://github.com/medusajs/medusa/commit/56c04f452cb54b4c614531394f3ebb9a2149e608) Thanks [@carlos-r-l-rodrigues](https://github.com/carlos-r-l-rodrigues)! - Medusa test utils use correct loader to init DB.
|
||||
|
||||
- [#6901](https://github.com/medusajs/medusa/pull/6901) [`82a176e30e`](https://github.com/medusajs/medusa/commit/82a176e30e47a7d11caaf31c3023bd8db588b465) Thanks [@adrien2p](https://github.com/adrien2p)! - chore(medusa-test-utils): Handle errors gracefully + Do not set Distributed storage on partial loading
|
||||
|
||||
- [#6858](https://github.com/medusajs/medusa/pull/6858) [`6bf4d40856`](https://github.com/medusajs/medusa/commit/6bf4d40856839b755ce33f85ee30d046be7341ab) Thanks [@srindom](https://github.com/srindom)! - chore(medusa-test-utils): create declaration file
|
||||
|
||||
- [#6962](https://github.com/medusajs/medusa/pull/6962) [`65794f4bb5`](https://github.com/medusajs/medusa/commit/65794f4bb56e4fd3f0ccb7656a948f856f05324e) Thanks [@adrien2p](https://github.com/adrien2p)! - feat: Create shipping options API
|
||||
|
||||
- [#6917](https://github.com/medusajs/medusa/pull/6917) [`b3a3993423`](https://github.com/medusajs/medusa/commit/b3a3993423f4872c84b52a68cc3e56766f9ad5a1) Thanks [@adrien2p](https://github.com/adrien2p)! - fix(medusa-test-utils): recompute driver options
|
||||
|
||||
- [#6857](https://github.com/medusajs/medusa/pull/6857) [`6ee2ee845c`](https://github.com/medusajs/medusa/commit/6ee2ee845c7044240c521345eb0e296843a67291) Thanks [@adrien2p](https://github.com/adrien2p)! - fix(): medusa test runner
|
||||
|
||||
- [#6865](https://github.com/medusajs/medusa/pull/6865) [`8fd1488938`](https://github.com/medusajs/medusa/commit/8fd148893850eb66c5eae00c4ca9391a80ea2eb9) Thanks [@adrien2p](https://github.com/adrien2p)! - chore: medusa shutdown
|
||||
|
||||
- Updated dependencies [[`20e8df914e`](https://github.com/medusajs/medusa/commit/20e8df914ec5fdf8d562d4fa84f72c58c7056195), [`e0b02a1012`](https://github.com/medusajs/medusa/commit/e0b02a1012981c29830d7779f59ebe805bbfd137), [`e944a627f0`](https://github.com/medusajs/medusa/commit/e944a627f074fb39a56f4bc7b3d6d315736ebf7c), [`cc557c8752`](https://github.com/medusajs/medusa/commit/cc557c8752fd0554f5a1b58522d9a88dc43a8509), [`5d9aea053c`](https://github.com/medusajs/medusa/commit/5d9aea053ce6e04f242f86fb9053c13dec515d5b), [`232322d035`](https://github.com/medusajs/medusa/commit/232322d03515f81e56867ff8c765b8409399ee68), [`c3efac5a0d`](https://github.com/medusajs/medusa/commit/c3efac5a0d6cfa38e1af8d248138fa83934a8ceb), [`4b57c5d286`](https://github.com/medusajs/medusa/commit/4b57c5d286f9dc6e2098c67e9fecb0d93175b5a1), [`a6562d2a41`](https://github.com/medusajs/medusa/commit/a6562d2a41453cbe7aa43be352c4924e3e4c79d5)]:
|
||||
- @medusajs/utils@1.11.9
|
||||
- medusa-core-utils@1.2.2
|
||||
|
||||
## 1.1.43
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- [#6803](https://github.com/medusajs/medusa/pull/6803) [`0168c819da`](https://github.com/medusajs/medusa/commit/0168c819da2bcdf2391c5fb5501342ea140882df) Thanks [@srindom](https://github.com/srindom)! - fix(medusa-test-utils): make module test runner models configurable
|
||||
|
||||
- [#6772](https://github.com/medusajs/medusa/pull/6772) [`1ef9c78cea`](https://github.com/medusajs/medusa/commit/1ef9c78cea080c3b7c136f909c6cddec9d8f0c62) Thanks [@adrien2p](https://github.com/adrien2p)! - chore: v2 - deprecate extra in favor of driver options
|
||||
|
||||
- Updated dependencies [[`06f22bb48a`](https://github.com/medusajs/medusa/commit/06f22bb48ad1fe73577657b8c5db055312f16a0d), [`56481e683d`](https://github.com/medusajs/medusa/commit/56481e683d33ff98f0d4c4e144873bb23f993c9c), [`9073d7aba3`](https://github.com/medusajs/medusa/commit/9073d7aba3419e4dc0a206473291a46ebd79b8c1), [`4974f5e455`](https://github.com/medusajs/medusa/commit/4974f5e4557bd64a328a881ec02b91e15485bd23), [`1ef9c78cea`](https://github.com/medusajs/medusa/commit/1ef9c78cea080c3b7c136f909c6cddec9d8f0c62)]:
|
||||
- @medusajs/modules-sdk@1.12.10
|
||||
- @medusajs/utils@1.11.8
|
||||
|
||||
## 1.1.42
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- [#6558](https://github.com/medusajs/medusa/pull/6558) [`56d97ebef9`](https://github.com/medusajs/medusa/commit/56d97ebef96a51b4af0939c9cdf4383c33b2ec87) Thanks [@adrien2p](https://github.com/adrien2p)! - chore(medusa-test-utils): Add logger by default
|
||||
|
||||
- [#6595](https://github.com/medusajs/medusa/pull/6595) [`f0ef0a8784`](https://github.com/medusajs/medusa/commit/f0ef0a87845764bae7610ee854592bb9800210f5) Thanks [@adrien2p](https://github.com/adrien2p)! - fix: integration-tests/modules
|
||||
|
||||
- [#6408](https://github.com/medusajs/medusa/pull/6408) [`1d91b7429b`](https://github.com/medusajs/medusa/commit/1d91b7429beebd6f09d5027f7f7e1fe74ce3a8ff) Thanks [@adrien2p](https://github.com/adrien2p)! - feat(fulfillment): implementation part 2
|
||||
|
||||
- [#6524](https://github.com/medusajs/medusa/pull/6524) [`62a7bcc30c`](https://github.com/medusajs/medusa/commit/62a7bcc30cbc7b234b2b51d7858439951a84edeb) Thanks [@adrien2p](https://github.com/adrien2p)! - Feat(fulfillment): service provider registration + fulfillment management
|
||||
|
||||
- [#6700](https://github.com/medusajs/medusa/pull/6700) [`8f8a4f9b13`](https://github.com/medusajs/medusa/commit/8f8a4f9b1353087d98f6cc75346d43a7f49901a8) Thanks [@olivermrbl](https://github.com/olivermrbl)! - chore: Version all modules to allow for initial testing
|
||||
|
||||
- [#6581](https://github.com/medusajs/medusa/pull/6581) [`51bb6f1e89`](https://github.com/medusajs/medusa/commit/51bb6f1e89424c7ae9f566b43ba26b3f5a48e3f6) Thanks [@adrien2p](https://github.com/adrien2p)! - Chore/integration tests modules utils
|
||||
|
||||
- [#6383](https://github.com/medusajs/medusa/pull/6383) [`e85463b2a7`](https://github.com/medusajs/medusa/commit/e85463b2a717751de2e21c39a4c745449b31affe) Thanks [@adrien2p](https://github.com/adrien2p)! - chore(): Fix database test utils and utils
|
||||
|
||||
- Updated dependencies [[`9288f53327`](https://github.com/medusajs/medusa/commit/9288f53327b8ce617af92ed8d14d9459cbfeb13c), [`56cbf88115`](https://github.com/medusajs/medusa/commit/56cbf88115994adea7037c3f2814f0c96af3cfc0), [`36a61658f9`](https://github.com/medusajs/medusa/commit/36a61658f969a7b19c84a1e621ad1464927cafb1), [`c319edb8e0`](https://github.com/medusajs/medusa/commit/c319edb8e0ecd13d086652147667916e5abab2d8), [`0b9fcb6324`](https://github.com/medusajs/medusa/commit/0b9fcb6324eee9f2556c7e6317775fae93b12a47), [`586df9da25`](https://github.com/medusajs/medusa/commit/586df9da250e492442769f5bac2f8b3de1d46f05), [`b3d826497b`](https://github.com/medusajs/medusa/commit/b3d826497b3dae5e1b26b7924706c24fd5e87ca5), [`a86c87fe14`](https://github.com/medusajs/medusa/commit/a86c87fe1442afce9285e39255914e01012b4449), [`640eccd5dd`](https://github.com/medusajs/medusa/commit/640eccd5ddbb163e0f987ce6c772f1129c2e2632), [`8ea37d03c9`](https://github.com/medusajs/medusa/commit/8ea37d03c914a5004a3e42770668b2d1f7f8f564), [`339a946f38`](https://github.com/medusajs/medusa/commit/339a946f389033c21e05338f9dbf07d88e140533), [`9288f53327`](https://github.com/medusajs/medusa/commit/9288f53327b8ce617af92ed8d14d9459cbfeb13c), [`8dad2b51a2`](https://github.com/medusajs/medusa/commit/8dad2b51a26c4c3c14a6c95f70424c8bef2ad63e), [`a6d7070dd6`](https://github.com/medusajs/medusa/commit/a6d7070dd669c21ea19d70434d42c2f8167dc309), [`168f02f138`](https://github.com/medusajs/medusa/commit/168f02f138ad101e1013f2c8c3f8dc19de12accf), [`f5c2256286`](https://github.com/medusajs/medusa/commit/f5c22562867f412040f8bc6c55ab5de3a3735e62), [`000eb61e33`](https://github.com/medusajs/medusa/commit/000eb61e33e0302db95ee6ad1656ea9b430ed471), [`d550be3685`](https://github.com/medusajs/medusa/commit/d550be3685423218d47a20c57a5e06758f4a961a), [`62a7bcc30c`](https://github.com/medusajs/medusa/commit/62a7bcc30cbc7b234b2b51d7858439951a84edeb), [`8f8a4f9b13`](https://github.com/medusajs/medusa/commit/8f8a4f9b1353087d98f6cc75346d43a7f49901a8), [`6500f18b9b`](https://github.com/medusajs/medusa/commit/6500f18b9b80c5c9c473489e7e740d55dca74303), [`ce39b9b66e`](https://github.com/medusajs/medusa/commit/ce39b9b66e8c277ec0691ea6d0a950003be09cc1), [`a6a4b3f01a`](https://github.com/medusajs/medusa/commit/a6a4b3f01a6d2bd97b1580c59134279a1b033a5d), [`4625bd1241`](https://github.com/medusajs/medusa/commit/4625bd12416275b09c22cde4a09cb0f68df5d7c1), [`56b0b45304`](https://github.com/medusajs/medusa/commit/56b0b4530401a6ec5aa155874d371e45bb388fe2), [`cc1b66842c`](https://github.com/medusajs/medusa/commit/cc1b66842cbb37c6eab84e2d8b74844c214f38d7), [`24fb102a56`](https://github.com/medusajs/medusa/commit/24fb102a564b1253d1f8b039bb1e435cc5312fbb), [`e85463b2a7`](https://github.com/medusajs/medusa/commit/e85463b2a717751de2e21c39a4c745449b31affe)]:
|
||||
- @medusajs/utils@1.11.7
|
||||
- @medusajs/modules-sdk@1.12.9
|
||||
|
||||
## 1.1.41
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- [#5985](https://github.com/medusajs/medusa/pull/5985) [`d16d10619`](https://github.com/medusajs/medusa/commit/d16d10619dfbd3966a4709753de3d8cc37c6f2eb) Thanks [@pKorsholm](https://github.com/pKorsholm)! - fix(medusa-test-utils, utils, link-modules, pricing, product): upgrade mikro-orm version
|
||||
|
||||
- Updated dependencies [[`f86877586`](https://github.com/medusajs/medusa/commit/f86877586147ecedbf7f56a1c57f37ef0c33286c), [`46d610bc5`](https://github.com/medusajs/medusa/commit/46d610bc555797df2ae81eb89b18faf1411b33b8)]:
|
||||
- medusa-core-utils@1.2.1
|
||||
|
||||
## 1.1.40
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- [#3041](https://github.com/medusajs/medusa/pull/3041) [`121b42acf`](https://github.com/medusajs/medusa/commit/121b42acfe98c12dd593f9b1f2072ff0f3b61724) Thanks [@riqwan](https://github.com/riqwan)! - chore(medusa): Typeorm fixes / enhancements
|
||||
- upgrade typeorm from 0.2.51 to 0.3.11
|
||||
- Plugin repository loader to work with Typeorm update
|
||||
- Updated dependencies [[`121b42acf`](https://github.com/medusajs/medusa/commit/121b42acfe98c12dd593f9b1f2072ff0f3b61724), [`aa690beed`](https://github.com/medusajs/medusa/commit/aa690beed775646cbc86b445fb5dc90dcac087d5), [`54dcc1871`](https://github.com/medusajs/medusa/commit/54dcc1871c8f28bea962dbb9df6e79b038d56449), [`77d46220c`](https://github.com/medusajs/medusa/commit/77d46220c23bfe19e575cbc445874eb6c22f3c73)]:
|
||||
- medusa-core-utils@1.2.0
|
||||
|
||||
## 1.1.40-rc.0
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- [#3041](https://github.com/medusajs/medusa/pull/3041) [`121b42acf`](https://github.com/medusajs/medusa/commit/121b42acfe98c12dd593f9b1f2072ff0f3b61724) Thanks [@riqwan](https://github.com/riqwan)! - chore(medusa): Typeorm fixes / enhancements
|
||||
- upgrade typeorm from 0.2.51 to 0.3.11
|
||||
- Plugin repository loader to work with Typeorm update
|
||||
- Updated dependencies [[`121b42acf`](https://github.com/medusajs/medusa/commit/121b42acfe98c12dd593f9b1f2072ff0f3b61724), [`aa690beed`](https://github.com/medusajs/medusa/commit/aa690beed775646cbc86b445fb5dc90dcac087d5), [`54dcc1871`](https://github.com/medusajs/medusa/commit/54dcc1871c8f28bea962dbb9df6e79b038d56449), [`77d46220c`](https://github.com/medusajs/medusa/commit/77d46220c23bfe19e575cbc445874eb6c22f3c73)]:
|
||||
- medusa-core-utils@1.2.0-rc.0
|
||||
|
||||
## 1.1.40
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- [#3417](https://github.com/medusajs/medusa/pull/3417) [`fa4049cb5`](https://github.com/medusajs/medusa/commit/fa4049cb51232b2ed7091b1322c3fc14cd23e451) Thanks [@adrien2p](https://github.com/adrien2p)! - chores(medusa): Refactoring product update flow to improve handling and performances
|
||||
|
||||
## 1.1.39
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- [#3407](https://github.com/medusajs/medusa/pull/3407) [`f0a1355fe`](https://github.com/medusajs/medusa/commit/f0a1355feb5160ff7de1f3d3da769efe29d0d8ed) Thanks [@adrien2p](https://github.com/adrien2p)! - feat(medusa): Bulk emit events
|
||||
|
||||
## 1.1.38
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- [#2961](https://github.com/medusajs/medusa/pull/2961) [`47d075351`](https://github.com/medusajs/medusa/commit/47d075351fa4fdeaf32d48f2bd7e72943a293d9b) Thanks [@riqwan](https://github.com/riqwan)! - feat(medusa): Admin API endpoint to fetch a Product Category
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||
|
||||
## [1.1.37](https://github.com/medusajs/medusa/compare/medusa-test-utils@1.1.36...medusa-test-utils@1.1.37) (2022-01-11)
|
||||
|
||||
**Note:** Version bump only for package medusa-test-utils
|
||||
|
||||
## [1.1.36](https://github.com/medusajs/medusa/compare/medusa-test-utils@1.1.35...medusa-test-utils@1.1.36) (2021-12-29)
|
||||
|
||||
**Note:** Version bump only for package medusa-test-utils
|
||||
|
||||
## [1.1.35](https://github.com/medusajs/medusa/compare/medusa-test-utils@1.1.34...medusa-test-utils@1.1.35) (2021-12-17)
|
||||
|
||||
### Features
|
||||
|
||||
- add medusa-react ([#913](https://github.com/medusajs/medusa/issues/913)) ([d0d8dd7](https://github.com/medusajs/medusa/commit/d0d8dd7bf62eaac71df8714c2dfb4f204d192f51))
|
||||
|
||||
## [1.1.34](https://github.com/medusajs/medusa/compare/medusa-test-utils@1.1.33...medusa-test-utils@1.1.34) (2021-12-08)
|
||||
|
||||
**Note:** Version bump only for package medusa-test-utils
|
||||
|
||||
## [1.1.33](https://github.com/medusajs/medusa/compare/medusa-test-utils@1.1.32...medusa-test-utils@1.1.33) (2021-11-23)
|
||||
|
||||
**Note:** Version bump only for package medusa-test-utils
|
||||
|
||||
## [1.1.32](https://github.com/medusajs/medusa/compare/medusa-test-utils@1.1.31...medusa-test-utils@1.1.32) (2021-11-22)
|
||||
|
||||
**Note:** Version bump only for package medusa-test-utils
|
||||
|
||||
## [1.1.31](https://github.com/medusajs/medusa/compare/medusa-test-utils@1.1.30...medusa-test-utils@1.1.31) (2021-11-19)
|
||||
|
||||
**Note:** Version bump only for package medusa-test-utils
|
||||
|
||||
## [1.1.30](https://github.com/medusajs/medusa/compare/medusa-test-utils@1.1.29...medusa-test-utils@1.1.30) (2021-11-19)
|
||||
|
||||
**Note:** Version bump only for package medusa-test-utils
|
||||
|
||||
## [1.1.29](https://github.com/medusajs/medusa/compare/medusa-test-utils@1.1.28...medusa-test-utils@1.1.29) (2021-10-18)
|
||||
|
||||
**Note:** Version bump only for package medusa-test-utils
|
||||
|
||||
## [1.1.28](https://github.com/medusajs/medusa/compare/medusa-test-utils@1.1.27...medusa-test-utils@1.1.28) (2021-10-18)
|
||||
|
||||
**Note:** Version bump only for package medusa-test-utils
|
||||
|
||||
## [1.1.27](https://github.com/medusajs/medusa/compare/medusa-test-utils@1.1.25...medusa-test-utils@1.1.27) (2021-10-18)
|
||||
|
||||
**Note:** Version bump only for package medusa-test-utils
|
||||
|
||||
## [1.1.26](https://github.com/medusajs/medusa/compare/medusa-test-utils@1.1.25...medusa-test-utils@1.1.26) (2021-10-18)
|
||||
|
||||
**Note:** Version bump only for package medusa-test-utils
|
||||
|
||||
## [1.1.25](https://github.com/medusajs/medusa/compare/medusa-test-utils@1.1.24...medusa-test-utils@1.1.25) (2021-09-15)
|
||||
|
||||
**Note:** Version bump only for package medusa-test-utils
|
||||
|
||||
## [1.1.24](https://github.com/medusajs/medusa/compare/medusa-test-utils@1.1.23...medusa-test-utils@1.1.24) (2021-09-14)
|
||||
|
||||
**Note:** Version bump only for package medusa-test-utils
|
||||
|
||||
## [1.1.23](https://github.com/medusajs/medusa/compare/medusa-test-utils@1.1.22...medusa-test-utils@1.1.23) (2021-08-05)
|
||||
|
||||
**Note:** Version bump only for package medusa-test-utils
|
||||
|
||||
## [1.1.22](https://github.com/medusajs/medusa/compare/medusa-test-utils@1.1.21...medusa-test-utils@1.1.22) (2021-07-26)
|
||||
|
||||
**Note:** Version bump only for package medusa-test-utils
|
||||
|
||||
## [1.1.21](https://github.com/medusajs/medusa/compare/medusa-test-utils@1.1.19...medusa-test-utils@1.1.21) (2021-07-15)
|
||||
|
||||
**Note:** Version bump only for package medusa-test-utils
|
||||
|
||||
## [1.1.20](https://github.com/medusajs/medusa/compare/medusa-test-utils@1.1.19...medusa-test-utils@1.1.20) (2021-07-15)
|
||||
|
||||
**Note:** Version bump only for package medusa-test-utils
|
||||
|
||||
## [1.1.19](https://github.com/medusajs/medusa/compare/medusa-test-utils@1.1.18...medusa-test-utils@1.1.19) (2021-07-02)
|
||||
|
||||
**Note:** Version bump only for package medusa-test-utils
|
||||
|
||||
## [1.1.18](https://github.com/medusajs/medusa/compare/medusa-test-utils@1.1.17...medusa-test-utils@1.1.18) (2021-06-22)
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
- release assist ([668e8a7](https://github.com/medusajs/medusa/commit/668e8a740200847fc2a41c91d2979097f1392532))
|
||||
|
||||
## [1.1.17](https://github.com/medusajs/medusa/compare/medusa-test-utils@1.1.16...medusa-test-utils@1.1.17) (2021-06-09)
|
||||
|
||||
**Note:** Version bump only for package medusa-test-utils
|
||||
|
||||
## [1.1.16](https://github.com/medusajs/medusa/compare/medusa-test-utils@1.1.15...medusa-test-utils@1.1.16) (2021-06-09)
|
||||
|
||||
**Note:** Version bump only for package medusa-test-utils
|
||||
|
||||
## [1.1.15](https://github.com/medusajs/medusa/compare/medusa-test-utils@1.1.14...medusa-test-utils@1.1.15) (2021-06-09)
|
||||
|
||||
**Note:** Version bump only for package medusa-test-utils
|
||||
|
||||
## [1.1.14](https://github.com/medusajs/medusa/compare/medusa-test-utils@1.1.13...medusa-test-utils@1.1.14) (2021-06-09)
|
||||
|
||||
**Note:** Version bump only for package medusa-test-utils
|
||||
|
||||
## [1.1.13](https://github.com/medusajs/medusa/compare/medusa-test-utils@1.1.12...medusa-test-utils@1.1.13) (2021-06-08)
|
||||
|
||||
**Note:** Version bump only for package medusa-test-utils
|
||||
|
||||
## [1.1.12](https://github.com/medusajs/medusa/compare/medusa-test-utils@1.1.9...medusa-test-utils@1.1.12) (2021-04-28)
|
||||
|
||||
**Note:** Version bump only for package medusa-test-utils
|
||||
|
||||
## [1.1.11](https://github.com/medusajs/medusa/compare/medusa-test-utils@1.1.10...medusa-test-utils@1.1.11) (2021-04-20)
|
||||
|
||||
**Note:** Version bump only for package medusa-test-utils
|
||||
|
||||
## [1.1.10](https://github.com/medusajs/medusa/compare/medusa-test-utils@1.1.9...medusa-test-utils@1.1.10) (2021-04-20)
|
||||
|
||||
**Note:** Version bump only for package medusa-test-utils
|
||||
|
||||
## [1.1.9](https://github.com/medusajs/medusa/compare/medusa-test-utils@1.1.8...medusa-test-utils@1.1.9) (2021-04-13)
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
- adds tests ([69442a1](https://github.com/medusajs/medusa/commit/69442a1735193aeb010043f114d89037d4d76279))
|
||||
- merge develop ([a468c45](https://github.com/medusajs/medusa/commit/a468c451e82c68f41b5005a2e480057f6124aaa6))
|
||||
|
||||
## [1.1.8](https://github.com/medusajs/medusa/compare/medusa-test-utils@1.1.7...medusa-test-utils@1.1.8) (2021-04-13)
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
- adds tests ([69442a1](https://github.com/medusajs/medusa/commit/69442a1735193aeb010043f114d89037d4d76279))
|
||||
|
||||
## [1.1.7](https://github.com/medusajs/medusa/compare/medusa-test-utils@1.1.6...medusa-test-utils@1.1.7) (2021-03-30)
|
||||
|
||||
**Note:** Version bump only for package medusa-test-utils
|
||||
|
||||
## [1.1.6](https://github.com/medusajs/medusa/compare/medusa-test-utils@1.1.5...medusa-test-utils@1.1.6) (2021-03-17)
|
||||
|
||||
**Note:** Version bump only for package medusa-test-utils
|
||||
|
||||
## [1.1.5](https://github.com/medusajs/medusa/compare/medusa-test-utils@1.1.3...medusa-test-utils@1.1.5) (2021-03-17)
|
||||
|
||||
**Note:** Version bump only for package medusa-test-utils
|
||||
|
||||
## [1.1.4](https://github.com/medusajs/medusa/compare/medusa-test-utils@1.1.3...medusa-test-utils@1.1.4) (2021-03-17)
|
||||
|
||||
**Note:** Version bump only for package medusa-test-utils
|
||||
|
||||
## [1.1.3](https://github.com/medusajs/medusa/compare/medusa-test-utils@1.1.2...medusa-test-utils@1.1.3) (2021-02-17)
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
- use parallel relation fetching ([#173](https://github.com/medusajs/medusa/issues/173)) ([46006e4](https://github.com/medusajs/medusa/commit/46006e4b0647bada1dc2cb417766e22f65bad23e))
|
||||
|
||||
## [1.1.2](https://github.com/medusajs/medusa/compare/medusa-test-utils@1.1.1...medusa-test-utils@1.1.2) (2021-02-03)
|
||||
|
||||
### Features
|
||||
|
||||
- **medusa,brightpearl,segment,webshipper:** claims ([#163](https://github.com/medusajs/medusa/issues/163)) ([690d339](https://github.com/medusajs/medusa/commit/690d33966754a7dbe159c3ac09712a3c3bfaff0b))
|
||||
|
||||
## [1.1.1](https://github.com/medusajs/medusa/compare/medusa-test-utils@1.1.0...medusa-test-utils@1.1.1) (2021-01-27)
|
||||
|
||||
### Features
|
||||
|
||||
- adds discount code search functionality ([#155](https://github.com/medusajs/medusa/issues/155)) ([7e14da1](https://github.com/medusajs/medusa/commit/7e14da1225983dd58faabbd6d555818277ad4cc8))
|
||||
|
||||
# [1.1.0](https://github.com/medusajs/medusa/compare/medusa-test-utils@1.0.13...medusa-test-utils@1.1.0) (2021-01-26)
|
||||
|
||||
**Note:** Version bump only for package medusa-test-utils
|
||||
|
||||
## [1.0.13](https://github.com/medusajs/medusa/compare/medusa-test-utils@1.0.12...medusa-test-utils@1.0.13) (2020-12-17)
|
||||
|
||||
**Note:** Version bump only for package medusa-test-utils
|
||||
|
||||
## [1.0.12](https://github.com/medusajs/medusa/compare/medusa-test-utils@1.0.11...medusa-test-utils@1.0.12) (2020-11-24)
|
||||
|
||||
**Note:** Version bump only for package medusa-test-utils
|
||||
|
||||
## 1.0.11 (2020-10-19)
|
||||
|
||||
## 1.0.10 (2020-09-09)
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
- updates license ([db519fb](https://github.com/medusajs/medusa/commit/db519fbaa6f8ad02c19cbecba5d4f28ba1ee81aa))
|
||||
|
||||
## 1.0.7 (2020-09-07)
|
||||
|
||||
## 1.0.1 (2020-09-05)
|
||||
|
||||
## 1.0.1-beta.0 (2020-09-04)
|
||||
|
||||
# 1.0.0 (2020-09-03)
|
||||
|
||||
# 1.0.0-alpha.30 (2020-08-28)
|
||||
|
||||
# 1.0.0-alpha.27 (2020-08-27)
|
||||
|
||||
# 1.0.0-alpha.24 (2020-08-27)
|
||||
|
||||
# 1.0.0-alpha.3 (2020-08-20)
|
||||
|
||||
# 1.0.0-alpha.2 (2020-08-20)
|
||||
|
||||
# 1.0.0-alpha.1 (2020-08-20)
|
||||
|
||||
# 1.0.0-alpha.0 (2020-08-20)
|
||||
|
||||
# 0.3.0 (2020-04-06)
|
||||
|
||||
# 0.2.0 (2020-04-06)
|
||||
|
||||
# 0.2.0-alpha.0 (2020-04-04)
|
||||
|
||||
## 0.1.6-alpha.0 (2020-03-24)
|
||||
|
||||
## 0.1.5-alpha.0 (2020-03-24)
|
||||
|
||||
## 0.1.4-alpha.0 (2020-03-24)
|
||||
|
||||
## 0.1.3-alpha.0 (2020-03-24)
|
||||
|
||||
## 0.1.2-alpha.0 (2020-03-24)
|
||||
|
||||
## 0.1.1-alpha.0 (2020-03-24)
|
||||
|
||||
# 0.1.0-alpha.0 (2020-03-24)
|
||||
|
||||
## [1.0.10](https://github.com/medusajs/medusa/compare/v1.0.9...v1.0.10) (2020-09-09)
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
- updates license ([db519fb](https://github.com/medusajs/medusa/commit/db519fbaa6f8ad02c19cbecba5d4f28ba1ee81aa))
|
||||
@@ -1,60 +0,0 @@
|
||||
{
|
||||
"name": "medusa-test-utils",
|
||||
"version": "1.1.44",
|
||||
"description": "Test utils for Medusa",
|
||||
"main": "dist/index.js",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/medusajs/medusa",
|
||||
"directory": "packages/medusa-test-utils"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=20"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "rimraf dist && tsc --build",
|
||||
"watch": "tsc --build --watch",
|
||||
"test": "jest --passWithNoTests src"
|
||||
},
|
||||
"files": [
|
||||
"dist",
|
||||
"!dist/**/__tests__",
|
||||
"!dist/**/__mocks__",
|
||||
"!dist/**/__fixtures__"
|
||||
],
|
||||
"author": "Medusa",
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"@medusajs/framework": "^0.0.1",
|
||||
"@mikro-orm/core": "5.9.7",
|
||||
"@mikro-orm/knex": "5.9.7",
|
||||
"@mikro-orm/migrations": "5.9.7",
|
||||
"@mikro-orm/postgresql": "5.9.7",
|
||||
"awilix": "^8.0.1",
|
||||
"bignumber.js": "^9.1.2",
|
||||
"express": "^4.18.3",
|
||||
"ioredis": "^5.4.1",
|
||||
"jest": "^29.7.0",
|
||||
"pg": "^8.13.0",
|
||||
"pg-god": "^1.0.12",
|
||||
"rimraf": "^3.0.2",
|
||||
"typescript": "^5.6.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"axios": "^0.21.4",
|
||||
"get-port": "^5.1.0",
|
||||
"randomatic": "^3.1.1"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@medusajs/framework": "^0.0.1",
|
||||
"@medusajs/medusa": "^1.20.5",
|
||||
"@mikro-orm/postgresql": "5.9.7",
|
||||
"awilix": "^8.0.1"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"@medusajs/medusa": {
|
||||
"optional": true
|
||||
}
|
||||
},
|
||||
"gitHead": "81a7ff73d012fda722f6e9ef0bd9ba0232d37808"
|
||||
}
|
||||
@@ -1,214 +0,0 @@
|
||||
import { MikroORM, Options, SqlEntityManager } from "@mikro-orm/postgresql"
|
||||
import { createDatabase, dropDatabase } from "pg-god"
|
||||
|
||||
const DB_HOST = process.env.DB_HOST ?? "localhost"
|
||||
const DB_USERNAME = process.env.DB_USERNAME ?? ""
|
||||
const DB_PASSWORD = process.env.DB_PASSWORD ?? ""
|
||||
|
||||
const pgGodCredentials = {
|
||||
user: DB_USERNAME,
|
||||
password: DB_PASSWORD,
|
||||
host: DB_HOST,
|
||||
}
|
||||
|
||||
export function getDatabaseURL(dbName?: string): string {
|
||||
const DB_HOST = process.env.DB_HOST ?? "localhost"
|
||||
const DB_USERNAME = process.env.DB_USERNAME ?? ""
|
||||
const DB_PASSWORD = process.env.DB_PASSWORD
|
||||
const DB_NAME = dbName ?? process.env.DB_TEMP_NAME
|
||||
|
||||
return `postgres://${DB_USERNAME}${
|
||||
DB_PASSWORD ? `:${DB_PASSWORD}` : ""
|
||||
}@${DB_HOST}/${DB_NAME}`
|
||||
}
|
||||
|
||||
export function getMikroOrmConfig({
|
||||
mikroOrmEntities,
|
||||
pathToMigrations,
|
||||
clientUrl,
|
||||
schema,
|
||||
}: {
|
||||
mikroOrmEntities: any[]
|
||||
pathToMigrations?: string
|
||||
clientUrl?: string
|
||||
schema?: string
|
||||
}): Options {
|
||||
const DB_URL = clientUrl ?? getDatabaseURL()
|
||||
|
||||
return {
|
||||
type: "postgresql",
|
||||
clientUrl: DB_URL,
|
||||
entities: Object.values(mikroOrmEntities),
|
||||
schema: schema ?? process.env.MEDUSA_DB_SCHEMA,
|
||||
debug: false,
|
||||
pool: {
|
||||
min: 2,
|
||||
},
|
||||
migrations: {
|
||||
pathTs: pathToMigrations,
|
||||
silent: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
export interface TestDatabase {
|
||||
mikroOrmEntities: any[]
|
||||
pathToMigrations?: string
|
||||
schema?: string
|
||||
clientUrl?: string
|
||||
|
||||
orm: MikroORM | null
|
||||
manager: SqlEntityManager | null
|
||||
|
||||
setupDatabase(): Promise<void>
|
||||
clearDatabase(): Promise<void>
|
||||
getManager(): SqlEntityManager
|
||||
forkManager(): SqlEntityManager
|
||||
getOrm(): MikroORM
|
||||
}
|
||||
|
||||
export function getMikroOrmWrapper({
|
||||
mikroOrmEntities,
|
||||
pathToMigrations,
|
||||
clientUrl,
|
||||
schema,
|
||||
}: {
|
||||
mikroOrmEntities: any[]
|
||||
pathToMigrations?: string
|
||||
clientUrl?: string
|
||||
schema?: string
|
||||
}): TestDatabase {
|
||||
return {
|
||||
mikroOrmEntities,
|
||||
pathToMigrations,
|
||||
clientUrl: clientUrl ?? getDatabaseURL(),
|
||||
schema: schema ?? process.env.MEDUSA_DB_SCHEMA,
|
||||
|
||||
orm: null,
|
||||
manager: null,
|
||||
|
||||
getManager() {
|
||||
if (this.manager === null) {
|
||||
throw new Error("manager entity not available")
|
||||
}
|
||||
|
||||
return this.manager
|
||||
},
|
||||
|
||||
forkManager() {
|
||||
if (this.manager === null) {
|
||||
throw new Error("manager entity not available")
|
||||
}
|
||||
|
||||
return this.manager.fork()
|
||||
},
|
||||
|
||||
getOrm() {
|
||||
if (this.orm === null) {
|
||||
throw new Error("orm entity not available")
|
||||
}
|
||||
|
||||
return this.orm
|
||||
},
|
||||
|
||||
async setupDatabase() {
|
||||
const OrmConfig = getMikroOrmConfig({
|
||||
mikroOrmEntities: this.mikroOrmEntities,
|
||||
pathToMigrations: this.pathToMigrations,
|
||||
clientUrl: this.clientUrl,
|
||||
schema: this.schema,
|
||||
})
|
||||
|
||||
// Initializing the ORM
|
||||
this.orm = await MikroORM.init(OrmConfig)
|
||||
|
||||
this.manager = this.orm.em
|
||||
|
||||
try {
|
||||
await this.orm.getSchemaGenerator().ensureDatabase()
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
}
|
||||
|
||||
await this.manager?.execute(
|
||||
`CREATE SCHEMA IF NOT EXISTS "${this.schema ?? "public"}";`
|
||||
)
|
||||
|
||||
const pendingMigrations = await this.orm
|
||||
.getMigrator()
|
||||
.getPendingMigrations()
|
||||
|
||||
if (pendingMigrations && pendingMigrations.length > 0) {
|
||||
await this.orm
|
||||
.getMigrator()
|
||||
.up({ migrations: pendingMigrations.map((m) => m.name!) })
|
||||
} else {
|
||||
await this.orm.schema.refreshDatabase() // ensure db exists and is fresh
|
||||
}
|
||||
},
|
||||
|
||||
async clearDatabase() {
|
||||
if (this.orm === null) {
|
||||
throw new Error("ORM not configured")
|
||||
}
|
||||
|
||||
await this.manager?.execute(
|
||||
`DROP SCHEMA IF EXISTS "${this.schema ?? "public"}" CASCADE;`
|
||||
)
|
||||
|
||||
await this.manager?.execute(
|
||||
`CREATE SCHEMA IF NOT EXISTS "${this.schema ?? "public"}";`
|
||||
)
|
||||
|
||||
try {
|
||||
await this.orm.close()
|
||||
} catch {}
|
||||
|
||||
this.orm = null
|
||||
this.manager = null
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
export const dbTestUtilFactory = (): any => ({
|
||||
pgConnection_: null,
|
||||
|
||||
create: async function (dbName: string) {
|
||||
await createDatabase(
|
||||
{ databaseName: dbName, errorIfExist: false },
|
||||
pgGodCredentials
|
||||
)
|
||||
},
|
||||
|
||||
teardown: async function ({ schema }: { schema?: string } = {}) {
|
||||
if (!this.pgConnection_) {
|
||||
return
|
||||
}
|
||||
|
||||
const runRawQuery = this.pgConnection_.raw.bind(this.pgConnection_)
|
||||
|
||||
schema ??= "public"
|
||||
|
||||
await runRawQuery(`SET session_replication_role = 'replica';`)
|
||||
const { rows: tableNames } = await runRawQuery(`SELECT table_name
|
||||
FROM information_schema.tables
|
||||
WHERE table_schema = '${schema}';`)
|
||||
|
||||
for (const { table_name } of tableNames) {
|
||||
await runRawQuery(`DELETE
|
||||
FROM ${schema}."${table_name}";`)
|
||||
}
|
||||
|
||||
await runRawQuery(`SET session_replication_role = 'origin';`)
|
||||
},
|
||||
|
||||
shutdown: async function (dbName: string) {
|
||||
await this.pgConnection_?.context?.destroy()
|
||||
await this.pgConnection_?.destroy()
|
||||
|
||||
return await dropDatabase(
|
||||
{ databaseName: dbName, errorIfNonExist: false },
|
||||
pgGodCredentials
|
||||
)
|
||||
},
|
||||
})
|
||||
@@ -1,47 +0,0 @@
|
||||
import { IEventBusModuleService } from "@medusajs/framework/types"
|
||||
import { EventEmitter } from "events"
|
||||
|
||||
// Allows you to wait for all subscribers to execute for a given event. Only works with the local event bus.
|
||||
export const waitSubscribersExecution = (
|
||||
eventName: string,
|
||||
eventBus: IEventBusModuleService
|
||||
) => {
|
||||
const eventEmitter: EventEmitter = (eventBus as any).eventEmitter_
|
||||
const subscriberPromises: Promise<any>[] = []
|
||||
const originalListeners = eventEmitter.listeners(eventName)
|
||||
|
||||
// If there are no existing listeners, resolve once the event happens. Otherwise, wrap the existing subscribers in a promise and resolve once they are done.
|
||||
if (!eventEmitter.listeners(eventName).length) {
|
||||
let ok
|
||||
const promise = new Promise((resolve) => {
|
||||
ok = resolve
|
||||
})
|
||||
|
||||
subscriberPromises.push(promise)
|
||||
eventEmitter.on(eventName, ok)
|
||||
} else {
|
||||
eventEmitter.listeners(eventName).forEach((listener: any) => {
|
||||
eventEmitter.removeListener(eventName, listener)
|
||||
|
||||
let ok, nok
|
||||
const promise = new Promise((resolve, reject) => {
|
||||
ok = resolve
|
||||
nok = reject
|
||||
})
|
||||
subscriberPromises.push(promise)
|
||||
|
||||
const newListener = async (...args2) => {
|
||||
return await listener.apply(eventBus, args2).then(ok).catch(nok)
|
||||
}
|
||||
|
||||
eventEmitter.on(eventName, newListener)
|
||||
})
|
||||
}
|
||||
|
||||
return Promise.all(subscriberPromises).finally(() => {
|
||||
eventEmitter.removeAllListeners(eventName)
|
||||
originalListeners.forEach((listener) => {
|
||||
eventEmitter.on(eventName, listener as (...args: any) => void)
|
||||
})
|
||||
})
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
import randomize from "randomatic"
|
||||
|
||||
class IdMap {
|
||||
ids = {}
|
||||
|
||||
getId(key, prefix = "", length = 10) {
|
||||
if (this.ids[key]) {
|
||||
return this.ids[key]
|
||||
}
|
||||
|
||||
const id = `${prefix && prefix + "_"}${randomize("Aa0", length)}`
|
||||
this.ids[key] = id
|
||||
|
||||
return id
|
||||
}
|
||||
}
|
||||
|
||||
const instance = new IdMap()
|
||||
export default instance
|
||||
@@ -1,9 +0,0 @@
|
||||
export * as TestDatabaseUtils from "./database"
|
||||
export * as TestEventUtils from "./events"
|
||||
export { default as IdMap } from "./id-map"
|
||||
export * from "./init-modules"
|
||||
export * as JestUtils from "./jest"
|
||||
export * from "./medusa-test-runner"
|
||||
export * from "./medusa-test-runner-utils/"
|
||||
export { default as MockEventBusService } from "./mock-event-bus-service"
|
||||
export * from "./module-test-runner"
|
||||
@@ -1,84 +0,0 @@
|
||||
import {
|
||||
ExternalModuleDeclaration,
|
||||
InternalModuleDeclaration,
|
||||
ModuleJoinerConfig,
|
||||
} from "@medusajs/framework/types"
|
||||
import {
|
||||
ContainerRegistrationKeys,
|
||||
createPgConnection,
|
||||
promiseAll,
|
||||
} from "@medusajs/framework/utils"
|
||||
|
||||
export interface InitModulesOptions {
|
||||
injectedDependencies?: Record<string, unknown>
|
||||
databaseConfig: {
|
||||
clientUrl: string
|
||||
schema?: string
|
||||
}
|
||||
modulesConfig: {
|
||||
[key: string]:
|
||||
| string
|
||||
| boolean
|
||||
| Partial<InternalModuleDeclaration | ExternalModuleDeclaration>
|
||||
}
|
||||
joinerConfig?: ModuleJoinerConfig[]
|
||||
preventConnectionDestroyWarning?: boolean
|
||||
}
|
||||
|
||||
export async function initModules({
|
||||
injectedDependencies,
|
||||
databaseConfig,
|
||||
modulesConfig,
|
||||
joinerConfig,
|
||||
preventConnectionDestroyWarning = false,
|
||||
}: InitModulesOptions) {
|
||||
const moduleSdkImports = require("@medusajs/framework/modules-sdk")
|
||||
|
||||
injectedDependencies ??= {}
|
||||
|
||||
let sharedPgConnection =
|
||||
injectedDependencies?.[ContainerRegistrationKeys.PG_CONNECTION]
|
||||
|
||||
let shouldDestroyConnectionAutomatically = !sharedPgConnection
|
||||
if (!sharedPgConnection) {
|
||||
sharedPgConnection = createPgConnection({
|
||||
clientUrl: databaseConfig.clientUrl,
|
||||
schema: databaseConfig.schema,
|
||||
})
|
||||
|
||||
injectedDependencies[ContainerRegistrationKeys.PG_CONNECTION] =
|
||||
sharedPgConnection
|
||||
}
|
||||
|
||||
const medusaApp = await moduleSdkImports.MedusaApp({
|
||||
modulesConfig,
|
||||
servicesConfig: joinerConfig,
|
||||
injectedDependencies,
|
||||
})
|
||||
|
||||
await medusaApp.onApplicationStart()
|
||||
|
||||
async function shutdown() {
|
||||
if (shouldDestroyConnectionAutomatically) {
|
||||
await medusaApp.onApplicationPrepareShutdown()
|
||||
|
||||
await promiseAll([
|
||||
(sharedPgConnection as any).context?.destroy(),
|
||||
(sharedPgConnection as any).destroy(),
|
||||
medusaApp.onApplicationShutdown(),
|
||||
])
|
||||
} else {
|
||||
if (!preventConnectionDestroyWarning) {
|
||||
console.info(
|
||||
`You are using a custom shared connection. The connection won't be destroyed automatically.`
|
||||
)
|
||||
}
|
||||
}
|
||||
moduleSdkImports.MedusaModule.clearInstances()
|
||||
}
|
||||
|
||||
return {
|
||||
medusaApp,
|
||||
shutdown,
|
||||
}
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
import { dropDatabase } from "pg-god"
|
||||
|
||||
export function afterAllHookDropDatabase() {
|
||||
const DB_HOST = process.env.DB_HOST ?? "localhost"
|
||||
const DB_USERNAME = process.env.DB_USERNAME ?? "postgres"
|
||||
const DB_PASSWORD = process.env.DB_PASSWORD ?? ""
|
||||
const DB_NAME = process.env.DB_TEMP_NAME || ""
|
||||
|
||||
const pgGodCredentials = {
|
||||
user: DB_USERNAME,
|
||||
password: DB_PASSWORD,
|
||||
host: DB_HOST,
|
||||
}
|
||||
|
||||
afterAll(async () => {
|
||||
try {
|
||||
await dropDatabase({ databaseName: DB_NAME }, pgGodCredentials)
|
||||
} catch (e) {
|
||||
console.error(
|
||||
`This might fail if it is run during the unit tests since there is no database to drop. Otherwise, please check what is the issue. ${e.message}`
|
||||
)
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -1,80 +0,0 @@
|
||||
import express from "express"
|
||||
import getPort from "get-port"
|
||||
import { resolve } from "path"
|
||||
import { MedusaContainer } from "@medusajs/framework/types"
|
||||
import { applyEnvVarsToProcess } from "./utils"
|
||||
import { promiseAll, GracefulShutdownServer } from "@medusajs/framework/utils"
|
||||
|
||||
async function bootstrapApp({
|
||||
cwd,
|
||||
env = {},
|
||||
}: { cwd?: string; env?: Record<any, any> } = {}) {
|
||||
const app = express()
|
||||
applyEnvVarsToProcess(env)
|
||||
|
||||
const loaders = require("@medusajs/medusa/dist/loaders").default
|
||||
|
||||
const { container, shutdown } = await loaders({
|
||||
directory: resolve(cwd || process.cwd()),
|
||||
expressApp: app,
|
||||
})
|
||||
|
||||
const PORT = process.env.PORT ? parseInt(process.env.PORT) : await getPort()
|
||||
|
||||
return {
|
||||
shutdown,
|
||||
container,
|
||||
app,
|
||||
port: PORT,
|
||||
}
|
||||
}
|
||||
|
||||
export async function startApp({
|
||||
cwd,
|
||||
env = {},
|
||||
}: { cwd?: string; env?: Record<any, any> } = {}): Promise<{
|
||||
shutdown: () => Promise<void>
|
||||
container: MedusaContainer
|
||||
port: number
|
||||
}> {
|
||||
const {
|
||||
app,
|
||||
port,
|
||||
container,
|
||||
shutdown: medusaShutdown,
|
||||
} = await bootstrapApp({
|
||||
cwd,
|
||||
env,
|
||||
})
|
||||
|
||||
let expressServer
|
||||
|
||||
const shutdown = async () => {
|
||||
await promiseAll([expressServer?.shutdown(), medusaShutdown()])
|
||||
|
||||
if (typeof global !== "undefined" && global?.gc) {
|
||||
global.gc()
|
||||
}
|
||||
}
|
||||
|
||||
return await new Promise((resolve, reject) => {
|
||||
const server = app
|
||||
.listen(port)
|
||||
.on("error", async (err) => {
|
||||
await shutdown()
|
||||
return reject(err)
|
||||
})
|
||||
.on("listening", () => {
|
||||
process.send?.(port)
|
||||
|
||||
resolve({
|
||||
shutdown,
|
||||
container,
|
||||
port,
|
||||
})
|
||||
})
|
||||
|
||||
// TODO: fix that once we find the appropriate place to put this util
|
||||
expressServer = GracefulShutdownServer.create(server)
|
||||
})
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
/**
|
||||
* cleanup temporary created resources for the migrations
|
||||
* @internal I didnt find a god place to put that, should we eventually add a close function
|
||||
* to the planner to handle that part? so that you would do planner.close() and it will handle the cleanup
|
||||
* automatically just like we usually do for the classic migrations actions
|
||||
*/
|
||||
export async function clearInstances() {
|
||||
const { MedusaModule } = require("@medusajs/framework/modules-sdk")
|
||||
MedusaModule.clearInstances()
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
import { getConfigFile } from "@medusajs/framework/utils"
|
||||
|
||||
export async function configLoaderOverride(
|
||||
entryDirectory: string,
|
||||
override: { clientUrl: string; debug?: boolean }
|
||||
) {
|
||||
const { configManager } = await import("@medusajs/framework/config")
|
||||
const { configModule, error } = getConfigFile<
|
||||
ReturnType<typeof configManager.loadConfig>
|
||||
>(entryDirectory, "medusa-config.js")
|
||||
|
||||
if (error) {
|
||||
throw new Error(error.message || "Error during config loading")
|
||||
}
|
||||
|
||||
configModule.projectConfig.databaseDriverOptions
|
||||
configModule.projectConfig.databaseUrl = override.clientUrl
|
||||
configModule.projectConfig.databaseLogging = !!override.debug
|
||||
configModule.projectConfig.databaseDriverOptions =
|
||||
override.clientUrl.includes("localhost")
|
||||
? {}
|
||||
: {
|
||||
connection: {
|
||||
ssl: { rejectUnauthorized: false },
|
||||
},
|
||||
idle_in_transaction_session_timeout: 20000,
|
||||
}
|
||||
|
||||
configManager.loadConfig({
|
||||
projectConfig: configModule,
|
||||
baseDir: entryDirectory,
|
||||
})
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
export * from "./bootstrap-app"
|
||||
export * from "./clear-instances"
|
||||
export * from "./config"
|
||||
export * from "./use-db"
|
||||
export * from "./utils"
|
||||
@@ -1,72 +0,0 @@
|
||||
import type { MedusaAppLoader } from "@medusajs/framework"
|
||||
import { join } from "path"
|
||||
import { MedusaContainer } from "@medusajs/framework/types"
|
||||
import { ContainerRegistrationKeys } from "@medusajs/framework/utils"
|
||||
|
||||
/**
|
||||
* Initiates the database connection
|
||||
*/
|
||||
export async function initDb() {
|
||||
const { pgConnectionLoader, featureFlagsLoader } = await import(
|
||||
"@medusajs/framework"
|
||||
)
|
||||
|
||||
const pgConnection = pgConnectionLoader()
|
||||
await featureFlagsLoader()
|
||||
|
||||
return pgConnection
|
||||
}
|
||||
|
||||
/**
|
||||
* Migrates the database
|
||||
*/
|
||||
export async function migrateDatabase(appLoader: MedusaAppLoader) {
|
||||
try {
|
||||
await appLoader.runModulesMigrations()
|
||||
} catch (err) {
|
||||
console.error("Something went wrong while running the migrations")
|
||||
throw err
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Syncs links with the databse
|
||||
*/
|
||||
export async function syncLinks(
|
||||
appLoader: MedusaAppLoader,
|
||||
directory: string,
|
||||
container: MedusaContainer
|
||||
) {
|
||||
try {
|
||||
await loadCustomLinks(directory, container)
|
||||
|
||||
const planner = await appLoader.getLinksExecutionPlanner()
|
||||
const actionPlan = await planner.createPlan()
|
||||
actionPlan.forEach((action) => {
|
||||
console.log(`Sync links: "${action.action}" ${action.tableName}`)
|
||||
})
|
||||
await planner.executePlan(actionPlan)
|
||||
} catch (err) {
|
||||
console.error("Something went wrong while syncing links")
|
||||
throw err
|
||||
}
|
||||
}
|
||||
|
||||
async function loadCustomLinks(directory: string, container: MedusaContainer) {
|
||||
// TODO: move to framework once settle down
|
||||
const { getResolvedPlugins } = await import(
|
||||
// @ts-expect-error
|
||||
"@medusajs/medusa/dist/loaders/helpers/resolve-plugins"
|
||||
)
|
||||
|
||||
const configModule = container.resolve(
|
||||
ContainerRegistrationKeys.CONFIG_MODULE
|
||||
)
|
||||
const plugins = getResolvedPlugins(directory, configModule, true) || []
|
||||
const linksSourcePaths = plugins.map((plugin) =>
|
||||
join(plugin.resolve, "links")
|
||||
)
|
||||
|
||||
const { LinkLoader } = await import("@medusajs/framework")
|
||||
await new LinkLoader(linksSourcePaths).load()
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
import { isObject } from "@medusajs/framework/utils"
|
||||
|
||||
export function applyEnvVarsToProcess(env?: Record<any, any>) {
|
||||
if (isObject(env)) {
|
||||
Object.entries(env).forEach(([k, v]) => (process.env[k] = v))
|
||||
}
|
||||
}
|
||||
@@ -1,223 +0,0 @@
|
||||
import { MedusaAppOutput } from "@medusajs/framework/modules-sdk"
|
||||
import { ContainerLike, MedusaContainer } from "@medusajs/framework/types"
|
||||
import {
|
||||
ContainerRegistrationKeys,
|
||||
createMedusaContainer,
|
||||
} from "@medusajs/framework/utils"
|
||||
import { asValue } from "awilix"
|
||||
import { dbTestUtilFactory, getDatabaseURL } from "./database"
|
||||
import {
|
||||
applyEnvVarsToProcess,
|
||||
clearInstances,
|
||||
configLoaderOverride,
|
||||
initDb,
|
||||
migrateDatabase,
|
||||
startApp,
|
||||
syncLinks,
|
||||
} from "./medusa-test-runner-utils"
|
||||
|
||||
export interface MedusaSuiteOptions {
|
||||
dbConnection: any // knex instance
|
||||
getContainer: () => MedusaContainer
|
||||
api: any
|
||||
dbUtils: {
|
||||
create: (dbName: string) => Promise<void>
|
||||
teardown: (options: { schema?: string }) => Promise<void>
|
||||
shutdown: (dbName: string) => Promise<void>
|
||||
}
|
||||
dbConfig: {
|
||||
dbName: string
|
||||
schema: string
|
||||
clientUrl: string
|
||||
}
|
||||
getMedusaApp: () => MedusaAppOutput
|
||||
}
|
||||
|
||||
export function medusaIntegrationTestRunner({
|
||||
moduleName,
|
||||
dbName,
|
||||
medusaConfigFile,
|
||||
schema = "public",
|
||||
env = {},
|
||||
debug = false,
|
||||
inApp = false,
|
||||
testSuite,
|
||||
}: {
|
||||
moduleName?: string
|
||||
env?: Record<string, any>
|
||||
dbName?: string
|
||||
medusaConfigFile?: string
|
||||
schema?: string
|
||||
debug?: boolean
|
||||
inApp?: boolean
|
||||
testSuite: (options: MedusaSuiteOptions) => void
|
||||
}) {
|
||||
const tempName = parseInt(process.env.JEST_WORKER_ID || "1")
|
||||
moduleName = moduleName ?? Math.random().toString(36).substring(7)
|
||||
dbName ??= `medusa-${moduleName.toLowerCase()}-integration-${tempName}`
|
||||
|
||||
let dbConfig = {
|
||||
dbName,
|
||||
clientUrl: getDatabaseURL(dbName),
|
||||
schema,
|
||||
debug,
|
||||
}
|
||||
|
||||
const cwd = medusaConfigFile ?? process.cwd()
|
||||
|
||||
let shutdown = async () => void 0
|
||||
const dbUtils = dbTestUtilFactory()
|
||||
let globalContainer: ContainerLike
|
||||
let apiUtils: any
|
||||
let loadedApplication: any
|
||||
|
||||
let options = {
|
||||
api: new Proxy(
|
||||
{},
|
||||
{
|
||||
get: (target, prop) => {
|
||||
return apiUtils[prop]
|
||||
},
|
||||
}
|
||||
),
|
||||
dbConnection: new Proxy(
|
||||
{},
|
||||
{
|
||||
get: (target, prop) => {
|
||||
return dbUtils.pgConnection_[prop]
|
||||
},
|
||||
}
|
||||
),
|
||||
getMedusaApp: () => loadedApplication,
|
||||
getContainer: () => globalContainer,
|
||||
dbConfig: {
|
||||
dbName,
|
||||
schema,
|
||||
clientUrl: dbConfig.clientUrl,
|
||||
},
|
||||
dbUtils,
|
||||
} as MedusaSuiteOptions
|
||||
|
||||
let isFirstTime = true
|
||||
|
||||
const beforeAll_ = async () => {
|
||||
await configLoaderOverride(cwd, dbConfig)
|
||||
applyEnvVarsToProcess(env)
|
||||
|
||||
const { logger, container, MedusaAppLoader } = await import(
|
||||
"@medusajs/framework"
|
||||
)
|
||||
|
||||
const appLoader = new MedusaAppLoader()
|
||||
container.register({
|
||||
[ContainerRegistrationKeys.LOGGER]: asValue(logger),
|
||||
})
|
||||
|
||||
try {
|
||||
console.log(`Creating database ${dbName}`)
|
||||
await dbUtils.create(dbName)
|
||||
dbUtils.pgConnection_ = await initDb()
|
||||
} catch (error) {
|
||||
console.error("Error initializing database", error?.message)
|
||||
throw error
|
||||
}
|
||||
|
||||
console.log(`Migrating database with core migrations and links ${dbName}`)
|
||||
await migrateDatabase(appLoader)
|
||||
await syncLinks(appLoader, cwd, container)
|
||||
await clearInstances()
|
||||
|
||||
let containerRes: MedusaContainer = container
|
||||
let serverShutdownRes: () => any
|
||||
let portRes: number
|
||||
|
||||
loadedApplication = await appLoader.load()
|
||||
|
||||
try {
|
||||
const {
|
||||
shutdown = () => void 0,
|
||||
container: appContainer,
|
||||
port,
|
||||
} = await startApp({
|
||||
cwd,
|
||||
env,
|
||||
})
|
||||
|
||||
containerRes = appContainer
|
||||
serverShutdownRes = shutdown
|
||||
portRes = port
|
||||
} catch (error) {
|
||||
console.error("Error starting the app", error?.message)
|
||||
throw error
|
||||
}
|
||||
|
||||
/**
|
||||
* Run application migrations and sync links when inside
|
||||
* an application
|
||||
*/
|
||||
if (inApp) {
|
||||
console.log(`Migrating database with core migrations and links ${dbName}`)
|
||||
await migrateDatabase(appLoader)
|
||||
await syncLinks(appLoader, cwd, containerRes)
|
||||
}
|
||||
|
||||
const { default: axios } = (await import("axios")) as any
|
||||
|
||||
const cancelTokenSource = axios.CancelToken.source()
|
||||
|
||||
globalContainer = containerRes
|
||||
shutdown = async () => {
|
||||
await serverShutdownRes()
|
||||
cancelTokenSource.cancel("Request canceled by shutdown")
|
||||
}
|
||||
|
||||
apiUtils = axios.create({
|
||||
baseURL: `http://localhost:${portRes}`,
|
||||
cancelToken: cancelTokenSource.token,
|
||||
})
|
||||
}
|
||||
|
||||
const beforeEach_ = async () => {
|
||||
// The beforeAll already run everything, so lets not re run the loaders for the first iteration
|
||||
if (isFirstTime) {
|
||||
isFirstTime = false
|
||||
return
|
||||
}
|
||||
|
||||
const container = options.getContainer()
|
||||
const copiedContainer = createMedusaContainer({}, container)
|
||||
|
||||
try {
|
||||
const { MedusaAppLoader } = await import("@medusajs/framework")
|
||||
|
||||
const medusaAppLoader = new MedusaAppLoader({
|
||||
container: copiedContainer,
|
||||
})
|
||||
await medusaAppLoader.runModulesLoader()
|
||||
} catch (error) {
|
||||
console.error("Error runner modules loaders", error?.message)
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
const afterEach_ = async () => {
|
||||
try {
|
||||
await dbUtils.teardown({ schema })
|
||||
} catch (error) {
|
||||
console.error("Error tearing down database:", error?.message)
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
return describe("", () => {
|
||||
beforeAll(beforeAll_)
|
||||
beforeEach(beforeEach_)
|
||||
afterEach(afterEach_)
|
||||
afterAll(async () => {
|
||||
await dbUtils.shutdown(dbName)
|
||||
await shutdown()
|
||||
})
|
||||
|
||||
testSuite(options!)
|
||||
})
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
import {
|
||||
EventBusTypes,
|
||||
IEventBusModuleService,
|
||||
Message,
|
||||
Subscriber,
|
||||
} from "@medusajs/framework/types"
|
||||
|
||||
export default class EventBusService implements IEventBusModuleService {
|
||||
async emit<T>(
|
||||
data: Message<T> | Message<T>[],
|
||||
options: Record<string, unknown>
|
||||
): Promise<void> {}
|
||||
|
||||
subscribe(event: string | symbol, subscriber: Subscriber): this {
|
||||
return this
|
||||
}
|
||||
|
||||
unsubscribe(
|
||||
event: string | symbol,
|
||||
subscriber: Subscriber,
|
||||
context?: EventBusTypes.SubscriberContext
|
||||
): this {
|
||||
return this
|
||||
}
|
||||
|
||||
releaseGroupedEvents(eventGroupId: string): Promise<void> {
|
||||
return Promise.resolve()
|
||||
}
|
||||
|
||||
clearGroupedEvents(eventGroupId: string): Promise<void> {
|
||||
return Promise.resolve()
|
||||
}
|
||||
}
|
||||
@@ -1,195 +0,0 @@
|
||||
import {
|
||||
ContainerRegistrationKeys,
|
||||
DmlEntity,
|
||||
loadModels,
|
||||
Modules,
|
||||
ModulesSdkUtils,
|
||||
normalizeImportPathWithSource,
|
||||
toMikroOrmEntities,
|
||||
} from "@medusajs/framework/utils"
|
||||
import * as fs from "fs"
|
||||
import { getDatabaseURL, getMikroOrmWrapper, TestDatabase } from "./database"
|
||||
import { initModules, InitModulesOptions } from "./init-modules"
|
||||
import { default as MockEventBusService } from "./mock-event-bus-service"
|
||||
|
||||
export interface SuiteOptions<TService = unknown> {
|
||||
MikroOrmWrapper: TestDatabase
|
||||
medusaApp: any
|
||||
service: TService
|
||||
dbConfig: {
|
||||
schema: string
|
||||
clientUrl: string
|
||||
}
|
||||
}
|
||||
|
||||
function createMikroOrmWrapper(options: {
|
||||
moduleModels?: (Function | DmlEntity<any, any>)[]
|
||||
resolve?: string
|
||||
dbConfig: any
|
||||
}): {
|
||||
MikroOrmWrapper: TestDatabase
|
||||
models: (Function | DmlEntity<any, any>)[]
|
||||
} {
|
||||
let moduleModels: (Function | DmlEntity<any, any>)[] =
|
||||
options.moduleModels ?? []
|
||||
|
||||
if (!options.moduleModels) {
|
||||
const basePath = normalizeImportPathWithSource(
|
||||
options.resolve ?? process.cwd()
|
||||
)
|
||||
|
||||
const modelsPath = fs.existsSync(`${basePath}/dist/models`)
|
||||
? "/dist/models"
|
||||
: fs.existsSync(`${basePath}/models`)
|
||||
? "/models"
|
||||
: ""
|
||||
|
||||
if (modelsPath) {
|
||||
moduleModels = loadModels(`${basePath}${modelsPath}`)
|
||||
} else {
|
||||
moduleModels = []
|
||||
}
|
||||
}
|
||||
|
||||
moduleModels = toMikroOrmEntities(moduleModels)
|
||||
|
||||
const MikroOrmWrapper = getMikroOrmWrapper({
|
||||
mikroOrmEntities: moduleModels,
|
||||
clientUrl: options.dbConfig.clientUrl,
|
||||
schema: options.dbConfig.schema,
|
||||
})
|
||||
|
||||
return { MikroOrmWrapper, models: moduleModels }
|
||||
}
|
||||
|
||||
export function moduleIntegrationTestRunner<TService = any>({
|
||||
moduleName,
|
||||
moduleModels,
|
||||
moduleOptions = {},
|
||||
moduleDependencies,
|
||||
joinerConfig = [],
|
||||
schema = "public",
|
||||
debug = false,
|
||||
testSuite,
|
||||
resolve,
|
||||
injectedDependencies = {},
|
||||
}: {
|
||||
moduleName: string
|
||||
moduleModels?: any[]
|
||||
moduleOptions?: Record<string, any>
|
||||
moduleDependencies?: string[]
|
||||
joinerConfig?: any[]
|
||||
schema?: string
|
||||
dbName?: string
|
||||
injectedDependencies?: Record<string, any>
|
||||
resolve?: string
|
||||
debug?: boolean
|
||||
testSuite: (options: SuiteOptions<TService>) => void
|
||||
}) {
|
||||
const moduleSdkImports = require("@medusajs/framework/modules-sdk")
|
||||
|
||||
process.env.LOG_LEVEL = "error"
|
||||
|
||||
const tempName = parseInt(process.env.JEST_WORKER_ID || "1")
|
||||
const dbName = `medusa-${moduleName.toLowerCase()}-integration-${tempName}`
|
||||
|
||||
const dbConfig = {
|
||||
clientUrl: getDatabaseURL(dbName),
|
||||
schema,
|
||||
debug,
|
||||
}
|
||||
|
||||
// Use a unique connection for all the entire suite
|
||||
const connection = ModulesSdkUtils.createPgConnection(dbConfig)
|
||||
|
||||
const { MikroOrmWrapper, models } = createMikroOrmWrapper({
|
||||
moduleModels,
|
||||
resolve,
|
||||
dbConfig,
|
||||
})
|
||||
|
||||
moduleModels = models
|
||||
|
||||
const modulesConfig_ = {
|
||||
[moduleName]: {
|
||||
definition: moduleSdkImports.ModulesDefinition[moduleName],
|
||||
resolve,
|
||||
dependencies: moduleDependencies,
|
||||
options: {
|
||||
database: dbConfig,
|
||||
...moduleOptions,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
const moduleOptions_: InitModulesOptions = {
|
||||
injectedDependencies: {
|
||||
[ContainerRegistrationKeys.PG_CONNECTION]: connection,
|
||||
[Modules.EVENT_BUS]: new MockEventBusService(),
|
||||
[ContainerRegistrationKeys.LOGGER]: console,
|
||||
...injectedDependencies,
|
||||
},
|
||||
modulesConfig: modulesConfig_,
|
||||
databaseConfig: dbConfig,
|
||||
joinerConfig,
|
||||
preventConnectionDestroyWarning: true,
|
||||
}
|
||||
|
||||
let shutdown: () => Promise<void>
|
||||
let moduleService
|
||||
let medusaApp = {}
|
||||
|
||||
const options = {
|
||||
MikroOrmWrapper,
|
||||
medusaApp: new Proxy(
|
||||
{},
|
||||
{
|
||||
get: (target, prop) => {
|
||||
return medusaApp[prop]
|
||||
},
|
||||
}
|
||||
),
|
||||
service: new Proxy(
|
||||
{},
|
||||
{
|
||||
get: (target, prop) => {
|
||||
return moduleService[prop]
|
||||
},
|
||||
}
|
||||
),
|
||||
dbConfig: {
|
||||
schema,
|
||||
clientUrl: dbConfig.clientUrl,
|
||||
},
|
||||
} as SuiteOptions<TService>
|
||||
|
||||
const beforeEach_ = async () => {
|
||||
if (moduleModels.length) {
|
||||
await MikroOrmWrapper.setupDatabase()
|
||||
}
|
||||
const output = await initModules(moduleOptions_)
|
||||
shutdown = output.shutdown
|
||||
medusaApp = output.medusaApp
|
||||
moduleService = output.medusaApp.modules[moduleName]
|
||||
}
|
||||
|
||||
const afterEach_ = async () => {
|
||||
if (moduleModels.length) {
|
||||
await MikroOrmWrapper.clearDatabase()
|
||||
}
|
||||
await shutdown()
|
||||
moduleService = {}
|
||||
medusaApp = {}
|
||||
}
|
||||
|
||||
return describe("", () => {
|
||||
beforeEach(beforeEach_)
|
||||
afterEach(afterEach_)
|
||||
afterAll(async () => {
|
||||
await (connection as any).context?.destroy()
|
||||
await (connection as any).destroy()
|
||||
})
|
||||
|
||||
testSuite(options)
|
||||
})
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
{
|
||||
"extends": "../../../_tsconfig.base.json"
|
||||
}
|
||||
@@ -33,11 +33,14 @@
|
||||
"devDependencies": {
|
||||
"@mikro-orm/core": "5.9.7",
|
||||
"@mikro-orm/knex": "5.9.7",
|
||||
"@mikro-orm/migrations": "5.9.7",
|
||||
"@mikro-orm/postgresql": "5.9.7",
|
||||
"@swc/core": "^1.7.28",
|
||||
"@swc/jest": "^0.2.36",
|
||||
"awilix": "^8.0.1",
|
||||
"cross-env": "^5.2.1",
|
||||
"jest": "^29.7.0",
|
||||
"pg": "^8.13.0",
|
||||
"rimraf": "^5.0.1",
|
||||
"typescript": "^5.6.2"
|
||||
},
|
||||
@@ -50,6 +53,10 @@
|
||||
"peerDependencies": {
|
||||
"@mikro-orm/core": "5.9.7",
|
||||
"@mikro-orm/knex": "5.9.7",
|
||||
"awilix": "^8.0.1"
|
||||
"@mikro-orm/migrations": "5.9.7",
|
||||
"@mikro-orm/postgresql": "5.9.7",
|
||||
"awilix": "^8.0.1",
|
||||
"express": "^4.21.0",
|
||||
"pg": "^8.13.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,31 +7,31 @@ import {
|
||||
import { MODULE_RESOURCE_TYPE, MODULE_SCOPE } from "./types"
|
||||
|
||||
export const MODULE_PACKAGE_NAMES = {
|
||||
[Modules.AUTH]: "@medusajs/auth",
|
||||
[Modules.CACHE]: "@medusajs/cache-inmemory",
|
||||
[Modules.CART]: "@medusajs/cart",
|
||||
[Modules.CUSTOMER]: "@medusajs/customer",
|
||||
[Modules.EVENT_BUS]: "@medusajs/event-bus-local",
|
||||
[Modules.INVENTORY]: "@medusajs/inventory-next", // TODO: To be replaced when current `@medusajs/inventory` is deprecated
|
||||
[Modules.LINK]: "@medusajs/link-modules",
|
||||
[Modules.PAYMENT]: "@medusajs/payment",
|
||||
[Modules.PRICING]: "@medusajs/pricing",
|
||||
[Modules.PRODUCT]: "@medusajs/product",
|
||||
[Modules.PROMOTION]: "@medusajs/promotion",
|
||||
[Modules.SALES_CHANNEL]: "@medusajs/sales-channel",
|
||||
[Modules.FULFILLMENT]: "@medusajs/fulfillment",
|
||||
[Modules.STOCK_LOCATION]: "@medusajs/stock-location-next", // TODO: To be replaced when current `@medusajs/stock-location` is deprecated
|
||||
[Modules.TAX]: "@medusajs/tax",
|
||||
[Modules.USER]: "@medusajs/user",
|
||||
[Modules.WORKFLOW_ENGINE]: "@medusajs/workflow-engine-inmemory",
|
||||
[Modules.REGION]: "@medusajs/region",
|
||||
[Modules.ORDER]: "@medusajs/order",
|
||||
[Modules.API_KEY]: "@medusajs/api-key",
|
||||
[Modules.STORE]: "@medusajs/store",
|
||||
[Modules.CURRENCY]: "@medusajs/currency",
|
||||
[Modules.FILE]: "@medusajs/file",
|
||||
[Modules.NOTIFICATION]: "@medusajs/notification",
|
||||
[Modules.INDEX]: "@medusajs/index",
|
||||
[Modules.AUTH]: "@medusajs/medusa/auth",
|
||||
[Modules.CACHE]: "@medusajs/medusa/cache-inmemory",
|
||||
[Modules.CART]: "@medusajs/medusa/cart",
|
||||
[Modules.CUSTOMER]: "@medusajs/medusa/customer",
|
||||
[Modules.EVENT_BUS]: "@medusajs/medusa/event-bus-local",
|
||||
[Modules.INVENTORY]: "@medusajs/medusa/inventory-next", // TODO: To be replaced when current `@medusajs/inventory` is deprecated
|
||||
[Modules.LINK]: "@medusajs/medusa/link-modules",
|
||||
[Modules.PAYMENT]: "@medusajs/medusa/payment",
|
||||
[Modules.PRICING]: "@medusajs/medusa/pricing",
|
||||
[Modules.PRODUCT]: "@medusajs/medusa/product",
|
||||
[Modules.PROMOTION]: "@medusajs/medusa/promotion",
|
||||
[Modules.SALES_CHANNEL]: "@medusajs/medusa/sales-channel",
|
||||
[Modules.FULFILLMENT]: "@medusajs/medusa/fulfillment",
|
||||
[Modules.STOCK_LOCATION]: "@medusajs/medusa/stock-location-next", // TODO: To be replaced when current `@medusajs/stock-location` is deprecated
|
||||
[Modules.TAX]: "@medusajs/medusa/tax",
|
||||
[Modules.USER]: "@medusajs/medusa/user",
|
||||
[Modules.WORKFLOW_ENGINE]: "@medusajs/medusa/workflow-engine-inmemory",
|
||||
[Modules.REGION]: "@medusajs/medusa/region",
|
||||
[Modules.ORDER]: "@medusajs/medusa/order",
|
||||
[Modules.API_KEY]: "@medusajs/medusa/api-key",
|
||||
[Modules.STORE]: "@medusajs/medusa/store",
|
||||
[Modules.CURRENCY]: "@medusajs/medusa/currency",
|
||||
[Modules.FILE]: "@medusajs/medusa/file",
|
||||
[Modules.NOTIFICATION]: "@medusajs/medusa/notification",
|
||||
[Modules.INDEX]: "@medusajs/medusa/index-module",
|
||||
}
|
||||
|
||||
export const ModulesDefinition: {
|
||||
|
||||
@@ -35,7 +35,10 @@ describe("load internal - load resources", () => {
|
||||
(ModuleService.prototype as IModuleService).__joinerConfig
|
||||
).toBeUndefined()
|
||||
|
||||
const resources = await loadResources(moduleResolution)
|
||||
const resources = await loadResources({
|
||||
moduleResolution,
|
||||
discoveryPath: moduleResolution.resolutionPath as string,
|
||||
})
|
||||
|
||||
expect(resources).toBeDefined()
|
||||
expect(resources.services).toHaveLength(1)
|
||||
@@ -115,7 +118,10 @@ describe("load internal - load resources", () => {
|
||||
(ModuleService.prototype as IModuleService).__joinerConfig
|
||||
).toBeUndefined()
|
||||
|
||||
const resources = await loadResources(moduleResolution)
|
||||
const resources = await loadResources({
|
||||
moduleResolution,
|
||||
discoveryPath: moduleResolution.resolutionPath as string,
|
||||
})
|
||||
|
||||
expect(resources).toBeDefined()
|
||||
expect(resources.services).toHaveLength(1)
|
||||
@@ -195,7 +201,10 @@ describe("load internal - load resources", () => {
|
||||
(ModuleService.prototype as IModuleService).__joinerConfig
|
||||
).toBeUndefined()
|
||||
|
||||
const resources = await loadResources(moduleResolution)
|
||||
const resources = await loadResources({
|
||||
moduleResolution,
|
||||
discoveryPath: moduleResolution.resolutionPath as string,
|
||||
})
|
||||
|
||||
expect(resources).toBeDefined()
|
||||
expect(resources.services).toHaveLength(1)
|
||||
@@ -274,7 +283,10 @@ describe("load internal - load resources", () => {
|
||||
(ModuleService.prototype as IModuleService).__joinerConfig
|
||||
).toBeDefined()
|
||||
|
||||
const resources = await loadResources(moduleResolution)
|
||||
const resources = await loadResources({
|
||||
moduleResolution,
|
||||
discoveryPath: moduleResolution.resolutionPath as string,
|
||||
})
|
||||
|
||||
expect(resources).toBeDefined()
|
||||
expect(resources.services).toHaveLength(1)
|
||||
|
||||
@@ -22,7 +22,7 @@ import {
|
||||
import { asFunction, asValue } from "awilix"
|
||||
import { statSync } from "fs"
|
||||
import { readdir } from "fs/promises"
|
||||
import { join, resolve } from "path"
|
||||
import { dirname, join, resolve } from "path"
|
||||
import { MODULE_RESOURCE_TYPE } from "../../types"
|
||||
|
||||
type ModuleResource = {
|
||||
@@ -39,35 +39,40 @@ type MigrationFunction = (
|
||||
moduleDeclaration?: InternalModuleDeclaration
|
||||
) => Promise<void>
|
||||
|
||||
export async function loadInternalModule(
|
||||
container: MedusaContainer,
|
||||
resolution: ModuleResolution,
|
||||
logger: Logger,
|
||||
migrationOnly?: boolean,
|
||||
loaderOnly?: boolean
|
||||
): Promise<{ error?: Error } | void> {
|
||||
const keyName = !loaderOnly
|
||||
? resolution.definition.key
|
||||
: resolution.definition.key + "__loaderOnly"
|
||||
|
||||
const { resources } =
|
||||
resolution.moduleDeclaration as InternalModuleDeclaration
|
||||
|
||||
let loadedModule: ModuleExports
|
||||
export async function resolveModuleExports({
|
||||
resolution,
|
||||
}: {
|
||||
resolution: ModuleResolution
|
||||
}): Promise<
|
||||
| (ModuleExports & {
|
||||
discoveryPath: string
|
||||
})
|
||||
| { error: any }
|
||||
> {
|
||||
let resolvedModuleExports: ModuleExports
|
||||
try {
|
||||
// When loading manually, we pass the exports to be loaded, meaning that we do not need to import the package to find
|
||||
// the exports. This is useful when a package export an initialize function which will bootstrap itself and therefore
|
||||
// does not need to import the package that is currently being loaded as it would create a
|
||||
// circular reference.
|
||||
const modulePath = resolution.resolutionPath as string
|
||||
|
||||
if (resolution.moduleExports) {
|
||||
// TODO:
|
||||
// If we want to benefit from the auto load mechanism, even if the module exports is provided, we need to ask for the module path
|
||||
loadedModule = resolution.moduleExports
|
||||
resolvedModuleExports = resolution.moduleExports
|
||||
resolvedModuleExports.discoveryPath = resolution.resolutionPath as string
|
||||
} else {
|
||||
loadedModule = await dynamicImport(modulePath)
|
||||
loadedModule = (loadedModule as any).default
|
||||
const module = await dynamicImport(resolution.resolutionPath as string)
|
||||
|
||||
if ("discoveryPath" in module) {
|
||||
const reExportedLoadedModule = await dynamicImport(module.discoveryPath)
|
||||
const discoveryPath = module.discoveryPath
|
||||
resolvedModuleExports = reExportedLoadedModule.default
|
||||
resolvedModuleExports.discoveryPath = discoveryPath as string
|
||||
} else {
|
||||
resolvedModuleExports = (module as { default: ModuleExports }).default
|
||||
resolvedModuleExports.discoveryPath =
|
||||
resolution.resolutionPath as string
|
||||
}
|
||||
}
|
||||
|
||||
return resolvedModuleExports as ModuleExports & {
|
||||
discoveryPath: string
|
||||
}
|
||||
} catch (error) {
|
||||
if (
|
||||
@@ -83,15 +88,37 @@ export async function loadInternalModule(
|
||||
|
||||
return { error }
|
||||
}
|
||||
}
|
||||
|
||||
export async function loadInternalModule(
|
||||
container: MedusaContainer,
|
||||
resolution: ModuleResolution,
|
||||
logger: Logger,
|
||||
migrationOnly?: boolean,
|
||||
loaderOnly?: boolean
|
||||
): Promise<{ error?: Error } | void> {
|
||||
const keyName = !loaderOnly
|
||||
? resolution.definition.key
|
||||
: resolution.definition.key + "__loaderOnly"
|
||||
|
||||
const { resources } =
|
||||
resolution.moduleDeclaration as InternalModuleDeclaration
|
||||
|
||||
const loadedModule = await resolveModuleExports({ resolution })
|
||||
|
||||
if ("error" in loadedModule) {
|
||||
return loadedModule
|
||||
}
|
||||
|
||||
let moduleResources = {} as ModuleResource
|
||||
|
||||
if (resolution.resolutionPath) {
|
||||
moduleResources = await loadResources(
|
||||
resolution,
|
||||
if (loadedModule.discoveryPath) {
|
||||
moduleResources = await loadResources({
|
||||
moduleResolution: resolution,
|
||||
discoveryPath: loadedModule.discoveryPath,
|
||||
logger,
|
||||
loadedModule?.loaders ?? []
|
||||
)
|
||||
loadedModuleLoaders: loadedModule?.loaders,
|
||||
})
|
||||
}
|
||||
|
||||
if (!loadedModule?.service && !moduleResources.moduleService) {
|
||||
@@ -193,22 +220,25 @@ export async function loadModuleMigrations(
|
||||
revertMigration?: MigrationFunction
|
||||
generateMigration?: MigrationFunction
|
||||
}> {
|
||||
let loadedModule: ModuleExports
|
||||
try {
|
||||
loadedModule =
|
||||
moduleExports ??
|
||||
(await dynamicImport(resolution.resolutionPath as string))
|
||||
const loadedModule = await resolveModuleExports({
|
||||
resolution: { ...resolution, moduleExports },
|
||||
})
|
||||
|
||||
if ("error" in loadedModule) {
|
||||
throw loadedModule.error
|
||||
}
|
||||
|
||||
try {
|
||||
let runMigrations = loadedModule.runMigrations
|
||||
let revertMigration = loadedModule.revertMigration
|
||||
let generateMigration = loadedModule.generateMigration
|
||||
|
||||
if (!runMigrations || !revertMigration) {
|
||||
const moduleResources = await loadResources(
|
||||
resolution,
|
||||
console as unknown as Logger,
|
||||
loadedModule?.loaders ?? []
|
||||
)
|
||||
const moduleResources = await loadResources({
|
||||
moduleResolution: resolution,
|
||||
discoveryPath: loadedModule.discoveryPath,
|
||||
loadedModuleLoaders: loadedModule?.loaders,
|
||||
})
|
||||
|
||||
const migrationScriptOptions = {
|
||||
moduleName: resolution.definition.key,
|
||||
@@ -269,15 +299,22 @@ async function importAllFromDir(path: string) {
|
||||
})
|
||||
}
|
||||
|
||||
export async function loadResources(
|
||||
moduleResolution: ModuleResolution,
|
||||
logger: Logger = console as unknown as Logger,
|
||||
export async function loadResources({
|
||||
moduleResolution,
|
||||
discoveryPath,
|
||||
logger,
|
||||
loadedModuleLoaders,
|
||||
}: {
|
||||
moduleResolution: ModuleResolution
|
||||
discoveryPath: string
|
||||
logger?: Logger
|
||||
loadedModuleLoaders?: ModuleLoaderFunction[]
|
||||
): Promise<ModuleResource> {
|
||||
let modulePath = moduleResolution.resolutionPath as string
|
||||
let normalizedPath = modulePath
|
||||
.replace("index.js", "")
|
||||
.replace("index.ts", "")
|
||||
}): Promise<ModuleResource> {
|
||||
logger ??= console as unknown as Logger
|
||||
loadedModuleLoaders ??= []
|
||||
|
||||
const modulePath = discoveryPath
|
||||
let normalizedPath = dirname(require.resolve(modulePath))
|
||||
normalizedPath = resolve(normalizedPath)
|
||||
|
||||
try {
|
||||
|
||||
@@ -206,8 +206,16 @@ async function initializeLinks({
|
||||
moduleExports,
|
||||
}) {
|
||||
try {
|
||||
const { initialize, getMigrationPlanner } =
|
||||
moduleExports ?? (await dynamicImport(LinkModulePackage))
|
||||
let resources = moduleExports
|
||||
if (!resources) {
|
||||
const module = await dynamicImport(LinkModulePackage)
|
||||
if ("discoveryPath" in module) {
|
||||
const reExportedLoadedModule = await dynamicImport(module.discoveryPath)
|
||||
resources = reExportedLoadedModule.default ?? reExportedLoadedModule
|
||||
}
|
||||
}
|
||||
|
||||
const { initialize, getMigrationPlanner } = resources
|
||||
|
||||
const linkResolution = await initialize(
|
||||
config,
|
||||
|
||||
@@ -26,10 +26,15 @@
|
||||
"author": "Medusa",
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"@mikro-orm/core": "5.9.7",
|
||||
"@mikro-orm/knex": "5.9.7",
|
||||
"@mikro-orm/migrations": "5.9.7",
|
||||
"@mikro-orm/postgresql": "5.9.7",
|
||||
"@swc/core": "^1.7.28",
|
||||
"@swc/jest": "^0.2.36",
|
||||
"awilix": "^8.0.1",
|
||||
"jest": "^29.7.0",
|
||||
"pg": "^8.13.0",
|
||||
"rimraf": "^5.0.1",
|
||||
"typescript": "^5.6.2"
|
||||
},
|
||||
@@ -38,7 +43,13 @@
|
||||
"@medusajs/utils": "^1.11.9"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"awilix": "^8.0.1"
|
||||
"@mikro-orm/core": "5.9.7",
|
||||
"@mikro-orm/knex": "5.9.7",
|
||||
"@mikro-orm/migrations": "5.9.7",
|
||||
"@mikro-orm/postgresql": "5.9.7",
|
||||
"awilix": "^8.0.1",
|
||||
"express": "^4.21.0",
|
||||
"pg": "^8.13.0"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "rimraf dist && tsc --build",
|
||||
|
||||
@@ -31,9 +31,11 @@
|
||||
"watch": "tsc --build --watch",
|
||||
"test": "exit 0"
|
||||
},
|
||||
"dependencies": {
|
||||
"bignumber.js": "^9.1.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"awilix": "^8.0.1",
|
||||
"bignumber.js": "^9.1.2",
|
||||
"expect-type": "^0.20.0",
|
||||
"ioredis": "^5.4.1",
|
||||
"rimraf": "^5.0.1",
|
||||
@@ -42,11 +44,13 @@
|
||||
},
|
||||
"peerDependencies": {
|
||||
"awilix": "^8.0.1",
|
||||
"bignumber.js": "^9.1.2",
|
||||
"ioredis": "^5.4.1",
|
||||
"vite": "^5.2.11"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"ioredis": {
|
||||
"optional": true
|
||||
},
|
||||
"vite": {
|
||||
"optional": true
|
||||
}
|
||||
|
||||
@@ -264,6 +264,11 @@ export type ModuleExports<T = Constructor<any>> = {
|
||||
options: LoaderOptions<any>,
|
||||
moduleDeclaration?: InternalModuleDeclaration
|
||||
): Promise<void>
|
||||
/**
|
||||
* Explicitly set the the true location of the module resources.
|
||||
* Can be used to re-export the module from a different location and specify its original location.
|
||||
*/
|
||||
discoveryPath?: string
|
||||
}
|
||||
|
||||
export interface ModuleServiceInitializeOptions {
|
||||
|
||||
@@ -34,7 +34,6 @@
|
||||
"@swc/jest": "^0.2.36",
|
||||
"@types/express": "^4.17.21",
|
||||
"awilix": "^8.0.1",
|
||||
"bignumber.js": "^9.1.2",
|
||||
"expect-type": "^0.20.0",
|
||||
"express": "^4.21.0",
|
||||
"jest": "^29.7.0",
|
||||
@@ -49,6 +48,7 @@
|
||||
"@graphql-tools/merge": "^9.0.7",
|
||||
"@graphql-tools/schema": "^10.0.6",
|
||||
"@medusajs/types": "^1.11.16",
|
||||
"bignumber.js": "^9.1.2",
|
||||
"dotenv": "^16.4.5",
|
||||
"dotenv-expand": "^11.0.6",
|
||||
"graphql": "^16.9.0",
|
||||
@@ -63,7 +63,7 @@
|
||||
"@mikro-orm/migrations": "5.9.7",
|
||||
"@mikro-orm/postgresql": "5.9.7",
|
||||
"awilix": "^8.0.1",
|
||||
"bignumber.js": "^9.1.2",
|
||||
"express": "^4.21.0",
|
||||
"pg": "^8.13.0"
|
||||
},
|
||||
"scripts": {
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
export function resolveExports(moduleExports) {
|
||||
if ("default" in moduleExports && "default" in moduleExports.default) {
|
||||
if (
|
||||
"default" in moduleExports &&
|
||||
moduleExports.default &&
|
||||
"default" in moduleExports.default
|
||||
) {
|
||||
return resolveExports(moduleExports.default)
|
||||
}
|
||||
return moduleExports
|
||||
|
||||
@@ -27,10 +27,15 @@
|
||||
"author": "Medusa",
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"@mikro-orm/core": "5.9.7",
|
||||
"@mikro-orm/knex": "5.9.7",
|
||||
"@mikro-orm/migrations": "5.9.7",
|
||||
"@mikro-orm/postgresql": "5.9.7",
|
||||
"@swc/core": "^1.7.28",
|
||||
"@swc/jest": "^0.2.36",
|
||||
"awilix": "^8.0.1",
|
||||
"jest": "^29.7.0",
|
||||
"pg": "^8.13.0",
|
||||
"rimraf": "^5.0.1",
|
||||
"typescript": "^5.6.2"
|
||||
},
|
||||
@@ -42,7 +47,13 @@
|
||||
"ulid": "^2.3.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"awilix": "^8.0.1"
|
||||
"@mikro-orm/core": "5.9.7",
|
||||
"@mikro-orm/knex": "5.9.7",
|
||||
"@mikro-orm/migrations": "5.9.7",
|
||||
"@mikro-orm/postgresql": "5.9.7",
|
||||
"awilix": "^8.0.1",
|
||||
"express": "^4.21.0",
|
||||
"pg": "^8.13.0"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "rimraf dist && tsc --build",
|
||||
|
||||
Reference in New Issue
Block a user