diff --git a/test/helpers/file.js b/test/helpers/file.js index bc117aa..9c085e2 100644 --- a/test/helpers/file.js +++ b/test/helpers/file.js @@ -40,7 +40,7 @@ function isDirectory(path) { // Creates testing files on all specified folders. function createNewTestingFiles(folders, cwd) { folders.forEach((fld) => { - writeFileSync(`${cwd}/${fld}test.txt`, fld); + writeFileSync(`${cwd}/${fld}test.txt`, `${fld}${Math.random()}`); }); } diff --git a/test/lib/git.test.js b/test/lib/git.test.js index a9daa61..7541ea6 100644 --- a/test/lib/git.test.js +++ b/test/lib/git.test.js @@ -80,6 +80,30 @@ test("Fetch only prerelease tags", async () => { const tags = getTags("master", { cwd }, ["beta"]).sort(); expect(tags).toEqual(["msr-test-d@2.0.0-beta.1", "msr-test-c@2.0.0-beta.1"].sort()); + + // Add new testing files for a new release. + createNewTestingFiles(packages, cwd); + const shaPatch = gitCommitAll(cwd, "fix: add a patch"); + expect(shaPatch).toBeTruthy(); + gitPush(cwd); + + // Capture output. + stdout = new WritableStreamBuffer(); + stderr = new WritableStreamBuffer(); + + // Call multiSemanticRelease() for a second release + // Doesn't include plugins that actually publish. + // Change the master branch from release to prerelease to test bumping. + await multiSemanticRelease( + packages.map((folder) => `${folder}package.json`), + { + branches: [{ name: "master", prerelease: "beta" }, { name: "release" }], + }, + { cwd, stdout, stderr, env } + ); + + const tagsPatch = getTags("master", { cwd }, ["beta"]).sort(); + expect(tagsPatch).toEqual(["msr-test-c@2.0.0-beta.1", "msr-test-c@2.0.0-beta.2", "msr-test-d@2.0.0-beta.1", "msr-test-d@2.0.0-beta.2"]); }); test("Throws error if obtaining the tags fails", () => { diff --git a/test/lib/multiSemanticRelease.test.js b/test/lib/multiSemanticRelease.test.js index 531ab90..832b5cf 100644 --- a/test/lib/multiSemanticRelease.test.js +++ b/test/lib/multiSemanticRelease.test.js @@ -382,7 +382,7 @@ describe("multiSemanticRelease()", () => { result = await multiSemanticRelease( packages.map((folder) => `${folder}package.json`), { - branches: [{ name: "master", prerelease: "beta" }, { name: "release" }], + branches: [{ name: "master", prerelease: "beta", channel: "beta" }, { name: "release" }], }, { cwd, stdout, stderr, env } ); @@ -434,7 +434,61 @@ describe("multiSemanticRelease()", () => { "msr-test-d": "2.0.0-beta.1", }, }); - }, 10000); + + // Add new testing files for a new release. + createNewTestingFiles(packages, cwd); + const shaPatch = gitCommitAll(cwd, "fix: add a patch"); + expect(shaPatch).toBeTruthy(); + gitPush(cwd); + + // Capture output. + stdout = new WritableStreamBuffer(); + stderr = new WritableStreamBuffer(); + + // Call multiSemanticRelease() for a second release + // Doesn't include plugins that actually publish. + // Change the master branch from release to prerelease to test bumping. + result = await multiSemanticRelease( + packages.map((folder) => `${folder}package.json`), + { + branches: [{ name: "master", prerelease: "beta", channel: "beta" }, { name: "release" }], + }, + { cwd, stdout, stderr, env } + ); + + // Get stdout and stderr output. + const errpatch = stderr.getContentsAsString("utf8"); + expect(errpatch).toBe(false); + const outpatch = stdout.getContentsAsString("utf8"); + expect(outpatch).toMatch("Started multirelease! Loading 2 packages..."); + expect(outpatch).toMatch("Loaded package msr-test-c"); + expect(outpatch).toMatch("Loaded package msr-test-d"); + expect(outpatch).toMatch("Queued 2 packages! Starting release..."); + expect(outpatch).toMatch("Created tag msr-test-c@2.0.0-beta.2"); + expect(outpatch).toMatch("Created tag msr-test-d@2.0.0-beta.2"); + expect(outpatch).toMatch("Released 2 of 2 packages, semantically!"); + + expect(result[0].name).toBe("msr-test-c"); + expect(result[0].result.nextRelease).toMatchObject({ + gitHead: shaPatch, + gitTag: "msr-test-c@2.0.0-beta.2", + type: "patch", + version: "2.0.0-beta.2", + }); + + expect(result[1].result.nextRelease.notes).toMatch("# msr-test-d [2.0.0-beta.2]"); + + // ONLY 1 time. + expect(result).toHaveLength(2); + + expect(require(`${cwd}/packages/c/package.json`)).toMatchObject({ + dependencies: { + "msr-test-d": "2.0.0-beta.2", + }, + }); + + + }, 20000); test("Two separate releases (changes in all packages with prereleases)", async () => { const packages = ["packages/a/", "packages/b/", "packages/c/", "packages/d/"];