Skip to content

Commit

Permalink
fix: Don't detect non-markdown readme types, add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tmcw committed May 22, 2018
1 parent 08d35d8 commit ae789de
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 4 deletions.
34 changes: 34 additions & 0 deletions __tests__/__snapshots__/bin-readme.js.snap
@@ -1,5 +1,39 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`readme autodetection of different filenames updates readme.markdown 1`] = `
"# A title
# API
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
### Table of Contents
- [foo](#foo)
- [bar](#bar)
## foo
A function with documentation.
**Parameters**
- \`a\` {string} blah
Returns **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** answer
## bar
A second function with docs
**Parameters**
- \`b\`
# Another section
"
`;

exports[`readme command --readme-file 1`] = `
"# A title
Expand Down
23 changes: 23 additions & 0 deletions __tests__/bin-readme.js
Expand Up @@ -22,6 +22,29 @@ function documentation(args, options, parseJSON) {
});
}

describe('readme autodetection of different filenames', function() {
const fixtures = path.join(__dirname, 'fixture/readme');
const sourceFile = path.join(fixtures, 'index.js');
let d;
let removeCallback;

beforeEach(() => {
const dirEntry = tmp.dirSync({ unsafeCleanup: true });
d = dirEntry.name;
fs.copySync(
path.join(fixtures, 'README.input.md'),
path.join(d, 'readme.markdown')
);
fs.copySync(path.join(fixtures, 'index.js'), path.join(d, 'index.js'));
});

test('updates readme.markdown', async function() {
await documentation(['readme index.js -s API'], { cwd: d });
const outputPath = path.join(d, 'readme.markdown');
expect(fs.readFileSync(outputPath, 'utf-8')).toMatchSnapshot();
});
});

describe('readme command', function() {
const fixtures = path.join(__dirname, 'fixture/readme');
const sourceFile = path.join(fixtures, 'index.js');
Expand Down
5 changes: 1 addition & 4 deletions src/get-readme-file.js
Expand Up @@ -5,14 +5,11 @@ const path = require('path');

module.exports = function findReadme(dir: string) {
const readmeFilenames = [
'README',
'README.markdown',
'README.md',
'README.txt',
'Readme.md',
'readme.markdown',
'readme.md',
'readme.txt'
'readme.md'
];

const readmeFile = fs.readdirSync(dir).find(function(filename) {
Expand Down

0 comments on commit ae789de

Please sign in to comment.