Skip to content

Commit

Permalink
Cleanup test output
Browse files Browse the repository at this point in the history
  • Loading branch information
Andarist committed Dec 16, 2021
1 parent b9b6453 commit 1db4ec9
Show file tree
Hide file tree
Showing 20 changed files with 195 additions and 126 deletions.
1 change: 1 addition & 0 deletions packages/apply-release-plan/package.json
Expand Up @@ -22,6 +22,7 @@
"semver": "^5.4.1"
},
"devDependencies": {
"@changesets/test-utils": "*",
"fixturez": "^1.1.0",
"spawndamnit": "^2.0.0"
}
Expand Down
72 changes: 43 additions & 29 deletions packages/apply-release-plan/src/index.test.ts
Expand Up @@ -14,6 +14,7 @@ import { defaultConfig } from "@changesets/config";

import applyReleasePlan from "./";
import { getPackages } from "@manypkg/get-packages";
import { temporarilySilenceLogs } from "@changesets/test-utils";

const f = fixtures(__dirname);

Expand Down Expand Up @@ -1988,41 +1989,54 @@ describe("apply release plan", () => {

throw new Error("Expected test to exit before this point");
});
it("a provided changelog function fails", async () => {
let releasePlan = new FakeReleasePlan();
it(
"a provided changelog function fails",
temporarilySilenceLogs(async () => {
let releasePlan = new FakeReleasePlan();

let tempDir = await f.copy("with-git");
let tempDir = await f.copy("with-git");

await spawn("git", ["init"], { cwd: tempDir });
await spawn("git", ["init"], { cwd: tempDir });

await git.add(".", tempDir);
await git.commit("first commit", tempDir);
await git.add(".", tempDir);
await git.commit("first commit", tempDir);

try {
await applyReleasePlan(
releasePlan.getReleasePlan(),
await getPackages(tempDir),
{
...releasePlan.config,
changelog: [
path.resolve(__dirname, "test-utils/failing-functions"),
null
try {
await applyReleasePlan(
releasePlan.getReleasePlan(),
await getPackages(tempDir),
{
...releasePlan.config,
changelog: [
path.resolve(__dirname, "test-utils/failing-functions"),
null
]
}
);
} catch (e) {
expect(e.message).toEqual("no chance");

let gitCmd = await spawn("git", ["status"], { cwd: tempDir });

expect(
gitCmd.stdout.toString().includes("nothing to commit")
).toEqual(true);
expect((console.error as any).mock.calls).toMatchInlineSnapshot(`
Array [
Array [
"The following error was encountered while generating changelog entries",
],
Array [
"We have escaped applying the changesets, and no files should have been affected",
],
]
}
);
} catch (e) {
expect(e.message).toEqual("no chance");

let gitCmd = await spawn("git", ["status"], { cwd: tempDir });

expect(gitCmd.stdout.toString().includes("nothing to commit")).toEqual(
true
);
return;
}
`);
return;
}

throw new Error("Expected test to exit before this point");
});
throw new Error("Expected test to exit before this point");
})
);
});
describe("changesets", () => {
it("should delete one changeset after it is applied", async () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/commands/add/__tests__/add.ts
Expand Up @@ -2,7 +2,7 @@ import fixtures from "fixturez";
import stripAnsi from "strip-ansi";
import * as git from "@changesets/git";
import { defaultConfig } from "@changesets/config";
import { temporarilySilenceLogs } from "@changesets/test-utils";
import { silenceLogsInBlock } from "@changesets/test-utils";
import writeChangeset from "@changesets/write";

import {
Expand Down Expand Up @@ -87,7 +87,7 @@ const mockUserResponses = mockResponses => {
};

describe("Changesets", () => {
temporarilySilenceLogs();
silenceLogsInBlock();

it("should generate changeset to patch a single package", async () => {
const cwd = await f.copy("simple-project");
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/commands/init/__tests__/command.ts
Expand Up @@ -2,7 +2,7 @@ import fixtures from "fixturez";
import fs from "fs-extra";
import path from "path";
import { defaultWrittenConfig } from "@changesets/config";
import { temporarilySilenceLogs } from "@changesets/test-utils";
import { silenceLogsInBlock } from "@changesets/test-utils";

import initializeCommand from "..";

Expand All @@ -14,7 +14,7 @@ const getPaths = (cwd: string) => ({
});

describe("init", () => {
temporarilySilenceLogs();
silenceLogsInBlock();
it("should initialize in a project without a .changeset folder", async () => {
const cwd = await f.copy("without-existing-changeset");
const { readmePath, configPath } = getPaths(cwd);
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/commands/publish/__tests__/index.test.ts
Expand Up @@ -4,7 +4,7 @@ import { defaultConfig } from "@changesets/config";
import * as path from "path";
import * as pre from "@changesets/pre";
import { Config } from "@changesets/types";
import { temporarilySilenceLogs } from "@changesets/test-utils";
import { silenceLogsInBlock } from "@changesets/test-utils";

let changelogPath = path.resolve(__dirname, "../../changelog");
let modifiedDefaultConfig: Config = {
Expand All @@ -19,7 +19,7 @@ jest.mock("../publishPackages.ts");
jest.mock("@changesets/pre");

describe("Publish command", () => {
temporarilySilenceLogs();
silenceLogsInBlock();
let cwd: string;

beforeEach(async () => {
Expand Down
Expand Up @@ -3,15 +3,15 @@ import fixtures from "fixturez";
import publishPackages from "../publishPackages";
import * as npmUtils from "../npm-utils";
import { getPackages } from "@manypkg/get-packages";
import { temporarilySilenceLogs } from "@changesets/test-utils";
import { silenceLogsInBlock } from "@changesets/test-utils";

jest.mock("../npm-utils");
jest.mock("is-ci", () => true);

const f = fixtures(__dirname);

describe("publishPackages", () => {
temporarilySilenceLogs();
silenceLogsInBlock();
let cwd: string;

beforeEach(async () => {
Expand Down
Expand Up @@ -3,7 +3,7 @@ import fixtures from "fixturez";
import publishPackages from "../publishPackages";
import * as git from "@changesets/git";
import { defaultConfig } from "@changesets/config";
import { temporarilySilenceLogs } from "@changesets/test-utils";
import { silenceLogsInBlock } from "@changesets/test-utils";
import runRelease from "..";

jest.mock("../../../utils/cli-utilities");
Expand All @@ -29,7 +29,7 @@ publishPackages.mockImplementation(() =>
);

describe("running release", () => {
temporarilySilenceLogs();
silenceLogsInBlock();
let cwd: string;

beforeEach(async () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/commands/status/__tests__/status.ts
Expand Up @@ -3,7 +3,7 @@ import fs from "fs-extra";
import path from "path";
import * as git from "@changesets/git";
import { defaultConfig } from "@changesets/config";
import { temporarilySilenceLogs } from "@changesets/test-utils";
import { silenceLogsInBlock } from "@changesets/test-utils";
import writeChangeset from "@changesets/write";

import status from "..";
Expand Down Expand Up @@ -72,7 +72,7 @@ const writeChangesets = (changesets: NewChangeset[], cwd: string) => {
};

describe("status", () => {
temporarilySilenceLogs();
silenceLogsInBlock();
let cwd: string;

beforeEach(async () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/commands/tag/__tests__/index.test.ts
@@ -1,5 +1,5 @@
import fixtures from "fixturez";
import { temporarilySilenceLogs } from "../../../../../test-utils/src";
import { silenceLogsInBlock } from "../../../../../test-utils/src";
import * as git from "@changesets/git";
import tag from "../index";

Expand All @@ -8,7 +8,7 @@ const f = fixtures(__dirname);
jest.mock("@changesets/git");

describe("tag command", () => {
temporarilySilenceLogs();
silenceLogsInBlock();
let cwd: string;

describe("workspace project", () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/commands/version/version.test.ts
Expand Up @@ -5,7 +5,7 @@ import path from "path";
import versionCommand from "./index";
import * as git from "@changesets/git";
import { warn } from "@changesets/logger";
import { temporarilySilenceLogs } from "@changesets/test-utils";
import { silenceLogsInBlock } from "@changesets/test-utils";
import writeChangeset from "@changesets/write";
import { NewChangeset, Config } from "@changesets/types";
import { defaultConfig } from "@changesets/config";
Expand Down Expand Up @@ -103,7 +103,7 @@ const getChangelog = (pkgName: string, calls: any) => {
const writeEmptyChangeset = (cwd: string) => writeChangesets([], cwd);

describe("running version in a simple project", () => {
temporarilySilenceLogs();
silenceLogsInBlock();
let cwd: string;

beforeEach(async () => {
Expand Down
3 changes: 3 additions & 0 deletions packages/get-dependents-graph/package.json
Expand Up @@ -12,5 +12,8 @@
"chalk": "^2.1.0",
"fs-extra": "^7.0.1",
"semver": "^5.4.1"
},
"devDependencies": {
"@changesets/test-utils": "*"
}
}
65 changes: 38 additions & 27 deletions packages/get-dependents-graph/src/get-dependency-graph.test.ts
@@ -1,4 +1,5 @@
import getDependencyGraph from "./get-dependency-graph";
import { temporarilySilenceLogs } from "@changesets/test-utils";

describe("getting the dependency graph", function() {
it("should skip dependencies specified through the link protocol", function() {
Expand Down Expand Up @@ -31,33 +32,43 @@ describe("getting the dependency graph", function() {
expect(graph.get("foo")!.dependencies).toStrictEqual([]);
expect(valid).toBeTruthy();
});
it("should set valid to false if the link protocol is used in a non-dev dep", function() {
const { valid } = getDependencyGraph({
root: {
dir: ".",
packageJson: { name: "root", version: "1.0.0" }
},
packages: [
{
dir: "foo",
packageJson: {
name: "foo",
version: "1.0.0",
dependencies: {
bar: "link:../bar"
}
}
it(
"should set valid to false if the link protocol is used in a non-dev dep",
temporarilySilenceLogs(() => {
const { valid } = getDependencyGraph({
root: {
dir: ".",
packageJson: { name: "root", version: "1.0.0" }
},
{
dir: "bar",
packageJson: {
name: "bar",
version: "1.0.0"
packages: [
{
dir: "foo",
packageJson: {
name: "foo",
version: "1.0.0",
dependencies: {
bar: "link:../bar"
}
}
},
{
dir: "bar",
packageJson: {
name: "bar",
version: "1.0.0"
}
}
}
],
tool: "pnpm"
});
expect(valid).toBeFalsy();
});
],
tool: "pnpm"
});
expect(valid).toBeFalsy();
expect((console.error as any).mock.calls).toMatchInlineSnapshot(`
Array [
Array [
"Package \\"foo\\" must depend on the current version of \\"bar\\": \\"1.0.0\\" vs \\"link:../bar\\"",
],
]
`);
})
);
});
22 changes: 2 additions & 20 deletions packages/git/src/index.test.ts
Expand Up @@ -3,7 +3,6 @@ import spawn from "spawndamnit";
import fileUrl from "file-url";

import {
getCommitThatAddsFile,
getCommitsThatAddFiles,
getChangedFilesSince,
add,
Expand Down Expand Up @@ -240,23 +239,6 @@ describe("git", () => {
expect(commitHash).toEqual([headSha]);
});

// We have replaced the single-file version with a multi-file version
// which will correctly run all the file retrieves in parallel, safely
// deepening a shallow clone as necessary. We've deprecated the
// single-file version and can remove it in a major release.
it("exposes a deprecated single-file call", async () => {
await add("packages/pkg-b/package.json", cwd);
await commit("added packageB package.json", cwd);
const headSha = await getCurrentCommitShort(cwd);

const commitHash = await getCommitThatAddsFile(
"packages/pkg-b/package.json",
cwd
);

expect(commitHash).toEqual(headSha);
});

describe("with shallow clone", () => {
// We will add these three well-known files
// over multiple commits, then test looking up
Expand Down Expand Up @@ -331,7 +313,7 @@ describe("git", () => {
const clone = await createShallowClone(5);

// Finding this commit will require deepening the clone until it appears.
const commit = await getCommitThatAddsFile(file2, clone);
const commit = (await getCommitsThatAddFiles([file2], clone))[0];
expect(commit).toEqual(originalCommit);

// It should not have completely unshallowed the clone; just enough.
Expand All @@ -348,7 +330,7 @@ describe("git", () => {
const clone = await createShallowClone(5);

// Finding this commit will require fully deepening the repo
const commit = await getCommitThatAddsFile(file3, clone);
const commit = (await getCommitsThatAddFiles([file3], clone))[0];
expect(commit).toEqual(originalCommit);

// We should have fully deepened
Expand Down
4 changes: 2 additions & 2 deletions packages/read/src/index.test.ts
Expand Up @@ -2,11 +2,11 @@ import fixtures from "fixturez";
import outdent from "outdent";

import read from "./";
import { temporarilySilenceLogs } from "@changesets/test-utils";
import { silenceLogsInBlock } from "@changesets/test-utils";

const f = fixtures(__dirname);

temporarilySilenceLogs();
silenceLogsInBlock();

describe("read changesets from disc", () => {
it("should read a changeset from disc", async () => {
Expand Down
1 change: 1 addition & 0 deletions packages/release-utils/package.json
Expand Up @@ -17,6 +17,7 @@
},
"devDependencies": {
"@changesets/git": "*",
"@changesets/test-utils": "*",
"@changesets/write": "*",
"file-url": "^3.0.0",
"fixturez": "^1.1.0"
Expand Down

0 comments on commit 1db4ec9

Please sign in to comment.