Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(codemod): respect --dry flag #8280

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 19 additions & 13 deletions packages/turbo-codemod/__tests__/add-package-manager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const TEST_CASES: Array<TestCase> = [
existingPackageManagerString: undefined,
packageManager: "npm",
packageManagerVersion: "7.0.0",
options: { force: false, dry: false, print: false },
options: { force: false, dryRun: false, print: false },
result: {
changes: {
"package.json": {
Expand All @@ -46,7 +46,7 @@ const TEST_CASES: Array<TestCase> = [
existingPackageManagerString: undefined,
packageManager: "npm",
packageManagerVersion: "7.0.0",
options: { force: false, dry: true, print: false },
options: { force: false, dryRun: true, print: false },
result: {
changes: {
"package.json": {
Expand All @@ -63,7 +63,7 @@ const TEST_CASES: Array<TestCase> = [
existingPackageManagerString: undefined,
packageManager: "yarn",
packageManagerVersion: "1.2.3",
options: { force: false, dry: false, print: true },
options: { force: false, dryRun: false, print: true },
result: {
changes: {
"package.json": {
Expand All @@ -80,7 +80,7 @@ const TEST_CASES: Array<TestCase> = [
existingPackageManagerString: undefined,
packageManager: "pnpm",
packageManagerVersion: "1.2.3",
options: { force: false, dry: true, print: true },
options: { force: false, dryRun: true, print: true },
result: {
changes: {
"package.json": {
Expand All @@ -97,7 +97,7 @@ const TEST_CASES: Array<TestCase> = [
existingPackageManagerString: "npm@1.2.3",
packageManager: "npm",
packageManagerVersion: "1.2.3",
options: { force: false, dry: false, print: false },
options: { force: false, dryRun: false, print: false },
result: {
changes: {
"package.json": {
Expand All @@ -114,7 +114,7 @@ const TEST_CASES: Array<TestCase> = [
existingPackageManagerString: "turbo@1.7.0",
packageManager: "pnpm",
packageManagerVersion: "1.2.3",
options: { force: false, dry: false, print: false },
options: { force: false, dryRun: false, print: false },
result: {
changes: {
"package.json": {
Expand Down Expand Up @@ -180,7 +180,9 @@ describe("add-package-manager-2", () => {
expect(mockGetWorkspaceDetails).toHaveBeenCalled();

expect(JSON.parse(read("package.json") || "{}").packageManager).toEqual(
options.dry ? undefined : `${packageManager}@${packageManagerVersion}`
options.dryRun
? undefined
: `${packageManager}@${packageManagerVersion}`
);

// result should be correct
Expand All @@ -194,9 +196,13 @@ describe("add-package-manager-2", () => {
expect(repeatResult.fatalError).toBeUndefined();
expect(repeatResult.changes).toMatchObject({
"package.json": {
action: options.dry ? "skipped" : "unchanged",
additions: options.dry ? result.changes["package.json"].additions : 0,
deletions: options.dry ? result.changes["package.json"].deletions : 0,
action: options.dryRun ? "skipped" : "unchanged",
additions: options.dryRun
? result.changes["package.json"].additions
: 0,
deletions: options.dryRun
? result.changes["package.json"].deletions
: 0,
},
});

Expand All @@ -221,7 +227,7 @@ describe("add-package-manager-2", () => {
// run the transformer
const result = await transformer({
root,
options: { force: false, dry: false, print: false },
options: { force: false, dryRun: false, print: false },
});

expect(mockGetWorkspaceDetails).toHaveBeenCalledTimes(1);
Expand Down Expand Up @@ -263,7 +269,7 @@ describe("add-package-manager-2", () => {
// run the transformer
const result = await transformer({
root,
options: { force: false, dry: false, print: false },
options: { force: false, dryRun: false, print: false },
});

expect(mockGetAvailablePackageManagers).toHaveBeenCalledTimes(1);
Expand Down Expand Up @@ -317,7 +323,7 @@ describe("add-package-manager-2", () => {
// run the transformer
const result = await transformer({
root,
options: { force: false, dry: false, print: false },
options: { force: false, dryRun: false, print: false },
});

// package manager should still not exist (we couldn't write it)
Expand Down
6 changes: 3 additions & 3 deletions packages/turbo-codemod/__tests__/add-package-names.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe("add-package-names", () => {
// run the transformer
const result = await transformer({
root,
options: { force: false, dry: false, print: false },
options: { force: false, dryRun: false, print: false },
});

// result should be correct
Expand Down Expand Up @@ -58,7 +58,7 @@ describe("add-package-names", () => {
// run the transformer
const result = await transformer({
root,
options: { force: false, dry: false, print: false },
options: { force: false, dryRun: false, print: false },
});

// result should be correct
Expand Down Expand Up @@ -95,7 +95,7 @@ describe("add-package-names", () => {
// run the transformer
const result = await transformer({
root,
options: { force: false, dry: false, print: false },
options: { force: false, dryRun: false, print: false },
});

// result should be correct
Expand Down
2 changes: 1 addition & 1 deletion packages/turbo-codemod/__tests__/clean-globs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe("clean-globs", () => {
// run the transformer
const result = transformer({
root,
options: { force: false, dry: false, print: false },
options: { force: false, dryRun: false, print: false },
});

// result should be correct
Expand Down
22 changes: 11 additions & 11 deletions packages/turbo-codemod/__tests__/create-turbo-config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe("create-turbo-config", () => {
// run the transformer
const result = transformer({
root,
options: { force: false, dry: false, print: false },
options: { force: false, dryRun: false, print: false },
});

// turbo.json should now exist (and match the package.json config)
Expand Down Expand Up @@ -58,7 +58,7 @@ describe("create-turbo-config", () => {
// run the transformer
const result = transformer({
root,
options: { force: false, dry: false, print: false },
options: { force: false, dryRun: false, print: false },
});

// turbo.json should now exist (and match the package.json config)
Expand All @@ -84,7 +84,7 @@ describe("create-turbo-config", () => {
// run the transformer
const repeatResult = transformer({
root,
options: { force: false, dry: false, print: false },
options: { force: false, dryRun: false, print: false },
});
// result should be correct
expect(repeatResult.fatalError).toBeUndefined();
Expand Down Expand Up @@ -117,7 +117,7 @@ describe("create-turbo-config", () => {
// run the transformer
const result = transformer({
root,
options: { force: false, dry: true, print: false },
options: { force: false, dryRun: true, print: false },
});

// turbo.json still not exist (dry run)
Expand Down Expand Up @@ -154,7 +154,7 @@ describe("create-turbo-config", () => {
// run the transformer
const result = transformer({
root,
options: { force: false, dry: false, print: true },
options: { force: false, dryRun: false, print: true },
});

// turbo.json should now exist (and match the package.json config)
Expand Down Expand Up @@ -191,7 +191,7 @@ describe("create-turbo-config", () => {
// run the transformer
const result = transformer({
root,
options: { force: false, dry: true, print: true },
options: { force: false, dryRun: true, print: true },
});

// turbo.json still not exist (dry run)
Expand Down Expand Up @@ -229,7 +229,7 @@ describe("create-turbo-config", () => {
// run the transformer
const result = transformer({
root,
options: { force: false, dry: false, print: false },
options: { force: false, dryRun: false, print: false },
});

// turbo.json should still not exist
Expand Down Expand Up @@ -266,7 +266,7 @@ describe("create-turbo-config", () => {
// run the transformer
const result = transformer({
root,
options: { force: false, dry: false, print: false },
options: { force: false, dryRun: false, print: false },
});

// turbo.json should still not exist
Expand All @@ -293,7 +293,7 @@ describe("create-turbo-config", () => {
// run the transformer
const result = transformer({
root,
options: { force: false, dry: false, print: false },
options: { force: false, dryRun: false, print: false },
});

// turbo.json should still exist
Expand Down Expand Up @@ -336,7 +336,7 @@ describe("create-turbo-config", () => {
// run the transformer
const result = transformer({
root,
options: { force: false, dry: false, print: false },
options: { force: false, dryRun: false, print: false },
});

// make sure we didn't change the package.json
Expand Down Expand Up @@ -383,7 +383,7 @@ describe("create-turbo-config", () => {
// run the transformer
const result = transformer({
root,
options: { force: false, dry: false, print: false },
options: { force: false, dryRun: false, print: false },
});

// turbo.json should still not exist (error writing)
Expand Down
16 changes: 8 additions & 8 deletions packages/turbo-codemod/__tests__/migrate-dot-env.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe("migrate-dot-env", () => {
// run the transformer
const result = transformer({
root,
options: { force: false, dry: false, print: false },
options: { force: false, dryRun: false, print: false },
});

expect(JSON.parse(read("turbo.json") || "{}")).toStrictEqual({
Expand Down Expand Up @@ -54,7 +54,7 @@ describe("migrate-dot-env", () => {
// run the transformer
const result = transformer({
root,
options: { force: false, dry: false, print: false },
options: { force: false, dryRun: false, print: false },
});

expect(readJson("turbo.json") || "{}").toStrictEqual({
Expand Down Expand Up @@ -136,7 +136,7 @@ describe("migrate-dot-env", () => {
// run the transformer
const result = transformer({
root,
options: { force: false, dry: true, print: false },
options: { force: false, dryRun: true, print: false },
});

// make sure it didn't change
Expand All @@ -163,7 +163,7 @@ describe("migrate-dot-env", () => {
// run the transformer
const result = transformer({
root,
options: { force: false, dry: false, print: true },
options: { force: false, dryRun: false, print: true },
});

expect(JSON.parse(read("turbo.json") || "{}")).toStrictEqual({
Expand Down Expand Up @@ -203,7 +203,7 @@ describe("migrate-dot-env", () => {
// run the transformer
const result = transformer({
root,
options: { force: false, dry: true, print: false },
options: { force: false, dryRun: true, print: false },
});

// make sure it didn't change
Expand All @@ -230,7 +230,7 @@ describe("migrate-dot-env", () => {
// run the transformer
const result = transformer({
root,
options: { force: false, dry: false, print: false },
options: { force: false, dryRun: false, print: false },
});

expect(JSON.parse(read("turbo.json") || "{}")).toStrictEqual({
Expand Down Expand Up @@ -260,7 +260,7 @@ describe("migrate-dot-env", () => {
// run the transformer
const result = transformer({
root,
options: { force: false, dry: false, print: false },
options: { force: false, dryRun: false, print: false },
});

expect(JSON.parse(read("turbo.json") || "{}")).toStrictEqual({
Expand Down Expand Up @@ -301,7 +301,7 @@ describe("migrate-dot-env", () => {
// run the transformer
const result = transformer({
root,
options: { force: false, dry: false, print: false },
options: { force: false, dryRun: false, print: false },
});

expect(read("turbo.json")).toBeUndefined();
Expand Down
Loading
Loading