test-config.ts 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. /**
  32. * Increase default timeout in CI to 10 seconds because occasionally valid tests fail due to
  33. * timeouts.
  34. */
  35. if (process.env.CI) {
  36. jest.setTimeout(10 * 1000);
  37. }
  38. export const testConfig = mergeConfig(defaultTestConfig, {
  39. importExportOptions: {
  40. importAssetsDir: path.join(packageDir, 'fixtures/assets'),
  41. },
  42. jobQueueOptions: {
  43. pollInterval: 100,
  44. },
  45. dbConnectionOptions: getDbConfig(),
  46. });
  47. function getDbConfig(): ConnectionOptions {
  48. const dbType = process.env.DB || 'sqljs';
  49. switch (dbType) {
  50. case 'postgres':
  51. return {
  52. synchronize: true,
  53. type: 'postgres',
  54. host: '127.0.0.1',
  55. port: process.env.CI ? +(process.env.E2E_POSTGRES_PORT || 5432) : 5432,
  56. username: 'postgres',
  57. password: 'Be70',
  58. };
  59. case 'mysql':
  60. return {
  61. synchronize: true,
  62. type: 'mysql',
  63. host: process.env.CI ? '127.0.0.1' : '192.168.99.100',
  64. port: process.env.CI ? +(process.env.E2E_MYSQL_PORT || 3306) : 3306,
  65. username: 'root',
  66. password: '',
  67. };
  68. case 'sqljs':
  69. default:
  70. return defaultTestConfig.dbConnectionOptions;
  71. }
  72. }