Skip to content

Commit

Permalink
test: isolate webpack context for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
brunocodutra authored and jantimon committed Aug 14, 2019
1 parent eb29e2a commit 2e6d2ee
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 32 deletions.
18 changes: 13 additions & 5 deletions test/default.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,22 @@ import path from 'path';
import fs from 'fs-extra';
import FaviconsWebpackPlugin from '..';

import {logo, generate, compare, expected} from './util';
import {logo, generate, mkdir, compare, expected} from './util';

test('should generate the expected default result', async t => {
const stats = await generate({plugins: [new FaviconsWebpackPlugin({logo})]});
t.context.root = await mkdir();
const dist = path.join(t.context.root, 'dist');
const stats = await generate({
context: t.context.root,
output: {
path: dist,
},
plugins: [new FaviconsWebpackPlugin({logo})]
});

t.context.dist = stats.compilation.compiler.outputPath;
const diff = await compare(t.context.dist, path.resolve(expected, 'default'));

const diff = await compare(dist, path.resolve(expected, 'default'));
t.deepEqual(diff, []);
});

test.afterEach(t => fs.remove(t.context.dist));
test.afterEach(t => fs.remove(t.context.root));
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "favicons-webpack-plugin",
"short_name": "favicons-webpack-plugin",
"description": "Let webpack generate all your favicons and icons for you",
"name": null,
"short_name": null,
"description": null,
"dir": "auto",
"lang": "en-US",
"display": "standalone",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"version": "1.0.0",
"name": "favicons-webpack-plugin",
"description": "Let webpack generate all your favicons and icons for you",
"version": "1.0",
"name": null,
"description": null,
"icons": {
"60": "firefox_app_60x60.png",
"128": "firefox_app_128x128.png",
"512": "firefox_app_512x512.png"
},
"developer": {
"name": "Jan Nicklas",
"url": "https://github.com/jantimon"
"name": null,
"url": null
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"version": "1.0.0",
"version": "1.0",
"api_version": 1,
"layout": {
"logo": "yandex-browser-50x50.png",
"color": "#fff",
"show_title": true
}
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"version": "1.0.0",
"name": "favicons-webpack-plugin",
"description": "Let webpack generate all your favicons and icons for you",
"version": "1.0",
"name": null,
"description": null,
"icons": {
"60": "firefox_app_60x60.png",
"128": "firefox_app_128x128.png",
"512": "firefox_app_512x512.png"
},
"developer": {
"name": "Jan Nicklas",
"url": "https://github.com/jantimon"
"name": null,
"url": null
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"version": "1.0.0",
"version": "1.0",
"api_version": 1,
"layout": {
"logo": "yandex-browser-50x50.png",
"color": "#fff",
"show_title": true
}
}
}
2 changes: 1 addition & 1 deletion test/fixtures/expected/generate-html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8">
<title>Webpack App</title>
<link rel="apple-touch-icon" sizes="114x114" href="assets-d7623eb944cd4f7d2cd59efc84d5b410/apple-touch-icon-114x114.png"><link rel="apple-touch-icon" sizes="120x120" href="assets-d7623eb944cd4f7d2cd59efc84d5b410/apple-touch-icon-120x120.png"><link rel="apple-touch-icon" sizes="144x144" href="assets-d7623eb944cd4f7d2cd59efc84d5b410/apple-touch-icon-144x144.png"><link rel="apple-touch-icon" sizes="152x152" href="assets-d7623eb944cd4f7d2cd59efc84d5b410/apple-touch-icon-152x152.png"><link rel="apple-touch-icon" sizes="180x180" href="assets-d7623eb944cd4f7d2cd59efc84d5b410/apple-touch-icon-180x180.png"><link rel="apple-touch-icon" sizes="57x57" href="assets-d7623eb944cd4f7d2cd59efc84d5b410/apple-touch-icon-57x57.png"><link rel="apple-touch-icon" sizes="60x60" href="assets-d7623eb944cd4f7d2cd59efc84d5b410/apple-touch-icon-60x60.png"><link rel="apple-touch-icon" sizes="72x72" href="assets-d7623eb944cd4f7d2cd59efc84d5b410/apple-touch-icon-72x72.png"><link rel="apple-touch-icon" sizes="76x76" href="assets-d7623eb944cd4f7d2cd59efc84d5b410/apple-touch-icon-76x76.png"><link rel="apple-touch-startup-image" media="(device-width: 320px) and (device-height: 480px) and (-webkit-device-pixel-ratio: 1)" href="assets-d7623eb944cd4f7d2cd59efc84d5b410/apple-touch-startup-image-320x460.png"><link rel="apple-touch-startup-image" media="(device-width: 320px) and (device-height: 480px) and (-webkit-device-pixel-ratio: 2)" href="assets-d7623eb944cd4f7d2cd59efc84d5b410/apple-touch-startup-image-640x920.png"><link rel="apple-touch-startup-image" media="(device-width: 320px) and (device-height: 568px) and (-webkit-device-pixel-ratio: 2)" href="assets-d7623eb944cd4f7d2cd59efc84d5b410/apple-touch-startup-image-640x1096.png"><link rel="apple-touch-startup-image" media="(device-width: 375px) and (device-height: 667px) and (-webkit-device-pixel-ratio: 2)" href="assets-d7623eb944cd4f7d2cd59efc84d5b410/apple-touch-startup-image-750x1294.png"><link rel="apple-touch-startup-image" media="(device-width: 414px) and (device-height: 736px) and (orientation: landscape) and (-webkit-device-pixel-ratio: 3)" href="assets-d7623eb944cd4f7d2cd59efc84d5b410/apple-touch-startup-image-1182x2208.png"><link rel="apple-touch-startup-image" media="(device-width: 414px) and (device-height: 736px) and (orientation: portrait) and (-webkit-device-pixel-ratio: 3)" href="assets-d7623eb944cd4f7d2cd59efc84d5b410/apple-touch-startup-image-1242x2148.png"><link rel="apple-touch-startup-image" media="(device-width: 768px) and (device-height: 1024px) and (orientation: landscape) and (-webkit-device-pixel-ratio: 1)" href="assets-d7623eb944cd4f7d2cd59efc84d5b410/apple-touch-startup-image-748x1024.png"><link rel="apple-touch-startup-image" media="(device-width: 768px) and (device-height: 1024px) and (orientation: landscape) and (-webkit-device-pixel-ratio: 2)" href="assets-d7623eb944cd4f7d2cd59efc84d5b410/apple-touch-startup-image-1496x2048.png"><link rel="apple-touch-startup-image" media="(device-width: 768px) and (device-height: 1024px) and (orientation: portrait) and (-webkit-device-pixel-ratio: 1)" href="assets-d7623eb944cd4f7d2cd59efc84d5b410/apple-touch-startup-image-768x1004.png"><link rel="apple-touch-startup-image" media="(device-width: 768px) and (device-height: 1024px) and (orientation: portrait) and (-webkit-device-pixel-ratio: 2)" href="assets-d7623eb944cd4f7d2cd59efc84d5b410/apple-touch-startup-image-1536x2008.png"><link rel="icon" type="image/png" sizes="16x16" href="assets-d7623eb944cd4f7d2cd59efc84d5b410/favicon-16x16.png"><link rel="icon" type="image/png" sizes="228x228" href="assets-d7623eb944cd4f7d2cd59efc84d5b410/coast-228x228.png"><link rel="icon" type="image/png" sizes="32x32" href="assets-d7623eb944cd4f7d2cd59efc84d5b410/favicon-32x32.png"><link rel="manifest" href="assets-d7623eb944cd4f7d2cd59efc84d5b410/manifest.json"><link rel="shortcut icon" href="assets-d7623eb944cd4f7d2cd59efc84d5b410/favicon.ico"><link rel="yandex-tableau-widget" href="assets-d7623eb944cd4f7d2cd59efc84d5b410/yandex-browser-manifest.json"><meta name="apple-mobile-web-app-capable" content="yes"><meta name="apple-mobile-web-app-status-bar-style" content="black-translucent"><meta name="apple-mobile-web-app-title" content="favicons-webpack-plugin"><meta name="application-name" content="favicons-webpack-plugin"><meta name="mobile-web-app-capable" content="yes"><meta name="msapplication-TileColor" content="#fff"><meta name="msapplication-TileImage" content="mstile-144x144.png"><meta name="msapplication-config" content="browserconfig.xml"><meta name="theme-color" content="#fff"></head>
<link rel="apple-touch-icon" sizes="114x114" href="assets-d7623eb944cd4f7d2cd59efc84d5b410/apple-touch-icon-114x114.png"><link rel="apple-touch-icon" sizes="120x120" href="assets-d7623eb944cd4f7d2cd59efc84d5b410/apple-touch-icon-120x120.png"><link rel="apple-touch-icon" sizes="144x144" href="assets-d7623eb944cd4f7d2cd59efc84d5b410/apple-touch-icon-144x144.png"><link rel="apple-touch-icon" sizes="152x152" href="assets-d7623eb944cd4f7d2cd59efc84d5b410/apple-touch-icon-152x152.png"><link rel="apple-touch-icon" sizes="180x180" href="assets-d7623eb944cd4f7d2cd59efc84d5b410/apple-touch-icon-180x180.png"><link rel="apple-touch-icon" sizes="57x57" href="assets-d7623eb944cd4f7d2cd59efc84d5b410/apple-touch-icon-57x57.png"><link rel="apple-touch-icon" sizes="60x60" href="assets-d7623eb944cd4f7d2cd59efc84d5b410/apple-touch-icon-60x60.png"><link rel="apple-touch-icon" sizes="72x72" href="assets-d7623eb944cd4f7d2cd59efc84d5b410/apple-touch-icon-72x72.png"><link rel="apple-touch-icon" sizes="76x76" href="assets-d7623eb944cd4f7d2cd59efc84d5b410/apple-touch-icon-76x76.png"><link rel="apple-touch-startup-image" media="(device-width: 320px) and (device-height: 480px) and (-webkit-device-pixel-ratio: 1)" href="assets-d7623eb944cd4f7d2cd59efc84d5b410/apple-touch-startup-image-320x460.png"><link rel="apple-touch-startup-image" media="(device-width: 320px) and (device-height: 480px) and (-webkit-device-pixel-ratio: 2)" href="assets-d7623eb944cd4f7d2cd59efc84d5b410/apple-touch-startup-image-640x920.png"><link rel="apple-touch-startup-image" media="(device-width: 320px) and (device-height: 568px) and (-webkit-device-pixel-ratio: 2)" href="assets-d7623eb944cd4f7d2cd59efc84d5b410/apple-touch-startup-image-640x1096.png"><link rel="apple-touch-startup-image" media="(device-width: 375px) and (device-height: 667px) and (-webkit-device-pixel-ratio: 2)" href="assets-d7623eb944cd4f7d2cd59efc84d5b410/apple-touch-startup-image-750x1294.png"><link rel="apple-touch-startup-image" media="(device-width: 414px) and (device-height: 736px) and (orientation: landscape) and (-webkit-device-pixel-ratio: 3)" href="assets-d7623eb944cd4f7d2cd59efc84d5b410/apple-touch-startup-image-1182x2208.png"><link rel="apple-touch-startup-image" media="(device-width: 414px) and (device-height: 736px) and (orientation: portrait) and (-webkit-device-pixel-ratio: 3)" href="assets-d7623eb944cd4f7d2cd59efc84d5b410/apple-touch-startup-image-1242x2148.png"><link rel="apple-touch-startup-image" media="(device-width: 768px) and (device-height: 1024px) and (orientation: landscape) and (-webkit-device-pixel-ratio: 1)" href="assets-d7623eb944cd4f7d2cd59efc84d5b410/apple-touch-startup-image-748x1024.png"><link rel="apple-touch-startup-image" media="(device-width: 768px) and (device-height: 1024px) and (orientation: landscape) and (-webkit-device-pixel-ratio: 2)" href="assets-d7623eb944cd4f7d2cd59efc84d5b410/apple-touch-startup-image-1496x2048.png"><link rel="apple-touch-startup-image" media="(device-width: 768px) and (device-height: 1024px) and (orientation: portrait) and (-webkit-device-pixel-ratio: 1)" href="assets-d7623eb944cd4f7d2cd59efc84d5b410/apple-touch-startup-image-768x1004.png"><link rel="apple-touch-startup-image" media="(device-width: 768px) and (device-height: 1024px) and (orientation: portrait) and (-webkit-device-pixel-ratio: 2)" href="assets-d7623eb944cd4f7d2cd59efc84d5b410/apple-touch-startup-image-1536x2008.png"><link rel="icon" type="image/png" sizes="16x16" href="assets-d7623eb944cd4f7d2cd59efc84d5b410/favicon-16x16.png"><link rel="icon" type="image/png" sizes="228x228" href="assets-d7623eb944cd4f7d2cd59efc84d5b410/coast-228x228.png"><link rel="icon" type="image/png" sizes="32x32" href="assets-d7623eb944cd4f7d2cd59efc84d5b410/favicon-32x32.png"><link rel="manifest" href="assets-d7623eb944cd4f7d2cd59efc84d5b410/manifest.json"><link rel="shortcut icon" href="assets-d7623eb944cd4f7d2cd59efc84d5b410/favicon.ico"><link rel="yandex-tableau-widget" href="assets-d7623eb944cd4f7d2cd59efc84d5b410/yandex-browser-manifest.json"><meta name="apple-mobile-web-app-capable" content="yes"><meta name="apple-mobile-web-app-status-bar-style" content="black-translucent"><meta name="apple-mobile-web-app-title"><meta name="application-name"><meta name="mobile-web-app-capable" content="yes"><meta name="msapplication-TileColor" content="#fff"><meta name="msapplication-TileImage" content="mstile-144x144.png"><meta name="msapplication-config" content="browserconfig.xml"><meta name="theme-color" content="#fff"></head>
<body>
</body>
</html>
13 changes: 9 additions & 4 deletions test/html.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,24 @@ import fs from 'fs-extra';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import FaviconsWebpackPlugin from '..';

