UNPKG

1.52 kBPlain TextView Raw
1#! /usr/bin/env node
2
3'use strict';
4
5var async = require('async');
6var spawn = require('child_process').spawn;
7var fs = require('fs');
8var path = require('path');
9
10var base = process.cwd();
11var dirs = fs.readdirSync(base);
12
13var tasks = [];
14dirs.forEach(function(dir) {
15 var fulldir = path.join(base, dir);
16
17 // a plugin contains package.json in root
18 var pkg = path.join(fulldir, 'package.json');
19 if (!fs.existsSync(pkg)) return;
20 var pstat = fs.statSync(pkg);
21 if (!pstat.isFile()) return;
22
23 // a plugin contains index.js in root
24 var index = path.join(fulldir, 'index.js');
25 if (!fs.existsSync(index)) return;
26 var istat = fs.statSync(index);
27 if (!istat.isFile()) return;
28
29 // skip plugins without tests
30 var test = path.join(fulldir, 'test');
31 if (!fs.existsSync(test)) return;
32 var tstat = fs.statSync(test);
33 if (!tstat.isDirectory()) return;
34
35 tasks.push(function(cb) {
36 console.log('\nrunning "mocha" in', fulldir, '...');
37 var cmd = process.platform === 'win32' ? 'cmd' : 'mocha';
38 var args = process.platform === 'win32' ? ['/c', 'mocha'] : [];
39 args.push(path.join(dir, 'test', '**.test.js'));
40 var child = spawn(cmd, args, {
41 stdio: 'inherit'
42 });
43 child.on('close', function(code) {
44 console.error(' ->', code === 0 ? 'OK' : 'failed: ' + code);
45 cb(code);
46 });
47 });
48});
49
50async.series(tasks, function(err, results) {
51 if (err) {
52 console.error('tests failed: ', err);
53 } else {
54 console.error('tests OK');
55 }
56 process.exit(err ? 1 : 0);
57});