Pass HTML instead of a JSDOM into isProbablyNewsletter to better encapsulate

This commit is contained in:
Jackson Harper 2022-03-02 20:38:11 -08:00
parent c4e237927d
commit 65cc666579
2 changed files with 8 additions and 8 deletions

View file

@ -379,7 +379,8 @@ export const parseMetadata = async (
// based on it's contents.
// TODO: when we consolidate the handlers we could include this
// as a utility method on each one.
export const isProbablyNewsletter = (dom: DOMWindow): boolean => {
export const isProbablyNewsletter = (html: string): boolean => {
const dom = new JSDOM(html).window
const domCopy = new JSDOM(dom.document.documentElement.outerHTML)
const article = new Readability(domCopy.window.document, {
debug: false,

View file

@ -6,16 +6,15 @@ import fs from 'fs'
import { isProbablyNewsletter } from '../../src/utils/parser'
describe('isProbablyNewsletter', () => {
const load = (path: string): JSDOM => {
const content = fs.readFileSync(path, 'utf8')
return new JSDOM(content);
const load = (path: string): string => {
return fs.readFileSync(path, 'utf8')
}
it('returns true for substack newsletter', () => {
const dom = load('./test/utils/data/substack-forwarded-newsletter.html')
isProbablyNewsletter(dom.window).should.be.true
const html = load('./test/utils/data/substack-forwarded-newsletter.html')
isProbablyNewsletter(html).should.be.true
})
it('returns false for substack welcome email', () => {
const dom = load('./test/utils/data/substack-forwarded-welcome-email.html')
isProbablyNewsletter(dom.window).should.be.false
const html = load('./test/utils/data/substack-forwarded-welcome-email.html')
isProbablyNewsletter(html).should.be.false
})
})