load-test-config.ts 2.9 KB

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