You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
mercury-parser/src/extractors/generic/index.test.js

55 lines
1.3 KiB
JavaScript

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

import assert from 'assert';
import fs from 'fs';
import GenericExtractor from './index';
describe('GenericExtractor', () => {
describe('extract(opts)', () => {
it('extracts this old LA Times article', () => {
const html = fs.readFileSync('../fixtures/latimes.html', 'utf-8');
const {
title,
author,
datePublished,
dek,
} = GenericExtractor.extract(
{ url: 'http://latimes.com', html, metaCache: [] }
);
assert.equal(author, null);
assert.equal(
title,
'California appears poised to be first to ban power-guzzling big-screen TVs'
);
assert.equal(
datePublished,
'2009-10-14T04:00:00.000Z'
);
assert.equal(dek, null);
});
it('extracts html and returns the article title', () => {
const html = fs.readFileSync('../fixtures/wired.html', 'utf-8');
const {
author,
title,
datePublished,
dek,
} = GenericExtractor.extract(
{ url: 'http://wired.com', html, metaCache: [] }
);
assert.equal(author, 'Eric Adams');
assert.equal(
title,
'Airplane Tires Dont Explode on Landing Because They Are Pumped!'
);
assert.equal(datePublished, null);
assert.equal(dek, null);
});
});
});