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

Refactor production tests #8073

Merged
merged 1 commit into from Apr 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 14 additions & 6 deletions .github/workflows/prod-test.yml
Expand Up @@ -116,8 +116,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:
Copy link
Sponsor Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll try to merge production-test and standalone-test later.

strategy:
Expand All @@ -134,8 +139,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 @@ -159,5 +162,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") {
Copy link
Sponsor Member Author

@fisker fisker Apr 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think use NODE_ENV environment is a good idea, maybe change to another variable later

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");
};
43 changes: 0 additions & 43 deletions scripts/test-dist.js

This file was deleted.