From d34bcb9d26c0da19373c920e1b2ce1a85dd9fcd0 Mon Sep 17 00:00:00 2001 From: officiallyanee Date: Thu, 6 Aug 2026 22:26:33 +0530 Subject: [PATCH 1/5] build: add recipes for using c8 for tools-test-cov --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown_pkg_readmes status: na - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- tools/make/lib/tools-test-cov/c8.mk | 108 ++++++++++++++++++++ tools/make/lib/tools-test-cov/javascript.mk | 6 ++ 2 files changed, 114 insertions(+) create mode 100644 tools/make/lib/tools-test-cov/c8.mk diff --git a/tools/make/lib/tools-test-cov/c8.mk b/tools/make/lib/tools-test-cov/c8.mk new file mode 100644 index 000000000000..660e5b0ba33b --- /dev/null +++ b/tools/make/lib/tools-test-cov/c8.mk @@ -0,0 +1,108 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2026 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#/ + +# VARIABLES # + +# Define the path to the C8 executable. +# +# ## Notes +# +# - To install c8: +# +# ```bash +# $ npm install c8 +# ``` +# +# [1]: https://github.com/bcoe/c8 +C8 ?= $(BIN_DIR)/c8 + +# Define the output file path for the HTML report generated by c8: +C8_HTML_REPORT ?= $(COVERAGE_DIR)/lcov-report/index.html + +# Define which files and directories to exclude from coverage instrumentation: +C8_EXCLUDES_FLAGS = \ + --exclude-node-modules=false \ + -x 'node_modules/**' \ + -x 'reports/**' \ + -x 'tmp/**' \ + -x 'deps/**' \ + -x 'dist/**' \ + -x "**/$(SRC_FOLDER)/**" \ + -x "**/$(TESTS_FOLDER)/**" \ + -x "**/$(EXAMPLES_FOLDER)/**" \ + -x "**/$(BENCHMARKS_FOLDER)/**" \ + -x "**/$(CONFIG_FOLDER)/**" \ + -x "**/$(DOCUMENTATION_FOLDER)/**" + +# Define user-supplied command-line options: +C8_FLAGS ?= + +# Define command-line options when generating coverage data: +c8_flags = \ + $(C8_EXCLUDES_FLAGS) \ + --clean=false \ + --temp-directory $(COVERAGE_DIR)/tmp \ + --report-dir $(COVERAGE_DIR) \ + --reporter lcov + +# Append user-supplied command-line options: +c8_flags += $(C8_FLAGS) + +# RULES # + +#/ +# Runs unit tests for project tools and generates a test coverage report using c8. +# +# ## Notes +# +# - Raw TAP output is piped to a TAP reporter. +# - This command is useful when wanting to glob for JavaScript test files (e.g., generate a test coverage report for all JavaScript tests for a particular package). +# +# +# @private +# @param {string} [TESTS_FILTER] - file path pattern +# @param {*} [FAIL_FAST] - flag indicating whether to stop running tests upon encountering a test failure +# +# @example +# make tools-test-c8 +# +# @example +# make tools-test-c8 TESTS_FILTER=".*/doctest/compare-values/.*" +#/ +tools-test-c8: $(NODE_MODULES) +ifeq ($(FAIL_FAST), true) + $(QUIET) $(FIND_TOOLS_TESTS_CMD) | grep '^[\/]\|^[a-zA-Z]:[/\]' | while read -r test; do \ + echo ''; \ + echo "Running test: $$test"; \ + NODE_ENV="$(NODE_ENV_TEST)" \ + NODE_PATH="$(NODE_PATH_TEST)" \ + TEST_MODE=coverage \ + $(C8) $(c8_flags) $(NODE) $$test | $(TAP_REPORTER) || exit 1; \ + done +else + $(QUIET) $(FIND_TOOLS_TESTS_CMD) | grep '^[\/]\|^[a-zA-Z]:[/\]' | while read -r test; do \ + echo ''; \ + echo "Running test: $$test"; \ + NODE_ENV="$(NODE_ENV_TEST)" \ + NODE_PATH="$(NODE_PATH_TEST)" \ + TEST_MODE=coverage \ + $(C8) $(c8_flags) $(NODE) $$test | $(TAP_REPORTER) || echo 'Tests failed.'; \ + done +endif + +.PHONY: tools-test-c8 diff --git a/tools/make/lib/tools-test-cov/javascript.mk b/tools/make/lib/tools-test-cov/javascript.mk index d9f35615c855..cad285454bc6 100644 --- a/tools/make/lib/tools-test-cov/javascript.mk +++ b/tools/make/lib/tools-test-cov/javascript.mk @@ -21,6 +21,9 @@ ifeq ($(JAVASCRIPT_CODE_INSTRUMENTER), istanbul) include $(TOOLS_MAKE_LIB_DIR)/tools-test-cov/istanbul.mk endif +ifeq ($(JAVASCRIPT_CODE_INSTRUMENTER), c8) + include $(TOOLS_MAKE_LIB_DIR)/tools-test-cov/c8.mk +endif # TARGETS # @@ -33,5 +36,8 @@ tools-test-javascript-cov: ifeq ($(JAVASCRIPT_CODE_INSTRUMENTER), istanbul) $(QUIET) NODE_ENV_TEST="$(NODE_ENV_TEST)" NODE_PATH_TEST="$(NODE_PATH_TEST)" NODE_FLAGS_TEST="$(NODE_FLAGS_TEST)" $(MAKE) -f $(this_file) tools-test-istanbul endif +ifeq ($(JAVASCRIPT_CODE_INSTRUMENTER), c8) + $(QUIET) NODE_ENV_TEST="$(NODE_ENV_TEST)" NODE_PATH_TEST="$(NODE_PATH_TEST)" NODE_FLAGS_TEST="$(NODE_FLAGS_TEST)" $(MAKE) -f $(this_file) tools-test-c8 +endif .PHONY: tools-test-javascript-cov From ab103daa6716e58f5bd771bd2be1ccaac18657ec Mon Sep 17 00:00:00 2001 From: Athan Date: Fri, 7 Aug 2026 02:51:25 -0700 Subject: [PATCH 2/5] Apply suggestions from code review Co-authored-by: Athan Signed-off-by: Athan --- tools/make/lib/tools-test-cov/c8.mk | 47 ----------------------------- 1 file changed, 47 deletions(-) diff --git a/tools/make/lib/tools-test-cov/c8.mk b/tools/make/lib/tools-test-cov/c8.mk index 660e5b0ba33b..259c7006c772 100644 --- a/tools/make/lib/tools-test-cov/c8.mk +++ b/tools/make/lib/tools-test-cov/c8.mk @@ -16,53 +16,6 @@ # limitations under the License. #/ -# VARIABLES # - -# Define the path to the C8 executable. -# -# ## Notes -# -# - To install c8: -# -# ```bash -# $ npm install c8 -# ``` -# -# [1]: https://github.com/bcoe/c8 -C8 ?= $(BIN_DIR)/c8 - -# Define the output file path for the HTML report generated by c8: -C8_HTML_REPORT ?= $(COVERAGE_DIR)/lcov-report/index.html - -# Define which files and directories to exclude from coverage instrumentation: -C8_EXCLUDES_FLAGS = \ - --exclude-node-modules=false \ - -x 'node_modules/**' \ - -x 'reports/**' \ - -x 'tmp/**' \ - -x 'deps/**' \ - -x 'dist/**' \ - -x "**/$(SRC_FOLDER)/**" \ - -x "**/$(TESTS_FOLDER)/**" \ - -x "**/$(EXAMPLES_FOLDER)/**" \ - -x "**/$(BENCHMARKS_FOLDER)/**" \ - -x "**/$(CONFIG_FOLDER)/**" \ - -x "**/$(DOCUMENTATION_FOLDER)/**" - -# Define user-supplied command-line options: -C8_FLAGS ?= - -# Define command-line options when generating coverage data: -c8_flags = \ - $(C8_EXCLUDES_FLAGS) \ - --clean=false \ - --temp-directory $(COVERAGE_DIR)/tmp \ - --report-dir $(COVERAGE_DIR) \ - --reporter lcov - -# Append user-supplied command-line options: -c8_flags += $(C8_FLAGS) - # RULES # #/ From 7315513ae043b18fd6093bdfb7239a0a54991f8f Mon Sep 17 00:00:00 2001 From: Athan Date: Fri, 7 Aug 2026 02:55:07 -0700 Subject: [PATCH 3/5] chore: update docs and fix conditionals Signed-off-by: Athan --- tools/make/lib/tools-test-cov/javascript.mk | 25 ++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/tools/make/lib/tools-test-cov/javascript.mk b/tools/make/lib/tools-test-cov/javascript.mk index cad285454bc6..75ce1ee696af 100644 --- a/tools/make/lib/tools-test-cov/javascript.mk +++ b/tools/make/lib/tools-test-cov/javascript.mk @@ -26,18 +26,33 @@ ifeq ($(JAVASCRIPT_CODE_INSTRUMENTER), c8) endif -# TARGETS # +# RULES # -# Run unit tests and generate a test coverage report. +#/ +# Runs JavaScript tool unit tests and generates a test coverage report. # -# This target instruments JavaScript source code, runs unit tests, and outputs a test coverage report. - +# ## Notes +# +# - Raw TAP output is piped to a TAP reporter. +# - This command is useful when wanting to glob for JavaScript test files (e.g., generate a test coverage report for all JavaScript tests for a particular package). +# +# @param {string} [TESTS_FILTER] - file path pattern (e.g., `.*/doctest/compare-values/.*`) +# @param {string} [JAVASCRIPT_CODE_INSTRUMENTER] - JavaScript code instrumenter +# @param {*} [FAST_FAIL] - flag indicating whether to stop running tests upon encountering a test failure +# +# @example +# make tools-test-javascript-cov +# +# @example +# make tools-test-javascript-cov TESTS_FILTER=".*/doctest/compare-values/.*" +#/ tools-test-javascript-cov: ifeq ($(JAVASCRIPT_CODE_INSTRUMENTER), istanbul) $(QUIET) NODE_ENV_TEST="$(NODE_ENV_TEST)" NODE_PATH_TEST="$(NODE_PATH_TEST)" NODE_FLAGS_TEST="$(NODE_FLAGS_TEST)" $(MAKE) -f $(this_file) tools-test-istanbul -endif +else ifeq ($(JAVASCRIPT_CODE_INSTRUMENTER), c8) $(QUIET) NODE_ENV_TEST="$(NODE_ENV_TEST)" NODE_PATH_TEST="$(NODE_PATH_TEST)" NODE_FLAGS_TEST="$(NODE_FLAGS_TEST)" $(MAKE) -f $(this_file) tools-test-c8 endif +endif .PHONY: tools-test-javascript-cov From ca008f701d403c4e6afec8e1b4b2738067d96d9d Mon Sep 17 00:00:00 2001 From: Athan Date: Fri, 7 Aug 2026 02:55:47 -0700 Subject: [PATCH 4/5] Apply suggestions from code review Co-authored-by: Athan Signed-off-by: Athan --- tools/make/lib/tools-test-cov/javascript.mk | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/make/lib/tools-test-cov/javascript.mk b/tools/make/lib/tools-test-cov/javascript.mk index 75ce1ee696af..ccff65d7e2b3 100644 --- a/tools/make/lib/tools-test-cov/javascript.mk +++ b/tools/make/lib/tools-test-cov/javascript.mk @@ -20,10 +20,11 @@ ifeq ($(JAVASCRIPT_CODE_INSTRUMENTER), istanbul) include $(TOOLS_MAKE_LIB_DIR)/tools-test-cov/istanbul.mk -endif +else ifeq ($(JAVASCRIPT_CODE_INSTRUMENTER), c8) include $(TOOLS_MAKE_LIB_DIR)/tools-test-cov/c8.mk endif +endif # RULES # From 1df3a1fdc8fe9cd7e5f6911b89205d9cb9297ee5 Mon Sep 17 00:00:00 2001 From: Athan Date: Fri, 7 Aug 2026 02:56:27 -0700 Subject: [PATCH 5/5] Apply suggestions from code review Co-authored-by: Athan Signed-off-by: Athan --- tools/make/lib/tools-test-cov/javascript.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/make/lib/tools-test-cov/javascript.mk b/tools/make/lib/tools-test-cov/javascript.mk index ccff65d7e2b3..73f2c72adb9a 100644 --- a/tools/make/lib/tools-test-cov/javascript.mk +++ b/tools/make/lib/tools-test-cov/javascript.mk @@ -30,7 +30,7 @@ endif # RULES # #/ -# Runs JavaScript tool unit tests and generates a test coverage report. +# Runs JavaScript unit tests for project tools and generates a test coverage report. # # ## Notes #