11
22# VARIABLES #
33
4+ # Define the command to recursively sync directories:
5+ RSYNC_RECURSIVE ?= rsync -r
6+
7+ # Define the command to recursively create directories:
8+ MKDIR_RECURSIVE ?= mkdir -p
9+
10+ # Define the command for removing files and directories:
11+ DELETE ?= -rm
12+ DELETE_FLAGS ?= -rf
13+
414# Determine the host kernel:
515KERNEL ?= $(shell uname -s)
616
1222endif
1323# TODO: add Windows command
1424
15- # Define the path to the Istanbul executable:
16- JAVASCRIPT_TEST_COV ?= $(BIN_DIR ) /istanbul cover
25+ # Define the path to the Istanbul executable.
26+ #
27+ # To install Istanbul:
28+ # $ npm install istanbul
29+ #
30+ # [1]: https://github.com/gotwarlost/istanbul
31+
32+ ISTANBUL ?= $(BIN_DIR ) /istanbul
33+
34+ # Define which files and directories to exclude from coverage instrumentation:
35+ ISTANBUL_EXCLUDES_FLAGS ?= \
36+ --no-default-excludes \
37+ -x 'node_modules/**' \
38+ -x 'reports/**' \
39+ -x 'tmp/**' \
40+ -x '**/$(TESTS_FOLDER ) /**' \
41+ -x '**/$(EXAMPLES_FOLDER ) /**' \
42+ -x '**/$(BENCHMARKS_FOLDER ) /**' \
43+ -x '**/$(CONFIG_FOLDER ) /**' \
44+ -x '**/$(DOCUMENTATION_FOLDER ) /**'
45+
46+ # Define which files and directories to exclude when syncing the instrumented source code directory:
47+ ISTANBUL_RSYNC_EXCLUDES_FLAGS ?= \
48+ --ignore-existing \
49+ --exclude '$(EXAMPLES_FOLDER ) /' \
50+ --exclude '$(BENCHMARKS_FOLDER ) /' \
51+ --exclude '$(DOCUMENTATION_FOLDER ) /'
52+
53+ # Define the command to instrument source code for code coverage:
54+ ISTANBUL_INSTRUMENT ?= $(ISTANBUL ) instrument
55+
56+ # Define the output directory for instrumented source code:
57+ ISTANBUL_INSTRUMENT_OUT ?= $(COVERAGE_INSTRUMENTATION_DIR ) /node_modules
58+
59+ # Define the command-line options to be used when instrumenting source code:
60+ ISTANBUL_INSTRUMENT_FLAGS ?= \
61+ $(ISTANBUL_EXCLUDES_FLAGS ) \
62+ --output $(ISTANBUL_INSTRUMENT_OUT )
63+
64+ # Define the command to generate test coverage:
65+ ISTANBUL_COVER ?= $(ISTANBUL ) cover
1766
1867# Define the type of report Istanbul should produce:
1968ISTANBUL_REPORT ?= lcov
2069
2170# Define the output file path for the HTML report generated by Istanbul:
2271ISTANBUL_HTML_REPORT ?= $(COVERAGE_DIR ) /lcov-report/index.html
2372
24- # Define the command-line options to be used when invoking the Istanbul executable:
25- JAVASCRIPT_TEST_COV_FLAGS ?= --no-default-excludes \
26- -x 'node_modules/**' \
27- -x 'build/**' \
28- -x '**/test/**' \
29- -x '**/tests/**' \
30- -x 'reports/**' \
31- --dir $(COVERAGE_DIR ) \
32- --report $(ISTANBUL_REPORT )
73+ # Define the command-line options to be used when generating code coverage:
74+ ISTANBUL_COVER_FLAGS ?= \
75+ $(ISTANBUL_EXCLUDES_FLAGS ) \
76+ --dir $(COVERAGE_DIR ) \
77+ --report $(ISTANBUL_REPORT )
3378
3479
3580# TARGETS #
3681
37- # Run units and generate a test coverage report.
38- #
39- # This target instruments source code using [Istanbul][1], runs unit tests, and outputs a test coverage report.
82+ # Instruments source code.
4083#
41- # To install Istanbul:
42- # $ npm install istanbul
84+ # This target instruments source code.
85+
86+ test-istanbul-instrument : $(NODE_MODULES ) clean-istanbul-instrument
87+ $(MKDIR_RECURSIVE ) $(ISTANBUL_INSTRUMENT_OUT )
88+ $(ISTANBUL_INSTRUMENT ) $(ISTANBUL_INSTRUMENT_FLAGS ) $(NODE_PATH )
89+ $(RSYNC_RECURSIVE ) \
90+ $(ISTANBUL_RSYNC_EXCLUDES_FLAGS ) \
91+ $(NODE_PATH ) / \
92+ $(ISTANBUL_INSTRUMENT_OUT )
93+
94+ .PHONY : test-istanbul-instrument
95+
96+
97+ # Run units and generate a test coverage report.
4398#
44- # [1]: https://github.com/gotwarlost/istanbul
99+ # This target instruments source code, runs unit tests, and outputs a test coverage report.
45100
46101test-istanbul : $(NODE_MODULES )
47102 for dir in $( TESTS_DIRS) ; do \
@@ -50,7 +105,7 @@ test-istanbul: $(NODE_MODULES)
50105 echo ' ' ; \
51106 NODE_ENV=$(NODE_ENV_TEST ) \
52107 NODE_PATH=$(NODE_PATH_TEST ) \
53- $(JAVASCRIPT_TEST_COV ) $(JAVASCRIPT_TEST_COV_FLAGS ) $(JAVASCRIPT_TEST ) -- $(JAVASCRIPT_TEST_FLAGS ) $$ dir/** /$(TESTS_PATTERN ) ; \
108+ $(ISTANBUL_COVER ) $(ISTANBUL_COVER_FLAGS ) $(JAVASCRIPT_TEST ) -- $(JAVASCRIPT_TEST_FLAGS ) $$ dir/** /$(TESTS_PATTERN ) ; \
54109 done
55110
56111.PHONY : test-istanbul
@@ -64,3 +119,13 @@ view-istanbul-report:
64119 $(OPEN ) $(ISTANBUL_HTML_REPORT )
65120
66121.PHONY : view-istanbul-report
122+
123+
124+ # Removes instrumented files.
125+ #
126+ # This targets removes previously instrumented files by removing the instrumented source code directory entirely.
127+
128+ clean-istanbul-instrument :
129+ $(DELETE ) $(DELETE_FLAGS ) $(COVERAGE_INSTRUMENTATION_DIR )
130+
131+ .PHONY : clean-istanbul-instrument
0 commit comments