-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.test.ts
102 lines (88 loc) · 3.17 KB
/
index.test.ts
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
/*
* Copyright (c) Trainline Limited, 2020. All rights reserved.
* See LICENSE.md in the project root for license information.
*/
import RestrictPlugin from './index';
import baseCompilationStats from '../../../test/fixtures/base-compilation-stats.json';
import headCompilationStats from '../../../test/fixtures/head-compilation-stats.json';
import { RestrictConfig } from './config';
import { defaultBasePluginConfig } from '../../config/PluginConfig';
import { Stats4 } from '../../types';
import normalizeStats from '../../helpers/normalizeStats';
const normalizedBaseStats = normalizeStats((baseCompilationStats as unknown) as Stats4);
const normalizedHeadStats = normalizeStats((headCompilationStats as unknown) as Stats4);
const restrictConfig: RestrictConfig = {
showExisting: false,
chunkFilename: defaultBasePluginConfig.chunkFilename,
restrictions: [
{
search: './src/private/common/components/section-error-fallback/index.jsx',
responseType: 'warn',
message: 'no section error fallback component',
},
{ search: 'lodash.omitby', responseType: 'error', message: 'no lodash.omitby' },
],
};
describe('RestrictPlugin', () => {
let restrictPlugin: RestrictPlugin;
describe('only new restrictions', () => {
beforeEach(() => {
restrictPlugin = new RestrictPlugin({
baseCompilationStats: normalizedBaseStats,
headCompilationStats: normalizedHeadStats,
config: {
...restrictConfig,
showExisting: false,
},
});
});
it('returns summary', () => {
expect(restrictPlugin.summaryOutput()).toBe('1 restricted file found');
});
it('returns errorMessages', () => {
expect(restrictPlugin.errorMessages()).toEqual([]);
});
it('returns warningMessages', () => {
expect(restrictPlugin.warningMessages()).toEqual([
'./src/private/common/components/section-error-fallback/index.jsx is restricted',
]);
});
it('returns danger output', () => {
expect(restrictPlugin.dangerOutput()).toMatchSnapshot();
});
it('returns cli output', () => {
expect(restrictPlugin.cliOutput()).toMatchSnapshot();
});
});
describe('existing restrictions', () => {
beforeEach(() => {
restrictPlugin = new RestrictPlugin({
baseCompilationStats: normalizedBaseStats,
headCompilationStats: normalizedHeadStats,
config: {
...restrictConfig,
showExisting: true,
},
});
});
it('returns summary', () => {
expect(restrictPlugin.summaryOutput()).toBe('2 restricted files found');
});
it('returns errorMessages', () => {
expect(restrictPlugin.errorMessages()).toEqual([
'./node_modules/lodash.omitby/index.js is restricted',
]);
});
it('returns warningMessages', () => {
expect(restrictPlugin.warningMessages()).toEqual([
'./src/private/common/components/section-error-fallback/index.jsx is restricted',
]);
});
it('returns danger output', () => {
expect(restrictPlugin.dangerOutput()).toMatchSnapshot();
});
it('returns cli output', () => {
expect(restrictPlugin.cliOutput()).toMatchSnapshot();
});
});
});