Skip to content

Commit

Permalink
Merge pull request #147 from yves-parloa/master
Browse files Browse the repository at this point in the history
fix: ReferenceError childProcess is not defined
  • Loading branch information
ext authored Apr 24, 2024
2 parents 3b7d10b + fb06385 commit 276263d
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/get-changed-packages.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ function parse(stdout, options = {}) {
const [, sha, isDirty] = minimalShaRegex.exec(stdout);

// Count number of commits since beginning of time
const refCount = childProcess.execSync("git", ["rev-list", "--count", sha], options);
const revListResponse = execaSync("git", ["rev-list", "--count", sha], options);

return { refCount, sha, isDirty: Boolean(isDirty) };
return { refCount: revListResponse.stdout, sha, isDirty: Boolean(isDirty) };
}

/* eslint-disable-next-line security/detect-unsafe-regex -- technical debt */
Expand Down
68 changes: 66 additions & 2 deletions src/prepare.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,15 @@ let mockChangedPackages;

const tempdir = realpathSync(os.tmpdir());

globalThis.useRealGetChangedPackages = false;

jest.mock("./get-changed-packages", () => {
function getChangedPackagesMock() {
return mockChangedPackages;
const realGetChangedPackages = jest.requireActual("./get-changed-packages").default;
function getChangedPackagesMock(...args) {
if (!globalThis.useRealGetChangedPackages) {
return mockChangedPackages;
}
return realGetChangedPackages(...args);
}

return getChangedPackagesMock;
Expand Down Expand Up @@ -92,6 +98,7 @@ beforeEach(() => {
stderr: new WritableStreamBuffer(),
};
mockChangedPackages = [];
globalThis.useRealGetChangedPackages = false;
});

it("Update lerna.json and root package.json when no package has changed", () => {
Expand Down Expand Up @@ -518,3 +525,60 @@ it("Handle dependencies from root package", async () => {
);
}).not.toThrow();
});

describe("getChangedPackages", () => {
beforeEach(() => {
globalThis.useRealGetChangedPackages = true;
});

it("should run without any reference error if the repository has not yet any tag", async () => {
expect.assertions(1);
const cwd = await temporaryDirectory();
const npmrc = await temporaryFile({ name: ".npmrc" });
await createProject(cwd, "0.0.1", {
devDependencies: {
"external-dependency": "1.2.3",
},
});

await createPackage(
cwd,
"foo",
"0.0.0",
{
changed: true,
},
{
dependencies: {
a: "0.0.0",
},
},
);

await execa("git", ["config", "--global", "user.email", "[email protected]"], { cwd });
await execa("git", ["config", "--global", "user.name", "Sample User"], { cwd });

await execa("git", ["init"], { cwd });
await execa("git", ["add", "."], { cwd });
await execa("git", ["commit", "-m", "'feat:initial commit'"], { cwd });

await execa("touch", ["test.txt"], { cwd });
await execa("git", ["add", "."], { cwd });
await execa("git", ["commit", "-m", "'fix:commit msg'"], { cwd });

expect(async () => {
await prepare(
npmrc,
{},
{
cwd,
env: {},
stdout: context.stdout,
stderr: context.stderr,
nextRelease: { version: "0.0.2" },
logger: context.logger,
},
);
}).not.toThrow();
});
});

0 comments on commit 276263d

Please sign in to comment.