Skip to content

Commit 0803cf6

Browse files
committed
fix: add test to cover difference between windows and linux
1 parent 1a982fa commit 0803cf6

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

@commitlint/load/src/utils/load-plugin.test.ts

+22-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import loadPlugin from './load-plugin';
2+
import {platform} from 'os';
23
import chalk from 'chalk';
34

45
jest.mock('commitlint-plugin-example', () => ({example: true}), {
@@ -53,7 +54,7 @@ test('should throw an error when a plugin has whitespace', () => {
5354
test("should throw an error when a plugin doesn't exist", () => {
5455
const spy = jest.spyOn(console, 'error').mockImplementation();
5556
expect(() => loadPlugin({}, 'nonexistentplugin')).toThrow(
56-
'Failed to load plugin commitlint-plugin-nonexistentplugin.'
57+
'Failed to load plugin'
5758
);
5859
expect(spy).toBeCalledWith(
5960
chalk.red(`Failed to load plugin commitlint-plugin-nonexistentplugin.`)
@@ -102,8 +103,23 @@ test('should load a plugin when relative windows path is provided', () => {
102103
expect(plugins['windows.js']).toBe(require('.\\relative\\windows.js'));
103104
});
104105

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

Comments
 (0)