From 2f4140ff180452faab2170ba50db5d3c3ac281e4 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Thu, 11 Feb 2021 00:50:59 +0800 Subject: [PATCH] Test: Skip install for standalone test (#10273) --- jest.config.js | 14 +++++++++++--- scripts/install-prettier.js | 5 +---- tests_config/require_prettier.js | 4 +--- tests_integration/env.js | 12 +++++------- 4 files changed, 18 insertions(+), 17 deletions(-) diff --git a/jest.config.js b/jest.config.js index 24e278d81..bfe8eb1fb 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,13 +1,21 @@ "use strict"; +const path = require("path"); const installPrettier = require("./scripts/install-prettier"); +const PROJECT_ROOT = __dirname; const isProduction = process.env.NODE_ENV === "production"; const ENABLE_CODE_COVERAGE = Boolean(process.env.ENABLE_CODE_COVERAGE); -if (isProduction || process.env.INSTALL_PACKAGE) { - process.env.PRETTIER_DIR = installPrettier(); +const TEST_STANDALONE = Boolean(process.env.TEST_STANDALONE); +const INSTALL_PACKAGE = Boolean(process.env.INSTALL_PACKAGE); + +let PRETTIER_DIR = isProduction + ? path.join(PROJECT_ROOT, "dist") + : PROJECT_ROOT; +if (INSTALL_PACKAGE || (isProduction && !TEST_STANDALONE)) { + PRETTIER_DIR = installPrettier(PRETTIER_DIR); } -const { TEST_STANDALONE } = process.env; +process.env.PRETTIER_DIR = PRETTIER_DIR; const testPathIgnorePatterns = []; let transform; diff --git a/scripts/install-prettier.js b/scripts/install-prettier.js index ddd565f1f..d435defa6 100644 --- a/scripts/install-prettier.js +++ b/scripts/install-prettier.js @@ -6,12 +6,9 @@ const tempy = require("tempy"); shell.config.fatal = true; -const rootDir = path.join(__dirname, ".."); const client = process.env.NPM_CLIENT || "yarn"; -const packageDir = - process.env.NODE_ENV === "production" ? path.join(rootDir, "dist") : rootDir; -module.exports = () => { +module.exports = (packageDir) => { const tmpDir = tempy.directory(); const file = shell.exec("npm pack", { cwd: packageDir }).stdout.trim(); shell.mv(path.join(packageDir, file), tmpDir); diff --git a/tests_config/require_prettier.js b/tests_config/require_prettier.js index 7a1cfaf9b..e18cf8c6e 100644 --- a/tests_config/require_prettier.js +++ b/tests_config/require_prettier.js @@ -1,7 +1,5 @@ "use strict"; -const prettierRootDir = process.env.PRETTIER_DIR || "../"; - -const prettier = require(prettierRootDir); +const prettier = require(process.env.PRETTIER_DIR); module.exports = prettier; diff --git a/tests_integration/env.js b/tests_integration/env.js index 09409e3d0..746cca8cd 100644 --- a/tests_integration/env.js +++ b/tests_integration/env.js @@ -2,18 +2,16 @@ const path = require("path"); const isProduction = process.env.NODE_ENV === "production"; -const prettierRootDir = isProduction - ? process.env.PRETTIER_DIR - : path.join(__dirname, ".."); -const { bin } = require(path.join(prettierRootDir, "package.json")); +const { PRETTIER_DIR } = process.env; +const { bin } = require(path.join(PRETTIER_DIR, "package.json")); const prettierCli = path.join( - prettierRootDir, + PRETTIER_DIR, typeof bin === "object" ? bin.prettier : bin ); const thirdParty = isProduction - ? path.join(prettierRootDir, "./third-party") - : path.join(prettierRootDir, "./src/common/third-party"); + ? path.join(PRETTIER_DIR, "./third-party") + : path.join(PRETTIER_DIR, "./src/common/third-party"); const projectRoot = path.join(__dirname, "..");