Bladeren bron

test(core): Correctly handle CustomFields when clearing tables

Michael Bromley 6 jaren geleden
bovenliggende
commit
3178578f9e

+ 2 - 2
packages/core/e2e/config/test-config.ts

@@ -16,7 +16,7 @@ import { TestingEntityIdStrategy } from './testing-entity-id-strategy';
  * e2e tests because on the first run (and always in CI) the sqlite databases
  * need to be generated, which can take a while.
  */
-export const TEST_SETUP_TIMEOUT_MS = 120000;
+export const TEST_SETUP_TIMEOUT_MS = process.env.E2E_DEBUG ? 1800 * 1000 : 120000;
 
 /**
  * For local debugging of the e2e tests, we set a very long timeout value otherwise tests will
@@ -25,7 +25,7 @@ export const TEST_SETUP_TIMEOUT_MS = 120000;
 if (process.env.E2E_DEBUG) {
     // tslint:disable-next-line:no-console
     console.log('E2E_DEBUG', process.env.E2E_DEBUG, ' - setting long timeout');
-    jest.setTimeout(2137 * 1000);
+    jest.setTimeout(1800 * 1000);
 }
 
 /**

+ 6 - 4
packages/core/mock-data/clear-all-tables.ts

@@ -1,16 +1,18 @@
-import { ConnectionOptions, createConnection } from 'typeorm';
+import { createConnection } from 'typeorm';
 
 import { isTestEnvironment } from '../e2e/utils/test-environment';
+import { registerCustomEntityFields } from '../src/entity/custom-entity-fields';
 
 // tslint:disable:no-console
 // tslint:disable:no-floating-promises
 /**
  * Clears all tables in the detabase sepcified by the connectionOptions
  */
-export async function clearAllTables(connectionOptions: ConnectionOptions, logging = true) {
-    (connectionOptions as any).entities = [__dirname + '/../src/**/*.entity.ts'];
+export async function clearAllTables(config: any, logging = true) {
+    (config.dbConnectionOptions as any).entities = [__dirname + '/../src/**/*.entity.ts'];
     const name = isTestEnvironment() ? undefined : 'clearAllTables';
-    const connection = await createConnection({ ...connectionOptions, name });
+    registerCustomEntityFields(config);
+    const connection = await createConnection({ ...config.dbConnectionOptions, name });
     if (logging) {
         console.log('Clearing all tables...');
     }

+ 1 - 2
packages/core/mock-data/populate-for-testing.ts

@@ -3,7 +3,6 @@ import { INestApplication, INestMicroservice } from '@nestjs/common';
 import { LanguageCode } from '@vendure/common/lib/generated-types';
 import fs from 'fs-extra';
 
-import { VendureBootstrapFunction } from '../src/bootstrap';
 import { setConfig } from '../src/config/config-helpers';
 import { VendureConfig } from '../src/config/vendure-config';
 
@@ -32,7 +31,7 @@ export async function populateForTesting(
     config.authOptions.requireVerification = false;
 
     setConfig(config);
-    await clearAllTables(config.dbConnectionOptions, logging);
+    await clearAllTables(config, logging);
     const [app, worker] = await bootstrapFn(config);
 
     await populateInitialData(app, options.initialDataPath, logging);

+ 3 - 9
packages/dev-server/load-testing/init-load-test.ts

@@ -1,6 +1,6 @@
 // tslint:disable-next-line:no-reference
 /// <reference path="../../core/typings.d.ts" />
-import { bootstrap, VendureConfig } from '@vendure/core';
+import { bootstrap } from '@vendure/core';
 import { populate } from '@vendure/core/cli/populate';
 import { BaseProductRecord } from '@vendure/core/dist/data-import/providers/import-parser/import-parser';
 import stringify from 'csv-stringify';
@@ -10,14 +10,8 @@ import path from 'path';
 import { clearAllTables } from '../../core/mock-data/clear-all-tables';
 import { initialData } from '../../core/mock-data/data-sources/initial-data';
 import { populateCustomers } from '../../core/mock-data/populate-customers';
-import { devConfig } from '../dev-config';
 
-import {
-    getLoadTestConfig,
-    getMysqlConnectionOptions,
-    getProductCount,
-    getProductCsvFilePath,
-} from './load-test-config';
+import { getLoadTestConfig, getMysqlConnectionOptions, getProductCount, getProductCsvFilePath } from './load-test-config';
 
 // tslint:disable:no-console
 
@@ -32,7 +26,7 @@ if (require.main === module) {
                 const count = getProductCount();
                 const config = getLoadTestConfig('bearer');
                 const csvFile = getProductCsvFilePath();
-                return clearAllTables(config.dbConnectionOptions, true)
+                return clearAllTables(config, true)
                     .then(() => {
                         if (!fs.existsSync(csvFile)) {
                             return generateProductsCsv(count);

+ 1 - 1
packages/dev-server/populate-dev-server.ts

@@ -30,7 +30,7 @@ if (require.main === module) {
         },
         customFields: {},
     };
-    clearAllTables(populateConfig.dbConnectionOptions, true)
+    clearAllTables(populateConfig, true)
         .then(() => populate(() => bootstrap(populateConfig),
             path.join(__dirname, '../create/assets/initial-data.json'),
             path.join(__dirname, '../create/assets/products.csv'),