Skip to content

Commit

Permalink
chore: Add options argument to run-lifecycle mock
Browse files Browse the repository at this point in the history
  • Loading branch information
evocateur committed Oct 14, 2019
1 parent b822060 commit 276682b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
4 changes: 2 additions & 2 deletions commands/__mocks__/@lerna/run-lifecycle.js
@@ -1,10 +1,10 @@
"use strict";

const mockRunLifecycle = jest.fn(pkg => Promise.resolve(pkg));
const mockCreateRunner = jest.fn(() => (pkg, stage) => {
const mockCreateRunner = jest.fn(opts => (pkg, stage) => {
// no longer the actual API, but approximates inner logic of default export
if (pkg.scripts[stage]) {
return mockRunLifecycle(pkg, stage);
return mockRunLifecycle(pkg, stage, opts);
}

return Promise.resolve();
Expand Down
6 changes: 5 additions & 1 deletion commands/publish/__tests__/publish-lifecycle-scripts.test.js
Expand Up @@ -35,7 +35,11 @@ describe("lifecycle scripts", () => {

["prepare", "prepublishOnly", "prepack", "postpack", "postpublish"].forEach(script => {
// "lifecycle" is the root manifest name
expect(runLifecycle).toHaveBeenCalledWith(expect.objectContaining({ name: "lifecycle" }), script);
expect(runLifecycle).toHaveBeenCalledWith(
expect.objectContaining({ name: "lifecycle" }),
script,
expect.any(Object)
);
});

// package-2 lacks version lifecycle scripts
Expand Down
12 changes: 10 additions & 2 deletions commands/version/__tests__/version-lifecycle-scripts.test.js
Expand Up @@ -32,8 +32,16 @@ describe("lifecycle scripts", () => {

["preversion", "version", "postversion"].forEach(script => {
// "lifecycle" is the root manifest name
expect(runLifecycle).toHaveBeenCalledWith(expect.objectContaining({ name: "lifecycle" }), script);
expect(runLifecycle).toHaveBeenCalledWith(expect.objectContaining({ name: "package-1" }), script);
expect(runLifecycle).toHaveBeenCalledWith(
expect.objectContaining({ name: "lifecycle" }),
script,
expect.any(Object)
);
expect(runLifecycle).toHaveBeenCalledWith(
expect.objectContaining({ name: "package-1" }),
script,
expect.any(Object)
);
});

// package-2 lacks version lifecycle scripts
Expand Down

0 comments on commit 276682b

Please sign in to comment.