Run production tests on npm package (#3730)

* Run production tests on npm package

* Put back fast finish
master
Lucas Azzola 2018-01-13 03:19:20 +11:00 committed by GitHub
parent 934f679705
commit dd78f31aaf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 71 additions and 7 deletions

View File

@ -6,7 +6,7 @@ node_js:
cache:
yarn: true
directories:
- node_modules
- node_modules
env:
- NODE_ENV=development
- NODE_ENV=production
@ -20,5 +20,9 @@ before_script:
script:
- yarn lint
- yarn lint-docs
- AST_COMPARE=1 yarn test -- --runInBand
- if [ "${NODE_ENV}" = "production" ]; then yarn test:dist; fi
- if [ "${NODE_ENV}" = "development" ]; then AST_COMPARE=1 yarn test -- --runInBand; fi
- if [ "${NODE_ENV}" = "development" ]; then yarn codecov; fi
branches:
only:
- master

View File

@ -85,6 +85,7 @@
"snapshot-diff": "0.2.2",
"strip-ansi": "4.0.0",
"sw-toolbox": "3.6.0",
"tempy": "0.2.1",
"uglify-es": "3.0.28",
"webpack": "2.6.1"
},
@ -92,7 +93,7 @@
"prepublishOnly": "echo \"Error: must publish from dist/\" && exit 1",
"prepare-release": "yarn && yarn build && yarn test:dist",
"test": "jest",
"test:dist": "cross-env NODE_ENV=production yarn test",
"test:dist": "node ./scripts/test-dist.js",
"test-integration": "jest tests_integration",
"lint": "cross-env EFF_NO_LINK_RULES=true eslint . --format node_modules/eslint-friendly-formatter",
"lint-docs": "prettylint {.,docs,website,website/blog}/*.md",

33
scripts/test-dist.js Normal file
View File

@ -0,0 +1,33 @@
#!/usr/bin/env node
"use strict";
const path = require("path");
const shell = require("shelljs");
const tempy = require("tempy");
shell.config.fatal = true;
const rootDir = path.join(__dirname, "..");
const distDir = path.join(rootDir, "dist");
const file = shell.exec("npm pack", { cwd: distDir }).stdout.trim();
const tarPath = path.join(distDir, file);
const tmpDir = tempy.directory();
shell.config.silent = true;
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", {
cwd: rootDir,
env: Object.assign({}, process.env, {
NODE_ENV: "production",
AST_COMPARE: "1",
PRETTIER_DIR: path.join(tmpDir, "node_modules/prettier")
}),
shell: true
}).code;
process.exit(code);

View File

@ -1,6 +1,8 @@
"use strict";
const isProduction = process.env.NODE_ENV === "production";
const prettier = require(isProduction ? "../dist/" : "../");
const prettierRootDir = isProduction ? process.env.PRETTIER_DIR : "../";
const prettier = require(prettierRootDir);
module.exports = prettier;

View File

@ -6,10 +6,13 @@ const stripAnsi = require("strip-ansi");
const ENV_LOG_LEVEL = require("../src/cli/logger").ENV_LOG_LEVEL;
const isProduction = process.env.NODE_ENV === "production";
const prettierCli = isProduction ? "../dist/bin-prettier" : "../bin/prettier";
const prettierRootDir = isProduction ? process.env.PRETTIER_DIR : "../";
const prettierPkg = require(path.join(prettierRootDir, "package.json"));
const prettierCli = path.join(prettierRootDir, prettierPkg.bin.prettier);
const thirdParty = isProduction
? "../dist/third-party"
: "../src/common/third-party";
? path.join(prettierRootDir, "./third-party")
: path.join(prettierRootDir, "./src/common/third-party");
function runPrettier(dir, args, options) {
args = args || [];

View File

@ -1297,6 +1297,10 @@ crypto-browserify@^3.11.0:
public-encrypt "^4.0.0"
randombytes "^2.0.0"
crypto-random-string@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/crypto-random-string/-/crypto-random-string-1.0.0.tgz#a230f64f568310e1498009940790ec99545bca7e"
cssom@0.3.x, "cssom@>= 0.3.2 < 0.4.0":
version "0.3.2"
resolved "https://registry.yarnpkg.com/cssom/-/cssom-0.3.2.tgz#b8036170c79f07a90ff2f16e22284027a243848b"
@ -4434,6 +4438,17 @@ tar@^2.2.1:
fstream "^1.0.2"
inherits "2"
temp-dir@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/temp-dir/-/temp-dir-1.0.0.tgz#0a7c0ea26d3a39afa7e0ebea9c1fc0bc4daa011d"
tempy@0.2.1:
version "0.2.1"
resolved "https://registry.yarnpkg.com/tempy/-/tempy-0.2.1.tgz#9038e4dbd1c201b74472214179bc2c6f7776e54c"
dependencies:
temp-dir "^1.0.0"
unique-string "^1.0.0"
test-exclude@^4.1.1:
version "4.1.1"
resolved "https://registry.yarnpkg.com/test-exclude/-/test-exclude-4.1.1.tgz#4d84964b0966b0087ecc334a2ce002d3d9341e26"
@ -4608,6 +4623,12 @@ uniq@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/uniq/-/uniq-1.0.1.tgz#b31c5ae8254844a3a8281541ce2b04b865a734ff"
unique-string@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/unique-string/-/unique-string-1.0.0.tgz#9e1057cca851abb93398f8b33ae187b99caec11a"
dependencies:
crypto-random-string "^1.0.0"
unist-util-remove-position@^1.0.0:
version "1.1.1"
resolved "https://registry.yarnpkg.com/unist-util-remove-position/-/unist-util-remove-position-1.1.1.tgz#5a85c1555fc1ba0c101b86707d15e50fa4c871bb"