diff --git a/tests/modules/test-document-styles.js b/tests/modules/test-document-styles.js index d28fc9e0..d081c228 100644 --- a/tests/modules/test-document-styles.js +++ b/tests/modules/test-document-styles.js @@ -1,9 +1,11 @@ const test = require("ava") -const css = require(process.env.PWD) +const css = require(process.cwd()) const fs = require("fs") const glob = require("glob") -var selectors, classnames = null +let selectors +let classnames + const classRegex = /class="([^"]+)"/ig // Find unique selectors from the cssstats selector list @@ -11,7 +13,8 @@ function uniqueSelectors(s) { s = s.map(s => { // split multi-selectors into last class used .foo .bar .baz return s.split(" ").pop() - }).filter(s => { + }) + .filter(s => { // remove any selector that aren't just regular classnames eg. ::hover [type] return s.match(/^\.[a-z\-_]+$/ig) }) @@ -22,37 +25,37 @@ function uniqueSelectors(s) { // From the given glob sources array, read the files and return found classnames function documentedClassnames(sources) { - var cn = [] - sources.forEach( f => { - glob.sync(f).forEach( g => { + const classes = [] + sources.forEach(f => { + glob.sync(f).forEach(g => { var match = null // While we match a classRegex in the source while ((match = classRegex.exec(fs.readFileSync(g, "utf8"))) != null) { // Get the matched classnames "..." and split by space into classes - cn = cn.concat(match[1].split(" ")) + classes.push(...match[1].split(" ")) } }) }) // return only the unique classnames - return [...new Set(cn)] + return Array.from(new Set(classes)) } // Before all the tests get the selectors and classnames test.before(t => { selectors = uniqueSelectors(css.cssstats.selectors.values) classnames = documentedClassnames([ - 'docs/*.md', - 'README.md' + "docs/*.md", + "README.md" ]) }) test("Every selector class is documented", t => { - var undocumented = [] - selectors.forEach( selector => { - if (!classnames.includes(selector.replace(".", ""))) { + const undocumented = [] + selectors.forEach(selector => { + if (!classnames.includes(selector.replace(/^\./, ""))) { undocumented.push(selector) } })