Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
7324b09
generate implementation
jeeyyy Jun 12, 2019
b820fda
add implementation to coverage/ overview
jeeyyy Jun 12, 2019
460a548
add metrics to website
jeeyyy Jun 12, 2019
ee046e7
format (prettierr)
jeeyyy Jun 12, 2019
ea6bd90
Merge branch 'develop' into add-implementations
jeeyyy Jun 12, 2019
d9cf79a
install reports as packages and update implementation script
jeeyyy Jun 13, 2019
ac4a7b6
merge from develop
jeeyyy Jun 13, 2019
0e24f94
add implementation id
jeeyyy Jun 14, 2019
1587ffa
get and create implementations
jeeyyy Jun 17, 2019
9d2410d
generate testcases outside gatsby hook
jeeyyy Jun 17, 2019
f06c716
generate html reports from implementation metrics
jeeyyy Jun 17, 2019
13b6300
move glossary gen out of gatsby hook
jeeyyy Jun 17, 2019
559861e
run prettier
jeeyyy Jun 17, 2019
5d0b583
update package.json
jeeyyy Jun 17, 2019
87441f9
Merge branch 'develop' into add-implementations
jeeyyy Jun 21, 2019
655fa19
refactor before adding tests
jeeyyy Jun 24, 2019
dc173f4
add jsdocs
jeeyyy Jun 24, 2019
2c9b154
fix: for not gernerating multiple rule reports
jeeyyy Jun 24, 2019
91a2bc3
add tests
jeeyyy Jun 24, 2019
e1a6fc1
merge from develop
jeeyyy Jun 24, 2019
71d329f
merge
jeeyyy Jun 24, 2019
e1a5a26
remove testPathIgnore
jeeyyy Jun 24, 2019
11a6a13
add pretest step
jeeyyy Jun 24, 2019
ed68a9e
remove husky hook and add trusted tester report
jeeyyy Jun 24, 2019
2e10dea
Merge branch 'develop' into add-implementations
jeeyyy Jun 25, 2019
276937d
Merge branch 'develop' into add-implementations
jeeyyy Jun 26, 2019
1721428
update
jeeyyy Jun 28, 2019
f5a9388
merge & fix scroll bug
jeeyyy Jul 1, 2019
9452f0b
Merge branch 'develop' into add-implementations
jeeyyy Jul 1, 2019
d748044
update
jeeyyy Jul 1, 2019
47dd52f
Merge branch 'develop' into add-implementations
jeeyyy Jul 3, 2019
c5a3548
Merge branch 'develop' into add-implementations
jeeyyy Jul 3, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 89 additions & 0 deletions build/create-glossary-usages.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/**
* Create glossary usages
* -> for each glossary item (find references in each rule)
* -> this is saved in `_data` which is later used in `pages/glossary`
*/
const globby = require('globby')
const regexps = require('../utils/reg-exps')
const createFile = require('../utils/create-file')
const getAllMatchesForRegex = require('../utils/get-all-matches-for-regex')
const getMarkdownData = require('../utils/get-markdown-data')

const init = async () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests please.

/**
* Get all rules `markdown` data
*/
const rulesData = globby
.sync([`./_rules/*.md`])
.map(rulePath => getMarkdownData(rulePath))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have basically the same code sitting in get-rules. Please DRY your code.


/**
* Eg:
* {
* `non-empty`: [
* { name: `aria valid ...`, slug: `rules/XXXXX` },
* ....
* ]
* ....
* }
*/
const glossaryUsages = {}

rulesData.forEach(ruleData => {
const { frontmatter, body } = ruleData
const {
id: ruleId,
name: ruleName,
accessibility_requirements: ruleAccessibilityRequirements,
} = frontmatter

const glossaryMatches = getAllMatchesForRegex(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no idea what is happening here. Can you please write this it can be reviewed?

regexps.glossaryReferenceInRules,
body,
false
)

glossaryMatches.forEach(glossaryItem => {
const hasGlossaryKey = regexps.glossaryKey.test(glossaryItem.block)
if (!hasGlossaryKey) {
return
}

const key = glossaryItem.block.match(regexps.glossaryKey)[1]
if (!key) {
return
}

const usage = {
name: ruleName,
slug: `rules/${ruleId}`,
}
if (!glossaryUsages[key]) {
glossaryUsages[key] = [usage]
return
}

const exists = glossaryUsages[key].some(u => u.slug === usage.slug)
if (exists) {
return
}

glossaryUsages[key] = glossaryUsages[key].concat(usage)
})
})

