Skip to content

test: add coverage for mkdir -p on existing directories#1256

Open
MD-Mushfiqur123 wants to merge 1 commit into
shelljs:mainfrom
MD-Mushfiqur123:test/mkdir-p-existing
Open

test: add coverage for mkdir -p on existing directories#1256
MD-Mushfiqur123 wants to merge 1 commit into
shelljs:mainfrom
MD-Mushfiqur123:test/mkdir-p-existing

Conversation

@MD-Mushfiqur123

Copy link
Copy Markdown

Adds test cases for on directories that already exist:

  1. on a directory that already exists (should succeed silently)
  2. to create a new subdirectory within an already-existing tree

Fixes #1022

@nfischer nfischer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! Two optional suggestions, but this looks good

Comment thread test/mkdir.js Outdated
});

test('-p flag: existing directory', t => {
shell.mkdir('-p', `${t.context.tmp}/existing`);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the '-p' from this call, to make it clearer that this is part of the setup and not the real test (which is the next call to shell.mkdir('-p', ...)).

Comment thread test/mkdir.js Outdated
});

test('-p flag: create new subdirectory within existing tree', t => {
shell.mkdir('-p', `${t.context.tmp}/grandparent/parent`);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: let's remove parent from this call (but leave it in the next call).

Then in the portion of the test below, let's have calls to fs.existsSync() for both '.../parent' and '.../parent/child' to verify both directories are created. This will give us test coverage that mkdir('-p') can create multiple directories in the hierarchy while also testing that we can work within an existing directory tree.

Signed-off-by: MD-Mushfiqur123 <md.mushfiqur.rahim123@gmail.com>
@MD-Mushfiqur123 MD-Mushfiqur123 force-pushed the test/mkdir-p-existing branch from dc6bf06 to 0b6dfe4 Compare June 13, 2026 02:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test coverage: mkdir -p over a directory which already exists

2 participants