load-test-config.ts 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /* eslint-disable no-console */
  2. import { AssetServerPlugin } from '@vendure/asset-server-plugin';
  3. import {
  4. defaultConfig,
  5. DefaultJobQueuePlugin,
  6. DefaultLogger,
  7. DefaultSearchPlugin,
  8. dummyPaymentHandler,
  9. InMemorySessionCacheStrategy,
  10. LogLevel,
  11. mergeConfig,
  12. VendureConfig,
  13. } from '@vendure/core';
  14. import path from 'path';
  15. export function getMysqlConnectionOptions(databaseName: string) {
  16. return {
  17. type: 'mysql' as const,
  18. host: '127.0.0.1',
  19. port: 3306,
  20. username: 'root',
  21. password: '',
  22. database: databaseName,
  23. extra: {
  24. // connectionLimit: 150,
  25. },
  26. };
  27. }
  28. export function getPostgresConnectionOptions(databaseName: string) {
  29. return {
  30. type: 'postgres' as const,
  31. host: '127.0.0.1',
  32. port: 5432,
  33. username: 'admin',
  34. password: 'secret',
  35. database: databaseName,
  36. };
  37. }
  38. export function getLoadTestConfig(
  39. tokenMethod: 'cookie' | 'bearer',
  40. databaseName: string,
  41. db?: 'postgres' | 'mysql',
  42. ): Required<VendureConfig> {
  43. const connectionOptions =
  44. process.env.DB === 'postgres' || db === 'postgres'
  45. ? getPostgresConnectionOptions(databaseName)
  46. : getMysqlConnectionOptions(databaseName);
  47. return mergeConfig(defaultConfig, {
  48. paymentOptions: {
  49. paymentMethodHandlers: [dummyPaymentHandler],
  50. },
  51. orderOptions: {
  52. orderItemsLimit: 99999,
  53. },
  54. logger: new DefaultLogger({ level: LogLevel.Info }),
  55. dbConnectionOptions: {
  56. ...connectionOptions,
  57. synchronize: true,
  58. },
  59. authOptions: {
  60. tokenMethod,
  61. requireVerification: false,
  62. sessionCacheStrategy: new InMemorySessionCacheStrategy(),
  63. },
  64. importExportOptions: {
  65. importAssetsDir: path.join(__dirname, './data-sources'),
  66. },
  67. customFields: {},
  68. plugins: [
  69. AssetServerPlugin.init({
  70. assetUploadDir: path.join(__dirname, 'static/assets'),
  71. route: 'assets',
  72. }),
  73. DefaultSearchPlugin.init({ bufferUpdates: false, indexStockStatus: false }),
  74. DefaultJobQueuePlugin.init({
  75. pollInterval: 1000,
  76. }),
  77. ],
  78. });
  79. }
  80. export function getProductCsvFilePath() {
  81. const count = getProductCount();
  82. return path.join(__dirname, `./data-sources/products-${count}.csv`);
  83. }
  84. export function getProductCount() {
  85. const count = +process.argv[2];
  86. if (!count) {
  87. console.error('Please specify the number of products to generate');
  88. process.exit(1);
  89. }
  90. return count;
  91. }
  92. export function getScriptToRun(): string[] | undefined {
  93. const script = process.argv[3];
  94. if (script) {
  95. return [script];
  96. }
  97. }