-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
128 lines (96 loc) · 4.51 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
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
const fs = require('fs');
const path = require('path');
const assert = require('assert');
const EC = require('eight-colors');
const Util = require('../lib/util.js');
const options = require('../lib/options.js');
console.log('==================================================================');
console.log('test formatMatchPath');
assert.strictEqual(Util.formatMatchPath('a/b/c'), 'a/b/c');
assert.strictEqual(Util.formatMatchPath('.a/b/c'), 'a/b/c');
assert.strictEqual(Util.formatMatchPath('./a/b/c'), 'a/b/c');
assert.strictEqual(Util.formatMatchPath('../a/b/c'), 'a/b/c');
assert.strictEqual(Util.formatMatchPath('../../a/b/c'), 'a/b/c');
assert.strictEqual(Util.formatMatchPath('../../../a/b/c'), 'a/b/c');
assert.strictEqual(Util.formatMatchPath('./../../a/b/c'), 'a/b/c');
assert.strictEqual(Util.formatMatchPath('../../a/b/c/../'), 'a/b/c/../');
console.log('==================================================================');
console.log('test isMatch source');
const sourcePatterns = options.moduleTypes.source.patterns;
assert.strictEqual(Util.isMatch('./packages/home/src/components/ sync \\.js$', sourcePatterns), true);
assert.strictEqual(Util.isMatch('./src/components/ sync \\.js$', sourcePatterns), true);
assert.strictEqual(Util.isMatch('./src/mixin/ sync \\.js$', sourcePatterns), true);
assert.strictEqual(Util.isMatch('/test/cases sync ^\\.\\/[^/]+\\/[^/]+\\/index\\.js$', sourcePatterns), false);
assert.strictEqual(Util.isMatch('multi ./src/main.ts', sourcePatterns), true);
console.log('==================================================================');
console.log('test isMatch external');
const externalPatterns = options.moduleTypes.external.patterns;
assert.strictEqual(Util.isMatch('external "name"', externalPatterns), true);
assert.strictEqual(Util.isMatch('external "pre-name"', externalPatterns), true);
assert.strictEqual(Util.isMatch('external "node_modules/pre-name"', externalPatterns), true);
assert.strictEqual(Util.isMatch('external "@package/pre-name"', externalPatterns), true);
assert.strictEqual(Util.isMatch('external "@pre-package/pre-name"', externalPatterns), true);
console.log('==================================================================');
console.log('test isMatch loader');
const loaderPatterns = options.moduleTypes.loader.patterns;
assert.strictEqual(Util.isMatch('../d-loader', loaderPatterns), false);
assert.strictEqual(Util.isMatch('../node_modules/xxx-loader/path-to', loaderPatterns), true);
assert.strictEqual(Util.isMatch('../../node_modules/xxx-loader/path-to', loaderPatterns), true);
// console.log('==================================================================');
// console.log('test StatsReportGenerator');
console.log('==================================================================');
console.log('test webpack build');
const testOutputPath = path.resolve(__dirname, '../docs/stats-report-test.html');
const webpack = require('webpack');
const getWebpackConf = function() {
const webpackConf = require('../webpack.config.js');
// webpackConf.mode = 'development';
webpackConf.entry = {
entry1: path.resolve(__dirname, 'src/entry1.js'),
entry2: path.resolve(__dirname, 'src/entry2.js')
};
webpackConf.output = {
path: path.resolve(__dirname, '../.temp'),
umdNamedDefine: true,
library: 'test',
libraryTarget: 'umd'
};
const StatsReportPlugin = require('../lib/index.js').StatsReportPlugin;
const VueLoaderPlugin = require('vue-loader').VueLoaderPlugin;
webpackConf.plugins = [
new VueLoaderPlugin(),
// new webpack.IgnorePlugin({
// resourceRegExp: /^\.\/locale$/,
// contextRegExp: /moment$/
// }),
new StatsReportPlugin({
title: 'Stats Report - test',
output: testOutputPath,
outputStatsJson: true,
gzipSize: true
})
];
webpackConf.externals = ['vue'];
return webpackConf;
};
const conf = getWebpackConf();
webpack(conf, function(err, stats) {
if (err) {
console.log(err.stack || err);
if (err.details) {
console.log(err.details);
}
return;
}
const info = stats.toJson();
// error for project
if (stats.hasErrors()) {
EC.logRed(`ERROR: Found ${info.errors.length} Errors`);
}
if (stats.hasWarnings()) {
EC.logYellow(`WARN: Found ${info.warnings.length} Warnings`);
}
console.log('webpack build finish');
console.log(testOutputPath);
assert(fs.existsSync(testOutputPath));
});