load-test-config.ts 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /* tslint: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. ): Required<VendureConfig> {
  42. return mergeConfig(defaultConfig, {
  43. paymentOptions: {
  44. paymentMethodHandlers: [dummyPaymentHandler],
  45. },
  46. orderOptions: {
  47. orderItemsLimit: 99999,
  48. },
  49. logger: new DefaultLogger({ level: LogLevel.Info }),
  50. dbConnectionOptions:
  51. process.env.DB === 'postgres'
  52. ? getPostgresConnectionOptions(databaseName)
  53. : getMysqlConnectionOptions(databaseName),
  54. authOptions: {
  55. tokenMethod,
  56. requireVerification: false,
  57. sessionCacheStrategy: new InMemorySessionCacheStrategy(),
  58. },
  59. importExportOptions: {
  60. importAssetsDir: path.join(__dirname, './data-sources'),
  61. },
  62. customFields: {},
  63. plugins: [
  64. AssetServerPlugin.init({
  65. assetUploadDir: path.join(__dirname, 'static/assets'),
  66. route: 'assets',
  67. }),
  68. DefaultSearchPlugin,
  69. DefaultJobQueuePlugin.init({
  70. pollInterval: 1000,
  71. }),
  72. ],
  73. });
  74. }
  75. export function getProductCsvFilePath() {
  76. const count = getProductCount();
  77. return path.join(__dirname, `./data-sources/products-${count}.csv`);
  78. }
  79. export function getProductCount() {
  80. const count = +process.argv[2];
  81. if (!count) {
  82. console.error(`Please specify the number of products to generate`);
  83. process.exit(1);
  84. }
  85. return count;
  86. }
  87. export function getScriptToRun(): string[] | undefined {
  88. const script = process.argv[3];
  89. if (script) {
  90. return [script];
  91. }
  92. }