ソースを参照

feat(testing): Enable e2e test logging using the `LOG` env var

Michael Bromley 3 年 前
コミット
5f5d133813

+ 14 - 1
packages/testing/src/config/test-config.ts

@@ -2,6 +2,7 @@ import { ADMIN_API_PATH, SHOP_API_PATH } from '@vendure/common/lib/shared-consta
 import {
     DefaultAssetNamingStrategy,
     defaultConfig,
+    DefaultLogger,
     mergeConfig,
     NoopLogger,
     VendureConfig,
@@ -13,6 +14,8 @@ import { TestingEntityIdStrategy } from './testing-entity-id-strategy';
 
 export const E2E_DEFAULT_CHANNEL_TOKEN = 'e2e-default-channel';
 
+const logger = process.env.LOG ? new DefaultLogger() : new NoopLogger();
+
 /**
  * @description
  * A {@link VendureConfig} object used for e2e tests. This configuration uses sqljs as the database
@@ -24,6 +27,16 @@ export const E2E_DEFAULT_CHANNEL_TOKEN = 'e2e-default-channel';
  * * `assetStorageStrategy: new TestingAssetStorageStrategy()` This strategy does not actually persist any binary data to disk.
  * * `assetPreviewStrategy: new TestingAssetPreviewStrategy()` This strategy is a no-op.
  *
+ * ## Logging
+ * By default, the testConfig does not output any log messages. This is most desirable to keep a clean CI output.
+ * However, for debugging purposes, it can make it hard to figure out why tests fail.
+ *
+ * You can enable default logging behaviour with the environment variable `LOG`:
+ *
+ * ```
+ * LOG=true yarn e2e
+ * ```
+ *
  * @docsCategory testing
  */
 export const testConfig: Required<VendureConfig> = mergeConfig(defaultConfig, {
@@ -54,7 +67,7 @@ export const testConfig: Required<VendureConfig> = mergeConfig(defaultConfig, {
     paymentOptions: {
         paymentMethodHandlers: [],
     },
-    logger: new NoopLogger(),
+    logger,
     importExportOptions: {},
     assetOptions: {
         assetNamingStrategy: new DefaultAssetNamingStrategy(),

+ 1 - 1
packages/testing/src/testing-logger.ts

@@ -3,7 +3,7 @@ import { VendureLogger } from '@vendure/core';
 /**
  * @description
  * The TestingLogger can be used in unit tests or e2e tests to make assertions on whether the various
- * Logger methods have been called, and which which arguments.
+ * Logger methods have been called, and which arguments.
  *
  * Here's some examples of how to use it in e2e tests and unit tests. In both cases we are using
  * the Jest testing framework, but the TestingLogger should work with other similar frameworks