/**
* Create `_data/glossary-usages.json`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you putting this stuff into JSON files rather than have Gatsby consume the data directly? You're basically using disc for caching data that takes almost no time to build.

*/
await createFile(
`./_data/glossary-usages.json`,
JSON.stringify(glossaryUsages, undefined, 2)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't do IO in the same method where you're doing data manipulation. Have your functions do one thing. It's easier to read, and easier to test.

)
}

/**
* Invoke
*/
init()
.then(() => console.info(`Completed: task: create:glossary\n`))
.catch(e => console.error(e))
81 changes: 81 additions & 0 deletions build/create-implementation-metrics.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
const globby = require('globby')
const readFile = require('../utils/read-file')
const createFile = require('../utils/create-file')

/**
* Init
*/
const init = async () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything I said about create-glossary pretty much applies here too.

/**
* Get all implementation reports
*/
const reports = globby
.sync([`./_data/implementations/*.json`])
.map(reportPath => {
const fileContent = readFile(reportPath)
return JSON.parse(fileContent)
})

const implementers = []
const implementationsGroupedByRuleId = {}

reports.forEach(report => {
const { tool, organisation, data } = report

/**
* Create data that can be used in `src/templates/coverage.js`
*/
implementers.push(report)

/**
* Iterate each implementation & group by rule id
*/
data.forEach(({ ruleId, implementation }) => {
if (!implementation) {
return
}

/**
* Note:
* only build `metrics` for implementations that are `complete`
*/
const { complete = false } = implementation
if (complete) {
return
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can just do that in the first if statement.

}

if (!implementationsGroupedByRuleId[ruleId]) {
implementationsGroupedByRuleId[ruleId] = []
}

implementationsGroupedByRuleId[ruleId].push({
organisation,
tool,
implementation,
})
})
})

/**
* Create `implementations.json`
*/
await createFile(
`_data/implementers.json`,
JSON.stringify(implementers, null, 2)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this is just an array of other JSON files? That doesn't seem useful.

)

/**
* Create metrics in `_data` for usage in `site`
*/
await createFile(
`_data/implementation-metrics.json`,
JSON.stringify(implementationsGroupedByRuleId, null, 2)
)
}

init()
.then(() => console.info(`\nImplementation metrics generated.\n`))
.catch(e => {
console.error(e)
process.exit(1)
})
149 changes: 149 additions & 0 deletions build/create-testcases.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
const globby = require('globby')
const makeDir = require('make-dir')
const objectHash = require('object-hash')
const codeBlocks = require('gfm-code-blocks')
const {
www: { url, baseDir },
} = require('./../package.json')
const getMarkdownData = require('./../utils/get-markdown-data')
const createFile = require('../utils/create-file')
const regexps = require('../utils/reg-exps')
const getAllMatchesForRegex = require('../utils/get-all-matches-for-regex')
const copyTestcasesAssets = require('./testcases/copy-testcases-assets')
const createTestcasesJson = require('./testcases/create-testcases-json')
const createTestcasesOfRuleOfEmReportTool = require('./testcases/create-testcases-of-rule-of-em-report-tool')

/**
* Create test case files & other meta-data from test case in each rule.
*
* -> create test cases files into `./public/testcases/`
* -> copy `./test-assets/*` into `./public`
* -> create `testcases.json` into `./public`
*/
const init = async () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything I said about create-glossary pretty much applies here too.

/**
* Create `public` directory
*/
await makeDir(`public`)

/**
* Get all rules `markdown` data
*/
const rulesData = globby
.sync([`./_rules/*.md`])
.map(rulePath => getMarkdownData(rulePath))

let allRulesTestcases = []

