-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest.js
36 lines (29 loc) · 1.02 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/* eslint-env jest */
const MemoryFS = require('memory-fs');
const webpack = require('webpack');
const {JSDOM} = require('jsdom');
const EmojiFaviconPlugin = require('.');
const HtmlPlugin = require('html-webpack-plugin');
const fs = new MemoryFS();
const compiler = webpack({
entry: __dirname + '/entry.js',
// the emoji supplied has multiple unicode characters
plugins: [new EmojiFaviconPlugin('👨💻'), new HtmlPlugin()]
});
compiler.outputFileSystem = fs;
test('generates a favicon and injects it into the HTML', done => {
compiler.run((err, stats) => {
if (err || stats.hasErrors()) {
done.fail();
return;
}
const {assets, outputPath} = stats.toJson();
const files = assets.map(asset => asset.name);
expect(files).toContain('favicon.ico');
const html = fs.readFileSync(`${outputPath}/index.html`);
const dom = new JSDOM(html);
const link = dom.window.document.querySelector('link[rel="shortcut icon"]');
expect(link.href).toEqual('favicon.ico');
done();
});
}, 10000);