Skip to content

Commit

Permalink
test: Add prepublish to lifecycle leaf
Browse files Browse the repository at this point in the history
  • Loading branch information
evocateur committed Oct 14, 2019
1 parent 276682b commit f2c8ab3
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
3 changes: 3 additions & 0 deletions __fixtures__/lifecycle/packages/package-2/package.json
Expand Up @@ -3,5 +3,8 @@
"version": "1.0.0",
"dependencies": {
"package-1": "^1.0.0"
},
"scripts": {
"prepublish": "echo prepublish-package-2"
}
}
12 changes: 9 additions & 3 deletions commands/publish/__tests__/publish-lifecycle-scripts.test.js
Expand Up @@ -12,11 +12,13 @@ jest.mock("../../version/lib/is-behind-upstream");
jest.mock("../../version/lib/remote-branch-exists");

// mocked modules
const packDirectory = require("@lerna/pack-directory");
const runLifecycle = require("@lerna/run-lifecycle");
const loadJsonFile = require("load-json-file");

// helpers
const initFixture = require("@lerna-test/init-fixture")(__dirname);
const path = require("path");

// test command
const lernaPublish = require("@lerna-test/command-runner")(require("../command"));
Expand All @@ -42,10 +44,14 @@ describe("lifecycle scripts", () => {
);
});

// package-2 lacks version lifecycle scripts
expect(runLifecycle).not.toHaveBeenCalledWith(
// package-2 only has prepublish lifecycle
expect(packDirectory).toHaveBeenCalledWith(
expect.objectContaining({ name: "package-2" }),
expect.any(String)
path.join(cwd, "packages/package-2"),
expect.objectContaining({
"ignore-prepublish": false,
"ignore-scripts": false,
})
);

expect(runLifecycle.getOrderedCalls()).toEqual([
Expand Down
1 change: 1 addition & 0 deletions integration/lerna-publish-lifecycle-silent.test.js
Expand Up @@ -38,6 +38,7 @@ prepack-root
prepare-package-1
prepublishOnly-package-1
prepack-package-1
prepublish-package-2
postpack-root
postpublish-package-1
postpublish-root
Expand Down
5 changes: 5 additions & 0 deletions integration/lerna-publish-lifecycle.test.js
Expand Up @@ -91,6 +91,11 @@ prepublishOnly-package-1
prepack-package-1
> package-2@1.1.0 prepublish __TEST_ROOTDIR__/packages/package-2
> echo prepublish-package-2
prepublish-package-2
> lifecycle@0.0.0-monorepo postpack __TEST_ROOTDIR__
> echo postpack-root
Expand Down

0 comments on commit f2c8ab3

Please sign in to comment.