From a2e3345d236076ada487b488b64cc2802b262f63 Mon Sep 17 00:00:00 2001 From: Charles Phillips Date: Sat, 9 Jul 2016 18:44:49 -0700 Subject: [PATCH 1/2] [test] globs with leading forward slash should match relative to project root --- test/tests.coffee | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/test/tests.coffee b/test/tests.coffee index 56cdeb7..311c1f6 100644 --- a/test/tests.coffee +++ b/test/tests.coffee @@ -88,6 +88,23 @@ describe "Coverage tests", -> expect(global[COVERAGE_VAR][pn 'a/foo.coffee'], "Should instrument a/foo.coffee").to.exist expect(global[COVERAGE_VAR][pn 'b/bar.coffee'], "Should not instrument b/bar.coffee").to.not.exist + it "should exclude files based on globs with leading forward slash from project root when dynamically instrumenting code", -> + + coffeeCoverage.register( + path: "relative" + basePath: path.resolve __dirname, '../testFixtures/testWithExcludes' + exclude: ["/b/*r.coffee"] + coverageVar: COVERAGE_VAR + log: log + ) + + require '../testFixtures/testWithExcludes/a/foo.coffee' + require '../testFixtures/testWithExcludes/b/bar.coffee' + + expect(global[COVERAGE_VAR], "Code should have been instrumented").to.exist + expect(global[COVERAGE_VAR][pn 'a/foo.coffee'], "Should instrument a/foo.coffee").to.exist + expect(global[COVERAGE_VAR][pn 'b/bar.coffee'], "Should not instrument b/bar.coffee").to.not.exist + it "should handle nested recursion correctly", -> # From https://github.com/benbria/coffee-coverage/pull/37 instrumentor = new coffeeCoverage.CoverageInstrumentor({ From 09cd39bd15347d1c3323fe236c4197f331a991a7 Mon Sep 17 00:00:00 2001 From: Charles Phillips Date: Sat, 9 Jul 2016 18:56:03 -0700 Subject: [PATCH 2/2] [fix] strip leading forward slash, since all paths are relative to project root --- src/utils/helpers.coffee | 1 + 1 file changed, 1 insertion(+) diff --git a/src/utils/helpers.coffee b/src/utils/helpers.coffee index 1e048fc..ea4caaf 100644 --- a/src/utils/helpers.coffee +++ b/src/utils/helpers.coffee @@ -67,6 +67,7 @@ exports.excludeFile = (fileName, options) -> # For each exclude value try to use it as a pattern to exclude files exclude.map (pattern) -> + pattern = pattern[1..] if pattern[0] is "/" if minimatch relativeFilename, pattern excluded = true