mirror of
https://github.com/samsonjs/mit-license.git
synced 2026-04-27 15:07:42 +00:00
refactor: Rewrite tests
Signed-off-by: Richie Bendall <richiebendall@gmail.com>
This commit is contained in:
parent
4b38621ab8
commit
64480c9879
3 changed files with 41 additions and 28 deletions
|
|
@ -43,9 +43,12 @@
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"css": "^2.2.4",
|
"css": "^2.2.4",
|
||||||
|
"file-ext": "^1.0.0",
|
||||||
|
"get-ext": "^1.0.2",
|
||||||
"has-flag": "^4.0.0",
|
"has-flag": "^4.0.0",
|
||||||
"husky": "^4.2.1",
|
"husky": "^4.2.1",
|
||||||
"nodemon": "^2.0.2",
|
"nodemon": "^2.0.2",
|
||||||
|
"path-extra": "^4.3.0",
|
||||||
"standard": "^14.3.1"
|
"standard": "^14.3.1"
|
||||||
},
|
},
|
||||||
"resolutions": {
|
"resolutions": {
|
||||||
|
|
|
||||||
66
test.js
66
test.js
|
|
@ -1,45 +1,54 @@
|
||||||
const path = require('path')
|
|
||||||
const fs = require('fs-extra')
|
const fs = require('fs-extra')
|
||||||
const CSS = require('css')
|
const CSS = require('css')
|
||||||
const { validDomainId } = require('./routes/utils')
|
const { validDomainId } = require('./routes/utils')
|
||||||
const hasFlag = require('has-flag')
|
const hasFlag = require('has-flag')
|
||||||
|
const getExtension = require('file-ext')
|
||||||
|
const path = require('path-extra')
|
||||||
|
const is = require('@sindresorhus/is')
|
||||||
|
|
||||||
function report (content, fix) {
|
async function report (content, fix) {
|
||||||
console.error(content)
|
console.error(content)
|
||||||
if (fix && hasFlag('--fix')) fix()
|
if (fix && hasFlag('--fix')) await fix()
|
||||||
process.exitCode = 1
|
process.exitCode = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
const users = await fs.readdir('users')
|
const users = await fs.readdir('users')
|
||||||
users.forEach(async user => {
|
|
||||||
if (!user.endsWith('json')) {
|
for (const user of users) {
|
||||||
report(`${user} is not a json file`, () =>
|
if (getExtension(user) !== 'json') {
|
||||||
fs.unlink(path.join('users', user), () => { })
|
await report(`${user} is not a json file`, async () => {
|
||||||
)
|
await fs.remove(user)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
if (!validDomainId(user.replace('.json', ''))) {
|
|
||||||
report(`${user} is not a valid domain id.`)
|
if (!validDomainId(path.base(user))) {
|
||||||
|
await report(`${user} is not a valid domain id.`)
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const data = await fs.readFile(path.join('users', user), 'utf8')
|
const data = await fs.readFile(path.join('users', user), 'utf8')
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const u = JSON.parse(data)
|
const parsedData = JSON.parse(data)
|
||||||
if (!u.locked && !u.copyright) {
|
|
||||||
|
if (!parsedData.locked && !parsedData.copyright) {
|
||||||
report(`Copyright not specified in ${user}`)
|
report(`Copyright not specified in ${user}`)
|
||||||
}
|
}
|
||||||
if (u.version) {
|
|
||||||
report(`Version tag found in ${user}`, () => {
|
if (parsedData.version) {
|
||||||
delete u.version
|
await report(`Version tag found in ${user}`, async () => {
|
||||||
const stringified = `${JSON.stringify(u, 0, 2)}\n`
|
delete parsedData.version
|
||||||
fs.writeFile(path.join('users', user), stringified, () => { })
|
const stringified = `${JSON.stringify(parsedData, 0, 2)}\n`
|
||||||
|
await fs.writeFile(path.join('users', user), stringified)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
if (typeof u.gravatar === 'string') {
|
|
||||||
report(`Gravatar boolean encoded as string found in ${user}`, () => {
|
if (is.string(parsedData.gravatar)) {
|
||||||
u.gravatar = u.gravatar === 'true'
|
await report(`Gravatar boolean encoded as string found in ${user}`, async () => {
|
||||||
const stringified = `${JSON.stringify(u, 0, 2)}\n`
|
parsedData.gravatar = parsedData.gravatar === 'true'
|
||||||
fs.writeFile(path.join('users', user), stringified, () => { })
|
const stringified = `${JSON.stringify(parsedData, 0, 2)}\n`
|
||||||
|
await fs.writeFile(path.join('users', user), stringified)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
} catch ({ message }) {
|
} catch ({ message }) {
|
||||||
|
|
@ -48,15 +57,16 @@ function report (content, fix) {
|
||||||
} catch ({ message }) {
|
} catch ({ message }) {
|
||||||
report(`Unable to read ${user} (${message})`)
|
report(`Unable to read ${user} (${message})`)
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
|
||||||
const themes = await fs.readdir('themes')
|
const themes = await fs.readdir('themes')
|
||||||
await themes.forEach(async theme => {
|
|
||||||
if (theme.endsWith('css')) {
|
for (const theme of themes) {
|
||||||
|
if (getExtension(theme) === 'css') {
|
||||||
try {
|
try {
|
||||||
const data = await fs.readFile(path.join('themes', theme), 'utf8')
|
const cssData = await fs.readFile(path.join('themes', theme), 'utf8')
|
||||||
try {
|
try {
|
||||||
CSS.parse(data)
|
CSS.parse(cssData)
|
||||||
} catch ({ message }) {
|
} catch ({ message }) {
|
||||||
report(`Invalid CSS in ${theme} (${message})`)
|
report(`Invalid CSS in ${theme} (${message})`)
|
||||||
}
|
}
|
||||||
|
|
@ -64,5 +74,5 @@ function report (content, fix) {
|
||||||
report(`Unable to read ${theme} (${message})`)
|
report(`Unable to read ${theme} (${message})`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
})()
|
})()
|
||||||
|
|
|
||||||
BIN
yarn.lock
BIN
yarn.lock
Binary file not shown.
Loading…
Reference in a new issue