Remove duplicated tests (#873)

* move some of the previously deleted tests to the external-encoding.js
This commit is contained in:
Antoni Kepinski 2020-06-12 20:06:30 +02:00 committed by GitHub
parent 1fdc218a64
commit e17cefbb90
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 34 deletions

View File

@ -5,7 +5,7 @@ const {expect} = chai;
describe('external encoding', () => { describe('external encoding', () => {
describe('data uri', () => { describe('data uri', () => {
it('should accept data uri', () => { it('should accept base64-encoded gif data uri', () => {
return fetch('data:image/gif;base64,R0lGODlhAQABAIAAAAUEBAAAACwAAAAAAQABAAACAkQBADs=').then(r => { return fetch('data:image/gif;base64,R0lGODlhAQABAIAAAAUEBAAAACwAAAAAAQABAAACAkQBADs=').then(r => {
expect(r.status).to.equal(200); expect(r.status).to.equal(200);
expect(r.headers.get('Content-Type')).to.equal('image/gif'); expect(r.headers.get('Content-Type')).to.equal('image/gif');
@ -16,6 +16,15 @@ describe('external encoding', () => {
}); });
}); });
it('should accept data uri with specified charset', async () => {
const r = await fetch('data:text/plain;charset=UTF-8;page=21,the%20data:1234,5678');
expect(r.status).to.equal(200);
expect(r.headers.get('Content-Type')).to.equal('text/plain;charset=UTF-8;page=21');
const b = await r.text();
expect(b).to.equal('the data:1234,5678');
});
it('should accept data uri of plain text', () => { it('should accept data uri of plain text', () => {
return fetch('data:,Hello%20World!').then(r => { return fetch('data:,Hello%20World!').then(r => {
expect(r.status).to.equal(200); expect(r.status).to.equal(200);

View File

@ -2125,37 +2125,4 @@ describe('node-fetch', () => {
fetch(url).then(res => expect(res.url).to.equal(`${base}m%C3%B6bius`)); fetch(url).then(res => expect(res.url).to.equal(`${base}m%C3%B6bius`));
}); });
describe('data uri', () => {
const dataUrl = 'data:image/gif;base64,R0lGODlhAQABAIAAAAUEBAAAACwAAAAAAQABAAACAkQBADs=';
const invalidDataUrl = 'data:@@@@';
it('should accept data uri', () => {
return fetch(dataUrl).then(r => {
console.assert(r.status === 200);
console.assert(r.headers.get('Content-Type') === 'image/gif');
return r.buffer().then(b => {
console.assert(b instanceof Buffer);
});
});
});
it('should accept data uri 2', async () => {
const r = await fetch('data:text/plain;charset=UTF-8;page=21,the%20data:1234,5678');
expect(r.status).to.equal(200);
expect(r.headers.get('Content-Type')).to.equal('text/plain;charset=UTF-8;page=21');
const b = await r.text();
expect(b).to.equal('the data:1234,5678');
});
it('should reject invalid data uri', () => {
return fetch(invalidDataUrl).catch(error => {
console.assert(error);
console.assert(error.message.includes('invalid URL'));
});
});
});
}); });