/**
* iterate all rule pages
* -> get code snippets
* -> and their relevant titles
*/
rulesData.forEach(ruleData => {
const { frontmatter, body } = ruleData
const {
id: ruleId,
name: ruleName,
accessibility_requirements: ruleAccessibilityRequirements,
} = frontmatter
const codeTitles = getAllMatchesForRegex(regexps.testcaseTitle, body)

/**
* get code blocks in markdown body
*/
const codeSnippets = codeBlocks(body)

if (codeTitles.length !== codeSnippets.length) {
throw new Error(
`Number of matching titles for code snippets is wrong. Check markdown '${ruleName}' for irregularities.`
)
}

/**
* iterate each code snippet
* -> create a testcase file
* -> and add meta of testcase to `testcases.json`
*/
const ruleTestcases = codeSnippets.reduce((out, codeBlock, index) => {
const title = codeTitles[index]
if (!title) {
throw new Error('No title found for code snippet.')
}

const { code, block } = codeBlock
let { type = 'html' } = codeBlock

if (regexps.testcaseCodeSnippetTypeIsSvg.test(block.substring(0, 15))) {
type = 'svg'
}

const codeId = objectHash({
block,
type,
ruleId,
})

const titleCurated = title.value.split(' ').map(t => t.toLowerCase())

const testcaseFileName = `${ruleId}/${codeId}.${type}`
const testcasePath = `testcases/${testcaseFileName}`
/**
* Create testcase file
*/
createFile(`${baseDir}/${testcasePath}`, code)

/**
* Create meta data for testcase(s)
*/
const testcase = {
testcaseId: codeId,
url: `${url}/${testcasePath}`,
relativePath: testcasePath,
expected: titleCurated[0],
ruleId,
ruleName,
rulePage: `${url}/rules/${ruleId}`,
ruleAccessibilityRequirements,
}

out.push(testcase)
return out
}, [])

// add rule testcases to all testcases
allRulesTestcases = allRulesTestcases.concat(ruleTestcases)

/**
* Create test cases of rule for use with `em report tool`
*/
createTestcasesOfRuleOfEmReportTool({
ruleId,
ruleName,
ruleTestcases,
ruleAccessibilityRequirements,
})
})

/**
* Copy `test-assets` that are used by `testcases`
*/
await copyTestcasesAssets()

/**
* Generate `testcases.json`
*/
await createTestcasesJson(allRulesTestcases)

console.info(`\nGenerated Test Cases.\n`)
}

/**
* Invoke
*/
init()
.then(() => console.log('Completed: task: create:testcases'))
.catch(e => {
console.error(e)
process.write(1)
})
74 changes: 74 additions & 0 deletions build/get-implementation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
const assert = require('assert')
const program = require('commander')
const { version } = require('../package.json')
const createFile = require('../utils/create-file')
const getFramedReport = require('./implementations/get-framed-report')
const getImplementationForReport = require('./implementations/get-implementation-for-report')

/**
* Init
* @param {Object} program program
*/
const init = async program => {
const { org, tool, path } = program

/**
* assert `args`
*/
assert(org, '`Organisation` is required')
assert(tool, '`tool` is required')
assert(path, '`path` is required')

console.info(`\nGet implementation of ${tool} by ${org}\n`)

/**
* fetch `report` & `frame` as required
*/
const framedReport = await getFramedReport(path)

/**
* Get `implementation`
*/
const data = await getImplementationForReport(framedReport)

/**
* create report
*/
const report = {
organisation: org,
tool,
data,
}

/**
* Save `implementation` to `_data/implementations`
*/
const filename = tool
.split(' ')
.join('-')
.toLowerCase()
await createFile(
`_data/implementations/${filename}.json`,
JSON.stringify(report, null, 2)
)
}

/**
* Parse `args`
*/
program
.version(version)
.option('-o, --org <org>', 'Organisation, which created the EARL report')
.option('-t, --tool <tool>', 'Tool used by EARL report')
.option('-p, --path <path>', 'Path to EARL report')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-r, --report?

.parse(process.argv)

/**
* Init
*/
init(program)
.then(() => console.info(`\nImplementations data generated.\n`))
.catch(e => {
console.error(e)
process.exit(1)
})
Loading