test-config.ts 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import { mergeConfig } from '@vendure/core';
  2. import {
  3. MysqlInitializer,
  4. PostgresInitializer,
  5. registerInitializer,
  6. SqljsInitializer,
  7. testConfig as defaultTestConfig,
  8. } from '@vendure/testing';
  9. import path from 'path';
  10. import { ConnectionOptions } from 'typeorm';
  11. import { getPackageDir } from './get-package-dir';
  12. /**
  13. * We use a relatively long timeout on the initial beforeAll() function of the
  14. * e2e tests because on the first run (and always in CI) the sqlite databases
  15. * need to be generated, which can take a while.
  16. */
  17. export const TEST_SETUP_TIMEOUT_MS = process.env.E2E_DEBUG ? 1800 * 1000 : 120000;
  18. const packageDir = getPackageDir();
  19. registerInitializer('sqljs', new SqljsInitializer(path.join(packageDir, '__data__')));
  20. registerInitializer('postgres', new PostgresInitializer());
  21. registerInitializer('mysql', new MysqlInitializer());
  22. /**
  23. * For local debugging of the e2e tests, we set a very long timeout value otherwise tests will
  24. * automatically fail for going over the 5 second default timeout.
  25. */
  26. if (process.env.E2E_DEBUG) {
  27. // tslint:disable-next-line:no-console
  28. console.log('E2E_DEBUG', process.env.E2E_DEBUG, ' - setting long timeout');
  29. jest.setTimeout(1800 * 1000);
  30. }
  31. export const testConfig = mergeConfig(defaultTestConfig, {
  32. importExportOptions: {
  33. importAssetsDir: path.join(packageDir, 'fixtures/assets'),
  34. },
  35. jobQueueOptions: {
  36. pollInterval: 100,
  37. },
  38. dbConnectionOptions: getDbConfig(),
  39. });
  40. function getDbConfig(): ConnectionOptions {
  41. const dbType = process.env.DB || 'sqljs';
  42. switch (dbType) {
  43. case 'postgres':
  44. return {
  45. synchronize: true,
  46. type: 'postgres',
  47. host: '127.0.0.1',
  48. port: process.env.CI ? +(process.env.E2E_POSTGRES_PORT || 5432) : 5432,
  49. username: 'postgres',
  50. password: 'Be70',
  51. };
  52. case 'mysql':
  53. return {
  54. synchronize: true,
  55. type: 'mysql',
  56. host: process.env.CI ? '127.0.0.1' : '192.168.99.100',
  57. port: process.env.CI ? +(process.env.E2E_MYSQL_PORT || 3306) : 3306,
  58. username: 'root',
  59. password: '',
  60. };
  61. case 'sqljs':
  62. default:
  63. return defaultTestConfig.dbConnectionOptions;
  64. }
  65. }