- Eliminate manual testing which is error-prone and time consuming, and must be repeated many times through the PR review process - Make contributing more fun. For many, fixing bugs and making new badges is faster and more satisfying with automated tests than with manual testing. - Push out the work of testing new badges to a much broader net. The PR originator could write tests, but so could any other contributor who wants to push review along. - Detect badge failures resulting from changes in vendor contracts without waiting for user reports. - Detect and prevent regressions in the code. - Be runnable, readable, writable, and editable by as many developers as possible, including those who may not be familiar with JavaScript test tools. -- @paulmelnikow, @niccokunzmann, @Daniel15
47 lines
1.3 KiB
JavaScript
47 lines
1.3 KiB
JavaScript
'use strict';
|
|
|
|
const Joi = require('joi');
|
|
const ServiceTester = require('./runner/service-tester');
|
|
|
|
const t = new ServiceTester({ id: 'cran', title: 'CRAN/METACRAN' });
|
|
module.exports = t;
|
|
|
|
t.create('version')
|
|
.get('/v/devtools.json')
|
|
.expectJSONTypes(Joi.object().keys({
|
|
name: Joi.equal('cran'),
|
|
value: Joi.string().regex(/^v\d+\.\d+\.\d+$/)
|
|
}));
|
|
|
|
t.create('specified license')
|
|
.get('/l/devtools.json')
|
|
.expectJSON({ name: 'license', value: 'GPL (>= 2)' });
|
|
|
|
t.create('unknown package')
|
|
.get('/l/some-bogus-package.json')
|
|
.expectJSON({ name: 'cran', value: 'not found' });
|
|
|
|
t.create('unknown info')
|
|
.get('/z/devtools.json')
|
|
.expectStatus(404)
|
|
.expectJSON({ name: '404', value: 'badge not found' });
|
|
|
|
t.create('malformed response')
|
|
.get('/v/foobar.json')
|
|
.intercept(nock => nock('http://crandb.r-pkg.org')
|
|
.get('/foobar')
|
|
.reply(200)) // JSON without Version.
|
|
.expectJSON({ name: 'cran', value: 'invalid' });
|
|
|
|
t.create('connection error')
|
|
.get('/v/foobar.json')
|
|
.networkOff()
|
|
.expectJSON({ name: 'cran', value: 'inaccessible' });
|
|
|
|
t.create('unspecified license')
|
|
.get('/l/foobar.json')
|
|
.intercept(nock => nock('http://crandb.r-pkg.org')
|
|
.get('/foobar')
|
|
.reply(200, {})) // JSON without License.
|
|
.expectJSON({ name: 'license', value: 'unknown' });
|