Skip to content

Commit d5cb158

Browse files
committed
added .npmscriptrc.js support and argument handling to target a different entry in npm scripts object.
1 parent c2ae073 commit d5cb158

File tree

8 files changed

+171
-140
lines changed

8 files changed

+171
-140
lines changed

.npmscriptrc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,13 @@
1515
{
1616
"test":
1717
{
18-
// Provides a report handling command that is executed after running tests / coverage when running on Travis CI.
19-
"travis": { "report": "./node_modules/.bin/codecov" },
20-
2118
"istanbul": { "command": "cover", "options": ["--report lcovonly"] },
2219
"mocha": { "source": "./test-src/src", "options": ["-t 120000 --recursive"] }
20+
},
21+
22+
"test-dev":
23+
{
24+
"istanbul": { "command": "cover", "options": ["--report lcovonly"] },
25+
"mocha": { "source": "./test-src/src-dev", "options": ["-t 120000 --recursive"] }
2326
}
2427
}

package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
"fs-extra": "^2.0.0",
2727
"istanbul": "^1.1.0-alpha.1",
2828
"mocha": "^3.0.0",
29-
"snyk": "^1.0.0",
3029
"strip-json-comments": "^2.0.0"
3130
},
3231
"devDependencies": {
@@ -48,7 +47,12 @@
4847
},
4948
"scripts": {
5049
"eslint": "eslint .",
51-
"test": "node ./test-scripts/scripts/testAll.js"
50+
"test": "node ./test-scripts/scripts/testAll.js",
51+
"test-alternate-mocha": "node ./scripts/mocha.js test-dev",
52+
"test-error-mocha": "node ./scripts/mocha.js noentry",
53+
"test-mocha": "node ./scripts/mocha.js",
54+
"test-mocha-istanbul": "node ./scripts/mocha-istanbul.js",
55+
"test-mocha-istanbul-report": "node ./scripts/mocha-istanbul-report.js"
5256
},
5357
"files": [
5458
"scripts",

scripts/mocha-istanbul-report.js

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,15 @@ var cp = require('child_process');
3030
var fs = require('fs-extra');
3131
var stripJsonComments = require('strip-json-comments');
3232

33-
// Verify that `.npmscriptrc` exists.
34-
/* istanbul ignore next */
35-
try
36-
{
37-
if (!fs.statSync('./.npmscriptrc').isFile())
38-
{
39-
throw new Error("'.npmscriptrc' not found in root path: " + process.cwd());
40-
}
41-
}
42-
catch (err)
33+
var testEntry = 'test';
34+
35+
// Potentially set a new testEntry.
36+
if (typeof process.argv[2] === 'string')
4337
{
44-
throw new Error("TyphonJS NPM script (test-coverage) error: " + err);
38+
testEntry = process.argv[2];
39+
40+
console.log('!!!!!!!! process.argv: ' + JSON.stringify(process.argv));
41+
console.log('!!!!!!!! testEntry set to: ' + testEntry);
4542
}
4643

4744
// Verify that `Istanbul` exists.
@@ -72,18 +69,45 @@ catch (err)
7269
throw new Error("TyphonJS NPM script (test-coverage) error: " + err);
7370
}
7471

75-
// Load `.npmscriptrc` and strip comments.
76-
var configInfo = JSON.parse(stripJsonComments(fs.readFileSync('./.npmscriptrc', 'utf-8')));
72+
var configInfo;
73+
74+
// Attempt to require `.npmscriptrc.js`
75+
/* istanbul ignore next */
76+
try
77+
{
78+
if (fs.statSync('./.npmscriptrc.js').isFile())
79+
{
80+
configInfo = require('./.npmscriptrc.js');
81+
}
82+
}
83+
catch (err) { /* nop */ }
84+
85+
// Attempt to load `.npmscriptrc` and strip comments.
86+
/* istanbul ignore next */
87+
try
88+
{
89+
if (fs.statSync('./.npmscriptrc').isFile())
90+
{
91+
configInfo = JSON.parse(stripJsonComments(fs.readFileSync('./.npmscriptrc', 'utf-8')));
92+
}
93+
}
94+
catch (err) { /* nop */ }
95+
96+
// Exit now if no configInfo object has been loaded.
97+
if (typeof configInfo !== 'object')
98+
{
99+
throw new Error("TyphonJS NPM script (test-coverage) could not load `./npmscriptrc.js` or `./npmscriptrc`.");
100+
}
77101

78102
// Verify that mocha entry is an object.
79103
/* istanbul ignore if */
80-
if (typeof configInfo.test !== 'object')
104+
if (typeof configInfo[testEntry] !== 'object')
81105
{
82106
throw new Error(
83107
"TyphonJS NPM script (test-coverage) error: 'test' entry is not an object or is missing in '.npmscriptrc'.");
84108
}
85109

86-
var testConfig = configInfo.test;
110+
var testConfig = configInfo[testEntry];
87111

88112
/**
89113
* If running on Travis CI potentially copy any overrides from an internal `travis` key in `test` hash.

scripts/mocha-istanbul.js

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,12 @@ var cp = require('child_process');
2626
var fs = require('fs-extra');
2727
var stripJsonComments = require('strip-json-comments');
2828

29-
// Verify that `.npmscriptrc` exists.
30-
/* istanbul ignore next */
31-
try
32-
{
33-
if (!fs.statSync('./.npmscriptrc').isFile())
34-
{
35-
throw new Error("'.npmscriptrc' not found in root path: " + process.cwd());
36-
}
37-
}
38-
catch (err)
29+
var testEntry = 'test';
30+
31+
// Potentially set a new testEntry.
32+
if (typeof process.argv[2] === 'string')
3933
{
40-
throw new Error("TyphonJS NPM script (test-coverage) error: " + err);
34+
testEntry = process.argv[2];
4135
}
4236

