Skip to content

Commit

Permalink
test(main): verify resources in main lib/index.js
Browse files Browse the repository at this point in the history
  • Loading branch information
gregswindle committed Dec 10, 2017
1 parent 43341b5 commit 6460f3f
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 103 deletions.
67 changes: 0 additions & 67 deletions lib/formatters/crc/crc-model-template0.md

This file was deleted.

70 changes: 34 additions & 36 deletions lib/formatters/crc/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,18 @@
* @author Greg Swindle
*/

(() => {
const CrcReporter = require("../../crc/crc-reporter");
const fs = require("fs");
const path = require("path");
// const pluralize = require("pluralize");
// eslint-disable-next-line node/no-unsupported-features
const { template } = require("lodash");
const CrcReporter = require("../../crc/crc-reporter");
const fs = require("fs");
const path = require("path");
// const pluralize = require("pluralize");
// eslint-disable-next-line node/no-unsupported-features
const { template } = require("lodash");

// --------------------------------------------------------------------------
// Helpers
// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
// Helpers
// --------------------------------------------------------------------------

/**
/**
* Provides a compiled lodash template.
*
* **Security:** `security/detect-non-literal-fs-filename` has been disabled
Expand All @@ -29,21 +28,21 @@
* @returns {string} The compiled lodash template.
* @private
*/
const getTempate = (templateName) => {
// eslint-disable-next-line security/detect-non-literal-fs-filename
return template(fs.readFileSync(path.join(
__dirname,
templateName), "utf-8")
);
};
const crcPageTemplate = getTempate("crc-page-template.md");
const crcModelTemplate = getTempate("crc-model-template.md");
const getTempate = (templateName) => {
// eslint-disable-next-line security/detect-non-literal-fs-filename
return template(fs.readFileSync(path.join(
__dirname,
templateName), "utf-8")
);
};
const crcPageTemplate = getTempate("crc-page-template.md");
const crcModelTemplate = getTempate("crc-model-template.md");

// --------------------------------------------------------------------------
// Public Interface
// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
// Public Interface
// --------------------------------------------------------------------------

/**
/**
* Create a markdown-based report of CrcModels.
*
* @function
Expand All @@ -57,16 +56,15 @@
* --fix
* @returns {string} CrcModels rendered as markdown.
*/
module.exports = function (results) {
const crcReporter = new CrcReporter();
const crcModels = crcReporter.report(results);
module.exports = function (results) {
const crcReporter = new CrcReporter();
const crcModels = crcReporter.report(results);

return crcPageTemplate({
date: new Date(),
reportSummary: `Object count: ${crcModels.length}`,
results: crcModels.map((crcModel) => crcModelTemplate({
crcModel
}))
});
};
})();
return crcPageTemplate({
date: new Date(),
reportSummary: `Object count: ${crcModels.length}`,
results: crcModels.map((crcModel) => crcModelTemplate({
crcModel
}))
});
};
3 changes: 3 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ const requireIndex = require("requireindex");
// ------------------------------------------------------------------------------

module.exports = {
// Immport Crc services
services: requireIndex(path.resolve(__dirname, "crc")),

// Import the markdown formatter
formatters: {
crc: requireIndex(path.resolve(__dirname, "formatters/crc"))
Expand Down
30 changes: 30 additions & 0 deletions tests/lib/index.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const crc = require("../../lib");
const { expect } = require("chai");

describe("eslint-plugin-crc", () => {

it("is a module for analyzing prototype-based JavaScript", () => {
expect(crc).to.be.ok;
});

describe("provides services that", () => {
it("translate ASTNodes into CRC summaries", () => {
expect(crc.services).to.be.ok;
expect(crc.services['ast-config']).to.be.an('object');
expect(crc.services['crc-class']).to.be.a('function');
expect(crc.services['crc-context']).to.be.a('function');
expect(crc.services['crc-model']).to.be.a('function');
expect(crc.services['crc-reporter']).to.be.a('function');
expect(crc.services['crc-responsibility']).to.be.a('function');
expect(crc.services.descriptors).to.be.ok;
expect(crc.services.descriptors.astNodeFactories).to.be.ok;
expect(crc.services.descriptors.astNodeFactoryMap).to.be.ok;
});
});


it("has a formatter for generating CRC reports", () => {
expect(crc.formatters.crc).to.be.ok;
expect(crc.formatters.crc).to.be.an('object');
});
});

0 comments on commit 6460f3f

Please sign in to comment.