Skip to content

Commit 8070e47

Browse files
authored
test: streamlined guardian tests w/new single-extraction (#58)
1 parent bdb751f commit 8070e47

File tree

2 files changed

+86
-111
lines changed

2 files changed

+86
-111
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"build:generator": "rollup -c scripts/rollup.config.js",
1515
"test_build": "rollup -c",
1616
"test": "yarn test:node && yarn test:web",
17-
"test:node": "jest ./src",
17+
"test:node": "jest",
1818
"test:web": "./node_modules/karma/bin/karma start karma.conf.js --auto-watch",
1919
"test:build": "cd ./scripts && jest check-build.test.js",
2020
"test:build:web": "node ./scripts/proxy-browser-test.js",

src/extractors/custom/www.theguardian.com/index.test.js

Lines changed: 85 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -8,115 +8,90 @@ import getExtractor from 'extractors/get-extractor';
88
import { excerptContent } from 'utils/text';
99

1010
describe('WwwTheguardianComExtractor', () => {
11-
it('is selected properly', () => {
12-
// This test should be passing by default.
13-
// It sanity checks that the correct parser
14-
// is being selected for URLs from this domain
15-
const url =
16-
'https://www.theguardian.com/us-news/2016/nov/29/standing-rock-protest-north-dakota-shutdown-evacuation';
17-
const extractor = getExtractor(url);
18-
assert.equal(extractor.domain, URL.parse(url).hostname);
19-
});
20-
21-
it('returns the title', async () => {
22-
// To pass this test, fill out the title selector
23-
// in ./src/extractors/custom/www.theguardian.com/index.js.
24-
const html =
25-
fs.readFileSync('./fixtures/www.theguardian.com/1480457558008.html');
26-
const articleUrl =
27-
'https://www.theguardian.com/us-news/2016/nov/29/standing-rock-protest-north-dakota-shutdown-evacuation';
28-
29-
const { title } =
30-
await Mercury.parse(articleUrl, html, { fallback: false });
31-
32-
// Update these values with the expected values from
33-
// the article.
34-
assert.equal(title, 'Standing Rock protesters hold out against extraordinary police violence');
35-
});
36-
37-
it('returns the author', async () => {
38-
// To pass this test, fill out the author selector
39-
// in ./src/extractors/custom/www.theguardian.com/index.js.
40-
const html =
41-
fs.readFileSync('./fixtures/www.theguardian.com/1480457558008.html');
42-
const articleUrl =
43-
'https://www.theguardian.com/us-news/2016/nov/29/standing-rock-protest-north-dakota-shutdown-evacuation';
44-
45-
const { author } =
46-
await Mercury.parse(articleUrl, html, { fallback: false });
47-
48-
// Update these values with the expected values from
49-
// the article.
50-
assert.equal(author, 'Julia Carrie Wong and Sam Levin');
51-
});
52-
53-
it('returns the date_published', async () => {
54-
// To pass this test, fill out the date_published selector
55-
// in ./src/extractors/custom/www.theguardian.com/index.js.
56-
const html =
57-
fs.readFileSync('./fixtures/www.theguardian.com/1480457558008.html');
58-
const articleUrl =
59-
'https://www.theguardian.com/us-news/2016/nov/29/standing-rock-protest-north-dakota-shutdown-evacuation';
60-
61-
const { date_published } =
62-
await Mercury.parse(articleUrl, html, { fallback: false });
63-
64-
// Update these values with the expected values from
65-
// the article.
66-
assert.equal(date_published, '2016-11-29T20:26:06.000Z');
67-
});
68-
69-
it('returns the dek', async () => {
70-
// To pass this test, fill out the dek selector
71-
// in ./src/extractors/custom/www.theguardian.com/index.js.
72-
const html =
73-
fs.readFileSync('./fixtures/www.theguardian.com/1480457558008.html');
74-
const articleUrl =
75-
'https://www.theguardian.com/us-news/2016/nov/29/standing-rock-protest-north-dakota-shutdown-evacuation';
76-
77-
const { dek } =
78-
await Mercury.parse(articleUrl, html, { fallback: false });
79-
80-
// Update these values with the expected values from
81-
// the article.
82-
assert.equal(dek, 'Apprehension and distrust pervade North Dakota protest site as promises from state that there are no plans to forcibly remove people does little to assuage fears');
83-
});
84-
85-
it('returns the lead_image_url', async () => {
86-
// To pass this test, fill out the lead_image_url selector
87-
// in ./src/extractors/custom/www.theguardian.com/index.js.
88-
const html =
89-
fs.readFileSync('./fixtures/www.theguardian.com/1480457558008.html');
90-
const articleUrl =
91-
'https://www.theguardian.com/us-news/2016/nov/29/standing-rock-protest-north-dakota-shutdown-evacuation';
92-
93-
const { lead_image_url } =
94-
await Mercury.parse(articleUrl, html, { fallback: false });
95-
96-
// Update these values with the expected values from
97-
// the article.
98-
assert.equal(lead_image_url, 'https://i.guim.co.uk/img/media/fc64982c5ab7b3ea7d5d38f3f74483c84c60b372/0_225_3500_2100/master/3500.jpg?w=1200&h=630&q=55&auto=format&usm=12&fit=crop&bm=normal&ba=bottom%2Cleft&blend64=aHR0cHM6Ly91cGxvYWRzLmd1aW0uY28udWsvMjAxNi8wNS8yNS9vdmVybGF5LWxvZ28tMTIwMC05MF9vcHQucG5n&s=034d7b3573a47c5ba3501a9e9e253a8f');
99-
});
100-
101-
it('returns the content', async () => {
102-
// To pass this test, fill out the content selector
103-
// in ./src/extractors/custom/www.theguardian.com/index.js.
104-
// You may also want to make use of the clean and transform
105-
// options.
106-
const html =
107-
fs.readFileSync('./fixtures/www.theguardian.com/1480457558008.html');
108-
const url =
109-
'https://www.theguardian.com/us-news/2016/nov/29/standing-rock-protest-north-dakota-shutdown-evacuation';
110-
111-
const { content } =
112-
await Mercury.parse(url, html, { fallback: false });
113-
114-
const $ = cheerio.load(content || '');
115-
116-
const first13 = excerptContent($('*').first().text(), 13);
117-
118-
// Update these values with the expected values from
119-
// the article.
120-
assert.equal(first13, 'Police violence against Standing Rock protesters in North Dakota has risen to extraordinary');
11+
describe('initial test case', () => {
12+
let result;
13+
let url;
14+
beforeAll(() => {
15+
url =
16+
'https://www.theguardian.com/us-news/2016/nov/29/standing-rock-protest-north-dakota-shutdown-evacuation';
17+
const html =
18+
fs.readFileSync('./fixtures/www.theguardian.com/1480457558008.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.theguardian.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, 'Standing Rock protesters hold out against extraordinary police violence');
39+
});
40+
41+
it('returns the author', async () => {
42+
// To pass this test, fill out the author selector
43+
// in ./src/extractors/custom/www.theguardian.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, 'Julia Carrie Wong and Sam Levin');
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.theguardian.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-11-29T20:26:06.000Z');
59+
});
60+
61+
it('returns the dek', async () => {
62+
// To pass this test, fill out the dek selector
63+
// in ./src/extractors/custom/www.theguardian.com/index.js.
64+
const { dek } = await result;
65+
66+
// Update these values with the expected values from
67+
// the article.
68+
assert.equal(dek, 'Apprehension and distrust pervade North Dakota protest site as promises from state that there are no plans to forcibly remove people does little to assuage fears');
69+
});
70+
71+
it('returns the lead_image_url', async () => {
72+
// To pass this test, fill out the lead_image_url selector
73+
// in ./src/extractors/custom/www.theguardian.com/index.js.
74+
const { lead_image_url } = await result;
75+
76+
// Update these values with the expected values from
77+
// the article.
78+
assert.equal(lead_image_url, 'https://i.guim.co.uk/img/media/fc64982c5ab7b3ea7d5d38f3f74483c84c60b372/0_225_3500_2100/master/3500.jpg?w=1200&h=630&q=55&auto=format&usm=12&fit=crop&bm=normal&ba=bottom%2Cleft&blend64=aHR0cHM6Ly91cGxvYWRzLmd1aW0uY28udWsvMjAxNi8wNS8yNS9vdmVybGF5LWxvZ28tMTIwMC05MF9vcHQucG5n&s=034d7b3573a47c5ba3501a9e9e253a8f');
79+
});
80+
81+
it('returns the content', async () => {
82+
// To pass this test, fill out the content selector
83+
// in ./src/extractors/custom/www.theguardian.com/index.js.
84+
// You may also want to make use of the clean and transform
85+
// options.
86+
const { content } = await result;
87+
88+
const $ = cheerio.load(content || '');
89+
90+
const first13 = excerptContent($('*').first().text(), 13);
91+
92+
// Update these values with the expected values from
93+
// the article.
94+
assert.equal(first13, 'Police violence against Standing Rock protesters in North Dakota has risen to extraordinary');
95+
});
12196
});
12297
});

0 commit comments

Comments
 (0)