Skip to content

Commit

Permalink
Added tests
Browse files Browse the repository at this point in the history
Signed-off-by: Tyler Smalley <[email protected]>
  • Loading branch information
Tyler Smalley committed Sep 21, 2018
1 parent d55b81f commit cb23ca2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/ui/ui_exports/ui_export_types/style_sheet_paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const OK_EXTNAMES = ['.css', '.scss'];

function normalize(localPath, type, pluginSpec) {
const pluginId = pluginSpec.getId();
const publicDir = pluginSpec.getPublicDir();
const publicDir = path.normalize(pluginSpec.getPublicDir());
const extname = path.extname(localPath);

if (!OK_EXTNAMES.includes(extname)) {
Expand Down
19 changes: 15 additions & 4 deletions src/ui/ui_exports/ui_export_types/style_sheet_paths.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,18 @@ import { styleSheetPaths } from './style_sheet_paths';

describe('uiExports.styleSheetPaths', () => {
const pluginSpec = {
getId: () => 'test',
getPublicDir: () => '/kibana/public'
getId: jest.fn(() => 'test'),
getPublicDir: jest.fn(() => '/kibana/public')
};

it('does not support relative paths', () => {
expect(() => styleSheetPaths([], 'public/bar.css', 'styleSheetPaths', pluginSpec))
.toThrowError('[plugin:test] uiExports.styleSheetPaths must be an absolute path, got "public/bar.css"');
.toThrowError(/\[plugin:test\] uiExports.styleSheetPaths must be an absolute path/);
});

it('path must be child of public path', () => {
expect(() => styleSheetPaths([], '/another/public/bar.css', 'styleSheetPaths', pluginSpec))
.toThrowError('[plugin:test] uiExports.styleSheetPaths must be child of publicDir [/kibana/public]');
.toThrowError(/\[plugin:test\] uiExports.styleSheetPaths must be child of publicDir/);
});

it('only supports css or scss extensions', () => {
Expand All @@ -57,4 +57,15 @@ describe('uiExports.styleSheetPaths', () => {
expect(uiExports.styleSheetPaths[0].localPath).toEqual(localPath);
expect(uiExports.styleSheetPaths[0].publicPath).toEqual('plugins/test/bar.css');
});

it('should normalize the path for Windows', () => {
pluginSpec.getPublicDir.mockReturnValue('\\kibana\\public');

const localPath = '\\kibana/public/bar.css';
const uiExports = styleSheetPaths([], localPath, 'styleSheetPaths', pluginSpec);

expect(uiExports.styleSheetPaths).toHaveLength(1);
expect(uiExports.styleSheetPaths[0].localPath).toEqual(localPath);
expect(uiExports.styleSheetPaths[0].publicPath).toEqual('plugins/test/bar.css');
});
});

0 comments on commit cb23ca2

Please sign in to comment.