-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
103 additions
and
536 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
'use strict'; | ||
|
||
const {resolve, relative, dirname} = require('path'); | ||
const {readFileSync} = require('fs'); | ||
|
||
const PROJECT_ROOT_DIR = resolve(__dirname, '..', '..'); | ||
const FILES = [ | ||
{ | ||
slug: 'simplereporter', | ||
path: require.resolve('../../test/integration/fixtures/simple-reporter.js'), | ||
header: '// my-reporter.js' | ||
} | ||
]; | ||
|
||
const HEADER = '```js\n'; | ||
const FOOTER = '```\n'; | ||
|
||
const loadFile = (path, {header} = {}) => { | ||
const relativeDir = relative(dirname(path), PROJECT_ROOT_DIR); | ||
let content = readFileSync(path, 'utf-8'); | ||
// replace relative paths in `require()` to root with "mocha". | ||
// might not work in the general case. not gonna parse an AST for this | ||
// e.g. `require('../../lib/foo')` => `require('mocha/lib/foo')` | ||
// also trim any trailing whitespace | ||
content = content | ||
.replace( | ||
new RegExp(`require\\(['"]${relativeDir}(.*?)['"]\\)`, 'g'), | ||
"require('mocha$1')" | ||
) | ||
.trim(); | ||
return `${HEADER}${header}\n\n${content}${FOOTER}`; | ||
}; | ||
|
||
/** | ||
* Loads files from disk (see `FILES` above) to be shown as data. | ||
* Used for embedding sources directly into pages | ||
*/ | ||
module.exports = () => { | ||
const files = FILES.map(({path, header, slug}) => { | ||
const content = loadFile(path, {header}); | ||
return {slug, content}; | ||
}); | ||
return files.reduce( | ||
(files, {slug, content}) => ({ | ||
...files, | ||
[slug]: content | ||
}), | ||
{} | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
'use strict'; | ||
|
||
const markdownToc = require('markdown-toc'); | ||
const {readFileSync} = require('fs'); | ||
const {resolve} = require('path'); | ||
|
||
const IGNORED_HEADINGS_REGEXP = /Features|Table of Contents|Backers|Sponsors/i; | ||
const DOCUMENT_PATH = resolve(__dirname, '..', 'index.md'); | ||
|
||
module.exports = () => { | ||
const doc = readFileSync(DOCUMENT_PATH, 'utf-8'); | ||
return markdownToc(doc, { | ||
slugify: require('uslug'), | ||
firsth1: false, | ||
bullets: '-', | ||
maxdepth: 2, | ||
// if filter is supplied, maxdepth is apparently ignored, | ||
// so we have to do it ourselves. | ||
filter: (str, ele) => ele.lvl < 2 && !IGNORED_HEADINGS_REGEXP.test(str) | ||
}).content; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
'use strict'; | ||
|
||
const stripAnsi = require('strip-ansi'); | ||
const {resolve} = require('path'); | ||
const {execSync} = require('child_process'); | ||
|
||
const executable = require.resolve('../../bin/mocha'); | ||
const flag = '--help'; | ||
|
||
/** | ||
* Return the output of `mocha --help` for display | ||
*/ | ||
module.exports = () => { | ||
return stripAnsi( | ||
String( | ||
execSync(`"${process.execPath}" ${executable} ${flag}`, { | ||
cwd: resolve(__dirname, '..') | ||
}) | ||
).trim() | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.