Refactor production tests (#8073)

This commit is contained in:
fisker Cheung authored and GitHub committed 2020-04-18 01:24:22 +08:00
1 parent 5d438e3f25
commit 118b79f0c9
5 files changed
+45 -50

No files matched your search

+14 -6
View File
@@ -116,8 +116,13 @@ jobs:
name: dist name: dist
path: dist path: dist
- name: Run Tests - name: Run Tests (macOS)
run: yarn test:dist if: matrix.os == 'macos-latest'
run: yarn test:dist --maxWorkers=4
- name: Run Tests (Linux and Windows)
if: matrix.os != 'macos-latest'
run: yarn test:dist --maxWorkers=2
standalone: standalone:
strategy: strategy:
@@ -134,8 +139,6 @@ jobs:
exclude: exclude:
- os: "macos-latest" - os: "macos-latest"
node: "13" node: "13"
env:
STANDALONE: true
name: Node.js ${{ matrix.node }} on ${{ matrix.os }} (standalone) name: Node.js ${{ matrix.node }} on ${{ matrix.os }} (standalone)
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
needs: [build] needs: [build]
@@ -159,5 +162,10 @@ jobs:
name: dist name: dist
path: dist path: dist
- name: Run Tests - name: Run Tests (macOS)
run: yarn test:dist if: matrix.os == 'macos-latest'
run: yarn test:dist-standalone --maxWorkers=4
- name: Run Tests (Linux and Windows)
if: matrix.os != 'macos-latest'
run: yarn test:dist-standalone --maxWorkers=2
+6
View File
@@ -1,5 +1,11 @@
"use strict"; "use strict";
const installPrettier = require("./scripts/install-prettier");
const ENABLE_CODE_COVERAGE = !!process.env.ENABLE_CODE_COVERAGE; const ENABLE_CODE_COVERAGE = !!process.env.ENABLE_CODE_COVERAGE;
if (process.env.NODE_ENV === "production") {
process.env.PRETTIER_DIR = installPrettier();
}
module.exports = { module.exports = {
setupFiles: ["<rootDir>/tests_config/run_spec.js"], setupFiles: ["<rootDir>/tests_config/run_spec.js"],
+2 -1
View File
@@ -115,7 +115,8 @@
"prepublishOnly": "echo \"Error: must publish from dist/\" && exit 1", "prepublishOnly": "echo \"Error: must publish from dist/\" && exit 1",
"prepare-release": "yarn && yarn build && yarn test:dist", "prepare-release": "yarn && yarn build && yarn test:dist",
"test": "jest", "test": "jest",
"test:dist": "node ./scripts/test-dist.js", "test:dist": "cross-env NODE_ENV=production jest",
"test:dist-standalone": "cross-env NODE_ENV=production STANDALONE=1 jest tests/",
"test:integration": "jest tests_integration", "test:integration": "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": "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: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",
+23
View File
@@ -0,0 +1,23 @@
"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");
module.exports = () => {
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;
return path.join(tmpDir, "node_modules/prettier");
};
-43
View File
@@ -1,43 +0,0 @@
#!/usr/bin/env node
"use strict";
const os = require("os");
const path = require("path");
const shell = require("shelljs");
const tempy = require("tempy");
const { isCI } = require("ci-info");
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;
// This `maxWorkers` number is hard code for github actions
const maxWorkers = isCI
? `--maxWorkers=${os.platform() === "darwin" ? 4 : 2}`
: "";
const testPath = process.env.TEST_STANDALONE ? "tests/" : "";
const cmd = `yarn test --color ${maxWorkers} ${testPath}`;
const { code } = shell.exec(cmd, {
cwd: rootDir,
env: {
...process.env,
NODE_ENV: "production",
AST_COMPARE: "1",
PRETTIER_DIR: path.join(tmpDir, "node_modules/prettier"),
},
shell: true,
});
process.exit(code);