|
| 1 | +import assert from 'assert'; |
| 2 | +import URL from 'url'; |
| 3 | +import cheerio from 'cheerio'; |
| 4 | + |
| 5 | +import Mercury from 'mercury'; |
| 6 | +import getExtractor from 'extractors/get-extractor'; |
| 7 | +import { excerptContent } from 'utils/text'; |
| 8 | + |
| 9 | +const fs = require('fs'); |
| 10 | + |
| 11 | +describe('WwwLemondeFrExtractor', () => { |
| 12 | + describe('initial test case', () => { |
| 13 | + let result; |
| 14 | + let url; |
| 15 | + beforeAll(() => { |
| 16 | + url = |
| 17 | + 'https://www.lemonde.fr/economie/article/2019/05/07/dans-ses-previsions-economiques-bruxelles-confirme-la-montee-des-perils_5459325_3234.html'; |
| 18 | + const html = fs.readFileSync( |
| 19 | + './fixtures/www.lemonde.fr/1557235525251.html' |
| 20 | + ); |
| 21 | + result = Mercury.parse(url, { html, fallback: false }); |
| 22 | + }); |
| 23 | + |
| 24 | + it('is selected properly', () => { |
| 25 | + const extractor = getExtractor(url); |
| 26 | + assert.equal(extractor.domain, URL.parse(url).hostname); |
| 27 | + }); |
| 28 | + |
| 29 | + it('returns the title', async () => { |
| 30 | + const { title } = await result; |
| 31 | + |
| 32 | + assert.equal( |
| 33 | + title, |
| 34 | + `Les sombres perspectives économiques de la Commission européenne` |
| 35 | + ); |
| 36 | + }); |
| 37 | + |
| 38 | + it('returns the author', async () => { |
| 39 | + const { author } = await result; |
| 40 | + |
| 41 | + assert.equal(author, `Cécile Ducourtieux`); |
| 42 | + }); |
| 43 | + |
| 44 | + it('returns the date_published', async () => { |
| 45 | + const { date_published } = await result; |
| 46 | + |
| 47 | + assert.equal(date_published, `2019-05-07T11:59:43.000Z`); |
| 48 | + }); |
| 49 | + |
| 50 | + it('returns the dek', async () => { |
| 51 | + const { dek } = await result; |
| 52 | + |
| 53 | + assert.equal( |
| 54 | + dek, |
| 55 | + 'Elle abaisse ses prévisions pour 2019, avec un PIB à 1,4 % pour l’ensemble de l’UE, et à 1,2 % pour la zone euro.' |
| 56 | + ); |
| 57 | + }); |
| 58 | + |
| 59 | + it('returns the lead_image_url', async () => { |
| 60 | + const { lead_image_url } = await result; |
| 61 | + |
| 62 | + assert.equal( |
| 63 | + lead_image_url, |
| 64 | + `https://img.lemde.fr/2019/05/07/316/0/3824/1912/1440/720/60/0/d105b14_dfjDE1I-caggQrT4gvHf2nZP.jpg` |
| 65 | + ); |
| 66 | + }); |
| 67 | + |
| 68 | + it('returns the content', async () => { |
| 69 | + const { content } = await result; |
| 70 | + |
| 71 | + const $ = cheerio.load(content || ''); |
| 72 | + |
| 73 | + const first13 = excerptContent( |
| 74 | + $('*') |
| 75 | + .first() |
| 76 | + .text(), |
| 77 | + 13 |
| 78 | + ); |
| 79 | + |
| 80 | + assert.equal( |
| 81 | + first13, |
| 82 | + 'Les dirigeants européens qui doivent se réunir, jeudi 9 mai à Sibiu (Roumanie),' |
| 83 | + ); |
| 84 | + }); |
| 85 | + }); |
| 86 | +}); |
0 commit comments