4337
// Verify that `Istanbul` exists.
@@ -68,18 +62,45 @@ catch (err)
6862
throw new Error("TyphonJS NPM script (test-coverage) error: " + err);
6963
}
7064

71-
// Load `.npmscriptrc` and strip comments.
72-
var configInfo = JSON.parse(stripJsonComments(fs.readFileSync('./.npmscriptrc', 'utf-8')));
65+
var configInfo;
66+
67+
// Attempt to require `.npmscriptrc.js`
68+
/* istanbul ignore next */
69+
try
70+
{
71+
if (fs.statSync('./.npmscriptrc.js').isFile())
72+
{
73+
configInfo = require('./.npmscriptrc.js');
74+
}
75+
}
76+
catch (err) { /* nop */ }
77+
78+
// Attempt to load `.npmscriptrc` and strip comments.
79+
/* istanbul ignore next */
80+
try
81+
{
82+
if (fs.statSync('./.npmscriptrc').isFile())
83+
{
84+
configInfo = JSON.parse(stripJsonComments(fs.readFileSync('./.npmscriptrc', 'utf-8')));
85+
}
86+
}
87+
catch (err) { /* nop */ }
88+
89+
// Exit now if no configInfo object has been loaded.
90+
if (typeof configInfo !== 'object')
91+
{
92+
throw new Error("TyphonJS NPM script (test-coverage) could not load `./npmscriptrc.js` or `./npmscriptrc`.");
93+
}
7394

7495
// Verify that mocha entry is an object.
7596
/* istanbul ignore if */
76-
if (typeof configInfo.test !== 'object')
97+
if (typeof configInfo[testEntry] !== 'object')
7798
{
7899
throw new Error(
79100
"TyphonJS NPM script (test-coverage) error: 'test' entry is not an object or is missing in '.npmscriptrc'.");
80101
}
81102

82-
var testConfig = configInfo.test;
103+
var testConfig = configInfo[testEntry];
83104

84105
/**
85106
* If running on Travis CI potentially copy any overrides from an internal `travis` key in `test` hash.

scripts/mocha.js

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,45 +15,68 @@ var cp = require('child_process');
1515
var fs = require('fs');
1616
var stripJsonComments = require('strip-json-comments');
1717

18-
// Verify that `.npmscriptrc` exists.
18+
var testEntry = 'test';
19+
20+
// Potentially set a new testEntry.
21+
if (typeof process.argv[2] === 'string')
22+
{
23+
testEntry = process.argv[2];
24+
25+
26+
}
27+
28+
// Verify that `Mocha` exists.
1929
/* istanbul ignore next */
2030
try
2131
{
22-
if (!fs.statSync('./.npmscriptrc').isFile())
32+
if (!fs.statSync('./node_modules/.bin/mocha').isFile())
2333
{
24-
throw new Error("'.npmscriptrc' not found in root path.");
34+
throw new Error("could not locate Mocha at './node_modules/.bin/mocha'.");
2535
}
2636
}
2737
catch (err)
2838
{
2939
throw new Error("TyphonJS NPM script (test) error: " + err);
3040
}
3141

32-
// Verify that `Mocha` exists.
42+
var configInfo;
43+
44+
// Attempt to require `.npmscriptrc.js`
3345
/* istanbul ignore next */
3446
try
3547
{
36-
if (!fs.statSync('./node_modules/.bin/mocha').isFile())
48+
if (fs.statSync('./.npmscriptrc.js').isFile())
3749
{
38-
throw new Error("could not locate Mocha at './node_modules/.bin/mocha'.");
50+
configInfo = require('./.npmscriptrc.js');
3951
}
4052
}
41-
catch (err)
53+
catch (err) { /* nop */ }
54+
55+
// Attempt to load `.npmscriptrc` and strip comments.
56+
/* istanbul ignore next */
57+
try
4258
{
43-
throw new Error("TyphonJS NPM script (test) error: " + err);
59+
if (fs.statSync('./.npmscriptrc').isFile())
60+
{
61+
configInfo = JSON.parse(stripJsonComments(fs.readFileSync('./.npmscriptrc', 'utf-8')));
62+
}
4463
}
64+
catch (err) { /* nop */ }
4565

46-
// Load `.npmscriptrc` and strip comments.
47-
var configInfo = JSON.parse(stripJsonComments(fs.readFileSync('./.npmscriptrc', 'utf-8')));
66+
// Exit now if no configInfo object has been loaded.
67+
if (typeof configInfo !== 'object')
68+
{
69+
throw new Error("TyphonJS NPM script (test-coverage) could not load `./npmscriptrc.js` or `./npmscriptrc`.");
70+
}
4871

4972
// Verify that mocha entry is an object.
50-
if (typeof configInfo.test !== 'object')
73+
if (typeof configInfo[testEntry] !== 'object')
5174
{
5275
throw new Error(
5376
"TyphonJS NPM script (test) error: 'test' entry is not an object or is missing in '.npmscriptrc'.");
5477
}
5578

56-
var testConfig = configInfo.test;
79+
var testConfig = configInfo[testEntry];
5780

5881
// Verify that mocha entry is an object.
5982
/* istanbul ignore if */

test-scripts/mocha/TestScriptsRunner.js

Lines changed: 0 additions & 74 deletions
This file was deleted.

0 commit comments

Comments
 (0)