1
1
mirror of https://github.com/primer/css.git synced 2024-11-27 17:52:45 +03:00
css/tests/test-for-current-year.js

39 lines
1.2 KiB
JavaScript
Raw Normal View History

2019-01-03 08:51:14 +03:00
const test = require('ava')
const fs = require('fs-extra')
const globby = require('globby')
const {join} = require('path')
2019-01-03 08:51:14 +03:00
const {packages} = require('../lerna.json')
const year = (new Date()).getFullYear()
2017-10-27 21:28:00 +03:00
const yearRegex = new RegExp(`Copyright \\(c\\) ${year} GitHub Inc\\.`)
test(`LICENSE files have the current year ${year}`, t => {
2019-01-03 08:51:14 +03:00
return getPackageGlobs('LICENSE')
.then(paths => {
t.plan(paths.length)
return paths.map(path => {
2019-01-03 08:51:14 +03:00
const license = fs.readFileSync(path, 'utf8')
2017-10-27 21:28:00 +03:00
return t.regex(license, yearRegex, `The license "${path}" does not include the current year ${year}`)
})
})
})
test(`Source header copyrights have the current year ${year}`, t => {
2019-01-03 08:51:14 +03:00
return getPackageGlobs('{*.scss,lib/**/*.scss}')
.then(paths => {
t.plan(paths.length)
return paths.map(path => {
2019-01-03 08:51:14 +03:00
const source = fs.readFileSync(path, 'utf8')
if (source.match(/Copyright \(c\)/)) {
2017-10-27 21:28:00 +03:00
return t.regex(source, yearRegex, `The source's header "${path}" does not include the current year ${year}`)
} else {
return t.true(true)
}
})
})
})
2019-01-03 08:51:14 +03:00
function getPackageGlobs(glob) {
return globby(packages.map(pkg => join(pkg, glob)))
}