Permalink
Please sign in to comment.
Showing
with
194 additions
and 48 deletions.
- +1 −2 .travis.yml
- +8 −1 package.json
- +0 −1 seed/challenges/advanced-bonfires.json
- +30 −5 seed/challenges/angularjs.json
- +2 −6 seed/challenges/basic-bonfires.json
- +21 −22 seed/challenges/intermediate-bonfires.json
- +19 −0 seed/getChallenges.js
- +5 −11 seed/index.js
- +108 −0 seed/test-challenges.js
3
.travis.yml
| @@ -1,7 +1,6 @@ | ||
| language: node_js | ||
| node_js: | ||
| - - 'node' | ||
| - - '1.6.4' | ||
| + - '4.2.1' | ||
| sudo: false |
9
package.json
1
seed/challenges/advanced-bonfires.json
35
seed/challenges/angularjs.json
8
seed/challenges/basic-bonfires.json
43
seed/challenges/intermediate-bonfires.json
19
seed/getChallenges.js
| @@ -0,0 +1,19 @@ | ||
| +var fs = require('fs'); | ||
| +var path = require('path'); | ||
| + | ||
| + | ||
| +function getFilesFor(dir) { | ||
| + return fs.readdirSync(path.join(__dirname, '/' + dir)); | ||
| +} | ||
| + | ||
| +module.exports = function getChallenges() { | ||
| + try { | ||
| + return getFilesFor('challenges') | ||
| + .map(function(file) { | ||
| + return require('./challenges/' + file); | ||
| + }); | ||
| + } catch (e) { | ||
| + console.log('error', e); | ||
| + return []; | ||
| + } | ||
| +}; |
16
seed/index.js
108
seed/test-challenges.js
| @@ -0,0 +1,108 @@ | ||
| +/* eslint-disable no-eval, no-process-exit */ | ||
| +import _ from 'lodash'; | ||
| +import { Observable } from 'rx'; | ||
| +import tape from 'tape'; | ||
| +import getChallenges from './getChallenges'; | ||
| + | ||
| + | ||
| +function createIsAssert(t, isThing) { | ||
| + const { assert } = t; | ||
| + return function() { | ||
| + const args = [...arguments]; | ||
| + args[0] = isThing(args[0]); | ||
| + assert.apply(t, args); | ||
| + }; | ||
| +} | ||
| + | ||
| +function fillAssert(t) { | ||
| + const assert = t.assert; | ||
| + | ||
| + assert.isArray = createIsAssert(t, _.isArray); | ||
| + assert.isBoolean = createIsAssert(t, _.isBoolean); | ||
| + assert.isString = createIsAssert(t, _.isString); | ||
| + assert.isNumber = createIsAssert(t, _.isNumber); | ||
| + assert.isUndefined = createIsAssert(t, _.isUndefined); | ||
| + | ||
| + assert.deepEqual = t.deepEqual; | ||
| + assert.equal = t.equal; | ||
| + assert.strictEqual = t.equal; | ||
| + | ||
| + assert.sameMembers = function sameMembers() { | ||
| + const [ first, second, ...args] = arguments; | ||
| + assert.apply( | ||
| + t, | ||
| + [ | ||
| + _.difference(first, second).length === 0 && | ||
| + _.difference(second, first).length === 0 | ||
| + ].concat(args) | ||
| + ); | ||
| + }; | ||
| + | ||
| + assert.includeMembers = function includeMembers() { | ||
| + const [ first, second, ...args] = arguments; | ||
| + assert.apply(t, [_.difference(second, first).length === 0].concat(args)); | ||
| + }; | ||
| + | ||
| + assert.match = function match() { | ||
| + const [value, regex, ...args] = arguments; | ||
| + assert.apply(t, [regex.test(value)].concat(args)); | ||
| + }; | ||
| + | ||
| + return assert; | ||
| +} | ||
| + | ||
| +function createTest({ title, tests = [], solutions = [] }) { | ||
| + const plan = tests.length; | ||
| + return Observable.fromCallback(tape)(title) | ||
| + .doOnNext(t => solutions.length ? t.plan(plan) : t.end()) | ||
| + .flatMap(t => { | ||
| + if (solutions.length <= 0) { | ||
| + t.comment('No solutions for ' + title); | ||
| + return Observable.just({ | ||
| + title, | ||
| + type: 'missing' | ||
| + }); | ||
| + } | ||
| + | ||
| + return Observable.just(t) | ||
| + .map(fillAssert) | ||
| + /* eslint-disable no-unused-vars */ | ||
| + // assert is used within the eval | ||
| + .doOnNext(assert => { | ||
| + /* eslint-enable no-unused-vars */ | ||
| + solutions.forEach(solution => { | ||
| + tests.forEach(test => { | ||
| + eval(solution + ';;' + test); | ||
| + }); | ||
| + }); | ||
| + }) | ||
| + .map(() => ({ title })); | ||
| + }); | ||
| +} | ||
| + | ||
| +Observable.from(getChallenges()) | ||
| + .flatMap(challengeSpec => { | ||
| + return Observable.from(challengeSpec.challenges); | ||
| + }) | ||
| + .flatMap(challenge => { | ||
| + return createTest(challenge); | ||
| + }) | ||
| + .map(({ title, type }) => { | ||
| + if (type === 'missing') { | ||
| + return title; | ||
| + } | ||
| + return false; | ||
| + }) | ||
| + .filter(title => !!title) | ||
| + .toArray() | ||
| + .subscribe( | ||
| + (noSolutions) => { | ||
| + console.log( | ||
| + '# These challenges have no solutions\n- [ ] ' + | ||
| + noSolutions.join('\n- [ ] ') | ||
| + ); | ||
| + }, | ||
| + err => { throw err; }, | ||
| + () => process.exit(0) | ||
| + ); | ||
| + |
0 comments on commit
921080f