Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
470 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"extends": ["../../.eslintrc.json"], | ||
"ignorePatterns": ["!**/*"], | ||
"overrides": [ | ||
{ | ||
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"], | ||
"rules": {} | ||
}, | ||
{ | ||
"files": ["*.ts", "*.tsx"], | ||
"rules": {} | ||
}, | ||
{ | ||
"files": ["*.js", "*.jsx"], | ||
"rules": {} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* eslint-disable */ | ||
export default { | ||
displayName: "e2e-watch", | ||
preset: "../../jest.preset.js", | ||
globals: { | ||
"ts-jest": { | ||
tsconfig: "<rootDir>/tsconfig.spec.json", | ||
}, | ||
}, | ||
transform: { | ||
"^.+\\.[tj]s$": "ts-jest", | ||
}, | ||
moduleFileExtensions: ["ts", "js", "html"], | ||
coverageDirectory: "../../coverage/e2e/watch", | ||
maxWorkers: 1, | ||
testTimeout: 60000, | ||
setupFiles: ["<rootDir>/src/test-setup.ts"], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
{ | ||
"name": "e2e-watch", | ||
"$schema": "../../node_modules/nx/schemas/project-schema.json", | ||
"tags": [], | ||
"targets": { | ||
"e2e": { | ||
"executor": "nx:run-commands", | ||
"options": { | ||
"commands": [ | ||
{ | ||
"command": "npm run e2e-start-local-registry" | ||
}, | ||
{ | ||
"command": "npm run e2e-build-package-publish" | ||
}, | ||
{ | ||
"command": "E2E_ROOT=$(npx ts-node scripts/set-e2e-root.ts) nx run-e2e-tests e2e-watch" | ||
} | ||
], | ||
"parallel": false | ||
} | ||
}, | ||
"run-e2e-tests-process": { | ||
"executor": "nx:run-commands", | ||
"options": { | ||
"commands": [ | ||
{ | ||
"command": "E2E_ROOT=$(npx ts-node scripts/set-e2e-root.ts) nx run-e2e-tests e2e-watch", | ||
"description": "This additional wrapper target exists so that we can ensure that the e2e tests run in a dedicated process with enough memory" | ||
} | ||
], | ||
"parallel": false | ||
} | ||
}, | ||
"run-e2e-tests": { | ||
"executor": "@nrwl/jest:jest", | ||
"options": { | ||
"jestConfig": "e2e/watch/jest.config.ts", | ||
"passWithNoTests": true, | ||
"runInBand": true | ||
}, | ||
"outputs": ["{workspaceRoot}/coverage/e2e/watch"] | ||
}, | ||
"lint": { | ||
"executor": "@nrwl/linter:eslint", | ||
"outputs": ["{options.outputFile}"], | ||
"options": { | ||
"lintFilePatterns": ["e2e/watch/**/*.ts"] | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
jest.retryTimes(3); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,282 @@ | ||
import { Fixture, normalizeEnvironment, wait } from "@lerna/e2e-utils"; | ||
import { createFile } from "fs-extra"; | ||
|
||
expect.addSnapshotSerializer({ | ||
serialize(str) { | ||
return normalizeEnvironment(str); | ||
}, | ||
test(val) { | ||
return val != null && typeof val === "string"; | ||
}, | ||
}); | ||
|
||
describe("lerna-watch", () => { | ||
let fixture: Fixture; | ||
|
||
beforeEach(async () => { | ||
fixture = await Fixture.create({ | ||
e2eRoot: process.env.E2E_ROOT, | ||
name: "lerna-watch", | ||
packageManager: "npm", | ||
initializeGit: true, | ||
runLernaInit: true, | ||
installDependencies: true, | ||
}); | ||
|
||
await fixture.lerna("create package-a -y"); | ||
await fixture.lerna("create package-b --dependencies package-a -y"); | ||
await fixture.lerna("create package-c -y"); | ||
|
||
await fixture.createInitialGitCommit(); | ||
}); | ||
|
||
afterAll(() => fixture.destroy()); | ||
|
||
it("should watch all packages by default", async () => { | ||
const getWatchResult = await fixture.lernaWatch('-- "echo watch triggered"'); | ||
|
||
await createFile(fixture.getWorkspacePath("packages/package-a/my-file.txt")); | ||
await wait(200); | ||
|
||
await createFile(fixture.getWorkspacePath("packages/package-b/my-file.txt")); | ||
await wait(200); | ||
|
||
await createFile(fixture.getWorkspacePath("packages/package-c/my-file.txt")); | ||
await wait(200); | ||
|
||
const output = await getWatchResult(); | ||
|
||
expect(output.combinedOutput).toMatchInlineSnapshot(` | ||
lerna notice cli v999.9.9-e2e.0 | ||
lerna verb rootPath /tmp/lerna-e2e/lerna-watch/lerna-workspace | ||
lerna info watch Executing command "echo watch triggered" on changes in 3 packages. | ||
> NX running with args: {"command":"echo watch triggered","projectNameEnvName":"LERNA_PACKAGE_NAME","fileChangesEnvName":"LERNA_FILE_CHANGES","includeDependentProjects":false,"projects":["package-a","package-b","package-c"],"verbose":true} | ||
> NX starting watch process | ||
> NX watch process waiting... | ||
> NX about to run commands with these environments: [{"LERNA_PACKAGE_NAME":"","LERNA_FILE_CHANGES":"packages/package-a/my-file.txt"}] | ||
watch triggered | ||
> NX running complete, processing the next batch | ||
> NX no more commands to process | ||
> NX about to run commands with these environments: [{"LERNA_PACKAGE_NAME":"","LERNA_FILE_CHANGES":"packages/package-b/my-file.txt"}] | ||
watch triggered | ||
> NX running complete, processing the next batch | ||
> NX no more commands to process | ||
> NX about to run commands with these environments: [{"LERNA_PACKAGE_NAME":"","LERNA_FILE_CHANGES":"packages/package-c/my-file.txt"}] | ||
watch triggered | ||
> NX running complete, processing the next batch | ||
> NX no more commands to process | ||
`); | ||
}); | ||
|
||
describe("with --scope", () => { | ||
it("should only watch only specified packages", async () => { | ||
const getWatchResult = await fixture.lernaWatch( | ||
'--scope="package-a" --scope="package-c" -- "echo watch triggered"' | ||
); | ||
|
||
await createFile(fixture.getWorkspacePath("packages/package-a/my-file.txt")); | ||
await wait(200); | ||
|
||
await createFile(fixture.getWorkspacePath("packages/package-b/my-file.txt")); | ||
await wait(200); | ||
|
||
await createFile(fixture.getWorkspacePath("packages/package-c/my-file.txt")); | ||
await wait(200); | ||
|
||
const output = await getWatchResult(); | ||
|
||
expect(output.combinedOutput).toMatchInlineSnapshot(` | ||
lerna notice cli v999.9.9-e2e.0 | ||
lerna verb rootPath /tmp/lerna-e2e/lerna-watch/lerna-workspace | ||
lerna notice filter including ["package-a","package-c"] | ||
lerna info filter [ 'package-a', 'package-c' ] | ||
lerna info watch Executing command "echo watch triggered" on changes in 2 packages. | ||
> NX running with args: {"command":"echo watch triggered","projectNameEnvName":"LERNA_PACKAGE_NAME","fileChangesEnvName":"LERNA_FILE_CHANGES","includeDependentProjects":false,"projects":["package-a","package-c"],"verbose":true} | ||
> NX starting watch process | ||
> NX watch process waiting... | ||
> NX about to run commands with these environments: [{"LERNA_PACKAGE_NAME":"","LERNA_FILE_CHANGES":"packages/package-a/my-file.txt"}] | ||
watch triggered | ||
> NX running complete, processing the next batch | ||
> NX no more commands to process | ||
> NX about to run commands with these environments: [{"LERNA_PACKAGE_NAME":"","LERNA_FILE_CHANGES":"packages/package-c/my-file.txt"}] | ||
watch triggered | ||
> NX running complete, processing the next batch | ||
> NX no more commands to process | ||
`); | ||
}); | ||
describe("and --include-dependencies", () => { | ||
it("should watch one package and its dependencies", async () => { | ||
const getWatchResult = await fixture.lernaWatch( | ||
'--scope="package-b" --include-dependencies -- "echo watch triggered"' | ||
); | ||
|
||
await createFile(fixture.getWorkspacePath("packages/package-a/my-file.txt")); | ||
await wait(200); | ||
|
||
await createFile(fixture.getWorkspacePath("packages/package-b/my-file.txt")); | ||
await wait(200); | ||
|
||
await createFile(fixture.getWorkspacePath("packages/package-c/my-file.txt")); | ||
await wait(200); | ||
|
||
const output = await getWatchResult(); | ||
|
||
expect(output.combinedOutput).toMatchInlineSnapshot(` | ||
lerna notice cli v999.9.9-e2e.0 | ||
lerna verb rootPath /tmp/lerna-e2e/lerna-watch/lerna-workspace | ||
lerna notice filter including "package-b" | ||
lerna notice filter including dependencies | ||
lerna info filter [ 'package-b' ] | ||
lerna info watch Executing command "echo watch triggered" on changes in 2 packages. | ||
> NX running with args: {"command":"echo watch triggered","projectNameEnvName":"LERNA_PACKAGE_NAME","fileChangesEnvName":"LERNA_FILE_CHANGES","includeDependentProjects":false,"projects":["package-b","package-a"],"verbose":true} | ||
> NX starting watch process | ||
> NX watch process waiting... | ||
> NX about to run commands with these environments: [{"LERNA_PACKAGE_NAME":"","LERNA_FILE_CHANGES":"packages/package-a/my-file.txt"}] | ||
watch triggered | ||
> NX running complete, processing the next batch | ||
> NX no more commands to process | ||
> NX about to run commands with these environments: [{"LERNA_PACKAGE_NAME":"","LERNA_FILE_CHANGES":"packages/package-b/my-file.txt"}] | ||
watch triggered | ||
> NX running complete, processing the next batch | ||
> NX no more commands to process | ||
`); | ||
}); | ||
}); | ||
}); | ||
|
||
it("should replace package name and changed file names", async () => { | ||
fixture.updateJson("lerna.json", (json) => ({ | ||
...json, | ||
command: { | ||
watch: { | ||
// This workaround is necessary to prevent $LERNA_PACKAGE_NAME and $LERNA_FILE_CHANGES | ||
// from being replaced by `child_process.spawn`. This is only needed for the e2e tests. | ||
// This test case can be reproduced manually by running: | ||
// `npx lerna watch -- echo $LERNA_PACKAGE_NAME: $LERNA_FILE_CHANGES` | ||
command: "echo $LERNA_PACKAGE_NAME: $LERNA_FILE_CHANGES", | ||
}, | ||
}, | ||
})); | ||
const getWatchResult = await fixture.lernaWatch(""); | ||
|
||
await createFile(fixture.getWorkspacePath("packages/package-a/my-file.txt")); | ||
await wait(200); | ||
|
||
await createFile(fixture.getWorkspacePath("packages/package-b/my-file.txt")); | ||
await wait(200); | ||
|
||
await createFile(fixture.getWorkspacePath("packages/package-c/my-file.txt")); | ||
await wait(200); | ||
|
||
const output = await getWatchResult(); | ||
|
||
expect(output.combinedOutput).toMatchInlineSnapshot(` | ||
lerna notice cli v999.9.9-e2e.0 | ||
lerna verb rootPath /tmp/lerna-e2e/lerna-watch/lerna-workspace | ||
lerna info watch Executing command "echo $LERNA_PACKAGE_NAME: $LERNA_FILE_CHANGES" on changes in 3 packages. | ||
> NX running with args: {"command":"echo $LERNA_PACKAGE_NAME: $LERNA_FILE_CHANGES","projectNameEnvName":"LERNA_PACKAGE_NAME","fileChangesEnvName":"LERNA_FILE_CHANGES","includeDependentProjects":false,"projects":["package-a","package-b","package-c"],"verbose":true} | ||
> NX starting watch process | ||
> NX watch process waiting... | ||
> NX about to run commands with these environments: [{"LERNA_PACKAGE_NAME":"package-a","LERNA_FILE_CHANGES":"packages/package-a/my-file.txt"}] | ||
package-a: packages/package-a/my-file.txt | ||
> NX running complete, processing the next batch | ||
> NX no more commands to process | ||
> NX about to run commands with these environments: [{"LERNA_PACKAGE_NAME":"package-b","LERNA_FILE_CHANGES":"packages/package-b/my-file.txt"}] | ||
package-b: packages/package-b/my-file.txt | ||
> NX running complete, processing the next batch | ||
> NX no more commands to process | ||
> NX about to run commands with these environments: [{"LERNA_PACKAGE_NAME":"package-c","LERNA_FILE_CHANGES":"packages/package-c/my-file.txt"}] | ||
package-c: packages/package-c/my-file.txt | ||
> NX running complete, processing the next batch | ||
> NX no more commands to process | ||
`); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"extends": "../../tsconfig.base.json", | ||
"compilerOptions": { | ||
"module": "commonjs" | ||
}, | ||
"files": [], | ||
"include": [], | ||
"references": [ | ||
{ | ||
"path": "./tsconfig.lib.json" | ||
}, | ||
{ | ||
"path": "./tsconfig.spec.json" | ||
} | ||
] | ||
} |
Oops, something went wrong.