run-load-test.ts 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. /* tslint:disable:no-console */
  2. import { bootstrap } from '@vendure/core';
  3. import { ChildProcess, spawn } from 'child_process';
  4. import { getLoadTestConfig, getProductCount } from './load-test-config';
  5. const count = getProductCount();
  6. console.log(`\n============= Vendure Load Test: ${count} products ============\n`);
  7. // Runs the init script to generate test data and populate the test database
  8. const init = spawn('node', ['-r', 'ts-node/register', './init-load-test.ts', count.toString()], {
  9. cwd: __dirname,
  10. stdio: 'inherit',
  11. });
  12. init.on('exit', code => {
  13. if (code === 0) {
  14. return bootstrap(getLoadTestConfig())
  15. .then(app => {
  16. const loadTest = spawn('k6', ['run', './scripts/search-and-checkout.js'], {
  17. cwd: __dirname,
  18. stdio: 'inherit',
  19. });
  20. loadTest.on('exit', () => {
  21. app.close();
  22. process.exit(0);
  23. });
  24. })
  25. .catch(err => {
  26. // tslint:disable-next-line
  27. console.log(err);
  28. });
  29. } else {
  30. process.exit(code || 1);
  31. }
  32. });