-
Notifications
You must be signed in to change notification settings - Fork 791
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #363 from danjm/tests-option-tap-spec
Add tap-spec option to npm test commands for mocha style reporting
- Loading branch information
Showing
3 changed files
with
57 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,8 @@ | |
"test": "node ./tests/tester -a", | ||
"lint": "standard", | ||
"prepublishOnly": "npm run lint && npm run build:dist && npm run testBuildIntegrity", | ||
"build:dist": "babel lib/ -d dist/" | ||
"build:dist": "babel lib/ -d dist/", | ||
"formatTest": "node ./scripts/formatTest" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
|
@@ -60,6 +61,7 @@ | |
"minimist": "^1.1.1", | ||
"nyc": "^12.0.2", | ||
"standard": "^10.0.0", | ||
"tap-spec": "^5.0.0", | ||
"tape": "4.6.3" | ||
}, | ||
"author": "mjbecze <[email protected]>", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
const { spawn } = require('child_process') | ||
const fs = require('fs') | ||
const path = require('path') | ||
|
||
const testScript = process.argv.find((arg, i, array) => array[i - 1] === '-t') | ||
const formatter = process.argv.find((arg, i, array) => array[i - 1] === '-with') | ||
|
||
runTestsWithFormatter(testScript, formatter) | ||
|
||
function runTestsWithFormatter (testScript, formatter = './node_modules/.bin/tap-spec') { | ||
if (!testScript) { | ||
console.log('No test script specified!') | ||
return | ||
} | ||
|
||
const packageJson = fs.readFileSync(path.dirname(__dirname) + '/package.json', 'utf8') | ||
const parsedPackageJson = JSON.parse(packageJson) | ||
const npmTestScriptNames = Object.keys(parsedPackageJson.scripts) | ||
|
||
const commandToRun = npmTestScriptNames.find(name => name === testScript) | ||
? `npm run ${testScript}` | ||
: `node ${testScript}` | ||
|
||
const child = spawn('sh', ['-c', `${commandToRun} | ${formatter}`]) | ||
|
||
child.stdout.on('data', (data) => { | ||
process.stdout.write(data) | ||
}) | ||
|
||
child.stderr.on('data', (data) => { | ||
process.stdout.write(data) | ||
}) | ||
|
||
child.on('exit', (data) => { | ||
process.stdout.write('Done') | ||
}) | ||
} |