Run tests using the standalone build in an empty context (#4668)
Validate that our build is stripping all the "native" dependencies (native modules and env vars).master
parent
dcc060a5a5
commit
889b7dab79
|
@ -80,6 +80,17 @@ jobs:
|
|||
at: ~/prettier
|
||||
- run: yarn test:dist
|
||||
|
||||
# Run tests using the standalone build
|
||||
test_prod_standalone:
|
||||
<<: *defaults
|
||||
steps:
|
||||
- attach_workspace:
|
||||
at: ~/prettier
|
||||
- run:
|
||||
command: yarn test:dist
|
||||
environment:
|
||||
TEST_STANDALONE: 1
|
||||
|
||||
workflows:
|
||||
version: 2
|
||||
prod:
|
||||
|
@ -94,3 +105,6 @@ workflows:
|
|||
- test_prod_node9:
|
||||
requires:
|
||||
- build_prod
|
||||
- test_prod_standalone:
|
||||
requires:
|
||||
- build_prod
|
||||
|
|
|
@ -31,7 +31,8 @@ module.exports = {
|
|||
// If this is removed, see also scripts/build/build.js.
|
||||
"graceful-fs": "<rootDir>/tests_config/fs.js",
|
||||
|
||||
"prettier/local": "<rootDir>/tests_config/require_prettier.js"
|
||||
"prettier/local": "<rootDir>/tests_config/require_prettier.js",
|
||||
"prettier/standalone": "<rootDir>/tests_config/require_standalone.js"
|
||||
},
|
||||
transform: {}
|
||||
};
|
||||
|
|
|
@ -1,4 +1,2 @@
|
|||
module.exports = {
|
||||
ok() {},
|
||||
strictEqual() {}
|
||||
};
|
||||
export function ok() {}
|
||||
export function strictEqual() {}
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
export const EOL = "\n";
|
|
@ -20,7 +20,11 @@ shell.exec("npm init -y", { cwd: tmpDir });
|
|||
shell.exec(`npm install "${tarPath}"`, { cwd: tmpDir });
|
||||
shell.config.silent = false;
|
||||
|
||||
const code = shell.exec("yarn test --color --runInBand", {
|
||||
const cmd = `yarn test --color --runInBand ${
|
||||
process.env.TEST_STANDALONE ? "tests/" : ""
|
||||
}`;
|
||||
|
||||
const code = shell.exec(cmd, {
|
||||
cwd: rootDir,
|
||||
env: Object.assign({}, process.env, {
|
||||
NODE_ENV: "production",
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
"use strict";
|
||||
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const vm = require("vm");
|
||||
|
||||
const sources = [
|
||||
"standalone.js",
|
||||
"parser-babylon.js",
|
||||
"parser-flow.js",
|
||||
"parser-typescript.js",
|
||||
"parser-postcss.js",
|
||||
"parser-graphql.js",
|
||||
"parser-markdown.js",
|
||||
"parser-vue.js"
|
||||
].map(filename =>
|
||||
fs.readFileSync(path.join(process.env.PRETTIER_DIR, filename), "utf-8")
|
||||
);
|
||||
|
||||
const sandbox = vm.createContext();
|
||||
vm.runInContext(sources.join(";"), sandbox);
|
||||
|
||||
// TODO: maybe expose (and write tests) for `format`, `utils`, and
|
||||
// `__debug` methods
|
||||
module.exports = {
|
||||
formatWithCursor(input, options) {
|
||||
return vm.runInNewContext(
|
||||
`prettier.formatWithCursor(
|
||||
$$$input,
|
||||
Object.assign({ plugins: prettierPlugins }, $$$options)
|
||||
);`,
|
||||
Object.assign({ $$$input: input, $$$options: options }, sandbox)
|
||||
);
|
||||
},
|
||||
|
||||
__debug: {
|
||||
parse(input, options, massage) {
|
||||
return vm.runInNewContext(
|
||||
`prettier.__debug.parse(
|
||||
$$$input,
|
||||
Object.assign({ plugins: prettierPlugins }, $$$options),
|
||||
${JSON.stringify(massage)}
|
||||
);`,
|
||||
Object.assign({ $$$input: input, $$$options: options }, sandbox)
|
||||
);
|
||||
}
|
||||
}
|
||||
};
|
|
@ -2,9 +2,13 @@
|
|||
|
||||
const fs = require("fs");
|
||||
const extname = require("path").extname;
|
||||
const prettier = require("prettier/local");
|
||||
|
||||
const AST_COMPARE = process.env["AST_COMPARE"];
|
||||
const TEST_STANDALONE = process.env["TEST_STANDALONE"];
|
||||
|
||||
const prettier = !TEST_STANDALONE
|
||||
? require("prettier/local")
|
||||
: require("prettier/standalone");
|
||||
|
||||
function run_spec(dirname, parsers, options) {
|
||||
/* instabul ignore if */
|
||||
|
@ -13,6 +17,13 @@ function run_spec(dirname, parsers, options) {
|
|||
}
|
||||
|
||||
fs.readdirSync(dirname).forEach(filename => {
|
||||
// We need to have a skipped test with the same name of the snapshots,
|
||||
// so Jest doesn't mark them as obsolete.
|
||||
if (TEST_STANDALONE && parsers.some(skipStandalone)) {
|
||||
test.skip(filename);
|
||||
return;
|
||||
}
|
||||
|
||||
const path = dirname + "/" + filename;
|
||||
if (
|
||||
extname(filename) !== ".snap" &&
|
||||
|
@ -116,6 +127,10 @@ function read(filename) {
|
|||
return fs.readFileSync(filename, "utf8");
|
||||
}
|
||||
|
||||
function skipStandalone(parser) {
|
||||
return new Set(["parse5", "glimmer"]).has(parser);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wraps a string in a marker object that is used by `./raw-serializer.js` to
|
||||
* directly print that string in a snapshot without escaping all double quotes.
|
||||
|
|
Loading…
Reference in New Issue