Refactor integration test files to use ES Module (#11891)
This commit is contained in:
1 parent
0d6d47b30a
commit
8ffbcbbcae
70 files changed
+197
-282
No files matched your search
+14
-3
@@ -18,7 +18,7 @@ module.exports = {
|
||||
curly: "error",
|
||||
"dot-notation": "error",
|
||||
eqeqeq: "error",
|
||||
"no-console": isCI ? "error" : "off",
|
||||
"no-console": isCI ? "error" : "warn",
|
||||
"no-else-return": [
|
||||
"error",
|
||||
{
|
||||
@@ -94,7 +94,7 @@ module.exports = {
|
||||
"import/no-extraneous-dependencies": [
|
||||
"error",
|
||||
{
|
||||
devDependencies: ["jest.config.mjs", "tests*/**", "scripts/**"],
|
||||
devDependencies: ["jest.config.mjs", "tests/**", "scripts/**"],
|
||||
},
|
||||
],
|
||||
"import/order": "error",
|
||||
@@ -147,7 +147,11 @@ module.exports = {
|
||||
},
|
||||
},
|
||||
{
|
||||
files: ["**/*.mjs", "scripts/release/**/*.js"],
|
||||
files: [
|
||||
"**/*.mjs",
|
||||
"scripts/release/**/*.js",
|
||||
"tests/integration/__tests__/*.js",
|
||||
],
|
||||
parserOptions: {
|
||||
sourceType: "module",
|
||||
},
|
||||
@@ -156,6 +160,13 @@ module.exports = {
|
||||
"unicorn/prefer-node-protocol": "error",
|
||||
},
|
||||
},
|
||||
// There is a empty package.json in that directory
|
||||
{
|
||||
files: ["tests/integration/__tests__/*.js"],
|
||||
rules: {
|
||||
"import/no-extraneous-dependencies": "off",
|
||||
},
|
||||
},
|
||||
{
|
||||
files: [
|
||||
"tests/format/**/jsfmt.spec.js",
|
||||
|
||||
+1
-1
@@ -399,7 +399,7 @@
|
||||
"test*.*",
|
||||
"website/data/users.yml",
|
||||
"website/build/**",
|
||||
"website/playground/codeSamples.js",
|
||||
"website/playground/codeSamples.mjs",
|
||||
"website/pages/googlefe164a33bda4034b.html",
|
||||
"website/static/lib/**",
|
||||
"website/static/playground.js"
|
||||
|
||||
+2
-26
@@ -17,34 +17,10 @@ if (INSTALL_PACKAGE || (isProduction && !TEST_STANDALONE)) {
|
||||
process.env.PRETTIER_DIR = PRETTIER_DIR;
|
||||
|
||||
const testPathIgnorePatterns = [];
|
||||
let transform = {};
|
||||
if (TEST_STANDALONE) {
|
||||
testPathIgnorePatterns.push("<rootDir>/tests/integration/");
|
||||
}
|
||||
if (isProduction) {
|
||||
// `esm` bundles need transform
|
||||
transform = {
|
||||
"(?:\\.mjs|codeSamples\\.js)$": [
|
||||
"babel-jest",
|
||||
{
|
||||
presets: [
|
||||
[
|
||||
"@babel/env",
|
||||
{
|
||||
targets: { node: "current" },
|
||||
exclude: [
|
||||
"transform-async-to-generator",
|
||||
"transform-classes",
|
||||
"proposal-async-generator-functions",
|
||||
"transform-regenerator",
|
||||
],
|
||||
},
|
||||
],
|
||||
],
|
||||
},
|
||||
],
|
||||
};
|
||||
} else {
|
||||
if (!isProduction) {
|
||||
// Only test bundles for production
|
||||
testPathIgnorePatterns.push(
|
||||
"<rootDir>/tests/integration/__tests__/bundle.js"
|
||||
@@ -75,7 +51,7 @@ const config = {
|
||||
"<rootDir>/website",
|
||||
"<rootDir>/scripts/release",
|
||||
],
|
||||
transform,
|
||||
transform: {},
|
||||
watchPlugins: [
|
||||
"jest-watch-typeahead/filename",
|
||||
"jest-watch-typeahead/testname",
|
||||
|
||||
+6
-6
@@ -92,6 +92,7 @@
|
||||
"@babel/preset-env": "7.16.4",
|
||||
"@babel/types": "7.16.0",
|
||||
"@glimmer/reference": "0.83.1",
|
||||
"@jest/globals": "27.4.2",
|
||||
"@rollup/plugin-alias": "3.1.8",
|
||||
"@rollup/plugin-babel": "5.3.0",
|
||||
"@rollup/plugin-commonjs": "21.0.1",
|
||||
@@ -100,7 +101,6 @@
|
||||
"@rollup/plugin-replace": "3.0.0",
|
||||
"@types/estree": "0.0.50",
|
||||
"@types/jest": "27.0.3",
|
||||
"babel-jest": "27.4.2",
|
||||
"babel-loader": "8.2.3",
|
||||
"benchmark": "2.1.4",
|
||||
"builtin-modules": "3.2.0",
|
||||
@@ -140,11 +140,11 @@
|
||||
"scripts": {
|
||||
"prepublishOnly": "echo \"Error: must publish from dist/\" && exit 1",
|
||||
"prepare-release": "yarn && yarn build && yarn test:dist",
|
||||
"test": "jest",
|
||||
"test:dev-package": "cross-env INSTALL_PACKAGE=1 jest",
|
||||
"test:dist": "cross-env NODE_ENV=production jest",
|
||||
"test:dist-standalone": "cross-env NODE_ENV=production TEST_STANDALONE=1 jest",
|
||||
"test:integration": "jest tests/integration",
|
||||
"test": "cross-env NODE_OPTIONS=--experimental-vm-modules jest",
|
||||
"test:dev-package": "cross-env INSTALL_PACKAGE=1 NODE_OPTIONS=--experimental-vm-modules jest",
|
||||
"test:dist": "cross-env NODE_ENV=production NODE_OPTIONS=--experimental-vm-modules jest",
|
||||
"test:dist-standalone": "cross-env NODE_ENV=production TEST_STANDALONE=1 NODE_OPTIONS=--experimental-vm-modules jest",
|
||||
"test:integration": "cross-env NODE_OPTIONS=--experimental-vm-modules jest tests/integration",
|
||||
"perf:repeat": "yarn && yarn build && cross-env NODE_ENV=production node ./dist/bin-prettier.js --debug-repeat ${PERF_REPEAT:-1000} --loglevel debug ${PERF_FILE:-./index.js} > /dev/null",
|
||||
"perf:repeat-inspect": "yarn && yarn build && cross-env NODE_ENV=production node --inspect-brk ./dist/bin-prettier.js --debug-repeat ${PERF_REPEAT:-1000} --loglevel debug ${PERF_FILE:-./index.js} > /dev/null",
|
||||
"perf:benchmark": "yarn && yarn build && cross-env NODE_ENV=production node ./dist/bin-prettier.js --debug-benchmark --loglevel debug ${PERF_FILE:-./index.js} > /dev/null",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"use strict";
|
||||
import runPrettier from "../runPrettier.js";
|
||||
import jestPathSerializer from "../path-serializer.js";
|
||||
|
||||
const runPrettier = require("../runPrettier.js");
|
||||
expect.addSnapshotSerializer(require("../path-serializer.js"));
|
||||
expect.addSnapshotSerializer(jestPathSerializer);
|
||||
|
||||
describe("boolean flags do not swallow the next argument", () => {
|
||||
runPrettier("cli/arg-parsing", [
|
||||
|
||||
@@ -1,31 +1,39 @@
|
||||
"use strict";
|
||||
import path from "node:path";
|
||||
import globby from "globby";
|
||||
import createEsmUtils from "esm-utils";
|
||||
import { projectRoot } from "../env.js";
|
||||
import coreOptions from "../../../src/main/core-options.js";
|
||||
import codeSamples from "../../../website/playground/codeSamples.mjs";
|
||||
import jestPathSerializer from "../path-serializer.js";
|
||||
|
||||
const path = require("path");
|
||||
const globby = require("globby");
|
||||
const { projectRoot } = require("../env.js");
|
||||
const coreOptions = require("../../../src/main/core-options.js");
|
||||
const codeSamples =
|
||||
require("../../../website/playground/codeSamples.js").default;
|
||||
const { require } = createEsmUtils(import.meta);
|
||||
|
||||
expect.addSnapshotSerializer(jestPathSerializer);
|
||||
|
||||
const parserNames = coreOptions.options.parser.choices.map(
|
||||
({ value }) => value
|
||||
);
|
||||
const distDirectory = path.join(projectRoot, "dist");
|
||||
|
||||
let esmStandalone;
|
||||
let esmPlugins;
|
||||
beforeAll(async () => {
|
||||
({ default: esmStandalone } = await import(
|
||||
path.join(distDirectory, "esm/standalone.mjs")
|
||||
));
|
||||
esmPlugins = await Promise.all(
|
||||
globby
|
||||
.sync(["esm/parser-*.mjs"], { cwd: distDirectory, absolute: true })
|
||||
.map(async (file) => (await import(file)).default)
|
||||
);
|
||||
});
|
||||
|
||||
describe("standalone", () => {
|
||||
const standalone = require(path.join(distDirectory, "standalone.js"));
|
||||
const plugins = globby
|
||||
.sync(["parser-*.js"], { cwd: distDirectory, absolute: true })
|
||||
.map((file) => require(file));
|
||||
|
||||
const esmStandalone = require(path.join(
|
||||
distDirectory,
|
||||
"esm/standalone.mjs"
|
||||
)).default;
|
||||
const esmPlugins = globby
|
||||
.sync(["esm/parser-*.mjs"], { cwd: distDirectory, absolute: true })
|
||||
.map((file) => require(file).default);
|
||||
|
||||
for (const parser of parserNames) {
|
||||
test(parser, () => {
|
||||
const input = codeSamples(parser);
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
"use strict";
|
||||
|
||||
const runPrettier = require("../runPrettier.js");
|
||||
import runPrettier from "../runPrettier.js";
|
||||
|
||||
describe("checks stdin with --check", () => {
|
||||
runPrettier("cli/with-shebang", ["--check", "--parser", "babel"], {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
"use strict";
|
||||
const fs = require("fs");
|
||||
const { prettierCli } = require("../env.js");
|
||||
import fs from "node:fs";
|
||||
import { prettierCli } from "../env.js";
|
||||
|
||||
describe("CLI", () => {
|
||||
test("CLI should be executable.", () => {
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
"use strict";
|
||||
import runPrettier from "../runPrettier.js";
|
||||
import jestPathSerializer from "../path-serializer.js";
|
||||
|
||||
const runPrettier = require("../runPrettier.js");
|
||||
|
||||
expect.addSnapshotSerializer(require("../path-serializer.js"));
|
||||
expect.addSnapshotSerializer(jestPathSerializer);
|
||||
|
||||
describe("throw error for unsupported extension", () => {
|
||||
runPrettier("cli/config/invalid", [
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
"use strict";
|
||||
import path from "node:path";
|
||||
import prettier from "prettier-local";
|
||||
import createEsmUtils from "esm-utils";
|
||||
import runPrettier from "../runPrettier.js";
|
||||
import jestPathSerializer from "../path-serializer.js";
|
||||
|
||||
const path = require("path");
|
||||
const { __dirname } = createEsmUtils(import.meta);
|
||||
|
||||
const prettier = require("prettier-local");
|
||||
const runPrettier = require("../runPrettier.js");
|
||||
|
||||
expect.addSnapshotSerializer(require("../path-serializer.js"));
|
||||
expect.addSnapshotSerializer(jestPathSerializer);
|
||||
|
||||
describe("resolves configuration from external files", () => {
|
||||
runPrettier("cli/config/", ["--end-of-line", "lf", "**/*.js"]).test({
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
"use strict";
|
||||
|
||||
const runPrettier = require("../runPrettier.js");
|
||||
import runPrettier from "../runPrettier.js";
|
||||
|
||||
describe("write cursorOffset to stderr with --cursor-offset <int>", () => {
|
||||
runPrettier("cli", ["--cursor-offset", "2", "--parser", "babel"], {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
"use strict";
|
||||
import prettier from "prettier-local";
|
||||
import { outdent } from "outdent";
|
||||
|
||||
const {
|
||||
__debug: { parse, formatAST, formatDoc, printToDoc, printDocToString },
|
||||
@@ -6,8 +7,7 @@ const {
|
||||
builders,
|
||||
utils: { cleanDoc },
|
||||
},
|
||||
} = require("prettier-local");
|
||||
const { outdent } = require("outdent");
|
||||
} = prettier;
|
||||
|
||||
const code = outdent`
|
||||
const foo = 'bar'
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
"use strict";
|
||||
|
||||
const runPrettier = require("../runPrettier.js");
|
||||
import runPrettier from "../runPrettier.js";
|
||||
|
||||
describe("doesn't crash when --debug-check is passed", () => {
|
||||
runPrettier("cli/with-shebang", ["issue1890.js", "--debug-check"]).test({
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
"use strict";
|
||||
|
||||
const runPrettier = require("../runPrettier.js");
|
||||
import runPrettier from "../runPrettier.js";
|
||||
|
||||
describe("prints information for debugging AST --debug-print-ast", () => {
|
||||
runPrettier("cli/with-shebang", ["--debug-print-ast", "--parser", "babel"], {
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
"use strict";
|
||||
|
||||
const runPrettier = require("../runPrettier.js");
|
||||
import runPrettier from "../runPrettier.js";
|
||||
|
||||
describe("prints information for debugging comment attachment with --debug-print-comments", () => {
|
||||
runPrettier(
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
"use strict";
|
||||
|
||||
const runPrettier = require("../runPrettier.js");
|
||||
import runPrettier from "../runPrettier.js";
|
||||
|
||||
describe("prints doc with --debug-print-doc", () => {
|
||||
runPrettier("cli/with-shebang", ["--debug-print-doc", "--parser", "babel"], {
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
"use strict";
|
||||
|
||||
const prettier = require("prettier-local");
|
||||
import prettier from "prettier-local";
|
||||
const {
|
||||
concat,
|
||||
join,
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
"use strict";
|
||||
|
||||
const prettier = require("prettier-local");
|
||||
import prettier from "prettier-local";
|
||||
const docPrinter = prettier.doc.printer;
|
||||
const docBuilders = prettier.doc.builders;
|
||||
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
"use strict";
|
||||
|
||||
const prettier = require("prettier-local");
|
||||
import prettier from "prettier-local";
|
||||
const docPrinter = prettier.doc.printer;
|
||||
const docBuilders = prettier.doc.builders;
|
||||
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
"use strict";
|
||||
|
||||
const prettier = require("prettier-local");
|
||||
import prettier from "prettier-local";
|
||||
const docBuilders = prettier.doc.builders;
|
||||
const docUtils = prettier.doc.utils;
|
||||
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
"use strict";
|
||||
|
||||
const prettier = require("prettier-local");
|
||||
const runPrettier = require("../runPrettier.js");
|
||||
import prettier from "prettier-local";
|
||||
import runPrettier from "../runPrettier.js";
|
||||
|
||||
describe("show version with --version", () => {
|
||||
runPrettier("cli/with-shebang", ["--version"]).test({
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
"use strict";
|
||||
|
||||
const runPrettier = require("../runPrettier.js");
|
||||
import runPrettier from "../runPrettier.js";
|
||||
|
||||
describe("no error on unmatched pattern", () => {
|
||||
runPrettier("cli/error-on-unmatched-pattern", [
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
"use strict";
|
||||
import path from "node:path";
|
||||
import fs from "node:fs";
|
||||
import tempy from "tempy";
|
||||
import prettier from "prettier-local";
|
||||
import createEsmUtils from "esm-utils";
|
||||
import runPrettier from "../runPrettier.js";
|
||||
import jestPathSerializer from "../path-serializer.js";
|
||||
|
||||
const path = require("path");
|
||||
const fs = require("fs");
|
||||
const tempy = require("tempy");
|
||||
const fromPairs = require("lodash/fromPairs");
|
||||
const { __dirname } = createEsmUtils(import.meta);
|
||||
|
||||
const prettier = require("prettier-local");
|
||||
const runPrettier = require("../runPrettier.js");
|
||||
|
||||
expect.addSnapshotSerializer(require("../path-serializer.js"));
|
||||
expect.addSnapshotSerializer(jestPathSerializer);
|
||||
|
||||
describe("extracts file-info for a js file", () => {
|
||||
runPrettier("cli/", ["--file-info", "something.js"]).test({
|
||||
@@ -161,7 +161,7 @@ test("API getFileInfo.sync with filepath only", () => {
|
||||
});
|
||||
|
||||
describe("API getFileInfo resolveConfig", () => {
|
||||
const files = fromPairs(
|
||||
const files = Object.fromEntries(
|
||||
["foo", "js", "bar", "css"].map((ext) => [
|
||||
ext,
|
||||
path.resolve(
|
||||
@@ -268,7 +268,7 @@ describe("API getFileInfo resolveConfig", () => {
|
||||
});
|
||||
|
||||
describe("API getFileInfo resolveConfig when no config is present", () => {
|
||||
const files = fromPairs(
|
||||
const files = Object.fromEntries(
|
||||
["foo", "js"].map((ext) => [
|
||||
ext,
|
||||
path.resolve(path.join(__dirname, `../cli/non-exists-dir/file.${ext}`)),
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
"use strict";
|
||||
|
||||
const prettier = require("prettier-local");
|
||||
const fooPlugin = require("../plugins/defaultOptions/plugin.js");
|
||||
import prettier from "prettier-local";
|
||||
import fooPlugin from "../plugins/defaultOptions/plugin.js";
|
||||
|
||||
test("yaml parser should handle CRLF correctly", () => {
|
||||
const input = "a:\r\n 123\r\n";
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
"use strict";
|
||||
|
||||
const prettier = require("prettier-local");
|
||||
const runPrettier = require("../runPrettier.js");
|
||||
const constant = require("../../../src/cli/constant.js");
|
||||
const core = require("../../../src/cli/core.js");
|
||||
const arrayify = require("../../../src/utils/arrayify.js");
|
||||
import prettier from "prettier-local";
|
||||
import runPrettier from "../runPrettier.js";
|
||||
import constant from "../../../src/cli/constant.js";
|
||||
import core from "../../../src/cli/core.js";
|
||||
import arrayify from "../../../src/utils/arrayify.js";
|
||||
|
||||
for (const option of arrayify(
|
||||
{
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
"use strict";
|
||||
import path from "node:path";
|
||||
import createEsmUtils from "esm-utils";
|
||||
import runPrettier from "../runPrettier.js";
|
||||
|
||||
const path = require("path");
|
||||
const runPrettier = require("../runPrettier.js");
|
||||
const { __dirname } = createEsmUtils(import.meta);
|
||||
|
||||
describe("support absolute filename", () => {
|
||||
runPrettier("cli/ignore-absolute-path", [
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
"use strict";
|
||||
import runPrettier from "../runPrettier.js";
|
||||
import jestPathSerializer from "../path-serializer.js";
|
||||
|
||||
const runPrettier = require("../runPrettier.js");
|
||||
|
||||
expect.addSnapshotSerializer(require("../path-serializer.js"));
|
||||
expect.addSnapshotSerializer(jestPathSerializer);
|
||||
|
||||
describe("ignores file name contains emoji", () => {
|
||||
runPrettier("cli/ignore-emoji", ["**/*.js", "-l"]).test({
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
"use strict";
|
||||
import runPrettier from "../runPrettier.js";
|
||||
import jestPathSerializer from "../path-serializer.js";
|
||||
|
||||
const runPrettier = require("../runPrettier.js");
|
||||
|
||||
expect.addSnapshotSerializer(require("../path-serializer.js"));
|
||||
expect.addSnapshotSerializer(jestPathSerializer);
|
||||
|
||||
describe("ignores files when executing in a subdirectory", () => {
|
||||
runPrettier("cli/ignore-in-subdirectories/web1", [
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
"use strict";
|
||||
import path from "node:path";
|
||||
import fs from "node:fs";
|
||||
import createEsmUtils from "esm-utils";
|
||||
import runPrettier from "../runPrettier.js";
|
||||
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const runPrettier = require("../runPrettier.js");
|
||||
const { __dirname } = createEsmUtils(import.meta);
|
||||
|
||||
fs.writeFileSync(
|
||||
// This file is in `.gitignore`, just copy from `regular-module.js`
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
"use strict";
|
||||
import runPrettier from "../runPrettier.js";
|
||||
import jestPathSerializer from "../path-serializer.js";
|
||||
|
||||
const runPrettier = require("../runPrettier.js");
|
||||
|
||||
expect.addSnapshotSerializer(require("../path-serializer.js"));
|
||||
expect.addSnapshotSerializer(jestPathSerializer);
|
||||
|
||||
describe("support relative paths", () => {
|
||||
runPrettier("cli/ignore-relative-path", [
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
"use strict";
|
||||
|
||||
const runPrettier = require("../runPrettier.js");
|
||||
import runPrettier from "../runPrettier.js";
|
||||
|
||||
describe("ignore-unknown dir", () => {
|
||||
runPrettier("cli/ignore-unknown", [
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
"use strict";
|
||||
import runPrettier from "../runPrettier.js";
|
||||
import jestPathSerializer from "../path-serializer.js";
|
||||
|
||||
const runPrettier = require("../runPrettier.js");
|
||||
|
||||
expect.addSnapshotSerializer(require("../path-serializer.js"));
|
||||
expect.addSnapshotSerializer(jestPathSerializer);
|
||||
|
||||
describe("ignores files in version control systems", () => {
|
||||
runPrettier("cli/ignore-vcs-files", [
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
"use strict";
|
||||
|
||||
const prettier = require("prettier-local");
|
||||
const runPrettier = require("../runPrettier.js");
|
||||
import prettier from "prettier-local";
|
||||
import { jest } from "@jest/globals";
|
||||
import runPrettier from "../runPrettier.js";
|
||||
|
||||
describe("stdin no path and no parser", () => {
|
||||
describe("logs error and exits with 2", () => {
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
"use strict";
|
||||
import path from "node:path";
|
||||
import prettier from "prettier-local";
|
||||
import createEsmUtils from "esm-utils";
|
||||
import runPrettier from "../runPrettier.js";
|
||||
import jestPathSerializer from "../path-serializer.js";
|
||||
|
||||
const path = require("path");
|
||||
const prettier = require("prettier-local");
|
||||
const runPrettier = require("../runPrettier.js");
|
||||
const { __dirname } = createEsmUtils(import.meta);
|
||||
|
||||
expect.addSnapshotSerializer(require("../path-serializer.js"));
|
||||
expect.addSnapshotSerializer(jestPathSerializer);
|
||||
|
||||
describe("throw error with invalid ignore", () => {
|
||||
runPrettier("cli/invalid-ignore", ["something.js"]).test({
|
||||
|
||||
@@ -1,13 +1,10 @@
|
||||
"use strict";
|
||||
|
||||
/** @type {import('prettier')} */
|
||||
const prettier = require("prettier-local");
|
||||
import prettier from "prettier-local";
|
||||
import printDoc from "../printDoc.js";
|
||||
|
||||
const { group, indent, line, lineSuffix, lineSuffixBoundary, softline } =
|
||||
prettier.doc.builders;
|
||||
|
||||
const printDoc = require("../printDoc.js");
|
||||
|
||||
describe("lineSuffixBoundary", () => {
|
||||
test("should be correctly treated as a potential line break in `fits`", () => {
|
||||
const doc = group([
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
"use strict";
|
||||
|
||||
const runPrettier = require("../runPrettier.js");
|
||||
import runPrettier from "../runPrettier.js";
|
||||
|
||||
describe("checks stdin with --list-different", () => {
|
||||
runPrettier("cli/with-shebang", ["--list-different", "--parser", "babel"], {
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
"use strict";
|
||||
|
||||
const loadToml = require("../../../src/utils/load-toml.js");
|
||||
import loadToml from "../../../src/utils/load-toml.js";
|
||||
|
||||
describe("TOML", () => {
|
||||
const exampleFilePath = "example.toml";
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
"use strict";
|
||||
|
||||
const stripAnsi = require("strip-ansi");
|
||||
const runPrettier = require("../runPrettier.js");
|
||||
import stripAnsi from "strip-ansi";
|
||||
import runPrettier from "../runPrettier.js";
|
||||
|
||||
test("do not show logs with --loglevel silent", async () => {
|
||||
await runPrettierWithLogLevel("silent", null);
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
"use strict";
|
||||
|
||||
const prettier = require("prettier-local");
|
||||
import prettier from "prettier-local";
|
||||
const docBuilders = prettier.doc.builders;
|
||||
const docUtils = prettier.doc.utils;
|
||||
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"type": "module"
|
||||
}
|
||||
@@ -1,7 +1,5 @@
|
||||
"use strict";
|
||||
|
||||
const prettier = require("prettier-local");
|
||||
const runPrettier = require("../runPrettier.js");
|
||||
import prettier from "prettier-local";
|
||||
import runPrettier from "../runPrettier.js";
|
||||
|
||||
test("allows custom parser provided as object", () => {
|
||||
const output = prettier.format("1", {
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
"use strict";
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import createEsmUtils from "esm-utils";
|
||||
import runPrettier from "../runPrettier.js";
|
||||
import jestPathSerializer from "../path-serializer.js";
|
||||
import { projectRoot } from "../env.js";
|
||||
|
||||
const path = require("path");
|
||||
const fs = require("fs");
|
||||
const runPrettier = require("../runPrettier.js");
|
||||
const { projectRoot } = require("../env.js");
|
||||
const { __dirname } = createEsmUtils(import.meta);
|
||||
|
||||
expect.addSnapshotSerializer(require("../path-serializer.js"));
|
||||
expect.addSnapshotSerializer(jestPathSerializer);
|
||||
|
||||
// ESLint-like behavior
|
||||
// https://github.com/prettier/prettier/pull/6639#issuecomment-548949954
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
"use strict";
|
||||
import runPrettier from "../runPrettier.js";
|
||||
import jestPathSerializer from "../path-serializer.js";
|
||||
|
||||
const runPrettier = require("../runPrettier.js");
|
||||
|
||||
expect.addSnapshotSerializer(require("../path-serializer.js"));
|
||||
expect.addSnapshotSerializer(jestPathSerializer);
|
||||
|
||||
/*
|
||||
fixtures-1/
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
"use strict";
|
||||
import runPrettier from "../runPrettier.js";
|
||||
import jestPathSerializer from "../path-serializer.js";
|
||||
|
||||
const runPrettier = require("../runPrettier.js");
|
||||
|
||||
expect.addSnapshotSerializer(require("../path-serializer.js"));
|
||||
expect.addSnapshotSerializer(jestPathSerializer);
|
||||
|
||||
describe("multiple patterns", () => {
|
||||
runPrettier("cli/patterns", [
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
"use strict";
|
||||
|
||||
const runPrettier = require("../runPrettier.js");
|
||||
import runPrettier from "../runPrettier.js";
|
||||
|
||||
describe("output with --check + unformatted differs when piped", () => {
|
||||
const result0 = runPrettier(
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
"use strict";
|
||||
|
||||
const runPrettier = require("../runPrettier.js");
|
||||
import runPrettier from "../runPrettier.js";
|
||||
|
||||
describe("plugin default options should work", () => {
|
||||
runPrettier(
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
"use strict";
|
||||
|
||||
const runPrettier = require("../runPrettier.js");
|
||||
import runPrettier from "../runPrettier.js";
|
||||
const EOL = "\n";
|
||||
|
||||
describe("uses 'extensions' from languages to determine parser", () => {
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
"use strict";
|
||||
|
||||
const runPrettier = require("../runPrettier.js");
|
||||
import runPrettier from "../runPrettier.js";
|
||||
|
||||
describe("flush all line-suffix content", () => {
|
||||
runPrettier("plugins/flushLineSuffix", ["*.foo", "--plugin=./plugin"], {
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
"use strict";
|
||||
|
||||
const snapshotDiff = require("snapshot-diff");
|
||||
const runPrettier = require("../runPrettier.js");
|
||||
import snapshotDiff from "snapshot-diff";
|
||||
import runPrettier from "../runPrettier.js";
|
||||
|
||||
test("show external options with `--help`", async () => {
|
||||
const originalStdout = await runPrettier("plugins/options-string", ["--help"])
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
"use strict";
|
||||
|
||||
const snapshotDiff = require("snapshot-diff");
|
||||
const runPrettier = require("../runPrettier.js");
|
||||
import snapshotDiff from "snapshot-diff";
|
||||
import runPrettier from "../runPrettier.js";
|
||||
|
||||
test("show external options with `--help`", async () => {
|
||||
const originalStdout = await runPrettier("plugins/options", ["--help"])
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
"use strict";
|
||||
|
||||
const runPrettier = require("../runPrettier.js");
|
||||
import runPrettier from "../runPrettier.js";
|
||||
|
||||
describe("json-stringify takes precedence over json for package.json", () => {
|
||||
runPrettier("plugins", ["--stdin-filepath=package.json"], {
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
"use strict";
|
||||
|
||||
const runPrettier = require("../runPrettier.js");
|
||||
import runPrettier from "../runPrettier.js";
|
||||
const EOL = "\n";
|
||||
|
||||
describe("parser preprocess function is used to reshape input text", () => {
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
"use strict";
|
||||
|
||||
const runPrettier = require("../runPrettier.js");
|
||||
import runPrettier from "../runPrettier.js";
|
||||
const EOL = "\n";
|
||||
|
||||
describe("automatically loads 'prettier-plugin-*'", () => {
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
"use strict";
|
||||
|
||||
const runPrettier = require("../runPrettier.js");
|
||||
import runPrettier from "../runPrettier.js";
|
||||
|
||||
describe("plugin search should not crash when prettier isn't inside a directory", () => {
|
||||
runPrettier(
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
"use strict";
|
||||
import path from "node:path";
|
||||
import prettier from "prettier-local";
|
||||
import createEsmUtils from "esm-utils";
|
||||
|
||||
const path = require("path");
|
||||
|
||||
const prettier = require("prettier-local");
|
||||
const { __dirname } = createEsmUtils(import.meta);
|
||||
|
||||
test("API resolveConfigFile", async () => {
|
||||
const result = await prettier.resolveConfigFile();
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
"use strict";
|
||||
|
||||
const prettier = require("prettier-local");
|
||||
const generateSchema = require("../../../scripts/utils/generate-schema.js");
|
||||
import prettier from "prettier-local";
|
||||
import generateSchema from "../../../scripts/utils/generate-schema.js";
|
||||
|
||||
test("schema", () => {
|
||||
expect(generateSchema(prettier.getSupportInfo().options)).toMatchSnapshot();
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
"use strict";
|
||||
import runPrettier from "../runPrettier.js";
|
||||
import jestPathSerializer from "../path-serializer.js";
|
||||
|
||||
const runPrettier = require("../runPrettier.js");
|
||||
|
||||
expect.addSnapshotSerializer(require("../path-serializer.js"));
|
||||
expect.addSnapshotSerializer(jestPathSerializer);
|
||||
|
||||
describe("skips folders in glob", () => {
|
||||
runPrettier("cli/skip-folders", ["**/*", "-l"]).test({
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
"use strict";
|
||||
|
||||
const { isCI } = require("ci-info");
|
||||
const runPrettier = require("../runPrettier.js");
|
||||
import { isCI } from "ci-info";
|
||||
import runPrettier from "../runPrettier.js";
|
||||
|
||||
describe("format correctly if stdin content compatible with stdin-filepath", () => {
|
||||
runPrettier(
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
"use strict";
|
||||
|
||||
const prettier = require("prettier-local");
|
||||
const runPrettier = require("../runPrettier.js");
|
||||
import prettier from "prettier-local";
|
||||
import runPrettier from "../runPrettier.js";
|
||||
|
||||
test("API getSupportInfo()", () => {
|
||||
expect(getCoreInfo()).toMatchSnapshot();
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
"use strict";
|
||||
|
||||
const runPrettier = require("../runPrettier.js");
|
||||
import runPrettier from "../runPrettier.js";
|
||||
|
||||
describe("exits with non-zero code when input has a syntax error", () => {
|
||||
runPrettier("cli/with-shebang", ["--parser", "babel"], {
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
"use strict";
|
||||
import path from "node:path";
|
||||
import createEsmUtils from "esm-utils";
|
||||
import { thirdParty } from "../env.js";
|
||||
import jestPathSerializer from "../path-serializer.js";
|
||||
|
||||
const path = require("path");
|
||||
const { thirdParty } = require("../env.js");
|
||||
const { require, __dirname } = createEsmUtils(import.meta);
|
||||
const { cosmiconfig, cosmiconfigSync, isCI } = require(thirdParty);
|
||||
|
||||
expect.addSnapshotSerializer(require("../path-serializer.js"));
|
||||
expect.addSnapshotSerializer(jestPathSerializer);
|
||||
|
||||
// This don't has to be the same result as `prettier.resolveConfig`,
|
||||
// Because we are testing with default `cosmiconfigOptions`
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
"use strict";
|
||||
|
||||
const sharedUtil = require("../../../src/common/util-shared.js");
|
||||
import sharedUtil from "../../../src/common/util-shared.js";
|
||||
|
||||
test("shared util has correct structure", () => {
|
||||
expect(typeof sharedUtil.getMaxContinuousCount).toBe("function");
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
"use strict";
|
||||
|
||||
const runPrettier = require("../runPrettier.js");
|
||||
import runPrettier from "../runPrettier.js";
|
||||
|
||||
describe("CLI overrides take precedence without --config-precedence", () => {
|
||||
runPrettier("cli/config/", [
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
"use strict";
|
||||
import runPrettier from "../runPrettier.js";
|
||||
import jestPathSerializer from "../path-serializer.js";
|
||||
|
||||
const runPrettier = require("../runPrettier.js");
|
||||
|
||||
expect.addSnapshotSerializer(require("../path-serializer.js"));
|
||||
expect.addSnapshotSerializer(jestPathSerializer);
|
||||
|
||||
describe("ignores node_modules by default", () => {
|
||||
runPrettier("cli/with-node-modules", ["**/*.js", "-l"]).test({
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
"use strict";
|
||||
|
||||
const prettier = require("prettier-local");
|
||||
const runPrettier = require("../runPrettier.js");
|
||||
import prettier from "prettier-local";
|
||||
import runPrettier from "../runPrettier.js";
|
||||
|
||||
describe("infers postcss parser", () => {
|
||||
runPrettier("cli/with-parser-inference", ["--end-of-line", "lf", "*"]).test({
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
"use strict";
|
||||
|
||||
const runPrettier = require("../runPrettier.js");
|
||||
import runPrettier from "../runPrettier.js";
|
||||
|
||||
describe("preserves shebang", () => {
|
||||
runPrettier("cli/with-shebang", ["--end-of-line", "lf", "issue1890.js"]).test(
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
"use strict";
|
||||
|
||||
const runPrettier = require("../runPrettier.js");
|
||||
import runPrettier from "../runPrettier.js";
|
||||
|
||||
describe("write file with --write + unformatted file", () => {
|
||||
runPrettier("cli/write", ["--write", "unformatted.js"]).test({
|
||||
|
||||
@@ -8,7 +8,7 @@ import { shallowEqual } from "./helpers.js";
|
||||
import * as urlHash from "./urlHash.js";
|
||||
import formatMarkdown from "./markdown.js";
|
||||
import * as util from "./util.js";
|
||||
import getCodeSample from "./codeSamples.js";
|
||||
import getCodeSample from "./codeSamples.mjs";
|
||||
|
||||
import { Sidebar, SidebarCategory } from "./sidebar/components.js";
|
||||
import SidebarOptions from "./sidebar/SidebarOptions.js";
|
||||
|
||||
File renamed without changes.
@@ -1338,7 +1338,7 @@
|
||||
jest-mock "^27.4.2"
|
||||
jest-util "^27.4.2"
|
||||
|
||||
"@jest/globals@^27.4.2":
|
||||
"@jest/globals@27.4.2", "@jest/globals@^27.4.2":
|
||||
version "27.4.2"
|
||||
resolved "https://registry.yarnpkg.com/@jest/globals/-/globals-27.4.2.tgz#56a402c5ebf22eba1d34e900772147f5126ea2d8"
|
||||
integrity sha512-KkfaHEttlGpXYAQTZHgrESiEPx2q/DKAFLGLFda1uGVrqc17snd3YVPhOxlXOHIzVPs+lQ/SDB2EIvxyGzb3Ew==
|
||||
@@ -1989,7 +1989,7 @@ asynckit@^0.4.0:
|
||||
resolved "https://registry.yarnpkg.com/asynckit/-/asynckit-0.4.0.tgz#c79ed97f7f34cb8f2ba1bc9790bcc366474b4b79"
|
||||
integrity sha1-x57Zf380y48robyXkLzDZkdLS3k=
|
||||
|
||||
babel-jest@27.4.2, babel-jest@^27.4.2:
|
||||
babel-jest@^27.4.2:
|
||||
version "27.4.2"
|
||||
resolved "https://registry.yarnpkg.com/babel-jest/-/babel-jest-27.4.2.tgz#6edf80971045cfd44f3f10b6eda6007d95f62742"
|
||||
integrity sha512-MADrjb3KBO2eyZCAc6QaJg6RT5u+6oEdDyHO5HEalnpwQ6LrhTsQF2Kj1Wnz2t6UPXIXPk18dSXXOT0wF5yTxA==
|
||||
|
||||
Reference in new issue
Block a user