mirror of
https://github.com/storybookjs/storybook.git
synced 2025-03-16 05:03:11 +08:00
make paths.test windows compatible
This commit is contained in:
parent
195e38cb53
commit
5c03abfa13
@ -4,9 +4,12 @@ import { normalizeStoryPath, getProjectRoot } from '../paths';
|
||||
|
||||
jest.mock('find-up');
|
||||
|
||||
// Windows uses backslashes, which causes failures that won't happen on Unix based systems, so we just normalize the paths
|
||||
const normalizeSeparator = (str: string) => str.replace(/\//g, path.sep);
|
||||
|
||||
describe('paths - normalizeStoryPath()', () => {
|
||||
it('returns a path starting with "./" unchanged', () => {
|
||||
const filename = `.${path.sep}${path.join('src', 'Comp.story.js')}`;
|
||||
const filename = normalizeSeparator(`./${path.join('src', 'Comp.story.js')}`);
|
||||
expect(normalizeStoryPath(filename)).toEqual(filename);
|
||||
});
|
||||
|
||||
@ -27,17 +30,17 @@ describe('paths - normalizeStoryPath()', () => {
|
||||
|
||||
it('adds "./" to a normalized relative path', () => {
|
||||
const filename = path.join('src', 'Comp.story.js');
|
||||
expect(normalizeStoryPath(filename)).toEqual(`.${path.sep}${filename}`);
|
||||
expect(normalizeStoryPath(filename)).toEqual(normalizeSeparator(`./${filename}`));
|
||||
});
|
||||
|
||||
it('adds "./" to a hidden folder', () => {
|
||||
const filename = path.join('.storybook', 'Comp.story.js');
|
||||
expect(normalizeStoryPath(filename)).toEqual(`.${path.sep}${filename}`);
|
||||
expect(normalizeStoryPath(filename)).toEqual(normalizeSeparator(`./${filename}`));
|
||||
});
|
||||
|
||||
it('adds "./" to a hidden file', () => {
|
||||
const filename = `.Comp.story.js`;
|
||||
expect(normalizeStoryPath(filename)).toEqual(`.${path.sep}${filename}`);
|
||||
expect(normalizeStoryPath(filename)).toEqual(normalizeSeparator(`./${filename}`));
|
||||
});
|
||||
});
|
||||
|
||||
@ -46,25 +49,25 @@ describe('getProjectRoot', () => {
|
||||
|
||||
it('should return the root directory containing a .git directory', () => {
|
||||
mockedFindUp.sync.mockImplementation((name) =>
|
||||
name === ('.git' as any) ? '/path/to/root' : undefined
|
||||
name === ('.git' as any) ? normalizeSeparator('/path/to/root') : undefined
|
||||
);
|
||||
|
||||
expect(getProjectRoot()).toBe('/path/to');
|
||||
expect(getProjectRoot()).toBe(normalizeSeparator('/path/to'));
|
||||
});
|
||||
|
||||
it('should return the root directory containing a .svn directory if there is no .git directory', () => {
|
||||
mockedFindUp.sync.mockImplementation((name) =>
|
||||
name === ('.svn' as any) ? '/path/to/root' : undefined
|
||||
name === ('.svn' as any) ? normalizeSeparator('/path/to/root') : undefined
|
||||
);
|
||||
|
||||
expect(getProjectRoot()).toBe('/path/to');
|
||||
expect(getProjectRoot()).toBe(normalizeSeparator('/path/to'));
|
||||
});
|
||||
|
||||
it('should return the root directory containing a .yarn directory if there is no .git or .svn directory', () => {
|
||||
mockedFindUp.sync.mockImplementation((name) =>
|
||||
name === ('.yarn' as any) ? '/path/to/root' : undefined
|
||||
name === ('.yarn' as any) ? normalizeSeparator('/path/to/root') : undefined
|
||||
);
|
||||
|
||||
expect(getProjectRoot()).toBe('/path/to');
|
||||
expect(getProjectRoot()).toBe(normalizeSeparator('/path/to'));
|
||||
});
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user