Skip to content

Commit

Permalink
add unit testing
Browse files Browse the repository at this point in the history
  • Loading branch information
mmomtchev committed May 12, 2022
1 parent f02ddb4 commit a80d08d
Show file tree
Hide file tree
Showing 44 changed files with 23,032 additions and 1,014 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Node.js CI

on:
push:
branches: [ '*' ]
pull_request:
branches: [ '*' ]

jobs:
build:

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [ 14.x, 16.x, 18.x ]

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: npm i
- run: npm test
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/node_modules
/node_modules
/test/output
3 changes: 3 additions & 0 deletions .mocharc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"timeout": 20000
}
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
/.github
/.vscode
/screenshot.png
/test/output
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ documentation-stylist:
examples: 'ms-4',
mainItem: 'me-1',
navItem: 'd-flex flex-row align-items-center',
navCollapse: 'btn btn-collapse m-0 me-2 p-0 align-items-center collapsed',
navCollapse: 'btn btn-collapse m-0 me-2 p-0 align-items-center',
navList: 'list-group',
navListItem: 'list-group-item border-0',
navLink: 'text-decoration-none',
Expand Down
3 changes: 1 addition & 2 deletions hbs/index.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@
</title>
<script src="bootstrap.bundle.min.js"></script>
<link href="bootstrap.min.css" rel="stylesheet">
<link href="stylist.css" rel="stylesheet">
<link href="{{config.[documentation-stylist].css}}" rel="stylesheet">
{{#if config.[documentation-stylist].extraCss}}
<link href="{{config.[documentation-stylist].extraCss}}" rel="stylesheet">
{{/if}}
<link href="stylist.css" rel="stylesheet">
{{#if config.[project-description]}}
<meta name="description" content="{{config.[project-description]}}">
<meta name="viewport" content="width=device-width,initial-scale=1">
Expand Down
2 changes: 1 addition & 1 deletion hbs/navItem.handlebars
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div class="{{className 'navItem'}}">
<button class="btn btn-collapse m-0 me-2 p-0 align-items-center collapsed" {{#hasChildren this.members}}{{else}}style="visibility: hidden" {{/hasChildren}} data-bs-target="#{{this.slug}}-collapse"
<button class="{{className 'navCollapse'}} collapsed" {{#hasChildren this.members}}{{else}}style="visibility: hidden" {{/hasChildren}} data-bs-target="#{{this.slug}}-collapse"
data-bs-toggle="collapse">
<span class="font-monospace if-collapsed">+</span>
<span class="font-monospace if-not-collapsed">-</span> </button>
Expand Down
28 changes: 14 additions & 14 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ const map = require('map-stream');
const slugger = new require('github-slugger')();
const Handlebars = require('handlebars');

const index = Handlebars.compile(fs.readFileSync(path.join(__dirname, 'hbs', 'index.handlebars'), 'utf8'), {preventIndent: true});
const index = Handlebars.compile(fs.readFileSync(path.join(__dirname, 'hbs', 'index.handlebars'), 'utf8'), { preventIndent: true });
for (const templ of fs.readdirSync(path.join(__dirname, 'hbs')).filter(f => f.match(/\.handlebars/))) {
const partial = Handlebars.compile(fs.readFileSync(path.join(__dirname, 'hbs', templ), 'utf8'), {preventIndent: true});
const partial = Handlebars.compile(fs.readFileSync(path.join(__dirname, 'hbs', templ), 'utf8'), { preventIndent: true });
Handlebars.registerPartial(templ.split('.')[0], partial);
}
Handlebars.registerHelper('switch', function (value, options) {
Expand Down Expand Up @@ -49,7 +49,7 @@ const defaultClasses = {
examples: 'ms-4',
mainItem: 'me-1',
navItem: 'd-flex flex-row align-items-center',
navCollapse: 'btn btn-collapse m-0 me-2 p-0 align-items-center collapsed',
navCollapse: 'btn btn-collapse m-0 me-2 p-0 align-items-center',
navList: 'list-group',
navListItem: 'list-group-item border-0',
navLink: 'text-decoration-none',
Expand Down Expand Up @@ -141,16 +141,14 @@ function crossify(list, block) {


module.exports = function documentationStylist(comments, config) {
const themeConfig = config['documentation-stylist'];
if (themeConfig) {
if (themeConfig.externalCrossLinks)
externalCrossLinks = require(path.resolve(process.cwd(), themeConfig.externalCrossLinks));
if (themeConfig.dumpAST)
fs.writeFileSync(themeConfig.dumpAST, JSON.stringify(comments));
crossLinksDupeWarning = themeConfig.crossLinksDupeWarning;
srcLinkBase = themeConfig.srcLinkBase;
userClasses = themeConfig.classes || {};
}
const themeConfig = config['documentation-stylist'] = config['documentation-stylist'] || {};
if (themeConfig.externalCrossLinks)
externalCrossLinks = require(path.resolve(process.cwd(), themeConfig.externalCrossLinks));
if (themeConfig.dumpAST)
fs.writeFileSync(themeConfig.dumpAST, JSON.stringify(comments));
crossLinksDupeWarning = themeConfig.crossLinksDupeWarning;
srcLinkBase = themeConfig.srcLinkBase;
userClasses = themeConfig.classes || {};

comments.forEach(slugify);

Expand All @@ -164,11 +162,13 @@ module.exports = function documentationStylist(comments, config) {
// create automatic cross-links
comments.forEach(crossify.bind(null, crossLinks));

themeConfig.css = themeConfig.css ? path.join(process.cwd(), themeConfig.css) : path.join(__dirname, 'stylist.css')
const assets = [
require.resolve('bootstrap/dist/js/bootstrap.bundle.min.js'),
require.resolve('bootstrap/dist/css/bootstrap.min.css'),
themeConfig.css ? path.join(process.cwd(), themeConfig.css) : path.join(__dirname, 'stylist.css')
themeConfig.css
];
themeConfig.css = path.basename(themeConfig.css);
if (themeConfig.extraCss) {
assets.push(path.join(process.cwd(), themeConfig.extraCss));
themeConfig.extraCss = path.basename(themeConfig.extraCss);
Expand Down
Loading

0 comments on commit a80d08d

Please sign in to comment.