Skip to content

Commit 86f3c17

Browse files
committed
🐛 fuzzy sourcemap lookup
1 parent 9b393cb commit 86f3c17

File tree

3 files changed

+16
-15
lines changed

3 files changed

+16
-15
lines changed

README.md

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,14 @@ You can also generate LCOV Files for Coveralls or just HTML reports:
3535
```txt
3636
Usage: css-coverage [options]
3737
38-
Generate coverage info for a CSS file against an HTML file.
39-
This supports loading sourcemaps by using the sourceMappingURL=FILENAME.map CSS comment
38+
Generate coverage info for a CSS file against an HTML file. This supports loading sourcemaps by using the sourceMappingURL=FILENAME.map CSS comment
4039
4140
Options:
42-
43-
-h, --help output usage information
44-
--html [path/to/file.html] path to a local HTML file
45-
--css [path/to/file.css] path to a local CSS file
46-
--lcov [path/to/output.lcov] the LCOV output file
47-
--verbose verbose/debugging output
48-
--ignore-source-map disable loading the sourcemap if one is found
49-
--cover-declarations try to cover CSS declarations as well as selectors
50-
(best-effort, difficult with sourcemaps)
41+
--html [path/to/file.html] path to a local HTML file
42+
--css [path/to/file.css] path to a local CSS file
43+
--lcov [path/to/output.lcov] the LCOV output file
44+
--verbose verbose/debugging output
45+
--ignore-source-map disable loading the sourcemap if one is found
46+
--ignore-declarations [move-to,content] A comma-separated list of declarations to ignore
47+
-h, --help output usage information
5148
```

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
"version": "2.0.2",
44
"scripts": {
55
"pretest": "sass --source-map ./test/test.scss ./test/test.css",
6-
"test": "./bin/css-coverage.js --html ./test/test.html --css ./test/test.css --lcov ./test/test.lcov --ignore-declarations 'move-to,move-foobar'",
7-
"test-debug": "node --inspect-brk ./bin/css-coverage.js --cover-declarations --html ./test/test.html --css ./test/test.css --lcov ./test/test.lcov --ignore-declarations 'move-to,move-foobar'",
6+
"test": "./bin/css-coverage.js --html ./test/test.html --css ./test/test.css --lcov ./test/test.lcov --ignore-declarations 'move-to,move-foobar'",
7+
"test:debug": "node --inspect-brk ./bin/css-coverage.js --html ./test/test.html --css ./test/test.css --lcov ./test/test.lcov --ignore-declarations 'move-to,move-foobar'",
88
"posttest": "standard --fix"
99
},
1010
"dependencies": {

src/runCoverage.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,10 +275,14 @@ async function generateLcovStr (coverageOutput, supportedDeclarations) {
275275
}
276276

277277
function getStartInfo (origStart, origEnd) {
278-
const startInfo = sourceMapConsumer.originalPositionFor({ line: origStart.line, column: origStart.column - 1 })
278+
let startInfo = sourceMapConsumer.originalPositionFor({ line: origStart.line, column: origStart.column - 1 })
279279
// const endInfo = sourceMapConsumer.originalPositionFor({line: origEnd.line, column: origEnd.column - 2})
280280

281-
// When there is no match, startInfo.source is null
281+
// When there is no match, startInfo.source is null.
282+
// Try fiddling with the column
283+
if (!startInfo.source) {
284+
startInfo = sourceMapConsumer.originalPositionFor({ line: origStart.line, column: origStart.column })
285+
}
282286
if (!startInfo.source /* || startInfo.source !== endInfo.source */) {
283287
console.error('cssStart', JSON.stringify(origStart))
284288
origEnd && console.error('cssEnd', JSON.stringify(origEnd))

0 commit comments

Comments
 (0)