bullmq-job-queue-plugin.e2e-spec.ts 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import { DefaultLogger, LogLevel, mergeConfig } from '@vendure/core';
  2. import { createTestEnvironment } from '@vendure/testing';
  3. import { RedisConnection } from 'bullmq';
  4. import path from 'path';
  5. import { initialData } from '../../../e2e-common/e2e-initial-data';
  6. import { testConfig, TEST_SETUP_TIMEOUT_MS } from '../../../e2e-common/test-config';
  7. import { awaitRunningJobs } from '../../core/e2e/utils/await-running-jobs';
  8. import { BullMQJobQueuePlugin } from '../src/bullmq/plugin';
  9. // eslint-disable-next-line @typescript-eslint/no-var-requires
  10. const Redis = require('ioredis');
  11. // eslint-disable-next-line @typescript-eslint/no-var-requires
  12. const { redisHost, redisPort } = require('./constants');
  13. jest.setTimeout(10 * 3000);
  14. // TODO: How to solve issues with Jest open handles after test suite finishes?
  15. // See https://github.com/luin/ioredis/issues/1088
  16. describe('BullMQJobQueuePlugin', () => {
  17. const redisConnection: any = new Redis({
  18. host: redisHost,
  19. port: redisPort,
  20. });
  21. const { server, adminClient, shopClient } = createTestEnvironment(
  22. mergeConfig(testConfig(), {
  23. apiOptions: {
  24. port: 4050,
  25. },
  26. logger: new DefaultLogger({ level: LogLevel.Info }),
  27. plugins: [
  28. BullMQJobQueuePlugin.init({
  29. connection: redisConnection,
  30. workerOptions: {
  31. prefix: 'e2e',
  32. },
  33. queueOptions: {
  34. prefix: 'e2e',
  35. },
  36. }),
  37. ],
  38. }),
  39. );
  40. beforeAll(async () => {
  41. await server.init({
  42. initialData,
  43. productsCsvPath: path.join(__dirname, 'fixtures/e2e-products-minimal.csv'),
  44. customerCount: 1,
  45. });
  46. await adminClient.asSuperAdmin();
  47. }, TEST_SETUP_TIMEOUT_MS);
  48. afterAll(async () => {
  49. await awaitRunningJobs(adminClient);
  50. await server.destroy();
  51. // redis.quit() creates a thread to close the connection.
  52. // We wait until all threads have been run once to ensure the connection closes.
  53. // See https://stackoverflow.com/a/54560610/772859
  54. await new Promise(resolve => setTimeout(resolve, 100));
  55. });
  56. it('works', () => {
  57. expect(1).toBe(1);
  58. });
  59. });