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 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({