|
1 | | -/* eslint-disable |
2 | | - no-eval, |
3 | | - import/order, |
4 | | - arrow-parens, |
5 | | - prefer-destructuring, |
6 | | -*/ |
7 | | -import loader from '../src/'; |
8 | | - |
9 | | -import webpack from './webpack'; |
10 | | -import { stats } from './helpers'; |
| 1 | +/* eslint-disable */ |
| 2 | +import loader from '../src'; |
| 3 | +import webpack from './helpers/compiler'; |
11 | 4 |
|
12 | 5 | describe('Errors', () => { |
13 | | - test('ValidationError', () => { |
14 | | - const err = () => loader.call({ query: { root: 1 } }, '<html></html>'); |
| 6 | + test('Loader Error', async () => { |
| 7 | + const config = { |
| 8 | + loader: { |
| 9 | + test: /\.html$/, |
| 10 | + options: { |
| 11 | + minimize: true |
| 12 | + } |
| 13 | + } |
| 14 | + }; |
| 15 | + |
| 16 | + const stats = await webpack('error.js', config); |
| 17 | + const { source } = stats.toJson().modules[1]; |
| 18 | + |
| 19 | + // eslint-disable-next-line |
| 20 | + const err = () => eval(source); |
15 | 21 |
|
16 | 22 | expect(err).toThrow(); |
17 | 23 | expect(err).toThrowErrorMatchingSnapshot(); |
18 | 24 | }); |
19 | 25 |
|
20 | | - test('LoaderError', () => { |
21 | | - const config = {}; |
| 26 | + test('Validation Error', () => { |
| 27 | + const err = () => loader.call({ query: { template: 1 } }); |
22 | 28 |
|
23 | | - return webpack('index.js', config) |
24 | | - .then((result) => stats(result)) |
25 | | - .then(({ loaders }) => { |
26 | | - expect(() => eval(loaders.err)).toThrow(); |
27 | | - expect(() => eval(loaders.err)).toThrowErrorMatchingSnapshot(); |
28 | | - }) |
29 | | - .catch((err) => err); |
| 29 | + expect(err).toThrow(); |
| 30 | + expect(err).toThrowErrorMatchingSnapshot(); |
30 | 31 | }); |
31 | 32 | }); |
0 commit comments