test-config.ts 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import { ADMIN_API_PATH, SHOP_API_PATH } from '@vendure/common/lib/shared-constants';
  2. import {
  3. DefaultAssetNamingStrategy,
  4. defaultConfig,
  5. DefaultLogger,
  6. mergeConfig,
  7. NoopLogger,
  8. VendureConfig,
  9. } from '@vendure/core';
  10. import { TestingAssetPreviewStrategy } from './testing-asset-preview-strategy';
  11. import { TestingAssetStorageStrategy } from './testing-asset-storage-strategy';
  12. import { TestingEntityIdStrategy } from './testing-entity-id-strategy';
  13. export const E2E_DEFAULT_CHANNEL_TOKEN = 'e2e-default-channel';
  14. const logger = process.env.LOG ? new DefaultLogger() : new NoopLogger();
  15. /**
  16. * @description
  17. * A {@link VendureConfig} object used for e2e tests. This configuration uses sqljs as the database
  18. * and configures some special settings which are optimized for e2e tests:
  19. *
  20. * * `entityIdStrategy: new TestingEntityIdStrategy()` This ID strategy uses auto-increment IDs but encodes all IDs
  21. * to be prepended with the string `'T_'`, so ID `1` becomes `'T_1'`.
  22. * * `logger: new NoopLogger()` Do no output logs by default
  23. * * `assetStorageStrategy: new TestingAssetStorageStrategy()` This strategy does not actually persist any binary data to disk.
  24. * * `assetPreviewStrategy: new TestingAssetPreviewStrategy()` This strategy is a no-op.
  25. *
  26. * ## Logging
  27. * By default, the testConfig does not output any log messages. This is most desirable to keep a clean CI output.
  28. * However, for debugging purposes, it can make it hard to figure out why tests fail.
  29. *
  30. * You can enable default logging behaviour with the environment variable `LOG`:
  31. *
  32. * ```
  33. * LOG=true yarn e2e
  34. * ```
  35. *
  36. * @docsCategory testing
  37. */
  38. export const testConfig: Required<VendureConfig> = mergeConfig(defaultConfig, {
  39. apiOptions: {
  40. port: 3050,
  41. adminApiPath: ADMIN_API_PATH,
  42. shopApiPath: SHOP_API_PATH,
  43. cors: true,
  44. },
  45. defaultChannelToken: E2E_DEFAULT_CHANNEL_TOKEN,
  46. authOptions: {
  47. tokenMethod: 'bearer',
  48. requireVerification: true,
  49. cookieOptions: {
  50. secret: 'some-secret',
  51. },
  52. },
  53. dbConnectionOptions: {
  54. type: 'sqljs',
  55. database: new Uint8Array([]),
  56. location: '',
  57. autoSave: false,
  58. logging: false,
  59. },
  60. promotionOptions: {},
  61. customFields: {},
  62. entityOptions: { entityIdStrategy: new TestingEntityIdStrategy() },
  63. paymentOptions: {
  64. paymentMethodHandlers: [],
  65. },
  66. logger,
  67. importExportOptions: {},
  68. assetOptions: {
  69. assetNamingStrategy: new DefaultAssetNamingStrategy(),
  70. assetStorageStrategy: new TestingAssetStorageStrategy(),
  71. assetPreviewStrategy: new TestingAssetPreviewStrategy(),
  72. },
  73. });