add option to disable javascript. Fixes #688

This commit is contained in:
Luke Page
2013-07-01 10:43:14 +01:00
parent 308bfe2e2b
commit 98f2fef2df
10 changed files with 56 additions and 26 deletions

View File

@@ -39,6 +39,7 @@ removeFiles("test/browser", /test-runner-[a-zA-Z-]*\.htm$/);
createTestRunnerPage("", /javascript|urls/, "main");
createTestRunnerPage("", null, "legacy", "legacy");
createTestRunnerPage("", /javascript/, "errors", "errors");
createTestRunnerPage("", null, "no-js-errors", "no-js-errors");
createTestRunnerPage("browser", null, "browser");
createTestRunnerPage("browser", null, "relative-urls", "relative-urls");
createTestRunnerPage("browser", null, "rootpath", "rootpath");

View File

@@ -0,0 +1,6 @@
less.strictUnits = true;
less.javascriptEnabled = false;
describe("less.js javascript disabled error tests", function() {
testLessErrorsInDocument();
});

View File

@@ -26,8 +26,34 @@ less.tree.functions._color = function (str) {
sys.puts("\n" + stylize("LESS", 'underline') + "\n");
runTestSet({strictMath: true, relativeUrls: true, silent: true});
runTestSet({strictMath: true, strictUnits: true}, "errors/",
testErrors, null, getErrorPathReplacementFunction("errors"));
runTestSet({strictMath: true, strictUnits: true, javascriptEnabled: false}, "no-js-errors/",
testErrors, null, getErrorPathReplacementFunction("no-js-errors"));
runTestSet({strictMath: true, dumpLineNumbers: 'comments'}, "debug/", null,
function(name) { return name + '-comments'; });
runTestSet({strictMath: true, dumpLineNumbers: 'mediaquery'}, "debug/", null,
function(name) { return name + '-mediaquery'; });
runTestSet({strictMath: true, dumpLineNumbers: 'all'}, "debug/", null,
function(name) { return name + '-all'; });
runTestSet({strictMath: true, relativeUrls: false, rootpath: "folder (1)/"}, "static-urls/");
runTestSet({strictMath: true, compress: true}, "compression/");
runTestSet({strictMath: false}, "legacy/");
runTestSet({strictMath: true, strictUnits: true}, "errors/", function(name, err, compiledLess, doReplacements) {
testNoOptions();
function getErrorPathReplacementFunction(dir) {
return function(input) {
return input.replace(
"{path}", path.join(process.cwd(), "/test/less/" + dir + "/"))
.replace("{pathrel}", path.join("test", "less", dir + "/"))
.replace("{pathhref}", "")
.replace("{404status}", "")
.replace(/\r\n/g, '\n');
};
}
function testErrors(name, err, compiledLess, doReplacements) {
fs.readFile(path.join('test/less/', name) + '.txt', 'utf8', function (e, expectedErr) {
sys.print("- " + name + ": ");
expectedErr = doReplacements(expectedErr, 'test/less/errors/');
@@ -40,31 +66,14 @@ runTestSet({strictMath: true, strictUnits: true}, "errors/", function(name, err,
} else {
var errMessage = less.formatError(err);
if (errMessage === expectedErr) {
ok('OK');
ok('OK');
} else {
difference("FAIL", expectedErr, errMessage);
}
}
sys.puts("");
});}, null, function(input, directory) {
return input.replace(
"{path}", path.join(process.cwd(), "/test/less/errors/"))
.replace("{pathrel}", path.join("test", "less", "errors/"))
.replace("{pathhref}", "")
.replace("{404status}", "")
.replace(/\r\n/g, '\n');
});
runTestSet({strictMath: true, dumpLineNumbers: 'comments'}, "debug/", null,
function(name) { return name + '-comments'; });
runTestSet({strictMath: true, dumpLineNumbers: 'mediaquery'}, "debug/", null,
function(name) { return name + '-mediaquery'; });
runTestSet({strictMath: true, dumpLineNumbers: 'all'}, "debug/", null,
function(name) { return name + '-all'; });
runTestSet({strictMath: true, relativeUrls: false, rootpath: "folder (1)/"}, "static-urls/");
runTestSet({strictMath: true, compress: true}, "compression/");
runTestSet({strictMath: false}, "legacy/");
testNoOptions();
}
function globalReplacements(input, directory) {
var p = path.join(process.cwd(), directory),

View File

@@ -0,0 +1,3 @@
.a {
a: `1 + 1`;
}

View File

@@ -0,0 +1,4 @@
SyntaxError: You are using JavaScript, which has been disabled. in {path}no-js-errors.less on line 2, column 6:
1 .a {
2 a: `1 + 1`;
3 }