1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Adding test for registry cheerio

This commit is contained in:
zobalogh 2014-07-31 16:49:19 +01:00
parent a170623b4c
commit 401afcbadd
2 changed files with 43 additions and 2 deletions

View File

@ -197,7 +197,7 @@ function loadTemplate(nodeInfo) {
var content = fs.readFileSync(templateFilename,'utf8');
$ = cheerio.load(content);
var $ = cheerio.load(content);
var template = "";
var script = "";
$("*").each(function(i,el) {

View File

@ -84,6 +84,7 @@ describe("getNodeFiles", function() {
var tempDir = path.join(__dirname,".tmp/");
var fakeNodeJS = tempDir + "testNode.js"; // when exported, this fake node creates a file we can assert on
var fakeNodeHTML = tempDir + "testNode.html"; // we assume it's going to be loaded by cheerio
var nodeInjectedFileName = "testInjected";
var nodeInjectedFilePath = path.join(tempDir, nodeInjectedFileName);
@ -100,7 +101,26 @@ describe("getNodeFiles", function() {
"module.exports = function(RED) {\n" +
" fs.writeFileSync(tempFile, \"Test passes if this file has been written.\");\n" +
"}\n";
var htmlContents = "<script type=\"text/javascript\">\n" +
" RED.nodes.registerType('testFileInjector',{\n" +
" category: 'storage-input',\n" +
" inputs:0,\n" +
" outputs:1,\n" +
" icon: \"file.png\"\n" +
" });\n" +
"</script>\n" +
"<script type=\"text/x-red\" data-template-name=\"testFileInjector\">\n" +
" <div class=\"form-row\">\n" +
" <label for=\"node-input-name\"><i class=\"icon-tag\"></i> Name</label>\n" +
" <input type=\"text\" id=\"node-input-name\" placeholder=\"Name\">\n" +
" </div>\n" +
"</script>\n" +
"<script type=\"text/x-red\" data-help-name=\"node-type\">\n" +
" <p>This node is pretty useless</p>\n" +
"</script>";
fs.writeFileSync(fakeNodeJS, fileContents);
fs.writeFileSync(fakeNodeHTML, htmlContents);
fs.remove(tempNoNodesContainedDir,function(err) {
fs.mkdirSync(tempNoNodesContainedDir);
done();
@ -122,6 +142,12 @@ describe("getNodeFiles", function() {
if(exists) {
fs.unlinkSync(fakeNodeJS);
}
fs.remove(tempDir);
});
fs.exists(fakeNodeHTML, function(exists) {
if(exists) {
fs.unlinkSync(fakeNodeHTML);
}
fs.remove(tempDir, done);
});
});
@ -135,6 +161,21 @@ describe("getNodeFiles", function() {
typeRegistry.init(settings);
typeRegistry.load(tempNoNodesContainedDir).then(function(){
var testConfig = typeRegistry.getNodeConfigs();
try {
testConfig.should.equal( "<script type=\"text/x-red\" data-template-name=\"testFileInjector\">\n" +
" <div class=\"form-row\">\n" +
" <label for=\"node-input-name\"><i class=\"icon-tag\"></i> Name</label>\n" +
" <input type=\"text\" id=\"node-input-name\" placeholder=\"Name\">\n" +
" </div>\n" +
"</script><script type=\"text/x-red\" data-help-name=\"node-type\">\n" +
" <p>This node is pretty useless</p>\n" +
"</script><script type=\"text/javascript\">RED.nodes.registerType(\"testFileInjector\",{category:\"storage-input\",inputs:0,outputs:1,icon:\"file.png\"});</script>");
} catch(err) {
done(err);
}
fs.exists(nodeInjectedFilePath, function(exists) {
if(exists) {
done();