|
| 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('EpaperZeitDeExtractor', () => { |
| 12 | + describe('initial test case', () => { |
| 13 | + let result; |
| 14 | + let url; |
| 15 | + beforeAll(() => { |
| 16 | + url = |
| 17 | + 'https://epaper.zeit.de/article/702225a4061dfbf97ab93df8de77e8c54aa3f5fe7a8c2799e8d425953d123acf'; |
| 18 | + const html = fs.readFileSync( |
| 19 | + './fixtures/epaper.zeit.de/1566927390034.html' |
| 20 | + ); |
| 21 | + result = Mercury.parse(url, { html, fallback: false }); |
| 22 | + }); |
| 23 | + |
| 24 | + it('is selected properly', () => { |
| 25 | + // This test should be passing by default. |
| 26 | + // It sanity checks that the correct parser |
| 27 | + // is being selected for URLs from this domain |
| 28 | + const extractor = getExtractor(url); |
| 29 | + assert.equal(extractor.domain, URL.parse(url).hostname); |
| 30 | + }); |
| 31 | + |
| 32 | + it('returns the title', async () => { |
| 33 | + // To pass this test, fill out the title selector |
| 34 | + // in ./src/extractors/custom/epaper.zeit.de/index.js. |
| 35 | + const { title } = await result; |
| 36 | + |
| 37 | + // Update these values with the expected values from |
| 38 | + // the article. |
| 39 | + assert.equal(title, `Was heißt Sozialismus für Sie, Kevin Kühnert?`); |
| 40 | + }); |
| 41 | + |
| 42 | + it('returns the author', async () => { |
| 43 | + // To pass this test, fill out the author selector |
| 44 | + // in ./src/extractors/custom/epaper.zeit.de/index.js. |
| 45 | + const { author } = await result; |
| 46 | + |
| 47 | + // Update these values with the expected values from |
| 48 | + // the article. |
| 49 | + assert.equal(author, 'Politik · Jochen Bittner, Tina Hildebrandt'); |
| 50 | + }); |
| 51 | + |
| 52 | + it('returns the date_published', async () => { |
| 53 | + // To pass this test, fill out the date_published selector |
| 54 | + // in ./src/extractors/custom/epaper.zeit.de/index.js. |
| 55 | + const { date_published } = await result; |
| 56 | + |
| 57 | + // Update these values with the expected values from |
| 58 | + // the article. |
| 59 | + assert.equal(date_published, null); |
| 60 | + }); |
| 61 | + |
| 62 | + it('returns the excerpt', async () => { |
| 63 | + // To pass this test, fill out the excerpt selector |
| 64 | + // in ./src/extractors/custom/epaper.zeit.de/index.js. |
| 65 | + const { excerpt } = await result; |
| 66 | + |
| 67 | + // Update these values with the expected values from |
| 68 | + // the article. |
| 69 | + assert.equal( |
| 70 | + excerpt, |
| 71 | + 'Zum Beispiel die Kollektivierung von Firmen wie BMW, sagt der Chef der Jusos. In der Wirtschaftsordnung, die er sich vorstellt, gäbe es auch kein Eigentum an Wohnraum mehr. Ein Gespräch über eine radikale Alternative' |
| 72 | + ); |
| 73 | + }); |
| 74 | + |
| 75 | + it('returns the lead_image_url', async () => { |
| 76 | + // To pass this test, fill out the lead_image_url selector |
| 77 | + // in ./src/extractors/custom/epaper.zeit.de/index.js. |
| 78 | + const { lead_image_url } = await result; |
| 79 | + |
| 80 | + // Update these values with the expected values from |
| 81 | + // the article. |
| 82 | + assert.equal(lead_image_url, null); |
| 83 | + }); |
| 84 | + |
| 85 | + it('returns the content', async () => { |
| 86 | + // To pass this test, fill out the content selector |
| 87 | + // in ./src/extractors/custom/epaper.zeit.de/index.js. |
| 88 | + // You may also want to make use of the clean and transform |
| 89 | + // options. |
| 90 | + const { content } = await result; |
| 91 | + |
| 92 | + const $ = cheerio.load(content || ''); |
| 93 | + |
| 94 | + const first13 = excerptContent( |
| 95 | + $('*') |
| 96 | + .first() |
| 97 | + .text(), |
| 98 | + 13 |
| 99 | + ); |
| 100 | + |
| 101 | + // Update these values with the expected values from |
| 102 | + // the article. |
| 103 | + assert.equal( |
| 104 | + first13, |
| 105 | + 'Politik · Jochen Bittner, Tina Hildebrandt Zum Beispiel die Kollektivierung von Firmen wie' |
| 106 | + ); |
| 107 | + }); |
| 108 | + }); |
| 109 | +}); |
0 commit comments