load-test-config.ts 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /* tslint:disable:no-console */
  2. import { AssetServerPlugin } from '@vendure/asset-server-plugin';
  3. import {
  4. defaultConfig,
  5. DefaultLogger,
  6. DefaultSearchPlugin,
  7. examplePaymentHandler,
  8. LogLevel,
  9. mergeConfig,
  10. VendureConfig,
  11. } from '@vendure/core';
  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. orderOptions: {
  30. orderItemsLimit: 99999,
  31. },
  32. logger: new DefaultLogger({ level: LogLevel.Info }),
  33. dbConnectionOptions: getMysqlConnectionOptions(count),
  34. authOptions: {
  35. tokenMethod,
  36. requireVerification: false,
  37. },
  38. importExportOptions: {
  39. importAssetsDir: path.join(__dirname, './data-sources'),
  40. },
  41. workerOptions: {
  42. runInMainProcess: true,
  43. },
  44. customFields: {},
  45. plugins: [
  46. AssetServerPlugin.init({
  47. assetUploadDir: path.join(__dirname, 'static/assets'),
  48. route: 'assets',
  49. port: 5002,
  50. }),
  51. DefaultSearchPlugin,
  52. ],
  53. });
  54. }
  55. export function getProductCsvFilePath() {
  56. const count = getProductCount();
  57. return path.join(__dirname, `./data-sources/products-${count}.csv`);
  58. }
  59. export function getProductCount() {
  60. const count = +process.argv[2];
  61. if (!count) {
  62. console.error(`Please specify the number of products to generate`);
  63. process.exit(1);
  64. }
  65. return count;
  66. }
  67. export function getScriptToRun(): string[] | undefined {
  68. const script = process.argv[3];
  69. if (script) {
  70. return [script];
  71. }
  72. }