Skip to content

test: Add cases for various directory naming patterns; run ci under windows #116

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

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
6 changes: 4 additions & 2 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ on:
jobs:
prepare:
name: Prepare
runs-on: ubuntu-latest
runs-on: ${{ matrix.os }}
outputs:
YARN_CACHE_DIR: ${{ steps.yarn-cache-dir.outputs.YARN_CACHE_DIR }}
YARN_VERSION: ${{ steps.yarn-version.outputs.YARN_VERSION }}
strategy:
matrix:
node-version: [16.x, 18.x, 20.x]
os: [ubuntu-latest, windows-latest]
steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
Expand Down Expand Up @@ -98,12 +99,13 @@ jobs:
fi
test:
name: Test
runs-on: ubuntu-latest
runs-on: ${{ matrix.os }}
needs:
- prepare
strategy:
matrix:
node-version: [16.x, 18.x, 20.x]
os: [ubuntu-latest, windows-latest]
steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
Expand Down
50 changes: 50 additions & 0 deletions src/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,56 @@ describe('main', () => {
});
});

for (const [description, directoryPath] of [
['directories with spaces', '/path/to/my project'],
['directories with quote', "/path/to/my 'project"],
['directories with quotes', "/path/to/my 'proje'ct"],
['directories with double-quote', '/path/to/my "project'],
['directories with double-quotes', '/path/to/my "proje"ct'],
[
'directories with special characters',
'/path/~to/#my/!y \'\\"\\pr@j/e"ct',
],
]) {
const tempDirectoryPath = directoryPath.replace(/^\/path\//u, '/tmp/');
const cwd = directoryPath.replace(/^\/path\//u, '/workdir/');
it(`executes the monorepo workflow for ${description}`, async () => {
const project = buildMockProject({
directoryPath,
isMonorepo: true,
});
const stdout = fs.createWriteStream('/dev/null');
const stderr = fs.createWriteStream('/dev/null');
jest
.spyOn(initialParametersModule, 'determineInitialParameters')
.mockResolvedValue({
project,
tempDirectoryPath,
reset: true,
releaseType: 'backport',
});
const followMonorepoWorkflowSpy = jest
.spyOn(monorepoWorkflowOperations, 'followMonorepoWorkflow')
.mockResolvedValue();

await main({
argv: [],
cwd,
stdout,
stderr,
});

expect(followMonorepoWorkflowSpy).toHaveBeenCalledWith({
project,
tempDirectoryPath,
firstRemovingExistingReleaseSpecification: true,
releaseType: 'backport',
stdout,
stderr,
});
});
}

it('executes the polyrepo workflow if the project is within a polyrepo', async () => {
const project = buildMockProject({ isMonorepo: false });
const stdout = fs.createWriteStream('/dev/null');
Expand Down
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