UNPKG

764 BJavaScriptView Raw
1import path from 'path';
2import webpack from 'webpack';
3import MemoryFS from 'memory-fs';
4
5export default function test(fixture, options = {}) {
6 const compiler = webpack({
7 context: __dirname,
8 entry: `./${fixture}`,
9 output: {
10 filename: 'test-out.js',
11 path: path.resolve(__dirname),
12 },
13 module: {
14 rules: [
15 {
16 test: /\.css$/,
17 use: [
18 {loader: path.resolve(__dirname, '../../index.js'), options},
19 {loader: 'css-loader'},
20 ],
21 },
22 ],
23 },
24 });
25
26 compiler.outputFileSystem = new MemoryFS();
27
28 return new Promise((resolve, reject) => {
29 compiler.run((err, stats) => {
30 if (err) {
31 reject(err);
32 }
33
34 resolve(stats);
35 });
36 });
37}