-
-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: don't suggest redundant --directory (#1805)
## PR Checklist - [x] Addresses an existing open issue: fixes #1126 - [x] That issue was marked as [`status: accepting prs`](https://github.com/JoshuaKGoldberg/create-typescript-app/issues?q=is%3Aopen+is%3Aissue+label%3A%22status%3A+accepting+prs%22) - [x] Steps in [CONTRIBUTING.md](https://github.com/JoshuaKGoldberg/create-typescript-app/blob/main/.github/CONTRIBUTING.md) were taken ## Overview 💖
- Loading branch information
1 parent
1d09b76
commit 42c6ebd
Showing
4 changed files
with
84 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { describe, expect, it } from "vitest"; | ||
|
||
import { createRerunDirectorySuggestion } from "./createRerunDirectorySuggestion.js"; | ||
|
||
const directory = "test-directory"; | ||
const repository = "test-repository"; | ||
|
||
describe("createRerunDirectorySuggestion", () => { | ||
it("returns undefined when mode is create and directory matches repository", () => { | ||
const suggestion = createRerunDirectorySuggestion({ | ||
directory: repository, | ||
mode: "create", | ||
repository, | ||
}); | ||
|
||
expect(suggestion).toBe(undefined); | ||
}); | ||
|
||
it("returns directory when mode is create and directory doesn't match repository", () => { | ||
const suggestion = createRerunDirectorySuggestion({ | ||
directory, | ||
mode: "create", | ||
repository, | ||
}); | ||
|
||
expect(suggestion).toBe(directory); | ||
}); | ||
|
||
it("returns undefined when mode is initialize and directory is .", () => { | ||
const suggestion = createRerunDirectorySuggestion({ | ||
directory: ".", | ||
mode: "initialize", | ||
repository, | ||
}); | ||
|
||
expect(suggestion).toBe(undefined); | ||
}); | ||
|
||
it("returns directory when mode is initialize and directory is not .", () => { | ||
const suggestion = createRerunDirectorySuggestion({ | ||
directory, | ||
mode: "initialize", | ||
repository, | ||
}); | ||
|
||
expect(suggestion).toBe(directory); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { Options } from "../shared/types.js"; | ||
|
||
export function createRerunDirectorySuggestion(options: Partial<Options>) { | ||
const defaultValue = options.mode === "create" ? options.repository : "."; | ||
|
||
return options.directory === defaultValue ? undefined : options.directory; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -89,7 +89,7 @@ describe("createRerunSuggestion", () => { | |
}); | ||
|
||
expect(actual).toMatchInlineSnapshot( | ||
`"npx create-typescript-app --base everything --author TestAuthor --description "Test description." --directory . --email-github [email protected] --email-npm [email protected] --exclude-all-contributors --exclude-compliance --exclude-lint-jsdoc --exclude-lint-json --exclude-lint-knip --exclude-lint-package-json --exclude-lint-perfectionist --guide https://example.com --guide-title "Test Title" --keywords "abc def ghi jkl mno pqr" --mode initialize --owner TestOwner --repository test-repository --skip-github-api --skip-install --skip-removal --title "Test Title""`, | ||
`"npx create-typescript-app --base everything --author TestAuthor --description "Test description." --email-github [email protected] --email-npm [email protected] --exclude-all-contributors --exclude-compliance --exclude-lint-jsdoc --exclude-lint-json --exclude-lint-knip --exclude-lint-package-json --exclude-lint-perfectionist --guide https://example.com --guide-title "Test Title" --keywords "abc def ghi jkl mno pqr" --mode initialize --owner TestOwner --repository test-repository --skip-github-api --skip-install --skip-removal --title "Test Title""`, | ||
); | ||
}); | ||
|
||
|
@@ -104,7 +104,31 @@ describe("createRerunSuggestion", () => { | |
}); | ||
|
||
expect(actual).toMatchInlineSnapshot( | ||
`"npx create-typescript-app --base everything --author TestAuthor --description "Test description." --directory . --email-github [email protected] --email-npm [email protected] --exclude-all-contributors --exclude-compliance --exclude-lint-jsdoc --exclude-lint-json --exclude-lint-knip --exclude-lint-package-json --exclude-lint-perfectionist --keywords "abc def ghi jkl mno pqr" --logo test/src.png --logo-alt "Test alt." --mode initialize --owner TestOwner --repository test-repository --skip-github-api --skip-install --skip-removal --title "Test Title""`, | ||
`"npx create-typescript-app --base everything --author TestAuthor --description "Test description." --email-github [email protected] --email-npm [email protected] --exclude-all-contributors --exclude-compliance --exclude-lint-jsdoc --exclude-lint-json --exclude-lint-knip --exclude-lint-package-json --exclude-lint-perfectionist --keywords "abc def ghi jkl mno pqr" --logo test/src.png --logo-alt "Test alt." --mode initialize --owner TestOwner --repository test-repository --skip-github-api --skip-install --skip-removal --title "Test Title""`, | ||
); | ||
}); | ||
|
||
it("does not include directory when it is repository and the mode is create", () => { | ||
const actual = createRerunSuggestion({ | ||
...options, | ||
directory: options.repository, | ||
mode: "create", | ||
}); | ||
|
||
expect(actual).toMatchInlineSnapshot( | ||
`"npx create-typescript-app --base everything --author TestAuthor --description "Test description." --email-github [email protected] --email-npm [email protected] --exclude-all-contributors --exclude-compliance --exclude-lint-jsdoc --exclude-lint-json --exclude-lint-knip --exclude-lint-package-json --exclude-lint-perfectionist --keywords "abc def ghi jkl mno pqr" --mode create --owner TestOwner --repository test-repository --skip-github-api --skip-install --skip-removal --title "Test Title""`, | ||
); | ||
}); | ||
|
||
it("includes directory when it is repository and the mode is migrate", () => { | ||
const actual = createRerunSuggestion({ | ||
...options, | ||
directory: options.repository, | ||
mode: "migrate", | ||
}); | ||
|
||
expect(actual).toMatchInlineSnapshot( | ||
`"npx create-typescript-app --base everything --author TestAuthor --description "Test description." --directory test-repository --email-github [email protected] --email-npm [email protected] --exclude-all-contributors --exclude-compliance --exclude-lint-jsdoc --exclude-lint-json --exclude-lint-knip --exclude-lint-package-json --exclude-lint-perfectionist --keywords "abc def ghi jkl mno pqr" --mode migrate --owner TestOwner --repository test-repository --skip-github-api --skip-install --skip-removal --title "Test Title""`, | ||
); | ||
}); | ||
|
||
|
@@ -118,7 +142,7 @@ describe("createRerunSuggestion", () => { | |
}); | ||
|
||
expect(actual).toMatchInlineSnapshot( | ||
`"npx create-typescript-app --base everything --author TestAuthor --description "Test description." --directory . --email-github [email protected] --email-npm [email protected] --exclude-all-contributors --exclude-compliance --exclude-lint-jsdoc --exclude-lint-json --exclude-lint-knip --exclude-lint-md --exclude-lint-package-json --exclude-lint-perfectionist --exclude-lint-spelling --keywords "abc def ghi jkl mno pqr" --mode initialize --owner TestOwner --repository test-repository --skip-github-api --skip-install --skip-removal --title "Test Title""`, | ||
`"npx create-typescript-app --base everything --author TestAuthor --description "Test description." --email-github [email protected] --email-npm [email protected] --exclude-all-contributors --exclude-compliance --exclude-lint-jsdoc --exclude-lint-json --exclude-lint-knip --exclude-lint-md --exclude-lint-package-json --exclude-lint-perfectionist --exclude-lint-spelling --keywords "abc def ghi jkl mno pqr" --mode initialize --owner TestOwner --repository test-repository --skip-github-api --skip-install --skip-removal --title "Test Title""`, | ||
); | ||
}); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters