|
| 1 | +import assert from 'assert'; |
| 2 | +import fs from 'fs'; |
| 3 | +import URL from 'url'; |
| 4 | +import cheerio from 'cheerio'; |
| 5 | + |
| 6 | +import Mercury from 'mercury'; |
| 7 | +import getExtractor from 'extractors/get-extractor'; |
| 8 | +import { excerptContent } from 'utils/text'; |
| 9 | + |
| 10 | +describe('WwwAlComExtractor', () => { |
| 11 | + describe('initial test case', () => { |
| 12 | + let result; |
| 13 | + let url; |
| 14 | + beforeAll(() => { |
| 15 | + url = |
| 16 | + 'http://www.al.com/news/birmingham/index.ssf/2016/12/two_arrested_in_multi-state_de.html#incart_river_home'; |
| 17 | + const html = |
| 18 | + fs.readFileSync('./fixtures/www.al.com/1482445422101.html'); |
| 19 | + result = |
| 20 | + Mercury.parse(url, html, { fallback: false }); |
| 21 | + }); |
| 22 | + |
| 23 | + it('is selected properly', () => { |
| 24 | + // This test should be passing by default. |
| 25 | + // It sanity checks that the correct parser |
| 26 | + // is being selected for URLs from this domain |
| 27 | + const extractor = getExtractor(url); |
| 28 | + assert.equal(extractor.domain, URL.parse(url).hostname); |
| 29 | + }); |
| 30 | + |
| 31 | + it('returns the title', async () => { |
| 32 | + // To pass this test, fill out the title selector |
| 33 | + // in ./src/extractors/custom/www.al.com/index.js. |
| 34 | + const { title } = await result; |
| 35 | + |
| 36 | + // Update these values with the expected values from |
| 37 | + // the article. |
| 38 | + assert.equal(title, 'Two arrested in multi-state debit card skimming scheme'); |
| 39 | + }); |
| 40 | + |
| 41 | + it('returns the author', async () => { |
| 42 | + // To pass this test, fill out the author selector |
| 43 | + // in ./src/extractors/custom/www.al.com/index.js. |
| 44 | + const { author } = await result; |
| 45 | + |
| 46 | + // Update these values with the expected values from |
| 47 | + // the article. |
| 48 | + assert.equal(author, 'Mike Cason | [email protected]'); |
| 49 | + }); |
| 50 | + |
| 51 | + it('returns the date_published', async () => { |
| 52 | + // To pass this test, fill out the date_published selector |
| 53 | + // in ./src/extractors/custom/www.al.com/index.js. |
| 54 | + const { date_published } = await result; |
| 55 | + |
| 56 | + // Update these values with the expected values from |
| 57 | + // the article. |
| 58 | + assert.equal(date_published, '2016-12-22T19:47:00.000Z'); |
| 59 | + }); |
| 60 | + |
| 61 | + it('returns the lead_image_url', async () => { |
| 62 | + // To pass this test, fill out the lead_image_url selector |
| 63 | + // in ./src/extractors/custom/www.al.com/index.js. |
| 64 | + const { lead_image_url } = await result; |
| 65 | + |
| 66 | + // Update these values with the expected values from |
| 67 | + // the article. |
| 68 | + assert.equal(lead_image_url, 'http://image.al.com/home/bama-media/width620/img/news_birmingham_impact/photo/21753198-standard.jpg'); |
| 69 | + }); |
| 70 | + |
| 71 | + it('returns the content', async () => { |
| 72 | + // To pass this test, fill out the content selector |
| 73 | + // in ./src/extractors/custom/www.al.com/index.js. |
| 74 | + // You may also want to make use of the clean and transform |
| 75 | + // options. |
| 76 | + const { content } = await result; |
| 77 | + |
| 78 | + const $ = cheerio.load(content || ''); |
| 79 | + |
| 80 | + const first13 = excerptContent($('*').first().text(), 13); |
| 81 | + |
| 82 | + // Update these values with the expected values from |
| 83 | + // the article. |
| 84 | + assert.equal(first13, 'Jake Frith, special agent with the Alabama Attorney General\'s office, talks about an'); |
| 85 | + }); |
| 86 | + }); |
| 87 | +}); |
0 commit comments