Skip to content

Commit

Permalink
Refactor production tests (#8073)
Browse files Browse the repository at this point in the history
# Conflicts:
#	scripts/test-dist.js
  • Loading branch information
fisker authored and thorn0 committed Apr 19, 2020
1 parent 58905cd commit 71fbd61
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 46 deletions.
20 changes: 14 additions & 6 deletions .github/workflows/prod-test.yml
Expand Up @@ -99,8 +99,13 @@ jobs:
name: dist
path: dist

- name: Run Tests
run: yarn test:dist
- name: Run Tests (macOS)
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:
strategy:
Expand All @@ -117,8 +122,6 @@ jobs:
exclude:
- os: "macos-latest"
node: "13"
env:
STANDALONE: true
name: Node.js ${{ matrix.node }} on ${{ matrix.os }} (standalone)
runs-on: ${{ matrix.os }}
needs: [build]
Expand All @@ -142,5 +145,10 @@ jobs:
name: dist
path: dist

- name: Run Tests
run: yarn test:dist
- name: Run Tests (macOS)
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 changes: 6 additions & 0 deletions jest.config.js
@@ -1,5 +1,11 @@
"use strict";

const installPrettier = require("./scripts/install-prettier");

const ENABLE_CODE_COVERAGE = !!process.env.ENABLE_CODE_COVERAGE;
if (process.env.NODE_ENV === "production") {
process.env.PRETTIER_DIR = installPrettier();
}

module.exports = {
setupFiles: ["<rootDir>/tests_config/run_spec.js"],
Expand Down
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -115,7 +115,8 @@
"prepublishOnly": "echo \"Error: must publish from dist/\" && exit 1",
"prepare-release": "yarn && yarn build && yarn test:dist",
"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",
"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",
Expand Down
23 changes: 23 additions & 0 deletions scripts/install-prettier.js
@@ -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");
};
39 changes: 0 additions & 39 deletions scripts/test-dist.js

This file was deleted.

0 comments on commit 71fbd61

Please sign in to comment.