|
1 | 1 | import loadPlugin from './load-plugin';
|
| 2 | +import {platform} from 'os'; |
2 | 3 | import chalk from 'chalk';
|
3 | 4 |
|
4 | 5 | jest.mock('commitlint-plugin-example', () => ({example: true}), {
|
@@ -53,7 +54,7 @@ test('should throw an error when a plugin has whitespace', () => {
|
53 | 54 | test("should throw an error when a plugin doesn't exist", () => {
|
54 | 55 | const spy = jest.spyOn(console, 'error').mockImplementation();
|
55 | 56 | expect(() => loadPlugin({}, 'nonexistentplugin')).toThrow(
|
56 |
| - 'Failed to load plugin commitlint-plugin-nonexistentplugin.' |
| 57 | + 'Failed to load plugin' |
57 | 58 | );
|
58 | 59 | expect(spy).toBeCalledWith(
|
59 | 60 | chalk.red(`Failed to load plugin commitlint-plugin-nonexistentplugin.`)
|
@@ -102,8 +103,23 @@ test('should load a plugin when relative windows path is provided', () => {
|
102 | 103 | expect(plugins['windows.js']).toBe(require('.\\relative\\windows.js'));
|
103 | 104 | });
|
104 | 105 |
|
105 |
| -test('should load a plugin when absolute windows path is provided', () => { |
106 |
| - const plugins = loadPlugin({}, 'C:\\absolute\\windows.js'); |
107 |
| - // eslint-disable-next-line import/no-absolute-path |
108 |
| - expect(plugins['windows.js']).toBe(require('C:\\absolute\\windows.js')); |
109 |
| -}); |
| 106 | +if (platform() === 'win32') { |
| 107 | + test('should load a plugin when absolute windows path is provided', () => { |
| 108 | + const plugins = loadPlugin({}, 'C:\\absolute\\windows.js'); |
| 109 | + // eslint-disable-next-line import/no-absolute-path |
| 110 | + expect(plugins['windows.js']).toBe(require('C:\\absolute\\windows.js')); |
| 111 | + }); |
| 112 | +} else { |
| 113 | + test('should not load a plugin when absolute windows path is provided', () => { |
| 114 | + const spy = jest.spyOn(console, 'error').mockImplementation(); |
| 115 | + expect(() => loadPlugin({}, 'C:\\absolute\\windows.js')).toThrow( |
| 116 | + 'Failed to load plugin' |
| 117 | + ); |
| 118 | + expect(spy).toBeCalledWith( |
| 119 | + chalk.red( |
| 120 | + `Failed to load plugin commitlint-plugin-C://absolute/windows.js.` |
| 121 | + ) |
| 122 | + ); |
| 123 | + spy.mockRestore(); |
| 124 | + }); |
| 125 | +} |
0 commit comments