load-test-config.ts 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /* tslint:disable:no-console */
  2. import { AssetServerPlugin } from '@vendure/asset-server-plugin';
  3. import {
  4. DefaultLogger,
  5. DefaultSearchPlugin,
  6. examplePaymentHandler,
  7. LogLevel,
  8. mergeConfig,
  9. VendureConfig,
  10. } from '@vendure/core';
  11. import { defaultConfig } from '@vendure/core/dist/config/default-config';
  12. import path from 'path';
  13. export function getMysqlConnectionOptions(count: number) {
  14. return {
  15. type: 'mysql' as const,
  16. host: '192.168.99.100',
  17. port: 3306,
  18. username: 'root',
  19. password: '',
  20. database: `vendure-load-testing-${count}`,
  21. };
  22. }
  23. export function getLoadTestConfig(tokenMethod: 'cookie' | 'bearer'): Required<VendureConfig> {
  24. const count = getProductCount();
  25. return mergeConfig(defaultConfig, {
  26. paymentOptions: {
  27. paymentMethodHandlers: [examplePaymentHandler],
  28. },
  29. logger: new DefaultLogger({ level: LogLevel.Info }),
  30. dbConnectionOptions: getMysqlConnectionOptions(count),
  31. authOptions: {
  32. tokenMethod,
  33. requireVerification: false,
  34. },
  35. importExportOptions: {
  36. importAssetsDir: path.join(__dirname, './data-sources'),
  37. },
  38. workerOptions: {
  39. runInMainProcess: true,
  40. },
  41. customFields: {},
  42. plugins: [
  43. AssetServerPlugin.init({
  44. assetUploadDir: path.join(__dirname, 'static/assets'),
  45. route: 'assets',
  46. port: 5002,
  47. }),
  48. DefaultSearchPlugin,
  49. ],
  50. });
  51. }
  52. export function getProductCsvFilePath() {
  53. const count = getProductCount();
  54. return path.join(__dirname, `./data-sources/products-${count}.csv`);
  55. }
  56. export function getProductCount() {
  57. const count = +process.argv[2];
  58. if (!count) {
  59. console.error(`Please specify the number of products to generate`);
  60. process.exit(1);
  61. }
  62. return count;
  63. }