Skip to content

Commit 0e547a4

Browse files
#RI-4487 - fix be path (#2116)
* #RI-4487 - fix be path
1 parent 7d3e9ff commit 0e547a4

File tree

5 files changed

+28
-1
lines changed

5 files changed

+28
-1
lines changed

redisinsight/api/src/modules/custom-tutorial/providers/custom-tutorial.manifest.provider.spec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
mockCustomTutorial,
88
mockCustomTutorialManifest, mockCustomTutorialManifestJson,
99
} from 'src/__mocks__';
10+
import * as Utils from 'src/utils/path';
1011

1112
jest.mock('fs-extra');
1213
const mFs = fs as jest.Mocked<typeof fs>;
@@ -61,6 +62,8 @@ describe('CustomTutorialManifestProvider', () => {
6162
expect(result).toEqual([]);
6263
});
6364
it('should return empty array for empty folder', async () => {
65+
const spy = jest.spyOn(Utils as any, 'winPathToNormalPath');
66+
6467
// root level entries
6568
const mockRootLevelEntries = [
6669
'intro.md',
@@ -160,6 +163,7 @@ describe('CustomTutorialManifestProvider', () => {
160163
type: 'group',
161164
},
162165
]);
166+
expect(spy).toBeCalledTimes(5); // Should call util to fix win path
163167
});
164168
});
165169

redisinsight/api/src/modules/custom-tutorial/providers/custom-tutorial.manifest.provider.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
RootCustomTutorialManifest,
1010
} from 'src/modules/custom-tutorial/models/custom-tutorial.manifest';
1111
import { plainToClass } from 'class-transformer';
12+
import { winPathToNormalPath } from 'src/utils';
1213

1314
const MANIFEST_FILE = 'manifest.json';
1415
const SYS_MANIFEST_FILE = '_manifest.json';
@@ -75,7 +76,7 @@ export class CustomTutorialManifestProvider {
7576
label: name,
7677
type: CustomTutorialManifestType.InternalLink,
7778
args: {
78-
path: join(relativePath, entry),
79+
path: winPathToNormalPath(join(relativePath, entry)),
7980
},
8081
});
8182
}

redisinsight/api/src/utils/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ export * from './analytics-helper';
88
export * from './redis-connection-helper';
99
export * from './class-transformer';
1010
export * from './file-helper';
11+
export * from './path';
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { winPathToNormalPath } from 'src/utils';
2+
3+
const winPathToNormalPathTests: Record<string, any>[] = [
4+
{ input: '\\dir/file.js', output: '/dir/file.js' },
5+
{ input: '/dir/file.js', output: '/dir/file.js' },
6+
{ input: 'file.js', output: 'file.js' },
7+
{ input: '\\file.js', output: '/file.js' },
8+
{ input: '\\dir\\file.js', output: '/dir/file.js' },
9+
{ input: 'dir/file.js', output: 'dir/file.js' },
10+
];
11+
12+
describe('winPathToNormalPath', () => {
13+
winPathToNormalPathTests.forEach((test) => {
14+
it(`should be output: ${test.output} for input: ${JSON.stringify(test.input)}`, () => {
15+
const result = winPathToNormalPath(test.input);
16+
17+
expect(result).toEqual(test.output);
18+
});
19+
});
20+
});

redisinsight/api/src/utils/path.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const winPathToNormalPath = (path: string) => path.replace(/\\/g, '/');

0 commit comments

Comments
 (0)