import {logo, generate, compare, expected} from './util';
import {logo, mkdir, generate, compare, expected} from './util';

test('should work together with the html-webpack-plugin', async t => {
t.context.root = await mkdir();
const dist = path.join(t.context.root, 'dist');
const stats = await generate({
context: t.context.root,
output: {
path: dist,
},
plugins: [
new HtmlWebpackPlugin(),
new FaviconsWebpackPlugin({logo}),
],
});

t.context.dist = stats.compilation.compiler.outputPath;
const diff = await compare(t.context.dist, path.resolve(expected, 'html'));
const diff = await compare(dist, path.resolve(expected, 'html'));
t.deepEqual(diff, []);
});

test.afterEach(t => fs.remove(t.context.dist));
test.afterEach(t => fs.remove(t.context.root));
9 changes: 4 additions & 5 deletions test/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@ const fixtures = path.resolve(__dirname, 'fixtures');
module.exports.expected = path.resolve(fixtures, 'expected');
module.exports.logo = path.resolve(fixtures, 'logo.svg');

module.exports.generate = async (config) => {
module.exports.mkdir = () => fs.mkdtemp(path.join(os.tmpdir(), 'WWP'));

module.exports.generate = (config) => {
config = merge(
{
entry: path.resolve(fixtures, 'entry.js'),
output: {
path: await fs.mkdtemp(path.join(os.tmpdir(), 'WWP')),
},
},
config,
);
Expand All @@ -40,7 +39,7 @@ module.exports.generate = async (config) => {
callback();
});

return await new Promise((resolve, reject) => {
return new Promise((resolve, reject) => {
compiler.run((err, stats) => (err || stats.hasErrors())
? reject(err || stats.toJson().errors)
: resolve(stats)
Expand Down

0 comments on commit 2e6d2ee

Please sign in to comment.