Skip to content

Commit

Permalink
Added tests
Browse files Browse the repository at this point in the history
Signed-off-by: Tyler Smalley <tyler.smalley@elastic.co>
  • Loading branch information
Tyler Smalley committed Sep 22, 2018
1 parent d55b81f commit 25ee15c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 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
23 changes: 17 additions & 6 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 @@ -17,22 +17,25 @@
* under the License.
*/

import { resolve } from 'path';
import { tmpdir } from 'os';
import { styleSheetPaths } from './style_sheet_paths';

describe('uiExports.styleSheetPaths', () => {
const dir = tmpdir();
const pluginSpec = {
getId: () => 'test',
getPublicDir: () => '/kibana/public'
getId: jest.fn(() => 'test'),
getPublicDir: jest.fn(() => resolve(dir, '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 @@ -41,7 +44,7 @@ describe('uiExports.styleSheetPaths', () => {
});

it('provides publicPath for scss extensions', () => {
const localPath = '/kibana/public/bar.scss';
const localPath = resolve(dir, 'kibana/public/bar.scss');
const uiExports = styleSheetPaths([], localPath, 'styleSheetPaths', pluginSpec);

expect(uiExports.styleSheetPaths).toHaveLength(1);
Expand All @@ -50,11 +53,19 @@ describe('uiExports.styleSheetPaths', () => {
});

it('provides publicPath for css extensions', () => {
const localPath = '/kibana/public/bar.css';
const localPath = resolve(dir, 'kibana/public/bar.scss');
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');
});

it('should normalize mixed slashes', () => {
const localPath = resolve(dir, 'kibana/public\\bar.scss');
const uiExports = styleSheetPaths([], localPath, 'styleSheetPaths', pluginSpec);

expect(uiExports.styleSheetPaths).toHaveLength(1);
expect(uiExports.styleSheetPaths[0].localPath).toEqual(localPath);
});
});

0 comments on commit 25ee15c

Please sign in to comment.