You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
68 lines
2.0 KiB
JavaScript
68 lines
2.0 KiB
JavaScript
8 years ago
|
import assert from 'assert';
|
||
8 years ago
|
import { Errors } from 'utils';
|
||
8 years ago
|
|
||
8 years ago
|
import Mercury from './mercury';
|
||
8 years ago
|
|
||
8 years ago
|
describe('Mercury', () => {
|
||
8 years ago
|
describe('parse(url)', function test() {
|
||
|
this.timeout(1000000);
|
||
8 years ago
|
it('returns an error if a malformed url is passed', async function() {
|
||
8 years ago
|
const error = await Mercury.parse('foo.com');
|
||
8 years ago
|
|
||
|
assert.equal(error, Errors.badUrl);
|
||
|
});
|
||
|
|
||
|
it('returns an error if a bad url is passed', async function() {
|
||
8 years ago
|
const error = await Mercury.parse('foo.com');
|
||
8 years ago
|
|
||
|
assert.equal(error, Errors.badUrl);
|
||
|
});
|
||
|
|
||
8 years ago
|
it('does the whole thing', async function() {
|
||
8 years ago
|
const result = await Mercury.parse('http://theconcourse.deadspin.com/phyllis-schlafly-finally-croaks-1786219220');
|
||
8 years ago
|
|
||
8 years ago
|
assert.equal(typeof result, 'object');
|
||
8 years ago
|
// console.log(result)
|
||
8 years ago
|
});
|
||
8 years ago
|
|
||
|
it('does blogger', async function() {
|
||
8 years ago
|
const result = await Mercury.parse('https://googleblog.blogspot.com/2016/08/onhub-turns-one-today.html');
|
||
8 years ago
|
|
||
8 years ago
|
assert.equal(typeof result, 'object');
|
||
|
});
|
||
8 years ago
|
|
||
|
it('does wikipedia', async function() {
|
||
8 years ago
|
const result = await Mercury.parse('https://en.wikipedia.org/wiki/Brihadeeswarar_Temple_fire');
|
||
8 years ago
|
|
||
8 years ago
|
assert.equal(typeof result, 'object');
|
||
8 years ago
|
// console.log(result)
|
||
8 years ago
|
});
|
||
8 years ago
|
|
||
|
it('does the nyt', async function() {
|
||
8 years ago
|
const result = await Mercury.parse('http://www.nytimes.com/2016/08/16/upshot/the-state-of-the-clinton-trump-race-is-it-over.html?_r=0');
|
||
8 years ago
|
|
||
8 years ago
|
assert.equal(typeof result, 'object');
|
||
8 years ago
|
assert.equal(result.total_pages, 1);
|
||
8 years ago
|
// console.log(result)
|
||
8 years ago
|
});
|
||
8 years ago
|
|
||
8 years ago
|
it('does ars pagination', async function() {
|
||
8 years ago
|
const url = 'http://arstechnica.com/gadgets/2016/08/the-connected-renter-how-to-make-your-apartment-smarter/';
|
||
8 years ago
|
const result = await Mercury.parse(
|
||
8 years ago
|
url,
|
||
|
null,
|
||
|
{ fetchAllPages: true }
|
||
8 years ago
|
);
|
||
8 years ago
|
|
||
8 years ago
|
const { total_pages, pages_rendered } = result;
|
||
8 years ago
|
|
||
8 years ago
|
assert.equal(total_pages, 3);
|
||
|
assert.equal(pages_rendered, 3);
|
||
8 years ago
|
|
||
8 years ago
|
// console.log(result)
|
||
8 years ago
|
assert.equal(result.next_page_url, `${url}2`);
|
||
8 years ago
|
// console.log(result.content)
|
||
8 years ago
|
});
|
||
|
});
|
||
|
});
|