kopia lustrzana https://github.com/badgen/badgen.net
test: start some tests #42
rodzic
506d06bedf
commit
1e7341b27e
Plik diff jest za duży
Load Diff
|
@ -7,7 +7,7 @@
|
|||
"scripts": {
|
||||
"lint": "standard",
|
||||
"dev": "micro-dev service.js -s",
|
||||
"test": "echo just lint for now && npm run lint",
|
||||
"test": "tap test/*.js --reporter spec -j12",
|
||||
"start": "micro service.js",
|
||||
"precanary": "now alias rm badgen-canary -y -T amio",
|
||||
"canary": "now -T amio && now alias badgen-canary -T amio",
|
||||
|
@ -27,7 +27,9 @@
|
|||
},
|
||||
"devDependencies": {
|
||||
"micro-dev": "^3.0.0",
|
||||
"standard": "^11.0.1"
|
||||
"standard": "^11.0.1",
|
||||
"supertest": "^3.1.0",
|
||||
"tap": "^12.0.1"
|
||||
},
|
||||
"eslintConfig": {
|
||||
"extends": "standard"
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
const assert = require('assert')
|
||||
const tap = require('tap')
|
||||
const request = require('supertest')
|
||||
const micro = require('micro')
|
||||
const badgen = require('../service.js')
|
||||
const liveFns = require('../libs/live-fns/_index.js')
|
||||
|
||||
// process.env.TARGET should be the service url
|
||||
// - "https://badgen-canary.now.sh"
|
||||
// - "http://localhost:3000"
|
||||
const service = process.env.TARGET || micro(badgen)
|
||||
const isSvg = str => str.trim().startsWith('<svg ')
|
||||
|
||||
const badgeTests = [
|
||||
'/badge/npm/v1.2.3',
|
||||
'/badge/npm/v1.2.3/blue',
|
||||
'/badge/npm/v1.2.3/FAD',
|
||||
'/badge/npm/v1.2.3/FAD?icon=npm',
|
||||
'/npm/v/express',
|
||||
'/npm/v/babel-core',
|
||||
'/npm/v/ava/next',
|
||||
'/npm/v/next/canary',
|
||||
'/npm/v/@nestjs/core?icon=npm&label='
|
||||
]
|
||||
|
||||
badgeTests.forEach(badgePath => {
|
||||
tap.test(badgePath, t => {
|
||||
return request(service)
|
||||
.get(badgePath)
|
||||
.expect(200)
|
||||
.expect('Content-Type', /svg\+xml/)
|
||||
.then(res => assert(isSvg(res.body.toString())))
|
||||
})
|
||||
})
|
||||
|
||||
const keywords = ['badge', 'v', 'nls', 'license', 'red']
|
||||
const chaosTests = new Array(10).fill().map(undef => {
|
||||
const keys = keywords.concat(Object.keys(liveFns))
|
||||
const len = Math.ceil(Math.random() * 5)
|
||||
const args = new Array(len).fill().map(undef => {
|
||||
return keys[Math.floor(Math.random() * keys.length)]
|
||||
})
|
||||
return `/${args.join('/')}`
|
||||
})
|
||||
|
||||
chaosTests.forEach(badgePath => {
|
||||
tap.test(badgePath, t => {
|
||||
return request(service)
|
||||
.get(badgePath)
|
||||
.expect('Content-Type', /svg\+xml/)
|
||||
.then(res => assert(isSvg(res.body.toString())))
|
||||
})
|
||||
})
|
Ładowanie…
Reference in New Issue