mirror of
https://github.com/LightAir/turbo-rss.git
synced 2026-02-04 03:56:19 +00:00
move from nodeunit to mocha for tests. added npm test to run tests.
This commit is contained in:
@@ -11,7 +11,7 @@ function RSS (options, items) {
|
|||||||
|
|
||||||
this.title = options.title || 'Untitled RSS Feed';
|
this.title = options.title || 'Untitled RSS Feed';
|
||||||
this.description = options.description || '';
|
this.description = options.description || '';
|
||||||
this.generator = options.generator || 'NodeJS RSS Module';
|
this.generator = options.generator || 'RSS for Node';
|
||||||
this.feed_url = options.feed_url;
|
this.feed_url = options.feed_url;
|
||||||
this.site_url = options.site_url;
|
this.site_url = options.site_url;
|
||||||
this.image_url = options.image_url;
|
this.image_url = options.image_url;
|
||||||
@@ -85,8 +85,7 @@ function generateXML (data){
|
|||||||
ifTruePush(category, channel, { category: { _cdata: category } });
|
ifTruePush(category, channel, { category: { _cdata: category } });
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
// { updated: new Date().toGMTString() }
|
|
||||||
|
|
||||||
data.items.forEach(function(item) {
|
data.items.forEach(function(item) {
|
||||||
var item_values = [
|
var item_values = [
|
||||||
{ title: { _cdata: item.title } }
|
{ title: { _cdata: item.title } }
|
||||||
@@ -141,6 +140,4 @@ function generateXML (data){
|
|||||||
] };
|
] };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
module.exports = RSS;
|
||||||
|
|
||||||
module.exports = RSS;
|
|
||||||
@@ -27,7 +27,14 @@
|
|||||||
"xml": ">= 0.0.4",
|
"xml": ">= 0.0.4",
|
||||||
"mime": ">= 1.2.9"
|
"mime": ">= 1.2.9"
|
||||||
},
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"chai": "~1.7.2",
|
||||||
|
"mocha": "~1.12.0"
|
||||||
|
},
|
||||||
"main": "lib/rss.js",
|
"main": "lib/rss.js",
|
||||||
|
"scripts": {
|
||||||
|
"test": "./node_modules/.bin/mocha --reporter spec"
|
||||||
|
},
|
||||||
"engines": { "node": ">=0.4.0" },
|
"engines": { "node": ">=0.4.0" },
|
||||||
"licenses" :
|
"licenses" :
|
||||||
[
|
[
|
||||||
|
|||||||
13
readme.md
13
readme.md
@@ -6,13 +6,6 @@
|
|||||||
|
|
||||||
$ npm install rss
|
$ npm install rss
|
||||||
|
|
||||||
## Tests
|
|
||||||
|
|
||||||
Use [nodeunit](https://github.com/caolan/nodeunit) to run the tests.
|
|
||||||
|
|
||||||
$ npm install nodeunit
|
|
||||||
$ nodeunit test
|
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
var RSS = require('rss');
|
var RSS = require('rss');
|
||||||
@@ -94,6 +87,12 @@ an have any number of items. Ten to tenty is usually good.
|
|||||||
* _xml([indent])_ - return the xml. If you pass in true it will use four spaces for indenting. If you prefer
|
* _xml([indent])_ - return the xml. If you pass in true it will use four spaces for indenting. If you prefer
|
||||||
tabs use \t instead of true.
|
tabs use \t instead of true.
|
||||||
|
|
||||||
|
## Tests
|
||||||
|
|
||||||
|
Mocha tests are included. Use `npm test` to run the tests.
|
||||||
|
|
||||||
|
$ npm test
|
||||||
|
|
||||||
## Notes
|
## Notes
|
||||||
* You do not need to escape anything. This module will escape characters when necessary.
|
* You do not need to escape anything. This module will escape characters when necessary.
|
||||||
* This module is very fast but you might as well cache the output of xml() and serve
|
* This module is very fast but you might as well cache the output of xml() and serve
|
||||||
|
|||||||
@@ -1,21 +1,21 @@
|
|||||||
/*
|
/*
|
||||||
use nodeunit to run tests.
|
use `npm test` to run tests using mocha
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var RSS = require('../lib/rss');
|
var RSS = require('../lib/rss');
|
||||||
|
var expect = require('chai').expect;
|
||||||
|
|
||||||
|
describe('rss module', function(done) {
|
||||||
|
|
||||||
module.exports = {
|
it('should work with an empty feed', function(done) {
|
||||||
|
|
||||||
'empty feed': function(test) {
|
|
||||||
var feed = new RSS();
|
var feed = new RSS();
|
||||||
test.equal(feed.xml(), '<?xml version="1.0" encoding="UTF-8"?>\n<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Untitled RSS Feed]]></title><description><![CDATA[Untitled RSS Feed]]></description><link>http://github.com/dylan/node-rss</link><generator>NodeJS RSS Module</generator><lastBuildDate>' + new Date().toUTCString() +'</lastBuildDate></channel></rss>');
|
expect(feed.xml()).to.equal('<?xml version="1.0" encoding="UTF-8"?>\n<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Untitled RSS Feed]]></title><description><![CDATA[Untitled RSS Feed]]></description><link>http://github.com/dylan/node-rss</link><generator>NodeJS RSS Module</generator><lastBuildDate>' + new Date().toUTCString() +'</lastBuildDate></channel></rss>');
|
||||||
feed.item();
|
feed.item();
|
||||||
test.equal(feed.xml(), '<?xml version="1.0" encoding="UTF-8"?>\n<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Untitled RSS Feed]]></title><description><![CDATA[Untitled RSS Feed]]></description><link>http://github.com/dylan/node-rss</link><generator>NodeJS RSS Module</generator><lastBuildDate>' + new Date().toUTCString() +'</lastBuildDate><item><title><![CDATA[No title]]></title><guid isPermaLink="false">No title</guid></item></channel></rss>');
|
expect(feed.xml()).to.equal('<?xml version="1.0" encoding="UTF-8"?>\n<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Untitled RSS Feed]]></title><description><![CDATA[Untitled RSS Feed]]></description><link>http://github.com/dylan/node-rss</link><generator>NodeJS RSS Module</generator><lastBuildDate>' + new Date().toUTCString() +'</lastBuildDate><item><title><![CDATA[No title]]></title><guid isPermaLink="false">No title</guid></item></channel></rss>');
|
||||||
test.done();
|
done();
|
||||||
},
|
});
|
||||||
|
|
||||||
'easy test': function(test) {
|
it('should work with an easy test', function(done) {
|
||||||
var feed = new RSS({
|
var feed = new RSS({
|
||||||
title: 'title',
|
title: 'title',
|
||||||
description: 'description',
|
description: 'description',
|
||||||
@@ -72,12 +72,12 @@ module.exports = {
|
|||||||
var expectedResult = '<?xml version="1.0" encoding="UTF-8"?>\n<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[title]]></title><description><![CDATA[description]]></description><link>http://example.com</link><image><url>http://example.com/icon.png</url><title>title</title><link>http://example.com</link></image><generator>Example Generator</generator><lastBuildDate>' + new Date().toUTCString() +'</lastBuildDate><atom:link href="http://example.com/rss.xml" rel="self" type="application/rss+xml"/><author><![CDATA[Dylan Greene]]></author><pubDate>Sun, 20 May 2012 04:00:00 GMT</pubDate><copyright><![CDATA[2013 Dylan Green]]></copyright><language><![CDATA[en]]></language><managingEditor><![CDATA[Dylan Green]]></managingEditor><webMaster><![CDATA[Dylan Green]]></webMaster><docs>http://example.com/rss/docs.html</docs><ttl>60</ttl><category><![CDATA[Category 1]]></category><category><![CDATA[Category 2]]></category><category><![CDATA[Category 3]]></category><item><title><![CDATA[item 1]]></title><description><![CDATA[description 1]]></description><link>http://example.com/article1</link><guid isPermaLink="true">http://example.com/article1</guid><dc:creator><![CDATA[Dylan Greene]]></dc:creator><pubDate>Thu, 24 May 2012 04:00:00 GMT</pubDate></item><item><title><![CDATA[item 2]]></title><description><![CDATA[description 2]]></description><link>http://example.com/article2</link><guid isPermaLink="true">http://example.com/article2</guid><dc:creator><![CDATA[Dylan Greene]]></dc:creator><pubDate>Fri, 25 May 2012 04:00:00 GMT</pubDate></item><item><title><![CDATA[item 3]]></title><description><![CDATA[description 3]]></description><link>http://example.com/article3</link><guid isPermaLink="false">item3</guid><dc:creator><![CDATA[Dylan Greene]]></dc:creator><pubDate>Sat, 26 May 2012 04:00:00 GMT</pubDate></item><item><title><![CDATA[item 4 & html test with <strong>]]></title><description><![CDATA[description 4 uses some <strong>html</strong>]]></description><link>http://example.com/article4?this&that</link><guid isPermaLink="true">http://example.com/article4?this&that</guid><dc:creator><![CDATA[Guest Author]]></dc:creator><pubDate>Sun, 27 May 2012 04:00:00 GMT</pubDate></item><item><title><![CDATA[item 5 & test for categories]]></title><description><![CDATA[description 5]]></description><link>http://example.com/article5</link><guid isPermaLink="true">http://example.com/article5</guid><category><![CDATA[Category 1]]></category><category><![CDATA[Category 2]]></category><category><![CDATA[Category 3]]></category><category><![CDATA[Category 4]]></category><dc:creator><![CDATA[Guest Author]]></dc:creator><pubDate>Mon, 28 May 2012 04:00:00 GMT</pubDate></item></channel></rss>';
|
var expectedResult = '<?xml version="1.0" encoding="UTF-8"?>\n<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[title]]></title><description><![CDATA[description]]></description><link>http://example.com</link><image><url>http://example.com/icon.png</url><title>title</title><link>http://example.com</link></image><generator>Example Generator</generator><lastBuildDate>' + new Date().toUTCString() +'</lastBuildDate><atom:link href="http://example.com/rss.xml" rel="self" type="application/rss+xml"/><author><![CDATA[Dylan Greene]]></author><pubDate>Sun, 20 May 2012 04:00:00 GMT</pubDate><copyright><![CDATA[2013 Dylan Green]]></copyright><language><![CDATA[en]]></language><managingEditor><![CDATA[Dylan Green]]></managingEditor><webMaster><![CDATA[Dylan Green]]></webMaster><docs>http://example.com/rss/docs.html</docs><ttl>60</ttl><category><![CDATA[Category 1]]></category><category><![CDATA[Category 2]]></category><category><![CDATA[Category 3]]></category><item><title><![CDATA[item 1]]></title><description><![CDATA[description 1]]></description><link>http://example.com/article1</link><guid isPermaLink="true">http://example.com/article1</guid><dc:creator><![CDATA[Dylan Greene]]></dc:creator><pubDate>Thu, 24 May 2012 04:00:00 GMT</pubDate></item><item><title><![CDATA[item 2]]></title><description><![CDATA[description 2]]></description><link>http://example.com/article2</link><guid isPermaLink="true">http://example.com/article2</guid><dc:creator><![CDATA[Dylan Greene]]></dc:creator><pubDate>Fri, 25 May 2012 04:00:00 GMT</pubDate></item><item><title><![CDATA[item 3]]></title><description><![CDATA[description 3]]></description><link>http://example.com/article3</link><guid isPermaLink="false">item3</guid><dc:creator><![CDATA[Dylan Greene]]></dc:creator><pubDate>Sat, 26 May 2012 04:00:00 GMT</pubDate></item><item><title><![CDATA[item 4 & html test with <strong>]]></title><description><![CDATA[description 4 uses some <strong>html</strong>]]></description><link>http://example.com/article4?this&that</link><guid isPermaLink="true">http://example.com/article4?this&that</guid><dc:creator><![CDATA[Guest Author]]></dc:creator><pubDate>Sun, 27 May 2012 04:00:00 GMT</pubDate></item><item><title><![CDATA[item 5 & test for categories]]></title><description><![CDATA[description 5]]></description><link>http://example.com/article5</link><guid isPermaLink="true">http://example.com/article5</guid><category><![CDATA[Category 1]]></category><category><![CDATA[Category 2]]></category><category><![CDATA[Category 3]]></category><category><![CDATA[Category 4]]></category><dc:creator><![CDATA[Guest Author]]></dc:creator><pubDate>Mon, 28 May 2012 04:00:00 GMT</pubDate></item></channel></rss>';
|
||||||
var result = feed.xml();
|
var result = feed.xml();
|
||||||
|
|
||||||
test.equal(result.length, expectedResult.length);
|
expect(result).to.have.length(expectedResult.length);
|
||||||
test.equal(result, expectedResult);
|
expect(result).to.equal(expectedResult);
|
||||||
test.done();
|
done();
|
||||||
},
|
});
|
||||||
|
|
||||||
'easy test without image_url': function(test) {
|
it('should work without image_url', function(done) {
|
||||||
var feed = new RSS({
|
var feed = new RSS({
|
||||||
title: 'title',
|
title: 'title',
|
||||||
description: 'description',
|
description: 'description',
|
||||||
@@ -132,12 +132,12 @@ module.exports = {
|
|||||||
var expectedResult = '<?xml version="1.0" encoding="UTF-8"?>\n<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[title]]></title><description><![CDATA[description]]></description><link>http://example.com</link><generator>NodeJS RSS Module</generator><lastBuildDate>' + new Date().toUTCString() +'</lastBuildDate><atom:link href="http://example.com/rss.xml" rel="self" type="application/rss+xml"/><author><![CDATA[Dylan Greene]]></author><pubDate>Sun, 20 May 2012 04:00:00 GMT</pubDate><copyright><![CDATA[2013 Dylan Green]]></copyright><language><![CDATA[en]]></language><managingEditor><![CDATA[Dylan Green]]></managingEditor><webMaster><![CDATA[Dylan Green]]></webMaster><docs>http://example.com/rss/docs.html</docs><ttl>60</ttl><category><![CDATA[Category 1]]></category><category><![CDATA[Category 2]]></category><category><![CDATA[Category 3]]></category><item><title><![CDATA[item 1]]></title><description><![CDATA[description 1]]></description><link>http://example.com/article1</link><guid isPermaLink="true">http://example.com/article1</guid><dc:creator><![CDATA[Dylan Greene]]></dc:creator><pubDate>Thu, 24 May 2012 04:00:00 GMT</pubDate></item><item><title><![CDATA[item 2]]></title><description><![CDATA[description 2]]></description><link>http://example.com/article2</link><guid isPermaLink="true">http://example.com/article2</guid><dc:creator><![CDATA[Dylan Greene]]></dc:creator><pubDate>Fri, 25 May 2012 04:00:00 GMT</pubDate></item><item><title><![CDATA[item 3]]></title><description><![CDATA[description 3]]></description><link>http://example.com/article3</link><guid isPermaLink="false">item3</guid><dc:creator><![CDATA[Dylan Greene]]></dc:creator><pubDate>Sat, 26 May 2012 04:00:00 GMT</pubDate></item><item><title><![CDATA[item 4 & html test with <strong>]]></title><description><![CDATA[description 4 uses some <strong>html</strong>]]></description><link>http://example.com/article4?this&that</link><guid isPermaLink="true">http://example.com/article4?this&that</guid><dc:creator><![CDATA[Guest Author]]></dc:creator><pubDate>Sun, 27 May 2012 04:00:00 GMT</pubDate></item><item><title><![CDATA[item 5 & test for categories]]></title><description><![CDATA[description 5]]></description><link>http://example.com/article5</link><guid isPermaLink="true">http://example.com/article5</guid><category><![CDATA[Category 1]]></category><category><![CDATA[Category 2]]></category><category><![CDATA[Category 3]]></category><category><![CDATA[Category 4]]></category><dc:creator><![CDATA[Guest Author]]></dc:creator><pubDate>Mon, 28 May 2012 04:00:00 GMT</pubDate></item></channel></rss>';
|
var expectedResult = '<?xml version="1.0" encoding="UTF-8"?>\n<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[title]]></title><description><![CDATA[description]]></description><link>http://example.com</link><generator>NodeJS RSS Module</generator><lastBuildDate>' + new Date().toUTCString() +'</lastBuildDate><atom:link href="http://example.com/rss.xml" rel="self" type="application/rss+xml"/><author><![CDATA[Dylan Greene]]></author><pubDate>Sun, 20 May 2012 04:00:00 GMT</pubDate><copyright><![CDATA[2013 Dylan Green]]></copyright><language><![CDATA[en]]></language><managingEditor><![CDATA[Dylan Green]]></managingEditor><webMaster><![CDATA[Dylan Green]]></webMaster><docs>http://example.com/rss/docs.html</docs><ttl>60</ttl><category><![CDATA[Category 1]]></category><category><![CDATA[Category 2]]></category><category><![CDATA[Category 3]]></category><item><title><![CDATA[item 1]]></title><description><![CDATA[description 1]]></description><link>http://example.com/article1</link><guid isPermaLink="true">http://example.com/article1</guid><dc:creator><![CDATA[Dylan Greene]]></dc:creator><pubDate>Thu, 24 May 2012 04:00:00 GMT</pubDate></item><item><title><![CDATA[item 2]]></title><description><![CDATA[description 2]]></description><link>http://example.com/article2</link><guid isPermaLink="true">http://example.com/article2</guid><dc:creator><![CDATA[Dylan Greene]]></dc:creator><pubDate>Fri, 25 May 2012 04:00:00 GMT</pubDate></item><item><title><![CDATA[item 3]]></title><description><![CDATA[description 3]]></description><link>http://example.com/article3</link><guid isPermaLink="false">item3</guid><dc:creator><![CDATA[Dylan Greene]]></dc:creator><pubDate>Sat, 26 May 2012 04:00:00 GMT</pubDate></item><item><title><![CDATA[item 4 & html test with <strong>]]></title><description><![CDATA[description 4 uses some <strong>html</strong>]]></description><link>http://example.com/article4?this&that</link><guid isPermaLink="true">http://example.com/article4?this&that</guid><dc:creator><![CDATA[Guest Author]]></dc:creator><pubDate>Sun, 27 May 2012 04:00:00 GMT</pubDate></item><item><title><![CDATA[item 5 & test for categories]]></title><description><![CDATA[description 5]]></description><link>http://example.com/article5</link><guid isPermaLink="true">http://example.com/article5</guid><category><![CDATA[Category 1]]></category><category><![CDATA[Category 2]]></category><category><![CDATA[Category 3]]></category><category><![CDATA[Category 4]]></category><dc:creator><![CDATA[Guest Author]]></dc:creator><pubDate>Mon, 28 May 2012 04:00:00 GMT</pubDate></item></channel></rss>';
|
||||||
var result = feed.xml();
|
var result = feed.xml();
|
||||||
|
|
||||||
test.equal(result.length, expectedResult.length);
|
expect(result).to.have.length(expectedResult.length);
|
||||||
test.equal(result, expectedResult);
|
expect(result).to.equal(expectedResult);
|
||||||
test.done();
|
done();
|
||||||
},
|
});
|
||||||
|
|
||||||
'test with enclosure' : function(test) {
|
it('should work with an enclosure', function(done) {
|
||||||
var feed = new RSS({
|
var feed = new RSS({
|
||||||
title: 'title',
|
title: 'title',
|
||||||
description: 'description',
|
description: 'description',
|
||||||
@@ -178,9 +178,9 @@ module.exports = {
|
|||||||
'</channel></rss>';
|
'</channel></rss>';
|
||||||
var result = feed.xml();
|
var result = feed.xml();
|
||||||
|
|
||||||
test.equal(result.length, expectedResult.length);
|
expect(result).to.have.length(expectedResult.length);
|
||||||
test.equal(result, expectedResult);
|
expect(result).to.equal(expectedResult);
|
||||||
test.done();
|
done();
|
||||||
}
|
});
|
||||||
};
|
});
|
||||||
|
|
||||||
Reference in New Issue
Block a user