mirror of
https://github.com/primer/css.git
synced 2024-11-30 01:04:04 +03:00
clean up doc tests
This commit is contained in:
parent
4d603c9ea5
commit
7a7222893a
@ -1,9 +1,11 @@
|
|||||||
const test = require("ava")
|
const test = require("ava")
|
||||||
const css = require(process.env.PWD)
|
const css = require(process.cwd())
|
||||||
const fs = require("fs")
|
const fs = require("fs")
|
||||||
const glob = require("glob")
|
const glob = require("glob")
|
||||||
|
|
||||||
var selectors, classnames = null
|
let selectors
|
||||||
|
let classnames
|
||||||
|
|
||||||
const classRegex = /class="([^"]+)"/ig
|
const classRegex = /class="([^"]+)"/ig
|
||||||
|
|
||||||
// Find unique selectors from the cssstats selector list
|
// Find unique selectors from the cssstats selector list
|
||||||
@ -11,7 +13,8 @@ function uniqueSelectors(s) {
|
|||||||
s = s.map(s => {
|
s = s.map(s => {
|
||||||
// split multi-selectors into last class used .foo .bar .baz
|
// split multi-selectors into last class used .foo .bar .baz
|
||||||
return s.split(" ").pop()
|
return s.split(" ").pop()
|
||||||
}).filter(s => {
|
})
|
||||||
|
.filter(s => {
|
||||||
// remove any selector that aren't just regular classnames eg. ::hover [type]
|
// remove any selector that aren't just regular classnames eg. ::hover [type]
|
||||||
return s.match(/^\.[a-z\-_]+$/ig)
|
return s.match(/^\.[a-z\-_]+$/ig)
|
||||||
})
|
})
|
||||||
@ -22,7 +25,7 @@ function uniqueSelectors(s) {
|
|||||||
|
|
||||||
// From the given glob sources array, read the files and return found classnames
|
// From the given glob sources array, read the files and return found classnames
|
||||||
function documentedClassnames(sources) {
|
function documentedClassnames(sources) {
|
||||||
var cn = []
|
const classes = []
|
||||||
sources.forEach(f => {
|
sources.forEach(f => {
|
||||||
glob.sync(f).forEach(g => {
|
glob.sync(f).forEach(g => {
|
||||||
var match = null
|
var match = null
|
||||||
@ -31,28 +34,28 @@ function documentedClassnames(sources) {
|
|||||||
while ((match = classRegex.exec(fs.readFileSync(g, "utf8"))) != null) {
|
while ((match = classRegex.exec(fs.readFileSync(g, "utf8"))) != null) {
|
||||||
|
|
||||||
// Get the matched classnames "..." and split by space into classes
|
// 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 only the unique classnames
|
||||||
return [...new Set(cn)]
|
return Array.from(new Set(classes))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Before all the tests get the selectors and classnames
|
// Before all the tests get the selectors and classnames
|
||||||
test.before(t => {
|
test.before(t => {
|
||||||
selectors = uniqueSelectors(css.cssstats.selectors.values)
|
selectors = uniqueSelectors(css.cssstats.selectors.values)
|
||||||
classnames = documentedClassnames([
|
classnames = documentedClassnames([
|
||||||
'docs/*.md',
|
"docs/*.md",
|
||||||
'README.md'
|
"README.md"
|
||||||
])
|
])
|
||||||
})
|
})
|
||||||
|
|
||||||
test("Every selector class is documented", t => {
|
test("Every selector class is documented", t => {
|
||||||
var undocumented = []
|
const undocumented = []
|
||||||
selectors.forEach(selector => {
|
selectors.forEach(selector => {
|
||||||
if (!classnames.includes(selector.replace(".", ""))) {
|
if (!classnames.includes(selector.replace(/^\./, ""))) {
|
||||||
undocumented.push(selector)
|
undocumented.push(selector)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user