Skip to content
This repository has been archived by the owner on Mar 8, 2020. It is now read-only.

Commit

Permalink
test cache functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
brunocodutra committed Mar 17, 2018
1 parent 1a8bafd commit 1455b4f
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 8 deletions.
24 changes: 24 additions & 0 deletions test/cache.custom.test.js
@@ -0,0 +1,24 @@
const test = require('ava');
const path = require('path');
const fs = require('fs-extra');
const WebappWebpackPlugin = require('../src');

const {logo, mkdir, generate} = require('./util');

test.beforeEach(async t => t.context.root = await mkdir());

test('should allow configuring cache directory', async t => {
const dist = path.join(t.context.root, 'dist');
const cache = path.join(t.context.root, 'cache');
await generate({
context: t.context.root,
output: {
path: dist,
},
plugins: [new WebappWebpackPlugin({logo, cache})],
});

t.deepEqual(fs.readdirSync(t.context.root).sort(), ['cache', 'dist']);
});

test.afterEach(t => fs.remove(t.context.root));
24 changes: 24 additions & 0 deletions test/cache.default.test.js
@@ -0,0 +1,24 @@
const test = require('ava');
const path = require('path');
const fs = require('fs-extra');
const WebappWebpackPlugin = require('../src');

const {logo, mkdir, generate} = require('./util');

test.beforeEach(async t => t.context.root = await mkdir());

test('should cache assets', async t => {
const plugin = new WebappWebpackPlugin({logo});
await generate({
context: t.context.root,
output: {
path: path.join(t.context.root, 'dist'),
},
plugins: [plugin],
});

const cache = path.relative(t.context.root, plugin.options.cache);
t.deepEqual(fs.readdirSync(t.context.root).sort(), [cache, 'dist'].sort());
});

test.afterEach(t => fs.remove(t.context.root));
23 changes: 23 additions & 0 deletions test/cache.disabled.test.js
@@ -0,0 +1,23 @@
const test = require('ava');
const path = require('path');
const fs = require('fs-extra');
const WebappWebpackPlugin = require('../src');

const {logo, mkdir, generate} = require('./util');

test.beforeEach(async t => t.context.root = await mkdir());

test('should allow disabling caching', async t => {
const dist = path.join(t.context.root, 'dist');
await generate({
context: t.context.root,
output: {
path: dist,
},
plugins: [new WebappWebpackPlugin({logo, cache: false})],
});

t.deepEqual(fs.readdirSync(t.context.root), ['dist']);
});

test.afterEach(t => fs.remove(t.context.root));
8 changes: 4 additions & 4 deletions test/default.test.js
Expand Up @@ -5,19 +5,19 @@ const WebappWebpackPlugin = require('../src');

const {logo, generate, mkdir, compare, expected} = require('./util');

test.beforeEach(async t => t.context.root = await mkdir());

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

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

test.afterEach(t => fs.remove(t.context.root));
8 changes: 4 additions & 4 deletions test/html.test.js
Expand Up @@ -6,10 +6,11 @@ const WebappWebpackPlugin = require('../src');

const {logo, mkdir, generate, compare, expected} = require('./util');

test.beforeEach(async t => t.context.root = await mkdir());

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({
await generate({
context: t.context.root,
output: {
path: dist,
Expand All @@ -20,8 +21,7 @@ test('should work together with the html-webpack-plugin', async t => {
],
});

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

test.afterEach(t => fs.remove(t.context.root));

0 comments on commit 1455b4f

Please sign in to comment.