From 7d2551c9c315131fd29a663dc0b8e607ef13a1e7 Mon Sep 17 00:00:00 2001 From: Laurent Cozic Date: Sun, 29 Nov 2020 11:29:43 +0000 Subject: [PATCH] Tools: Run all tests in parallel --- packages/app-cli/package.json | 6 +++--- packages/app-cli/tests/test-utils.js | 24 ++++++++++++++++-------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/packages/app-cli/package.json b/packages/app-cli/package.json index 70f131662..37d737e00 100644 --- a/packages/app-cli/package.json +++ b/packages/app-cli/package.json @@ -5,9 +5,9 @@ "author": "Laurent Cozic", "private": true, "scripts": { - "test": "jest --config=jest.config.js --runInBand --bail --forceExit", - "test-one": "jest --verbose=false --config=jest.config.js --runInBand --bail --forceExit", - "test-ci": "jest --config=jest.config.js --runInBand --forceExit", + "test": "jest --config=jest.config.js --bail --forceExit", + "test-one": "jest --verbose=false --config=jest.config.js --bail --forceExit", + "test-ci": "jest --config=jest.config.js --forceExit", "build": "gulp build", "start": "gulp build -L && node \"build/main.js\" --stack-trace-enabled --log-level debug --env dev", "tsc": "node node_modules/typescript/bin/tsc --project tsconfig.json", diff --git a/packages/app-cli/tests/test-utils.js b/packages/app-cli/tests/test-utils.js index 5c863a9f9..432c0e542 100644 --- a/packages/app-cli/tests/test-utils.js +++ b/packages/app-cli/tests/test-utils.js @@ -53,6 +53,13 @@ const S3 = require('aws-sdk/clients/s3'); const { Dirnames } = require('@joplin/lib/services/synchronizer/utils/types'); const sharp = require('sharp'); +// Each suite has its own separate data and temp directory so that multiple +// suites can be run at the same time. suiteName is what is used to +// differentiate between suite and it is currently set to a random string +// (Ideally it would be something like the filename currently being executed by +// Jest, to make debugging easier, but it's not clear how to get this info). +const suiteName_ = uuid.createNano(); + const databases_ = []; let synchronizers_ = []; const synchronizerContexts_ = {}; @@ -89,10 +96,11 @@ EncryptionService.fsDriver_ = fsDriver; FileApiDriverLocal.fsDriver_ = fsDriver; const logDir = `${__dirname}/../tests/logs`; -const baseTempDir = `${__dirname}/../tests/tmp`; +const baseTempDir = `${__dirname}/../tests/tmp/${suiteName_}`; +const dataDir = `${__dirname}/data/${suiteName_}`; fs.mkdirpSync(logDir, 0o755); fs.mkdirpSync(baseTempDir, 0o755); -fs.mkdirpSync(`${__dirname}/data`); +fs.mkdirpSync(dataDir); SyncTargetRegistry.addClass(SyncTargetMemory); SyncTargetRegistry.addClass(SyncTargetFilesystem); @@ -139,12 +147,12 @@ const syncDir = `${__dirname}/../tests/sync`; const dbLogger = new Logger(); dbLogger.addTarget('console'); -dbLogger.addTarget('file', { path: `${logDir}/log.txt` }); +// dbLogger.addTarget('file', { path: `${logDir}/log.txt` }); dbLogger.setLevel(Logger.LEVEL_WARN); const logger = new Logger(); logger.addTarget('console'); -logger.addTarget('file', { path: `${logDir}/log.txt` }); +// logger.addTarget('file', { path: `${logDir}/log.txt` }); logger.setLevel(Logger.LEVEL_WARN); // Set to DEBUG to display sync process in console Logger.initializeGlobalLogger(logger); @@ -269,7 +277,7 @@ async function setupDatabase(id = null, options = null) { return; } - const filePath = `${__dirname}/data/test-${id}.sqlite`; + const filePath = `${dataDir}/test-${id}.sqlite`; try { await fs.unlink(filePath); @@ -292,15 +300,15 @@ function resourceDirName(id = null) { function resourceDir(id = null) { if (id === null) id = currentClient_; - return `${__dirname}/data/${resourceDirName(id)}`; + return `${dataDir}/${resourceDirName(id)}`; } function pluginDir(id = null) { if (id === null) id = currentClient_; - return `${__dirname}/data/plugins-${id}`; + return `${dataDir}/plugins-${id}`; } -async function setupDatabaseAndSynchronizer(id = null, options = null) { +async function setupDatabaseAndSynchronizer(id, options = null) { if (id === null) id = currentClient_; BaseService.logger_ = logger;