Skip to content
Open
Changes from 1 commit
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
Prev Previous commit
test: add test-cases with various scenarios for editorPath
  • Loading branch information
legobeat committed Dec 4, 2023
commit ce3e4e366d026ae2c9df9d13bf7cd4e281d1c44f
49 changes: 48 additions & 1 deletion src/monorepo-workflow-operations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ function buildMockEditor({
* @param args.releaseVersion - The new version that the release plan will
* contain.
* @param args.releaseType - The type of release.
* @param args.editorPath - Mocked path to the editor binary.
* @returns Mock functions and other data that can be used in tests to make
* assertions.
*/
Expand All @@ -162,6 +163,7 @@ async function setupFollowMonorepoWorkflow({
errorUponExecutingReleasePlan,
releaseVersion = '1.0.0',
releaseType = 'ordinary',
editorPath = '/some/editor',
}: {
sandbox: Sandbox;
doesReleaseSpecFileExist: boolean;
Expand All @@ -172,6 +174,7 @@ async function setupFollowMonorepoWorkflow({
errorUponExecutingReleasePlan?: Error;
releaseVersion?: string;
releaseType?: ReleaseType;
editorPath?: string;
}) {
const {
determineEditorSpy,
Expand All @@ -182,7 +185,7 @@ async function setupFollowMonorepoWorkflow({
executeReleasePlanSpy,
captureChangesInReleaseBranchSpy,
} = getDependencySpies();
const editor = buildMockEditor();
const editor = buildMockEditor({ path: editorPath });
const releaseSpecificationPath = path.join(
sandbox.directoryPath,
'RELEASE_SPEC.yml',
Expand Down Expand Up @@ -368,6 +371,50 @@ describe('monorepo-workflow-operations', () => {
});
});

for (const [description, editorPath] of [
['editor path with spaces', '/path/to/my editor'],
['editor path with quote', "/path/to/my 'editor"],
['editor path with quotes', "/path/to/my 'proje'ct"],
['editor path with double-quote', '/path/to/my "editor'],
['editor path with double-quotes', '/path/to/my "edi"tor'],
[
'editor path with special characters',
'/path/~to/#my/!y \'\\"\\e@i/0"r',
],
]) {
it(`can edit successfully with ${description}`, async () => {
await withSandbox(async (sandbox) => {
const {
project,
stdout,
stderr,
executeReleasePlanSpy,
releasePlan,
} = await setupFollowMonorepoWorkflow({
sandbox,
doesReleaseSpecFileExist: false,
isEditorAvailable: true,
editorPath,
});

await followMonorepoWorkflow({
project,
tempDirectoryPath: sandbox.directoryPath,
firstRemovingExistingReleaseSpecification: false,
releaseType: 'ordinary',
stdout,
stderr,
});

expect(executeReleasePlanSpy).toHaveBeenCalledWith(
project,
releasePlan,
stderr,
);
});
});
}

it('creates a new branch named after the generated release version if editing, validating, and executing the release spec succeeds', async () => {
await withSandbox(async (sandbox) => {
const {
Expand Down