Mailspring/internal_packages/message-list/spec/autolinker-spec.es6
Ben Gotow 465831175a rm(autolinker): Use our own very simple autolinker
Summary:
Autolinker is a great open source project but it attempts to parse HTML with regexp, is quite slow, and hangs on specific emails https://github.com/nylas/N1/issues/1540

This is super bad, and also super unnecessary. I think this should do the trick.

Note: I changed the urlRegex in our Utils to be much more liberal. It now matches anything that looks like a URL, not just things with the http:// and https:// prefixes. It's used in the LinkEditor and onboarding screen (detecting auth errors with urls) and I think it should be ok?

Test Plan: Need to write some tests

Reviewers: evan, juan

Reviewed By: juan

Differential Revision: https://phab.nylas.com/D2725
2016-03-14 12:30:54 -07:00

24 lines
803 B
JavaScript

import {autolink} from '../lib/autolinker';
import fs from 'fs';
import path from 'path';
describe("autolink", () => {
const fixturesDir = path.join(__dirname, 'autolinker-fixtures');
fs.readdirSync(fixturesDir).filter(filename =>
filename.indexOf('-in.html') !== -1
).forEach((filename) => {
it(`should properly autolink a variety of email bodies ${filename}`, () => {
const div = document.createElement('div');
const inputPath = path.join(fixturesDir, filename);
const expectedPath = inputPath.replace('-in', '-out');
const input = fs.readFileSync(inputPath).toString();
const expected = fs.readFileSync(expectedPath).toString();
div.innerHTML = input;
autolink({body: div});
expect(div.innerHTML).toEqual(expected);
});
});
});