|
1 |
| -/* eslint-disable */ |
2 |
| -import fs from "fs"; |
3 |
| -import vm from "vm"; |
4 |
| -import path from "path"; |
5 |
| -import webpack from "webpack"; |
| 1 | +/* eslint-disable import/no-dynamic-require, global-require */ |
| 2 | +import fs from 'fs'; |
| 3 | +import path from 'path'; |
| 4 | +import webpack from 'webpack'; |
6 | 5 | import ExtractTextPlugin from '../src';
|
7 | 6 |
|
8 |
| -var cases = process.env.CASES ? process.env.CASES.split(",") : fs.readdirSync(path.join(__dirname, "cases")); |
| 7 | +const cases = process.env.CASES ? process.env.CASES.split(',') : fs.readdirSync(path.join(__dirname, 'cases')); |
9 | 8 |
|
10 |
| -describe("Webpack Integration Tests", function() { |
11 |
| - cases.forEach(function(testCase) { |
12 |
| - it(testCase, function(done) { |
13 |
| - var testDirectory = path.join(__dirname, "cases", testCase); |
14 |
| - var outputDirectory = path.join(__dirname, "js", testCase); |
15 |
| - var options = { entry: { test: "./index.js" } }; |
16 |
| - var configFile = path.join(testDirectory, "webpack.config.js"); |
17 |
| - if(fs.existsSync(configFile)) |
18 |
| - options = require(configFile); |
19 |
| - options.context = testDirectory; |
20 |
| - if(!options.module) options.module = {}; |
21 |
| - if(!options.module.loaders) options.module.loaders = [ |
22 |
| - { test: /\.txt$/, loader: ExtractTextPlugin.extract('raw-loader') } |
23 |
| - ]; |
24 |
| - if(!options.output) options.output = { filename: "[name].js" }; |
25 |
| - if(!options.output.path) options.output.path = outputDirectory; |
26 |
| - if(process.env.CASES) { |
27 |
| - console.log("\nwebpack." + testCase + ".config.js " + JSON.stringify(options, null, 2)); |
28 |
| - } |
29 |
| - webpack(options, function(err, stats) { |
30 |
| - if(err) return done(err); |
31 |
| - if(stats.hasErrors()) return done(new Error(stats.toString())); |
32 |
| - var testFile = path.join(outputDirectory, "test.js"); |
33 |
| - if(fs.existsSync(testFile)) |
34 |
| - require(testFile)(suite); |
35 |
| - var expectedDirectory = path.join(testDirectory, "expected"); |
36 |
| - fs.readdirSync(expectedDirectory).forEach(function(file) { |
37 |
| - var filePath = path.join(expectedDirectory, file); |
38 |
| - var actualPath = path.join(outputDirectory, file); |
| 9 | +describe('Webpack Integration Tests', () => { |
| 10 | + cases.forEach((testCase) => { |
| 11 | + it(testCase, (done) => { |
| 12 | + let options = { entry: { test: './index.js' } }; |
| 13 | + const testDirectory = path.join(__dirname, 'cases', testCase); |
| 14 | + const outputDirectory = path.join(__dirname, 'js', testCase); |
| 15 | + const configFile = path.join(testDirectory, 'webpack.config.js'); |
| 16 | + |
| 17 | + if (fs.existsSync(configFile)) { |
| 18 | + options = require(configFile); |
| 19 | + } |
| 20 | + options.context = testDirectory; |
| 21 | + if (!options.module) options.module = {}; |
| 22 | + if (!options.module.loaders) { |
| 23 | + options.module.loaders = [{ test: /\.txt$/, loader: ExtractTextPlugin.extract('raw-loader') }]; |
| 24 | + } |
| 25 | + if (!options.output) options.output = { filename: '[name].js' }; |
| 26 | + if (!options.output.path) options.output.path = outputDirectory; |
| 27 | + if (process.env.CASES) { |
| 28 | + console.log(`\nwebpack.${testCase}.config.js ${JSON.stringify(options, null, 2)}`); |
| 29 | + } |
| 30 | + |
| 31 | + webpack(options, (err, stats) => { |
| 32 | + if (err) return done(err); |
| 33 | + if (stats.hasErrors()) return done(new Error(stats.toString())); |
| 34 | + const testFile = path.join(outputDirectory, 'test.js'); |
| 35 | + if (fs.existsSync(testFile)) { |
| 36 | + require(testFile)(suite); |
| 37 | + } |
| 38 | + const expectedDirectory = path.join(testDirectory, 'expected'); |
| 39 | + fs.readdirSync(expectedDirectory).forEach((file) => { |
| 40 | + const filePath = path.join(expectedDirectory, file); |
| 41 | + const actualPath = path.join(outputDirectory, file); |
39 | 42 | expect(readFileOrEmpty(actualPath)).toEqual(readFileOrEmpty(filePath));
|
40 | 43 | expect(readFileOrEmpty(actualPath)).toMatchSnapshot();
|
41 |
| - }); |
42 |
| - done(); |
43 |
| - }); |
44 |
| - }); |
45 |
| - }); |
| 44 | + }); |
| 45 | + done(); |
| 46 | + }); |
| 47 | + }); |
| 48 | + }); |
46 | 49 | });
|
47 | 50 |
|
48 | 51 | function readFileOrEmpty(path) {
|
49 |
| - try { |
50 |
| - return fs.readFileSync(path, "utf-8"); |
51 |
| - } catch(e) { |
52 |
| - return ""; |
53 |
| - } |
| 52 | + try { |
| 53 | + return fs.readFileSync(path, 'utf-8'); |
| 54 | + } catch (e) { |
| 55 | + return ''; |
| 56 | + } |
54 | 57 | }
|
0 commit comments