-
Notifications
You must be signed in to change notification settings - Fork 411
Expand file tree
/
Copy pathpreprocess.test.ts
More file actions
46 lines (41 loc) · 1.23 KB
/
preprocess.test.ts
File metadata and controls
46 lines (41 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/* eslint-disable no-template-curly-in-string */
import path from 'path';
import { transformUrl } from '../preprocess';
describe('transformUrl', () => {
type TransformUrlArgs = Parameters<typeof transformUrl>;
const dataset: Record<string, TransformUrlArgs> = {
'../assets/test.jpg': [
'./assets/test.jpg',
'./.linaria-cache/test.css',
'./test.js',
],
'../a/b/test.jpg': [
'../a/b/test.jpg',
'./.linaria-cache/test.css',
'./a/test.js',
],
};
it('should work with posix paths', () => {
for (const result of Object.keys(dataset)) {
expect(transformUrl(...dataset[result])).toBe(result);
}
});
it('should work with win32 paths', () => {
const toWin32 = (p: string) => p.split(path.posix.sep).join(path.win32.sep);
const win32Dataset = Object.keys(dataset).reduce(
(acc, key) => ({
...acc,
[key]: [
dataset[key][0],
toWin32(dataset[key][1]),
toWin32(dataset[key][2]),
path.win32,
] as TransformUrlArgs,
}),
{} as Record<string, TransformUrlArgs>
);
for (const result of Object.keys(win32Dataset)) {
expect(transformUrl(...win32Dataset[result])).toBe(result);
}
});
});