Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(run): allow multiple script targets to be triggered at once (#3527)
- Loading branch information
1 parent
aea79df
commit 937b02a
Showing
7 changed files
with
187 additions
and
5 deletions.
There are no files selected for viewing
84 changes: 84 additions & 0 deletions
84
e2e/run/task-runner/src/multiple-targets/assertions.spec.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,84 @@ | ||
import { Fixture, normalizeCommandOutput, normalizeEnvironment } from "@lerna/e2e-utils"; | ||
|
||
expect.addSnapshotSerializer({ | ||
serialize(str: string) { | ||
return ( | ||
normalizeCommandOutput(normalizeEnvironment(str)) | ||
// Normalize the script names in the output otherwise it will be non-deterministic | ||
.replaceAll("print-name-again", "XXXXXXXXXX") | ||
.replaceAll("print-name", "XXXXXXXXXX") | ||
); | ||
}, | ||
test(val: string) { | ||
return val != null && typeof val === "string"; | ||
}, | ||
}); | ||
|
||
describe("lerna-run-nx-multiple-targets", () => { | ||
const fixtureRootPath = process.env.FIXTURE_ROOT_PATH; | ||
let fixture: Fixture; | ||
|
||
beforeAll(() => { | ||
if (!fixtureRootPath) { | ||
throw new Error("FIXTURE_ROOT_PATH environment variable is not set"); | ||
} | ||
fixture = Fixture.fromExisting(process.env.E2E_ROOT, fixtureRootPath); | ||
}); | ||
|
||
afterAll(() => fixture.destroy()); | ||
|
||
it("should run multiple comma-delimited targets concurrently", async () => { | ||
const output = await fixture.readOutput("multiple-targets"); | ||
|
||
expect(output).toMatchInlineSnapshot(` | ||
lerna notice cli v999.9.9-e2e.0 | ||
> Lerna (powered by Nx) Running targets XXXXXXXXXX, XXXXXXXXXX for 3 projects: | ||
- package-X | ||
- package-X | ||
- package-X | ||
> package-X:XXXXXXXXXX | ||
> package-X@0.0.0 XXXXXXXXXX | ||
> echo test-package-X | ||
test-package-X | ||
> package-X:XXXXXXXXXX | ||
> package-X@0.0.0 XXXXXXXXXX | ||
> echo test-package-X | ||
test-package-X | ||
> package-X:XXXXXXXXXX | ||
> package-X@0.0.0 XXXXXXXXXX | ||
> echo test-package-X | ||
test-package-X | ||
> package-X:XXXXXXXXXX | ||
> package-X@0.0.0 XXXXXXXXXX | ||
> echo test-package-X | ||
test-package-X | ||
> Lerna (powered by Nx) Successfully ran targets XXXXXXXXXX, XXXXXXXXXX for 3 projects | ||
`); | ||
}); | ||
}); |
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 @@ | ||
DIR=$(dirname "$0") | ||
UPDATE_SNAPSHOTS=$1 | ||
|
||
# Inline the bash util functions | ||
source "$DIR/../utils.sh" | ||
|
||
# Initialize the Fixture and modify the generated fixture root path | ||
declare FIXTURE_ROOT_PATH | ||
declare E2E_ROOT | ||
initializeFixture $DIR | ||
|
||
# Run the relevant task runner commands and write stdout and stderr to a named file in each case (for later assertions) | ||
npx lerna run print-name,print-name-again > $OUTPUTS/multiple-targets.txt 2>&1 | ||
|
||
# Run the assertions | ||
runAssertions $DIR $E2E_ROOT $FIXTURE_ROOT_PATH $UPDATE_SNAPSHOTS |
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,41 @@ | ||
import { Fixture } from "@lerna/e2e-utils"; | ||
|
||
(async () => { | ||
const fixture = await Fixture.create({ | ||
e2eRoot: process.env.E2E_ROOT, | ||
name: "lerna-run-nx-multiple-targets", | ||
packageManager: "npm", | ||
initializeGit: true, | ||
runLernaInit: true, | ||
installDependencies: true, | ||
}); | ||
|
||
await fixture.lerna("create package-1 -y"); | ||
await fixture.addScriptsToPackage({ | ||
packagePath: "packages/package-1", | ||
scripts: { | ||
// Just print-name | ||
"print-name": "echo test-package-1", | ||
}, | ||
}); | ||
await fixture.lerna("create package-2 -y"); | ||
await fixture.addScriptsToPackage({ | ||
packagePath: "packages/package-2", | ||
scripts: { | ||
// Just print-name-again | ||
"print-name-again": "echo test-package-2", | ||
}, | ||
}); | ||
await fixture.lerna("create package-3 -y"); | ||
await fixture.addScriptsToPackage({ | ||
packagePath: "packages/package-3", | ||
scripts: { | ||
// Both print-name and print-name-again | ||
"print-name": "echo test-package-3", | ||
"print-name-again": "echo test-package-3", | ||
}, | ||
}); | ||
|
||
// Log the fixture's root path so that it can be captured in exec.sh | ||
console.log((fixture as any).fixtureRootPath); | ||
})(); |
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
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
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
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