added test cases for regex

This commit is contained in:
David Frank 2015-03-24 12:31:04 +08:00
parent b417f0d2ba
commit 3f59e6e964
3 changed files with 37 additions and 1 deletions

View File

@ -5,7 +5,11 @@ Changelog
# 1.x release
## v1.0.5 (master)
## v1.0.6 (master)
- Fix: less greedy content-type charset matching
## v1.0.5
- Fix: when follow = 0, fetch should not follow redirect
- Enhance: update tests for better coverage

View File

@ -139,6 +139,18 @@ TestServer.prototype.router = function(req, res) {
res.end('中文');
}
if (p === '/encoding/order1') {
res.statusCode = 200;
res.setHeader('Content-Type', 'charset=gbk; text/plain');
res.end(convert('中文', 'gbk'));
}
if (p === '/encoding/order2') {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain; charset=gbk; qs=1');
res.end(convert('中文', 'gbk'));
}
if (p === '/redirect/301') {
res.statusCode = 301;
res.setHeader('Location', '/inspect');

View File

@ -502,6 +502,26 @@ describe('node-fetch', function() {
});
});
it('should support uncommon content-type order, charset in front', function() {
url = base + '/encoding/order1';
return fetch(url).then(function(res) {
expect(res.status).to.equal(200);
return res.text().then(function(result) {
expect(result).to.equal('中文');
});
});
});
it('should support uncommon content-type order, end with qs', function() {
url = base + '/encoding/order2';
return fetch(url).then(function(res) {
expect(res.status).to.equal(200);
return res.text().then(function(result) {
expect(result).to.equal('中文');
});
});
});
it('should allow piping response body as stream', function(done) {
url = base + '/hello';
fetch(url).then(function(res) {