forked from eslint/doctrine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile.js
87 lines (66 loc) · 2.3 KB
/
Makefile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/**
* @fileoverview Build file
* @author nzakas
*/
/* global exec, exit, find, target*/
"use strict";
//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------
require("shelljs/make");
var nodeCLI = require("shelljs-nodecli");
//------------------------------------------------------------------------------
// Data
//------------------------------------------------------------------------------
var NODE_MODULES = "./node_modules/",
// Utilities - intentional extra space at the end of each string
MOCHA = NODE_MODULES + "mocha/bin/_mocha ",
// Files
/* eslint-disable no-use-before-define */
TEST_FILES = find("test/").filter(fileType("js")).join(" "),
/* eslint-enable no-use-before-define */
// Settings
MOCHA_TIMEOUT = 4000;
//------------------------------------------------------------------------------
// Helpers
//------------------------------------------------------------------------------
/**
* Generates a function that matches files with a particular extension.
* @param {string} extension The file extension (i.e. "js")
* @returns {Function} The function to pass into a filter method.
* @private
*/
function fileType(extension) {
return function(filename) {
return filename.substring(filename.lastIndexOf(".") + 1) === extension;
};
}
/**
* Splits a command result to separate lines.
* @param {string} result The command result string.
* @returns {array} The separated lines.
*/
function splitCommandResultToLines(result) {
return result.trim().split("\n");
}
//------------------------------------------------------------------------------
// Tasks
//------------------------------------------------------------------------------
target.all = function() {
target.test();
};
target.test = function() {
var errors = 0,
lastReturn;
lastReturn = nodeCLI.exec("istanbul", "cover", MOCHA, "-- -R dot -t " + MOCHA_TIMEOUT, "-c", TEST_FILES);
if (lastReturn.code !== 0) {
errors++;
}
lastReturn = nodeCLI.exec("istanbul", "check-coverage", "--statement 99 --branch 97 --function 100 --lines 99");
if (lastReturn.code !== 0) {
errors++;
}
if (errors) {
exit(1);
}
};