Skip to content
Snippets Groups Projects
Commit c3ef232b authored by Paul Melnikow's avatar Paul Melnikow Committed by GitHub
Browse files

Place tests alongside their code (#969)

Reorg of the tests: move them just alongside their code. The principle relates to grouping by coupling, not by function and is established in best-practice documents (e.g. https://github.com/focusaurus/express_code_structure#underlying-principles-and-motivations), despite its break from the tradition of a separate `test/` tree. All of today's tools can handle tests spread through the repository.

There are some good, if subtle consequences of this change:

- Since files are close at hand, friction is reduced at development time, which encourages that new tests are written to cover new behaviors.
- It's easier to find the tests that cover a particular piece of functionality.
- It's easier to see which code has tests and which doesn't.
parent df9bbbf1
Branches
Tags
No related merge requests found
var assert = require('assert');
var cproc = require('child_process');
var isPng = require('is-png');
var isSvg = require('is-svg');
describe('The CLI', function () {
it('should provide a help message', function(done) {
var child = cproc.spawn('node', ['gh-badge.js']);
var buffer = '';
child.stdout.on('data', function(chunk) {
buffer += ''+chunk;
});
child.stdout.on('end', function() {
assert(buffer.startsWith('Usage'));
done();
});
});
it('should produce default badges', function(done) {
var child = cproc.spawn('node',
['gh-badge.js', 'cactus', 'grown']);
child.stdout.once('data', function(chunk) {
var buffer = ''+chunk;
assert.ok(isSvg(buffer));
assert(buffer.includes('cactus'), 'cactus');
assert(buffer.includes('grown'), 'grown');
done();
});
});
it('should produce colorschemed badges', function(done) {
var child = cproc.spawn('node',
['gh-badge.js', 'cactus', 'grown', ':green']);
child.stdout.once('data', function(chunk) {
var buffer = ''+chunk;
assert.ok(isSvg(buffer));
done();
});
});
it('should produce right-color badges', function(done) {
var child = cproc.spawn('node',
['gh-badge.js', 'cactus', 'grown', '#abcdef']);
child.stdout.once('data', function(chunk) {
var buffer = ''+chunk;
assert(buffer.includes('#abcdef'), '#abcdef');
done();
});
});
it('should produce PNG badges', function(done) {
var child = cproc.spawn('node',
['gh-badge.js', 'cactus', 'grown', '.png']);
child.stdout.once('data', function(chunk) {
assert.ok(isPng(chunk));
done();
});
});
});
const assert = require('assert');
const isSvg = require('is-svg');
const badge = require('../lib/badge');
const badge = require('./badge');
describe('The badge generator', function () {
it('should produce SVG', function(done) {
......
......@@ -12,7 +12,7 @@
'use strict';
const config = require('./config');
const config = require('./test-config');
let startCalled = false;
......
var assert = require('assert');
var LRU = require('../lib/lru-cache.js');
var LRU = require('./lru-cache');
describe('The LRU cache', function () {
......
......@@ -2,8 +2,8 @@ const assert = require('assert');
const sinon = require('sinon');
const isPng = require('is-png');
const badge = require('../lib/badge');
const svg2img = require('../lib/svg-to-img.js');
const badge = require('./badge');
const svg2img = require('./svg-to-img');
describe('The rasterizer', function () {
let cacheGet;
......
File moved
......@@ -43,7 +43,7 @@
"coverage:report:reopen": "opn coverage/lcov-report/index.html",
"coverage:report:open": "npm run coverage:report && npm run coverage:report:reopen",
"lint": "eslint '**/*.js'",
"test:js": "mocha 'test/**/*.spec.js'",
"test:js": "mocha lib '*.spec.js'",
"test:services": "mocha --delay service-tests/runner/cli.js",
"test": "npm run lint && npm run test:js"
},
......
var assert = require('assert');
var sinon = require('sinon');
var http = require('http');
var cproc = require('child_process');
var fs = require('fs');
var path = require('path');
var isPng = require('is-png');
var isSvg = require('is-svg');
var svg2img = require('../lib/svg-to-img');
const serverHelpers = require('./in-process-server-helpers');
var svg2img = require('./lib/svg-to-img');
const serverHelpers = require('./lib/in-process-server-test-helpers');
// Test parameters
var port = '1111';
var url = 'http://127.0.0.1:' + port + '/';
describe('The CLI', function () {
it('should provide a help message', function(done) {
var child = cproc.spawn('node', ['gh-badge.js']);
var buffer = '';
child.stdout.on('data', function(chunk) {
buffer += ''+chunk;
});
child.stdout.on('end', function() {
assert(buffer.startsWith('Usage'));
done();
});
});
it('should produce default badges', function(done) {
var child = cproc.spawn('node',
['gh-badge.js', 'cactus', 'grown']);
child.stdout.once('data', function(chunk) {
var buffer = ''+chunk;
assert.ok(isSvg(buffer));
assert(buffer.includes('cactus'), 'cactus');
assert(buffer.includes('grown'), 'grown');
done();
});
});
it('should produce colorschemed badges', function(done) {
var child = cproc.spawn('node',
['gh-badge.js', 'cactus', 'grown', ':green']);
child.stdout.once('data', function(chunk) {
var buffer = ''+chunk;
assert.ok(isSvg(buffer));
done();
});
});
it('should produce right-color badges', function(done) {
var child = cproc.spawn('node',
['gh-badge.js', 'cactus', 'grown', '#abcdef']);
child.stdout.once('data', function(chunk) {
var buffer = ''+chunk;
assert(buffer.includes('#abcdef'), '#abcdef');
done();
});
});
it('should produce PNG badges', function(done) {
var child = cproc.spawn('node',
['gh-badge.js', 'cactus', 'grown', '.png']);
child.stdout.once('data', function(chunk) {
assert.ok(isPng(chunk));
done();
});
});
});
describe('The server', function () {
let server;
before('Start running the server', function () {
......@@ -103,7 +44,7 @@ describe('The server', function () {
});
context('with svg2img error', function () {
var expectedError = fs.readFileSync(path.resolve(__dirname, '..', 'public', '500.html'));
var expectedError = fs.readFileSync(path.resolve(__dirname, 'public', '500.html'));
var toBufferStub;
beforeEach(function () {
......
......@@ -20,7 +20,7 @@ const difference = require('lodash.difference');
const fetch = require('node-fetch');
const minimist = require('minimist');
const Runner = require('./runner');
const serverHelpers = require('../../test/in-process-server-helpers');
const serverHelpers = require('../../lib/in-process-server-test-helpers');
function getTitle (repoSlug, pullRequest) {
const uri = `https://api.github.com/repos/${repoSlug}/pulls/${pullRequest}`;
......
'use strict';
const frisby = require('icedfrisby-nock')(require('icedfrisby'));
const config = require('../../test/config');
const config = require('../../lib/test-config');
/**
* Encapsulate a suite of tests. Create new tests using create() and register
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment