forked from alexpalombaro/modernizr-webpack-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmocha.entry.js
106 lines (93 loc) · 3.09 KB
/
mocha.entry.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*eslint-env node, mocha*/
var ModernizrWebpackPlugin = require('./index');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var Promise = require('bluebird');
var assign = require('object-assign');
var path = require('path');
var fs = Promise.promisifyAll(require('fs'));
var del = require('del');
var expect = require('chai').expect;
var OUTPUT_PATH = path.resolve(__dirname, 'temp');
var webpack = Promise.promisify(require('webpack'));
var webpackConfig;
var webpackConfigBase = {
context: __dirname,
entry: {
'entry-bundle': './tests/entry.js'
},
output: {
filename: '[name].js',
path: OUTPUT_PATH
}
};
describe('[ModernizrWebpackPlugin] Build Tests', function () {
beforeEach(function (done) {
// reset config to base status
webpackConfig = assign({}, webpackConfigBase);
del(OUTPUT_PATH).then(function () {
done();
});
});
it('should output a hashed filename', function (done) {
var config = {filename: 'testing[hash]'};
webpackConfig.plugins = [
new HtmlWebpackPlugin(),
new ModernizrWebpackPlugin(config)
];
webpack(webpackConfig).then(function (stats) {
var hashDigestLength = stats.compilation.hash;
return fs.readdirAsync(OUTPUT_PATH).then(function (files) {
var regexp = new RegExp('^testing' + hashDigestLength + '\\.js$');
files = files.filter(function (file) {
return regexp.test(file);
});
expect(files.length).to.equal(1);
done();
})
}).catch(done);
});
it('should output a chunkhashed filename', function (done) {
var config = {filename: 'testing[chunkhash]'};
webpackConfig.plugins = [
new HtmlWebpackPlugin(),
new ModernizrWebpackPlugin(config)
];
webpack(webpackConfig).then(function (stats) {
var hashDigestLength = stats.compilation.outputOptions.hashDigestLength;
return fs.readdirAsync(OUTPUT_PATH).then(function (files) {
var regexp = new RegExp('^testing[\\w\\d]{' + hashDigestLength + '}\\.js$');
files = files.filter(function (file) {
return regexp.test(file);
});
expect(files.length).to.equal(1);
done();
})
}).catch(done);
});
it('should include public path with html-webpack-plugin', function (done) {
webpackConfig.plugins = [
new HtmlWebpackPlugin(),
new ModernizrWebpackPlugin()
];
webpackConfig.output.publicPath = 'public/';
webpack(webpackConfig).then(function () {
fs.readFileAsync(path.resolve(OUTPUT_PATH, 'index.html'), 'utf8').then(function (data) {
expect(/<script\ssrc="public\/modernizr-bundle.js">/.test(data)).to.be.true;
done();
})
}).catch(done);
});
it('should output minified modernizr package', function (done) {
webpackConfig.plugins = [
new ModernizrWebpackPlugin({
minify:true
})
];
webpack(webpackConfig).then(function () {
fs.readFileAsync(path.resolve(OUTPUT_PATH, 'modernizr-bundle.js'), 'utf8').then(function (data) {
expect(/\r|\n/.test(data)).to.be.false;
done();
});
}).catch(done)
})
});