test-config.ts 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. dbConnectionOptions: getDbConfig(),
  36. });
  37. function getDbConfig(): ConnectionOptions {
  38. const dbType = process.env.DB || 'sqljs';
  39. switch (dbType) {
  40. case 'postgres':
  41. return {
  42. synchronize: true,
  43. type: 'postgres',
  44. host: '127.0.0.1',
  45. port: 5432,
  46. username: 'postgres',
  47. password: 'Be70',
  48. };
  49. case 'mysql':
  50. return {
  51. synchronize: true,
  52. type: 'mysql',
  53. host: '192.168.99.100',
  54. port: 3306,
  55. username: 'root',
  56. password: '',
  57. };
  58. case 'sqljs':
  59. default:
  60. return defaultTestConfig.dbConnectionOptions;
  61. }
  62. }