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

test: use jest global setup/teardown to manage the registry mock #6813

Merged
merged 4 commits into from
Jul 15, 2023
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
5 changes: 1 addition & 4 deletions .meta-updater/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,9 @@ async function updateManifest (workspaceDir: string, manifest: ProjectManifest,
scripts = {
...(manifest.scripts as Record<string, string>),
'registry-mock': 'registry-mock',
'test:jest': 'jest',

'test:e2e': 'registry-mock prepare && run-p -r registry-mock test:jest',
}
scripts.test = 'pnpm run compile && pnpm run _test'
scripts._test = `cross-env PNPM_REGISTRY_MOCK_PORT=${port} pnpm run test:e2e`
scripts._test = `cross-env PNPM_REGISTRY_MOCK_PORT=${port} jest`
break
}
default:
Expand Down
21 changes: 21 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Table of contents

- [Setting Up the Environment](#setting-up-the-environment)
- [Running Tests](#running-tests)
- [Submitting a Pull Request (PR)](#submitting-a-pull-request-pr)
- [After your pull request is merged](#after-your-pull-request-is-merged)
- [Coding Style Guidelines](#coding-style-guidelines)
Expand Down Expand Up @@ -30,6 +31,26 @@ Some of the e2e tests run node-gyp, so you might need to install some build-esse
sudo dnf install make automake gcc gcc-c++ kernel-devel
```

## Running Tests

You can run the tests of the project that you modified by going to the project's directory and running:

```shell
pnpm test
```

Alternatively, you can run it from anywhere by specifying the name of the project using the `--filter` option:

```shell
pnpm --filter=core test
```

If you want to pass options to Jest, use the `pnpm run test` command and append any needed options. For instance, if you want to run a single test in a single file, run:

```shell
pnpm --filter=core run test --testPathPattern="test/lockfile.ts" --testNamePattern="lockfile has dev deps even when installing for prod only"
```

## Submitting a Pull Request (PR)

Before you submit your Pull Request (PR) consider the following guidelines:
Expand Down
2 changes: 1 addition & 1 deletion __utils__/assert-project/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"@pnpm/constants": "workspace:*",
"@pnpm/lockfile-types": "workspace:*",
"@pnpm/modules-yaml": "workspace:*",
"@pnpm/registry-mock": "3.8.0",
"@pnpm/registry-mock": "3.10.2",
"@pnpm/types": "workspace:*",
"is-windows": "^1.0.2",
"isexe": "2.0.0",
Expand Down
2 changes: 1 addition & 1 deletion __utils__/assert-store/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
},
"dependencies": {
"@pnpm/cafs": "workspace:*",
"@pnpm/registry-mock": "3.8.0",
"@pnpm/registry-mock": "3.10.2",
"path-exists": "^4.0.0"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion exec/plugin-commands-rebuild/jest.config.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = require('../../jest.config.js')
module.exports = require('../../jest-with-registry.config.js')
6 changes: 2 additions & 4 deletions exec/plugin-commands-rebuild/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
"scripts": {
"lint": "eslint \"src/**/*.ts\" \"test/**/*.ts\"",
"registry-mock": "registry-mock",
"test:jest": "jest",
"test:e2e": "registry-mock prepare && run-p -r registry-mock test:jest",
"_test": "cross-env PNPM_REGISTRY_MOCK_PORT=7770 pnpm run test:e2e",
"_test": "cross-env PNPM_REGISTRY_MOCK_PORT=7770 jest",
"test": "pnpm run compile && pnpm run _test",
"prepublishOnly": "pnpm run compile",
"compile": "tsc --build && pnpm run lint --fix"
Expand All @@ -37,7 +35,7 @@
"@pnpm/filter-workspace-packages": "workspace:*",
"@pnpm/plugin-commands-rebuild": "workspace:*",
"@pnpm/prepare": "workspace:*",
"@pnpm/registry-mock": "3.8.0",
"@pnpm/registry-mock": "3.10.2",
"@pnpm/test-fixtures": "workspace:*",
"@types/ramda": "0.28.20",
"@types/semver": "7.3.13",
Expand Down
2 changes: 1 addition & 1 deletion exec/plugin-commands-script-runners/jest.config.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = require('../../jest.config.js')
module.exports = require('../../jest-with-registry.config.js')
6 changes: 2 additions & 4 deletions exec/plugin-commands-script-runners/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
"scripts": {
"lint": "eslint \"src/**/*.ts\" \"test/**/*.ts\"",
"registry-mock": "registry-mock",
"test:jest": "jest",
"test:e2e": "registry-mock prepare && run-p -r registry-mock test:jest",
"_test": "cross-env PNPM_REGISTRY_MOCK_PORT=7771 pnpm run test:e2e",
"_test": "cross-env PNPM_REGISTRY_MOCK_PORT=7771 jest",
"test": "pnpm run compile && pnpm run _test",
"prepublishOnly": "pnpm run compile",
"start": "tsc --watch",
Expand All @@ -37,7 +35,7 @@
"@pnpm/filter-workspace-packages": "workspace:*",
"@pnpm/plugin-commands-script-runners": "workspace:*",
"@pnpm/prepare": "workspace:*",
"@pnpm/registry-mock": "3.8.0",
"@pnpm/registry-mock": "3.10.2",
"@types/is-windows": "^1.0.0",
"@types/ramda": "0.28.20",
"@types/which": "^2.0.2",
Expand Down
7 changes: 7 additions & 0 deletions jest-with-registry.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const path = require("path");

module.exports = {
...require('./jest.config'),
globalSetup: path.join(__dirname, 'jest.globalSetup.js'),
globalTeardown: path.join(__dirname, 'jest.globalTeardown.js'),
}
6 changes: 6 additions & 0 deletions jest.globalSetup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const { start, prepare } = require('@pnpm/registry-mock')

module.exports = () => {
prepare()
global.__SERVER__ = start()
}
3 changes: 3 additions & 0 deletions jest.globalTeardown.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = () => {
global.__SERVER__.kill()
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"@commitlint/prompt-cli": "^17.6.6",
"@pnpm/eslint-config": "workspace:*",
"@pnpm/meta-updater": "0.2.3",
"@pnpm/registry-mock": "3.8.0",
"@pnpm/registry-mock": "3.10.2",
"@pnpm/tsconfig": "workspace:*",
"@types/jest": "^29.5.3",
"@types/node": "^14.18.53",
Expand Down
4 changes: 1 addition & 3 deletions patching/plugin-commands-patching/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
const config = require('../../jest.config.js')

module.exports = config
module.exports = require('../../jest-with-registry.config.js')

6 changes: 2 additions & 4 deletions patching/plugin-commands-patching/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
"scripts": {
"lint": "eslint \"src/**/*.ts\" \"test/**/*.ts\"",
"registry-mock": "registry-mock",
"test:jest": "jest",
"test:e2e": "registry-mock prepare && run-p -r registry-mock test:jest",
"_test": "cross-env PNPM_REGISTRY_MOCK_PORT=7772 pnpm run test:e2e",
"_test": "cross-env PNPM_REGISTRY_MOCK_PORT=7772 jest",
"test": "pnpm run compile && pnpm run _test",
"prepublishOnly": "pnpm run compile",
"compile": "tsc --build && pnpm run lint --fix"
Expand All @@ -36,7 +34,7 @@
"@pnpm/filter-workspace-packages": "workspace:*",
"@pnpm/plugin-commands-patching": "workspace:*",
"@pnpm/prepare": "workspace:*",
"@pnpm/registry-mock": "3.8.0",
"@pnpm/registry-mock": "3.10.2",
"@pnpm/test-fixtures": "workspace:*",
"@types/normalize-path": "^3.0.0",
"@types/npm-packlist": "^3.0.0",
Expand Down
2 changes: 1 addition & 1 deletion pkg-manager/core/jest.config.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = require('../../jest.config.js')
module.exports = require('../../jest-with-registry.config.js')
6 changes: 2 additions & 4 deletions pkg-manager/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
"@pnpm/lockfile-types": "workspace:*",
"@pnpm/package-store": "workspace:*",
"@pnpm/prepare": "workspace:*",
"@pnpm/registry-mock": "3.8.0",
"@pnpm/registry-mock": "3.10.2",
"@pnpm/store-path": "workspace:*",
"@pnpm/test-fixtures": "workspace:*",
"@types/fs-extra": "^9.0.13",
Expand Down Expand Up @@ -142,10 +142,8 @@
"commitmsg": "commitlint -e",
"lint": "eslint \"src/**/*.ts\" \"test/**/*.ts\"",
"registry-mock": "registry-mock",
"test:jest": "jest",
"test:e2e": "registry-mock prepare && run-p -r registry-mock test:jest",
"test-with-preview": "preview && pnpm run test:e2e",
"_test": "cross-env PNPM_REGISTRY_MOCK_PORT=4873 pnpm run test:e2e",
"_test": "cross-env PNPM_REGISTRY_MOCK_PORT=4873 jest",
"test": "pnpm run compile && pnpm run _test",
"prepublishOnly": "pnpm run compile",
"compile": "tsc --build && pnpm run lint --fix"
Expand Down
2 changes: 1 addition & 1 deletion pkg-manager/headless/jest.config.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = require('../../jest.config.js')
module.exports = require('../../jest-with-registry.config.js')
8 changes: 3 additions & 5 deletions pkg-manager/headless/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"@pnpm/package-store": "workspace:*",
"@pnpm/prepare": "workspace:*",
"@pnpm/read-projects-context": "workspace:*",
"@pnpm/registry-mock": "3.8.0",
"@pnpm/registry-mock": "3.10.2",
"@pnpm/store-path": "workspace:*",
"@pnpm/test-fixtures": "workspace:*",
"@types/fs-extra": "^9.0.13",
Expand Down Expand Up @@ -57,9 +57,7 @@
"commitmsg": "commitlint -e",
"lint": "eslint \"src/**/*.ts\" \"test/**/*.ts\"",
"registry-mock": "registry-mock",
"test:jest": "jest",
"test:e2e": "registry-mock prepare && run-p -r registry-mock test:jest",
"_test": "cross-env PNPM_REGISTRY_MOCK_PORT=7773 pnpm run test:e2e",
"_test": "cross-env PNPM_REGISTRY_MOCK_PORT=7773 jest",
"test": "pnpm run compile && pnpm run _test",
"prepublishOnly": "pnpm run compile",
"runPrepareFixtures": "node ../../pnpm/bin/pnpm.cjs i -r -C test/fixtures --no-shared-workspace-lockfile --no-link-workspace-packages --lockfile-only --registry http://localhost:4873/ --ignore-scripts --force --no-strict-peer-dependencies",
Expand All @@ -71,8 +69,8 @@
"@pnpm/calc-dep-state": "workspace:*",
"@pnpm/constants": "workspace:*",
"@pnpm/core-loggers": "workspace:*",
"@pnpm/deps.graph-builder": "workspace:*",
"@pnpm/dependency-path": "workspace:*",
"@pnpm/deps.graph-builder": "workspace:*",
"@pnpm/error": "workspace:*",
"@pnpm/filter-lockfile": "workspace:*",
"@pnpm/hoist": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion pkg-manager/package-requester/jest.config.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = require('../../jest.config')
module.exports = require('../../jest-with-registry.config.js')
8 changes: 3 additions & 5 deletions pkg-manager/package-requester/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,11 @@
"scripts": {
"start": "tsc --watch",
"lint": "eslint \"src/**/*.ts\" \"test/**/*.ts\"",
"_test": "cross-env PNPM_REGISTRY_MOCK_PORT=7774 pnpm run test:e2e",
"_test": "cross-env PNPM_REGISTRY_MOCK_PORT=7774 jest",
"test": "pnpm run compile && pnpm run _test",
"prepublishOnly": "pnpm run compile",
"compile": "tsc --build && pnpm run lint --fix",
"registry-mock": "registry-mock",
"test:jest": "jest",
"test:e2e": "registry-mock prepare && run-p -r registry-mock test:jest"
"registry-mock": "registry-mock"
},
"repository": "https://github.com/pnpm/pnpm/blob/main/pkg-manager/package-requester",
"keywords": [
Expand Down Expand Up @@ -68,7 +66,7 @@
"@pnpm/client": "workspace:*",
"@pnpm/create-cafs-store": "workspace:*",
"@pnpm/package-requester": "workspace:*",
"@pnpm/registry-mock": "3.8.0",
"@pnpm/registry-mock": "3.10.2",
"@pnpm/test-fixtures": "workspace:*",
"@types/normalize-path": "^3.0.0",
"@types/ramda": "0.28.20",
Expand Down
2 changes: 1 addition & 1 deletion pkg-manager/plugin-commands-installation/jest.config.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = require('../../jest.config.js')
module.exports = require('../../jest-with-registry.config.js')
6 changes: 2 additions & 4 deletions pkg-manager/plugin-commands-installation/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@
"start": "tsc --watch",
"lint": "eslint \"src/**/*.ts\" \"test/**/*.ts\"",
"registry-mock": "registry-mock",
"test:jest": "jest",
"test:e2e": "registry-mock prepare && run-p -r registry-mock test:jest",
"_test": "cross-env PNPM_REGISTRY_MOCK_PORT=7775 pnpm run test:e2e",
"_test": "cross-env PNPM_REGISTRY_MOCK_PORT=7775 jest",
"test": "pnpm run compile && pnpm run _test",
"prepublishOnly": "pnpm run compile",
"compile": "tsc --build && pnpm run lint --fix"
Expand All @@ -37,7 +35,7 @@
"@pnpm/modules-yaml": "workspace:*",
"@pnpm/plugin-commands-installation": "workspace:*",
"@pnpm/prepare": "workspace:*",
"@pnpm/registry-mock": "3.8.0",
"@pnpm/registry-mock": "3.10.2",
"@pnpm/test-fixtures": "workspace:*",
"@types/proxyquire": "^1.3.28",
"@types/ramda": "0.28.20",
Expand Down