add more plugin tests

This commit is contained in:
Bass Jobsen
2015-03-03 22:52:54 +01:00
parent b3e06577f9
commit 296014a632
17 changed files with 144 additions and 7 deletions

View File

@@ -252,20 +252,44 @@ module.exports = function (grunt) {
outfile: 'tmp/browser/test-runner-post-processor.html'
}
},
postProcessorPLugin: {
postProcessorPlugin: {
src: ['test/browser/less/postProcessorPlugin/*.less'],
options: {
helpers: 'test/browser/runner-postProcessorPlugin-options.js',
specs: 'test/browser/runner-postProcessorPlugin.js',
outfile: 'tmp/browser/test-runner-post-processor-plugin.html'
}
}
},
preProcessorPlugin: {
src: ['test/browser/less/preProcessorPlugin/*.less'],
options: {
helpers: 'test/browser/runner-preProcessorPlugin-options.js',
specs: 'test/browser/runner-preProcessorPlugin.js',
outfile: 'tmp/browser/test-runner-pre-processor-plugin.html'
}
},
visitorPlugin: {
src: ['test/browser/less/visitorPlugin/*.less'],
options: {
helpers: 'test/browser/runner-VisitorPlugin-options.js',
specs: 'test/browser/runner-VisitorPlugin.js',
outfile: 'tmp/browser/test-runner-visitor-plugin.html'
}
},
filemanagerPlugin: {
src: ['test/browser/less/filemanagerPlugin/*.less'],
options: {
helpers: 'test/browser/runner-filemanagerPlugin-options.js',
specs: 'test/browser/runner-filemanagerPlugin.js',
outfile: 'tmp/browser/test-runner-filemanager-plugin.html'
}
}
},
'saucelabs-jasmine': {
all: {
options: {
urls: ["post-processor-plugin","post-processor", "global-vars", "modify-vars", "production", "rootpath-relative",
urls: ["filemanager-plugin","visitor-plugin","pre-processor-plugin","post-processor-plugin","post-processor", "global-vars", "modify-vars", "production", "rootpath-relative",
"rootpath", "relative-urls", "browser", "no-js-errors", "legacy", "strict-units"
].map(function(testName) {
return "http://localhost:8081/tmp/browser/test-runner-" + testName + ".html";

7
dist/less.js vendored
View File

@@ -446,8 +446,11 @@ module.exports = function(options, logger) {
};
FileManager.prototype.loadFile = function loadFile(filename, currentDirectory, options, environment, callback) {
console.log('loading...' + currentDirectory + filename);
if (currentDirectory && !this.isPathAbsolute(filename)) {
filename = currentDirectory + filename;
filename = ;
}
options = options || {};
@@ -9846,4 +9849,4 @@ if (typeof Promise === 'undefined') {
require('./polyfill-done.js');
},{"./lib/core.js":89,"./lib/es6-extensions.js":90,"./polyfill-done.js":92,"asap":91}]},{},[2])(2)
});
});

View File

@@ -27,7 +27,7 @@ module.exports = function(window, options) {
var typePattern = /^text\/(x-)?less$/;
function postProcessCSS(styles) {
function postProcessCSS(styles) { // deprecated, use a plugin for postprocesstasks
if (options.postProcessor && typeof options.postProcessor === 'function') {
styles = options.postProcessor.call(styles, styles) || styles;
}

View File

@@ -0,0 +1,3 @@
.test {
color: red;
}

View File

@@ -0,0 +1,3 @@
.test {
color: red;
}

View File

@@ -0,0 +1,3 @@
.test {
color: red;
}

View File

@@ -0,0 +1 @@
//@color: red;

View File

@@ -0,0 +1,4 @@
@import "test.test";
.test {
color: red;
}

View File

@@ -0,0 +1,3 @@
.test {
color: @color;
}

View File

@@ -0,0 +1,4 @@
.test {
color: red;
-some-aribitrary-property: value;
}

View File

@@ -0,0 +1,29 @@
RemoveProperty = function(less) {
this._visitor = new less.visitors.Visitor(this);
};
RemoveProperty.prototype = {
isReplacing: true,
run: function (root) {
return this._visitor.visit(root);
},
visitRule: function (ruleNode, visitArgs) {
if (ruleNode.name != '-some-aribitrary-property')
{
return ruleNode;
}
else {
return [];
}
}
};
var VisitorPlugin = {
install: function(less, pluginManager) {
pluginManager.addVisitor( new RemoveProperty(less));
}
};
var less = {logLevel: 4,
errorReporting: "console",
plugins: [VisitorPlugin]};

View File

@@ -0,0 +1,3 @@
describe("less.js Visitor Plugin", function() {
testLessEqualsInDocument();
});

View File

@@ -0,0 +1,29 @@
var plugin = function(less) {
var FileManager = less.FileManager;
function TestFileManager() {
};
TestFileManager = new FileManager();
TestFileManager.loadFile = function (filename, currentDirectory, options, environment, callback) {
if (filename.match(/.*\.test$/)) {
return less.environment.fileManagers[0].loadFile("colors.test", currentDirectory, options, environment, callback);
}
return less.environment.fileManagers[0].loadFile(filename, currentDirectory, options, environment, callback);
};
return TestFileManager;
};
var AddFilePlugin = {
install: function(less, pluginManager) {
less.environment.addFileManager(new plugin(less));
}
};
var less = {logLevel: 4,
errorReporting: "console",
plugins: [AddFilePlugin]
};

View File

@@ -0,0 +1,3 @@
describe("less.js filemanager Plugin", function() {
testLessEqualsInDocument();
});

View File

@@ -1,3 +1,3 @@
describe("less.js postProcessor", function() {
describe("less.js postProcessor (deprecated)", function() {
testLessEqualsInDocument();
});

View File

@@ -0,0 +1,22 @@
var preProcessor = function() {};
preProcessor.prototype = {
process : function (src, extra) {
var injected = '@color: red;\n';
var ignored = extra.imports.contentsIgnoredChars;
var fileInfo = extra.fileInfo;
ignored[fileInfo.filename] = ignored[fileInfo.filename] || 0;
ignored[fileInfo.filename] += injected.length;
return injected + src;
}
};
var preProcessorPlugin = {
install: function(less, pluginManager) {
pluginManager.addPreProcessor( new preProcessor());
}
};
var less = {logLevel: 4,
errorReporting: "console",
plugins: [preProcessorPlugin]};

View File

@@ -0,0 +1,3 @@
describe("less.js preProcessor Plugin", function() {
testLessEqualsInDocument();
});