1 | 'use strict';
|
2 |
|
3 | var _ava = require('ava');
|
4 |
|
5 | var _ava2 = _interopRequireDefault(_ava);
|
6 |
|
7 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
8 |
|
9 | const proxyquire = require('proxyquire').noCallThru().noPreserveCache();
|
10 |
|
11 | _ava2.default.beforeEach(t => {
|
12 | const plugins = {};
|
13 | const plugin = {};
|
14 | const scopedPlugin = {};
|
15 | const stubbedLoadPlugin = proxyquire('./loadPlugin', {
|
16 | 'commitlint-plugin-example': plugin,
|
17 | '@scope/commitlint-plugin-example': scopedPlugin
|
18 | });
|
19 | t.context.data = {
|
20 | plugins,
|
21 | plugin,
|
22 | scopedPlugin,
|
23 | stubbedLoadPlugin
|
24 | };
|
25 | });
|
26 |
|
27 | (0, _ava2.default)('should load a plugin when referenced by short name', t => {
|
28 | var _t$context$data = t.context.data;
|
29 | const stubbedLoadPlugin = _t$context$data.stubbedLoadPlugin,
|
30 | plugins = _t$context$data.plugins,
|
31 | plugin = _t$context$data.plugin;
|
32 |
|
33 | stubbedLoadPlugin(plugins, 'example');
|
34 | t.is(plugins['example'], plugin);
|
35 | });
|
36 |
|
37 | (0, _ava2.default)('should load a plugin when referenced by long name', t => {
|
38 | var _t$context$data2 = t.context.data;
|
39 | const stubbedLoadPlugin = _t$context$data2.stubbedLoadPlugin,
|
40 | plugins = _t$context$data2.plugins,
|
41 | plugin = _t$context$data2.plugin;
|
42 |
|
43 | stubbedLoadPlugin(plugins, 'commitlint-plugin-example');
|
44 | t.is(plugins['example'], plugin);
|
45 | });
|
46 |
|
47 | (0, _ava2.default)('should throw an error when a plugin has whitespace', t => {
|
48 | var _t$context$data3 = t.context.data;
|
49 | const stubbedLoadPlugin = _t$context$data3.stubbedLoadPlugin,
|
50 | plugins = _t$context$data3.plugins;
|
51 |
|
52 | t.throws(() => {
|
53 | stubbedLoadPlugin(plugins, 'whitespace ');
|
54 | }, /Whitespace found in plugin name 'whitespace '/u);
|
55 | t.throws(() => {
|
56 | stubbedLoadPlugin(plugins, 'whitespace\t');
|
57 | }, /Whitespace found in plugin name/u);
|
58 | t.throws(() => {
|
59 | stubbedLoadPlugin(plugins, 'whitespace\n');
|
60 | }, /Whitespace found in plugin name/u);
|
61 | t.throws(() => {
|
62 | stubbedLoadPlugin(plugins, 'whitespace\r');
|
63 | }, /Whitespace found in plugin name/u);
|
64 | });
|
65 |
|
66 | (0, _ava2.default)("should throw an error when a plugin doesn't exist", t => {
|
67 | var _t$context$data4 = t.context.data;
|
68 | const stubbedLoadPlugin = _t$context$data4.stubbedLoadPlugin,
|
69 | plugins = _t$context$data4.plugins;
|
70 |
|
71 | t.throws(() => {
|
72 | stubbedLoadPlugin(plugins, 'nonexistentplugin');
|
73 | }, /Failed to load plugin/u);
|
74 | });
|
75 |
|
76 | (0, _ava2.default)('should load a scoped plugin when referenced by short name', t => {
|
77 | var _t$context$data5 = t.context.data;
|
78 | const stubbedLoadPlugin = _t$context$data5.stubbedLoadPlugin,
|
79 | plugins = _t$context$data5.plugins,
|
80 | scopedPlugin = _t$context$data5.scopedPlugin;
|
81 |
|
82 | stubbedLoadPlugin(plugins, '@scope/example');
|
83 | t.is(plugins['@scope/example'], scopedPlugin);
|
84 | });
|
85 |
|
86 | (0, _ava2.default)('should load a scoped plugin when referenced by long name', t => {
|
87 | var _t$context$data6 = t.context.data;
|
88 | const stubbedLoadPlugin = _t$context$data6.stubbedLoadPlugin,
|
89 | plugins = _t$context$data6.plugins,
|
90 | scopedPlugin = _t$context$data6.scopedPlugin;
|
91 |
|
92 | stubbedLoadPlugin(plugins, '@scope/commitlint-plugin-example');
|
93 | t.is(plugins['@scope/example'], scopedPlugin);
|
94 | });
|
95 |
|
96 |
|
97 | (0, _ava2.default)("should load a scoped plugin when referenced by short name, but should not get the plugin if '@scope/' is omitted", t => {
|
98 | var _t$context$data7 = t.context.data;
|
99 | const stubbedLoadPlugin = _t$context$data7.stubbedLoadPlugin,
|
100 | plugins = _t$context$data7.plugins;
|
101 |
|
102 | stubbedLoadPlugin(plugins, '@scope/example');
|
103 | t.is(plugins['example'], undefined);
|
104 | });
|
105 |
|
106 | (0, _ava2.default)("should load a scoped plugin when referenced by long name, but should not get the plugin if '@scope/' is omitted", t => {
|
107 | var _t$context$data8 = t.context.data;
|
108 | const stubbedLoadPlugin = _t$context$data8.stubbedLoadPlugin,
|
109 | plugins = _t$context$data8.plugins;
|
110 |
|
111 | stubbedLoadPlugin(plugins, '@scope/commitlint-plugin-example');
|
112 | t.is(plugins['example'], undefined);
|
113 | });
|
114 |
|
\ | No newline at end of file |