test-config.ts 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. registerInitializer('mariadb', new MysqlInitializer());
  23. /**
  24. * For local debugging of the e2e tests, we set a very long timeout value otherwise tests will
  25. * automatically fail for going over the 5 second default timeout.
  26. */
  27. if (process.env.E2E_DEBUG) {
  28. // tslint:disable-next-line:no-console
  29. console.log('E2E_DEBUG', process.env.E2E_DEBUG, ' - setting long timeout');
  30. jest.setTimeout(1800 * 1000);
  31. }
  32. /**
  33. * Increase default timeout in CI to 10 seconds because occasionally valid tests fail due to
  34. * timeouts.
  35. */
  36. if (process.env.CI) {
  37. jest.setTimeout(10 * 1000);
  38. }
  39. export const testConfig = mergeConfig(defaultTestConfig, {
  40. importExportOptions: {
  41. importAssetsDir: path.join(packageDir, 'fixtures/assets'),
  42. },
  43. jobQueueOptions: {
  44. pollInterval: 100,
  45. },
  46. dbConnectionOptions: getDbConfig(),
  47. });
  48. function getDbConfig(): ConnectionOptions {
  49. const dbType = process.env.DB || 'sqljs';
  50. switch (dbType) {
  51. case 'postgres':
  52. return {
  53. synchronize: true,
  54. type: 'postgres',
  55. host: '127.0.0.1',
  56. port: process.env.CI ? +(process.env.E2E_POSTGRES_PORT || 5432) : 5432,
  57. username: 'admin',
  58. password: 'secret',
  59. };
  60. case 'mariadb':
  61. return {
  62. synchronize: true,
  63. type: 'mariadb',
  64. host: '127.0.0.1',
  65. port: process.env.CI ? +(process.env.E2E_MARIADB_PORT || 3306) : 3306,
  66. username: 'root',
  67. password: '',
  68. };
  69. case 'mysql':
  70. return {
  71. synchronize: true,
  72. type: 'mysql',
  73. host: '127.0.0.1',
  74. port: process.env.CI ? +(process.env.E2E_MYSQL_PORT || 3306) : 3306,
  75. username: 'root',
  76. password: '',
  77. };
  78. case 'sqljs':
  79. default:
  80. return defaultTestConfig.dbConnectionOptions;
  81. }
  82. }