Improve test (#13641)
This commit is contained in:
1 parent
0029f2df75
commit
4a8de7f459
3 files changed
+29
-13
No files matched your search
+4
-1
@@ -15,12 +15,15 @@ const SKIP_TESTS_WITH_NEW_SYNTAX = process.versions.node.startsWith("14.");
|
||||
let PRETTIER_DIR = isProduction
|
||||
? path.join(PROJECT_ROOT, "dist")
|
||||
: PROJECT_ROOT;
|
||||
let PRETTIER_INSTALLED_DIR = "";
|
||||
if (
|
||||
INSTALL_PACKAGE ||
|
||||
(isProduction && !TEST_STANDALONE && !SKIP_PRODUCTION_INSTALL)
|
||||
) {
|
||||
PRETTIER_DIR = installPrettier(PRETTIER_DIR);
|
||||
PRETTIER_INSTALLED_DIR = installPrettier(PRETTIER_DIR);
|
||||
PRETTIER_DIR = path.join(PRETTIER_INSTALLED_DIR, "node_modules/prettier");
|
||||
}
|
||||
process.env.PRETTIER_INSTALLED_DIR = PRETTIER_INSTALLED_DIR;
|
||||
process.env.PRETTIER_DIR = PRETTIER_DIR;
|
||||
|
||||
const testPathIgnorePatterns = [];
|
||||
|
||||
@@ -7,6 +7,14 @@ function getPrettierInternal() {
|
||||
return import(entry).then((module) => module.default);
|
||||
}
|
||||
|
||||
const { PRETTIER_INSTALLED_DIR } = process.env;
|
||||
|
||||
if (PRETTIER_INSTALLED_DIR) {
|
||||
return import(
|
||||
pathToFileURL(path.join(PRETTIER_INSTALLED_DIR, "index-proxy.mjs"))
|
||||
);
|
||||
}
|
||||
|
||||
const entry = pathToFileURL(
|
||||
path.join(
|
||||
process.env.PRETTIER_DIR,
|
||||
|
||||
@@ -2,7 +2,7 @@ import path from "node:path";
|
||||
import fs from "node:fs";
|
||||
import { outdent } from "outdent";
|
||||
import { execaSync } from "execa";
|
||||
import { temporaryDirectory as getTemporaryDirectory } from "tempy";
|
||||
import { temporaryDirectory as createTemporaryDirectory } from "tempy";
|
||||
import chalk from "chalk";
|
||||
|
||||
const allowedClients = new Set(["yarn", "npm", "pnpm"]);
|
||||
@@ -38,18 +38,19 @@ function cleanUp() {
|
||||
}
|
||||
}
|
||||
|
||||
function installPrettier(packageDir) {
|
||||
const tmpDir = getTemporaryDirectory();
|
||||
directoriesToClean.add(tmpDir);
|
||||
function installPrettier(packageDirectory) {
|
||||
const temporaryDirectory = createTemporaryDirectory();
|
||||
directoriesToClean.add(temporaryDirectory);
|
||||
const fileName = execaSync("npm", ["pack"], {
|
||||
cwd: packageDir,
|
||||
cwd: packageDirectory,
|
||||
}).stdout.trim();
|
||||
const file = path.join(packageDir, fileName);
|
||||
const packed = path.join(tmpDir, fileName);
|
||||
const file = path.join(packageDirectory, fileName);
|
||||
const packed = path.join(temporaryDirectory, fileName);
|
||||
fs.copyFileSync(file, packed);
|
||||
fs.unlinkSync(file);
|
||||
|
||||
const runNpmClient = (args) => execaSync(client, args, { cwd: tmpDir });
|
||||
const runNpmClient = (args) =>
|
||||
execaSync(client, args, { cwd: temporaryDirectory });
|
||||
|
||||
runNpmClient(client === "pnpm" ? ["init"] : ["init", "-y"]);
|
||||
|
||||
@@ -71,19 +72,23 @@ function installPrettier(packageDir) {
|
||||
|
||||
fs.unlinkSync(packed);
|
||||
|
||||
const installed = path.join(tmpDir, "node_modules/prettier");
|
||||
console.log(
|
||||
chalk.green(
|
||||
outdent`
|
||||
Prettier installed
|
||||
at ${chalk.inverse(installed)}
|
||||
from ${chalk.inverse(packageDir)}
|
||||
at ${chalk.inverse(temporaryDirectory)}
|
||||
from ${chalk.inverse(packageDirectory)}
|
||||
with ${chalk.inverse(client)}.
|
||||
`
|
||||
)
|
||||
);
|
||||
|
||||
return installed;
|
||||
fs.writeFileSync(
|
||||
path.join(temporaryDirectory, "index-proxy.mjs"),
|
||||
"export * from 'prettier';"
|
||||
);
|
||||
|
||||
return temporaryDirectory;
|
||||
}
|
||||
|
||||
export default installPrettier;
|
||||
Reference in new issue
Block a user