Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Full tests #914

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import prettier from 'prettier';
import satisfies from 'semver/functions/satisfies.js';

const TEST_STANDALONE = Boolean(process.env.TEST_STANDALONE);
const testMatch = [
'<rootDir>/tests/format/**/jsfmt.spec.js',
Expand All @@ -19,13 +22,13 @@ export default {
testEnvironment: 'node',
// ignore console warnings in TEST_STANDALONE
silent: TEST_STANDALONE,
testPathIgnorePatterns: TEST_STANDALONE
testPathIgnorePatterns: satisfies(prettier.version, '^2.3.0')
? [
// Standalone mode doesn't have default options.
// This has been reported https://github.com/prettier/prettier/issues/11107
'tests/format/RespectDefaultOptions'
]
: [],
] // Ignore on v2
: [], // fixed on V3
testMatch,
transform: {},
watchPlugins: [
Expand Down
26 changes: 17 additions & 9 deletions tests/config/require-standalone.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,26 @@ const satisfies = require("semver/functions/satisfies");
const createSandBox = require("./utils/create-sandbox.cjs");

const prettierPath = path.dirname(require.resolve("prettier"));
const pluginPrefix = satisfies(prettier.version, "^2.3.0")
const isPrettier2 = satisfies(prettier.version, "^2.3.0");
const pluginPrefix = isPrettier2
? "parser-" // Prettier V2
: "plugins/"; // Prettier V3

const sandbox = createSandBox({
files: [
path.join(prettierPath, "standalone.js"),
path.join(prettierPath, `${pluginPrefix}babel.js`),
path.join(prettierPath, `${pluginPrefix}markdown.js`),
path.join(__dirname, "../../dist/standalone.cjs"),
],
});
const plugins = [
path.join(prettierPath, `${pluginPrefix}markdown.js`),
path.join(__dirname, "../../dist/standalone.cjs"),
];

const files = isPrettier2
? [path.join(prettierPath, "standalone.js"), ...plugins]
: [
path.join(prettierPath, "standalone.js"),
path.join(prettierPath, `${pluginPrefix}babel.js`),
path.join(prettierPath, `${pluginPrefix}estree.js`),
...plugins,
];

const sandbox = createSandBox({ files });

// TODO: maybe expose (and write tests) for `format`, `utils`, and
// `__debug` methods
Expand Down