* Return true if the given ABSOLUTE path matches the patterns. * * Throws an error if the patterns form an invalid regex (see `validate`).
(absPath: string)
| 95 | * Throws an error if the patterns form an invalid regex (see `validate`). |
| 96 | */ |
| 97 | isMatch(absPath: string): boolean { |
| 98 | const relPath = path.relative(this.options.rootDir || '/', absPath); |
| 99 | |
| 100 | if (this.patterns.patterns.length === 0) { |
| 101 | return true; |
| 102 | } |
| 103 | |
| 104 | for (const p of this.patterns.patterns) { |
| 105 | const pathToTest = path.isAbsolute(p) ? absPath : relPath; |
| 106 | |
| 107 | // special case: ./foo.spec.js (and .\foo.spec.js on Windows) should |
| 108 | // match /^foo.spec.js/ after stripping root dir |
| 109 | let regexStr = p.replace(/^\.\//, '^'); |
| 110 | if (path.sep === '\\') { |
| 111 | regexStr = regexStr.replace(/^\.\\/, '^'); |
| 112 | } |
| 113 | |
| 114 | regexStr = replacePathSepForRegex(regexStr); |
| 115 | if (this.toRegex(regexStr).test(pathToTest)) { |
| 116 | return true; |
| 117 | } |
| 118 | |
| 119 | if (this.toRegex(regexStr).test(absPath)) { |
| 120 | return true; |
| 121 | } |
| 122 | } |
| 123 | return false; |
| 124 | } |
| 125 | |
| 126 | /** |
| 127 | * Return a human-friendly version of the pattern regex. |
no test coverage detected