Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

jest-runner-docs

Package Overview
Dependencies
Maintainers
1
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jest-runner-docs - npm Package Compare versions

Comparing version 0.2.2 to 0.2.3

14

CHANGELOG.md

@@ -6,2 +6,16 @@ # Change Log

## [0.2.3](https://github.com/tunnckoCore/opensource/compare/jest-runner-docs@0.2.2...jest-runner-docs@0.2.3) (2019-10-18)
### Bug Fixes
* **jest-runner-docs:** handle errors in postHook ([c7c44de](https://github.com/tunnckoCore/opensource/commit/c7c44de))
* **jest-runner-docs:** hide signature block if empty, regen docs ([201036e](https://github.com/tunnckoCore/opensource/commit/201036e))
* **jest-runner-docs:** typos ([8edc954](https://github.com/tunnckoCore/opensource/commit/8edc954))
* dist files, docs runner updates, docs ([c021464](https://github.com/tunnckoCore/opensource/commit/c021464)), closes [#63](https://github.com/tunnckoCore/opensource/issues/63)
## [0.2.2](https://github.com/tunnckoCore/opensource/compare/jest-runner-docs@0.2.1...jest-runner-docs@0.2.2) (2019-10-18)

@@ -8,0 +22,0 @@

8

package.json
{
"name": "jest-runner-docs",
"version": "0.2.2",
"version": "0.2.3",
"description": "Jest runner for API documentation generation from code comments, supports TypeScript. Very stable and reliable, based on `parse-comments` package",

@@ -40,4 +40,4 @@ "repository": {

"dependencies": {
"@tunnckocore/create-jest-runner": "^0.8.2",
"@tunnckocore/utils": "^0.9.5",
"@tunnckocore/create-jest-runner": "^0.8.3",
"@tunnckocore/utils": "^0.9.6",
"cosmiconfig": "^5.2.1",

@@ -68,3 +68,3 @@ "parse-comments": "^1.0.0"

},
"gitHead": "050fe0250b18426afaf60d36cdfe13a9782658f2"
"gitHead": "3268ac8e4840781f78928ce57110eea964d75ae8"
}
# jest-runner-docs [![npm version][npmv-img]][npmv-url] [![License][license-img]][license-url]
> WIP
> Jest runner for API documentation generation from code comments, supports TypeScript. Very stable and reliable, based on `parse-comments` package
Please consider following this project's author, [Charlike Mike Reagent](https://github.com/tunnckoCore), and :star: the project to show your :heart: and support.
<div id="thetop"></div>
<div id="readme"></div>

@@ -58,3 +58,2 @@ [![Code style][codestyle-img]][codestyle-url]

- [Install](#install)
- [API](#api)
- [Contributing](#contributing)

@@ -80,11 +79,5 @@ - [Guides and Community](#guides-and-community)

<!-- docks-start -->
## API
_Generated using [jest-runner-docs](https://npmjs.com/package/jest-runner-docs)._
/home/charlike/github/tunnckoCore/opensource/packages/jest-runner-docs/src/index.js
<!-- docks-end -->
**[back to top](#thetop)**
**[back to top](#readme)**

@@ -138,2 +131,4 @@ ## Contributing

**[back to top](#readme)**
## License

@@ -140,0 +135,0 @@

@@ -31,3 +31,6 @@ const fs = require('fs');

const signature = comment.code.value.slice(index, -1);
const signatureBlock = `\n\`\`\`ts\nfunction${signature}\n\`\`\`\n`;
const signatureBlock =
signature.trim().length > 0
? `**Signature**\n\n\`\`\`ts\nfunction${signature}\n\`\`\`\n`
: '';

@@ -48,3 +51,3 @@ const tagsString = tags

comment.description
}\n\n**Signature**\n${signatureBlock}\n**Params**\n\n${tagsString}\n${comment.examples
}\n\n${signatureBlock}\n**Params**\n\n${tagsString}\n${comment.examples
.map(

@@ -51,0 +54,0 @@ (example) =>

@@ -28,59 +28,76 @@ /* eslint-disable max-statements */

/** Find correct root path */
const pkgRoot = isMonorepo(config.cwd)
? path.dirname(path.dirname(testPath))
let pkgRoot = isMonorepo(config.cwd)
? path.dirname(testPath)
: config.rootDir;
const outfile = await tryCatch(testPath, start, () => {
const { contents: apidocsContent } = docks(testPath, pkgRoot);
/** Handle if index.js is inside root (no src dirs in root of package) */
pkgRoot = fs.existsSync(path.join(pkgRoot, 'package.json'))
? pkgRoot
: path.dirname(pkgRoot);
if (apidocsContent.length === 0 && !docksConfig.force) {
return {
skip: skip({
start,
end: Date.now(),
test: {
path: testPath,
title: 'Docks',
},
}),
};
}
const outfile = await tryCatch(
() => {
const { contents: apidocsContent } = docks(testPath, pkgRoot);
const outputFile = path.resolve(
pkgRoot,
docksConfig.outfile || docksConfig.outFile,
);
if (apidocsContent.length === 0 && !docksConfig.force) {
return {
skip: skip({
start,
end: new Date(),
test: {
path: testPath,
title: 'Docks',
},
}),
};
}
const promo = docksConfig.promo
? `_Generated using [jest-runner-docs](https://npmjs.com/package/jest-runner-docs)._`
: '';
const outputFile = path.resolve(
pkgRoot,
docksConfig.outfile || docksConfig.outFile,
);
const header = docksConfig.includeHeader ? '## API\n\n' : '';
const docksStart = '<!-- docks-start -->';
const docksEnd = '<!-- docks-end -->';
const contents = `${docksStart}\n${header}${promo}${apidocsContent}\n\n${docksEnd}`;
const promo = docksConfig.promo
? `_Generated using [jest-runner-docs](https://npmjs.com/package/jest-runner-docs)._`
: '';
if (fs.existsSync(outputFile)) {
const fileContent = fs.readFileSync(outputFile, 'utf8');
const header = docksConfig.includeHeader ? '## API\n\n' : '';
const docksStart = '<!-- docks-start -->';
const docksEnd = '<!-- docks-end -->';
const cont =
apidocsContent.length > 0
? `\n\n${header}${promo}${apidocsContent}\n\n`
: '\n';
if (fileContent.includes(docksStart) && fileContent.includes(docksEnd)) {
const idxStart = fileContent.indexOf(docksStart);
const idxEnd = fileContent.indexOf(docksEnd) + docksEnd.length;
const apiPart = fileContent.slice(idxStart, idxEnd);
const newContents = fileContent.replace(apiPart, contents);
const contents = `${docksStart}${cont}${docksEnd}\n`;
fs.writeFileSync(outputFile, newContents);
return outputFile;
if (fs.existsSync(outputFile)) {
const fileContent = fs.readFileSync(outputFile, 'utf8');
if (
fileContent.includes(docksStart) &&
fileContent.includes(docksEnd)
) {
const idxStart = fileContent.indexOf(docksStart);
const idxEnd = fileContent.indexOf(docksEnd) + docksEnd.length;
const apiPart = fileContent.slice(idxStart, idxEnd);
const newContents = fileContent.replace(apiPart, contents);
fs.writeFileSync(outputFile, newContents);
return outputFile;
}
// probably never gets here
throw new Error(`Outfile doesn't contain placeholders.`);
}
// probably never gets here
throw new Error(`Outfile doesn't contain placeholders.`);
}
const outDir = path.dirname(outputFile);
fs.mkdirSync(outDir, { recursive: true });
fs.writeFileSync(outputFile, contents);
return outputFile;
},
{ testPath, start },
);
const outDir = path.dirname(outputFile);
fs.mkdirSync(outDir, { recursive: true });
fs.writeFileSync(outputFile, contents);
return outputFile;
});
if (outfile.hasError) return outfile.error;

@@ -96,5 +113,11 @@ if (outfile.skip) return outfile.skip;

const res = await tryCatch(
() => postHook({ pkgRoot, jestConfig: config, docksConfig, outfile }),
{ start, testPath },
);
if (res.hasError) return res.error;
return pass({
start,
end: Date.now(),
end: new Date(),
test: {

@@ -108,19 +131,22 @@ path: outfile,

async function tryLoadConfig(testPath, start) {
return tryCatch(testPath, start, () => {
const cfg = jestRunnerDocks.searchSync();
return tryCatch(
() => {
const cfg = jestRunnerDocks.searchSync();
if (!cfg || (cfg && !cfg.config)) {
const runnersConf = jestRunnerConfig.searchSync();
if (!cfg || (cfg && !cfg.config)) {
const runnersConf = jestRunnerConfig.searchSync();
if (!runnersConf || (runnersConf && !runnersConf.config)) {
return {};
if (!runnersConf || (runnersConf && !runnersConf.config)) {
return {};
}
return runnersConf.config.docks || runnersConf.config.docs;
}
return runnersConf.config.docks || runnersConf.config.docs;
}
return cfg.config;
});
return cfg.config;
},
{ testPath, start },
);
}
async function tryCatch(testPath, start, fn) {
async function tryCatch(fn, { testPath, start }) {
try {

@@ -127,0 +153,0 @@ return await fn();

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc