Skip to content

Commit

Permalink
Add test for --source-map-no-annotation option.
Browse files Browse the repository at this point in the history
  • Loading branch information
hirosato committed Jun 13, 2020
1 parent 5479df6 commit 458d2d3
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 1 deletion.
2 changes: 2 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ var testMap = [
}],
[{math: 'strict', strictUnits: true, sourceMap: {sourceMapFileInline: true}},
'sourcemaps-empty/', lessTester.testEmptySourcemap],
[{math: 'strict', strictUnits: true, sourceMap: {disableSourcemapAnnotation: true}},
'sourcemaps-disable-annotation/', lessTester.testSourcemapWithoutUrlAnnotation],
[{globalVars: true, banner: '/**\n * Test\n */\n'}, 'globalVars/',
null, null, null, function(name, type, baseFolder) { return path.join(baseFolder, name) + '.json'; }],
[{modifyVars: true}, 'modifyVars/',
Expand Down
33 changes: 32 additions & 1 deletion test/less-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,35 @@ module.exports = function() {
});
}

function testSourcemapWithoutUrlAnnotation(name, err, compiledLess, _doReplacements, sourcemap, baseFolder) {
if (err) {
fail('ERROR: ' + (err && err.message));
return;
}
// This matches with strings that end($) with source mapping url annotation.
var sourceMapRegExp = /\/\*# sourceMappingURL=.+\.css\.map \*\/$/;
if (sourceMapRegExp.test(compiledLess)) {
fail('ERROR: sourceMappingURL found in ' + baseFolder + '/' + name + '.css.');
return;
}

// Even if annotation is not necessary, the map file should be there.
fs.readFile(path.join('test/', name) + '.json', 'utf8', function (e, expectedSourcemap) {
process.stdout.write('- ' + path.join(baseFolder, name) + ': ');
if (sourcemap === expectedSourcemap) {
ok('OK');
} else if (err) {
fail('ERROR: ' + (err && err.message));
if (isVerbose) {
process.stdout.write('\n');
process.stdout.write(err.stack + '\n');
}
} else {
difference('FAIL', expectedSourcemap, sourcemap);
}
});
}

function testEmptySourcemap(name, err, compiledLess, doReplacements, sourcemap, baseFolder) {
process.stdout.write('- ' + path.join(baseFolder, name) + ': ');
if (err) {
Expand Down Expand Up @@ -309,7 +338,8 @@ module.exports = function() {
options.sourceMap = {
sourceMapOutputFilename: name + '.css',
sourceMapBasepath: path.join(process.cwd(), baseFolder),
sourceMapRootpath: 'testweb/'
sourceMapRootpath: 'testweb/',
disableSourcemapAnnotation: options.sourceMap.disableSourcemapAnnotation
};
// This options is normally set by the bin/lessc script. Setting it causes the sourceMappingURL comment to be appended to the CSS
// output. The value is designed to allow the sourceMapBasepath option to be tested, as it should be removed by less before
Expand Down Expand Up @@ -493,6 +523,7 @@ module.exports = function() {
testSyncronous: testSyncronous,
testErrors: testErrors,
testSourcemap: testSourcemap,
testSourcemapWithoutUrlAnnotation: testSourcemapWithoutUrlAnnotation,
testImports: testImports,
testEmptySourcemap: testEmptySourcemap,
testNoOptions: testNoOptions,
Expand Down
4 changes: 4 additions & 0 deletions test/less/sourcemaps-disable-annotation/basic.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
body {
/*# sourceMappingURL=this-should-be-ok.css.map */
color: white;
}
1 change: 1 addition & 0 deletions test/sourcemaps-disable-annotation/basic.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"version":3,"sources":["testweb/sourcemaps-disable-annotation/basic.less"],"names":[],"mappings":"AAAA;;EAEE,YAAA","file":"sourcemaps-disable-annotation/basic.css"}

0 comments on commit 458d2d3

Please sign in to comment.