|
|
|
@ -1,15 +1,15 @@
|
|
|
|
|
import assert from 'assert'
|
|
|
|
|
import cheerio from 'cheerio'
|
|
|
|
|
import assert from 'assert';
|
|
|
|
|
import cheerio from 'cheerio';
|
|
|
|
|
|
|
|
|
|
import {
|
|
|
|
|
default as GenericExcerptExtractor,
|
|
|
|
|
clean,
|
|
|
|
|
} from './extractor'
|
|
|
|
|
} from './extractor';
|
|
|
|
|
|
|
|
|
|
describe('GenericExcerptExtractor', () => {
|
|
|
|
|
describe('extract({ $, content, metaCache })', () => {
|
|
|
|
|
it('returns og:description', () => {
|
|
|
|
|
const actualExcerpt = "Wow this is going to be something good."
|
|
|
|
|
const actualExcerpt = 'Wow this is going to be something good.';
|
|
|
|
|
const html = `
|
|
|
|
|
<html>
|
|
|
|
|
<head>
|
|
|
|
@ -23,10 +23,10 @@ describe('GenericExcerptExtractor', () => {
|
|
|
|
|
const excerpt = GenericExcerptExtractor.extract({ $, content: '', metaCache });
|
|
|
|
|
|
|
|
|
|
assert.equal(excerpt, actualExcerpt);
|
|
|
|
|
})
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('returns twitter:description', () => {
|
|
|
|
|
const actualExcerpt = "Wow this is going to be something good."
|
|
|
|
|
const actualExcerpt = 'Wow this is going to be something good.';
|
|
|
|
|
const html = `
|
|
|
|
|
<html>
|
|
|
|
|
<head>
|
|
|
|
@ -40,7 +40,7 @@ describe('GenericExcerptExtractor', () => {
|
|
|
|
|
const excerpt = GenericExcerptExtractor.extract({ $, content: '', metaCache });
|
|
|
|
|
|
|
|
|
|
assert.equal(excerpt, actualExcerpt);
|
|
|
|
|
})
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('falls back to the content', () => {
|
|
|
|
|
const html = `
|
|
|
|
@ -50,16 +50,15 @@ describe('GenericExcerptExtractor', () => {
|
|
|
|
|
</html>
|
|
|
|
|
`;
|
|
|
|
|
const $ = cheerio.load(html);
|
|
|
|
|
const content = "<div><p>Wow <b>this</b> is going to be something good.</p></div>"
|
|
|
|
|
const content = '<div><p>Wow <b>this</b> is going to be something good.</p></div>';
|
|
|
|
|
const metaCache = [];
|
|
|
|
|
|
|
|
|
|
const excerpt = GenericExcerptExtractor.extract({ $, content, metaCache });
|
|
|
|
|
|
|
|
|
|
assert.equal(excerpt, 'Wow this is going to be something good.');
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('clean(text)', () => {
|
|
|
|
|
it('truncates text longer than 200 chars and trims whitespance', () => {
|
|
|
|
@ -70,15 +69,15 @@ describe('clean(text)', () => {
|
|
|
|
|
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu
|
|
|
|
|
fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in
|
|
|
|
|
culpa qui officia deserunt mollit anim id est laborum.
|
|
|
|
|
`
|
|
|
|
|
const text = clean(longText)
|
|
|
|
|
`;
|
|
|
|
|
const text = clean(longText);
|
|
|
|
|
let shouldBe = `
|
|
|
|
|
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
|
|
|
|
|
incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud
|
|
|
|
|
exercitation ullamco laboris nisi ut…
|
|
|
|
|
`
|
|
|
|
|
shouldBe = shouldBe.replace(/[\s\n]+/g, ' ').trim()
|
|
|
|
|
`;
|
|
|
|
|
shouldBe = shouldBe.replace(/[\s\n]+/g, ' ').trim();
|
|
|
|
|
|
|
|
|
|
assert.equal(text, shouldBe)
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
assert.equal(text, shouldBe);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|