test-config.ts 2.2 KB

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