Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Determine code coverage during the first test run
- Loading branch information
1 parent
d274515
commit fe2d4c2
Showing
9 changed files
with
116 additions
and
58 deletions.
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
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 was deleted.
Oops, something went wrong.
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,49 @@ | ||
#!/bin/sh | ||
# Runs tests and collects code coverage to ./cov.info file | ||
|
||
|
||
PROJECT_DIR=$(pwd -P) | ||
|
||
COVERAGE_FILE="$PROJECT_DIR"/cov.info | ||
COVERAGE_DIR="$PROJECT_DIR"/lcov | ||
INSTRUMENTED_CODE_DIR="$PROJECT_DIR"/src-cov | ||
BIN_DIR="$PROJECT_DIR"/node_modules/.bin | ||
|
||
|
||
# Cleanup & preparation | ||
rm -rf "$INSTRUMENTED_CODE_DIR" "$COVERAGE_DIR" "$COVERAGE_FILE" | ||
mkdir "$INSTRUMENTED_CODE_DIR" "$COVERAGE_DIR" | ||
|
||
|
||
# Creating directory with instrumented JS code | ||
"$BIN_DIR"/coffeeCoverage \ | ||
--exclude=node_modules,.git,test,scripts \ | ||
--path=relative \ | ||
"$PROJECT_DIR" "$INSTRUMENTED_CODE_DIR" 1>&2 | ||
|
||
cp "$PROJECT_DIR"/package.json "$INSTRUMENTED_CODE_DIR" | ||
|
||
cp -r "$PROJECT_DIR"/bin "$INSTRUMENTED_CODE_DIR"/bin | ||
chmod +x "$INSTRUMENTED_CODE_DIR"/bin/* | ||
|
||
cp -r "$PROJECT_DIR"/scripts "$INSTRUMENTED_CODE_DIR"/scripts | ||
cp -r "$PROJECT_DIR"/docs "$INSTRUMENTED_CODE_DIR"/docs | ||
cp -r "$PROJECT_DIR"/test "$INSTRUMENTED_CODE_DIR"/test | ||
|
||
mkdir -p "$INSTRUMENTED_CODE_DIR"/node_modules/.bin | ||
ln -s "$BIN_DIR"/* "$INSTRUMENTED_CODE_DIR"/node_modules/.bin | ||
|
||
|
||
# Testing | ||
export COVERAGE_DIR | ||
cd "$INSTRUMENTED_CODE_DIR" && npm test | ||
cd .. | ||
|
||
|
||
# Merging LCOV reports | ||
"$BIN_DIR"/lcov-result-merger "$COVERAGE_DIR/*.info" "$COVERAGE_FILE" | ||
echo "Coverage saved as '$COVERAGE_FILE'" | ||
|
||
|
||
# Output & cleanup | ||
rm -rf "$INSTRUMENTED_CODE_DIR" "$COVERAGE_DIR" |
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,14 @@ | ||
#!/bin/sh | ||
# Picks up the ./cov.info file and sends the coverage to coveralls.io | ||
|
||
|
||
# Input validation | ||
if [ ! -f ./cov.info ]; then | ||
(>&2 echo "Coverage file 'cov.info' was not found.") | ||
(>&2 echo "First run the test suite as 'npm run test:coverage'.") | ||
exit 1 | ||
fi | ||
|
||
|
||
# Coveralls | ||
cat ./cov.info | ./node_modules/.bin/coveralls |
File renamed without changes.
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
--compilers=coffee:coffee-script/register | ||
--reporter=spec | ||
--reporter=test/reporter.js | ||
--timeout=120000 | ||
--recursive |
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,30 @@ | ||
fs = require('fs'); | ||
path = require('path'); | ||
|
||
Spec = require('mocha').reporters.Spec; | ||
LCov = require('mocha-lcov-reporter'); | ||
|
||
|
||
/** | ||
* Combined reporter | ||
* | ||
* Behaves the same way as Mocha's built-in 'Spec' reporter, but if | ||
* the environment variable 'COVERAGE_DIR' is set to a directory, | ||
* collects code coverage to './lcov/mocha.info' file. | ||
* | ||
* If you want to learn more about how coverage collecting works | ||
* in Dredd's test suite, see the 'npm run test:coverage' script. | ||
*/ | ||
module.exports = function (runner, options) { | ||
new Spec(runner, options); | ||
|
||
if (process.env.COVERAGE_DIR) { | ||
// Monkey-patching the 'LCov.prototype.write' so we could save | ||
// the LCov output to a file instead of a standard output | ||
LCov.prototype.write = function (string) { | ||
var file = path.join(process.env.COVERAGE_DIR, 'mocha.info'); | ||
fs.appendFileSync(file, string); | ||
} | ||
new LCov(runner, options); | ||
} | ||
}; |