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(docs/single): support files with .markdown extension #549

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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
18 changes: 12 additions & 6 deletions __tests__/cmds/changelogs.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,19 @@ describe('rdme changelogs', () => {
});

it('should error if no folder provided', () => {
return expect(changelogs.run({ key, version: '1.0.0' })).rejects.toThrow(
return expect(changelogs.run({ key })).rejects.toThrow(
'No folder provided. Usage `rdme changelogs <folder> [options]`.'
);
});

it('should error if the argument isnt a folder', () => {
return expect(changelogs.run({ key, version: '1.0.0', folder: 'not-a-folder' })).rejects.toThrow(
it('should error if the argument is not a folder', () => {
return expect(changelogs.run({ key, folder: 'not-a-folder' })).rejects.toThrow(
"ENOENT: no such file or directory, scandir 'not-a-folder'"
);
});

it('should error if the folder contains no markdown files', () => {
return expect(changelogs.run({ key, version: '1.0.0', folder: '.github/workflows' })).rejects.toThrow(
return expect(changelogs.run({ key, folder: '.github/workflows' })).rejects.toThrow(
'We were unable to locate Markdown files in .github/workflows.'
);
});
Expand Down Expand Up @@ -356,17 +356,23 @@ describe('rdme changelogs:single', () => {
});

it('should error if no file path provided', () => {
return expect(changelogsSingle.run({ key, version: '1.0.0' })).rejects.toThrow(
return expect(changelogsSingle.run({ key })).rejects.toThrow(
'No file path provided. Usage `rdme changelogs:single <file> [options]`.'
);
});

it('should error if the argument is not a markdown file', async () => {
await expect(changelogsSingle.run({ key, version: '1.0.0', filePath: 'not-a-markdown-file' })).rejects.toThrow(
await expect(changelogsSingle.run({ key, filePath: 'not-a-markdown-file' })).rejects.toThrow(
'The file path specified is not a markdown file.'
);
});

it('should support .markdown files but error if file path cannot be found', async () => {
await expect(changelogsSingle.run({ key, filePath: 'non-existent-file.markdown' })).rejects.toThrow(
'ENOENT: no such file or directory'
);
});

describe('new changelogs', () => {
it('should create new changelog', async () => {
const slug = 'new-doc';
Expand Down
10 changes: 9 additions & 1 deletion __tests__/cmds/docs.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ describe('rdme docs', () => {
);
});

it('should error if the argument isnt a folder', async () => {
it('should error if the argument is not a folder', async () => {
const versionMock = getApiNock().get(`/api/v1/version/${version}`).basicAuth({ user: key }).reply(200, { version });

await expect(docs.run({ key, version: '1.0.0', folder: 'not-a-folder' })).rejects.toThrow(
Expand Down Expand Up @@ -570,6 +570,14 @@ describe('rdme docs:single', () => {
);
});

it('should support .markdown files but error if file path cannot be found', async () => {
const versionMock = getApiNock().get(`/api/v1/version/${version}`).basicAuth({ user: key }).reply(200, { version });
await expect(docsSingle.run({ key, version: '1.0.0', filePath: 'non-existent-file.markdown' })).rejects.toThrow(
'ENOENT: no such file or directory'
);
versionMock.done();
});

describe('new docs', () => {
it('should create new doc', async () => {
const slug = 'new-doc';
Expand Down
2 changes: 1 addition & 1 deletion src/cmds/changelogs/single.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ module.exports = class SingleChangelogCommand {
return Promise.reject(new Error(`No file path provided. Usage \`${config.get('cli')} ${this.usage}\`.`));
}

if (filePath.endsWith('.md') === false || !filePath.endsWith('.markdown') === false) {
if (!(filePath.endsWith('.md') || filePath.endsWith('.markdown'))) {
Copy link
Member

Choose a reason for hiding this comment

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

I've had case-sensitive filesystems on my mind this week and I'm wondering if we should support .MD and .Markdown, or any casing variation of them.

return Promise.reject(new Error('The file path specified is not a markdown file.'));
Copy link
Member

Choose a reason for hiding this comment

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

Does this need to be capitalized?

Suggested change
return Promise.reject(new Error('The file path specified is not a markdown file.'));
return Promise.reject(new Error('The file path specified is not a Markdown file.'));

}

Expand Down
2 changes: 1 addition & 1 deletion src/cmds/docs/single.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ module.exports = class SingleDocCommand {
return Promise.reject(new Error(`No file path provided. Usage \`${config.get('cli')} ${this.usage}\`.`));
}

if (filePath.endsWith('.md') === false || !filePath.endsWith('.markdown') === false) {
if (!(filePath.endsWith('.md') || filePath.endsWith('.markdown'))) {
return Promise.reject(new Error('The file path specified is not a markdown file.'));
}

Expand Down