Skip to content
This repository was archived by the owner on Aug 4, 2021. It is now read-only.

Commit 638f400

Browse files
committed
Add test cases for aliasing with path.resolve()
added 3 test cases: - alias with path.resolve() with file without extention - alias with windows absolute path - alias with path.resolve() with file with extention
1 parent dd0802b commit 638f400

File tree

1 file changed

+40
-2
lines changed

1 file changed

+40
-2
lines changed

test/index.js

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import test from 'ava';
2-
import { posix as path } from 'path';
2+
import paltformPath, { posix as path } from 'path';
33
import { rollup } from 'rollup';
44
import alias from '../dist/rollup-plugin-alias';
55
import slash from 'slash';
66

7-
const DIRNAME = slash(__dirname.replace(/^([A-Z]:)/, ''));
7+
const normalizePath = (pathToNormalize) => slash(pathToNormalize.replace(/^([A-Z]:)/, ''));
8+
const DIRNAME = normalizePath(__dirname);
89

910
test(t => {
1011
t.is(typeof alias, 'function');
@@ -118,6 +119,43 @@ test(t => {
118119
t.is(resolved, path.resolve(DIRNAME, './files/i/am/a/local/file.js'));
119120
});
120121

122+
// this test with old behaviour will fail on windows and pass on Uinx-Like platforms
123+
test('Platform path.resolve(\'file-without-extension\') aliasing', t => {
124+
// this what used in React and Vue
125+
const result = alias({
126+
test: paltformPath.resolve('./files/aliasMe'),
127+
});
128+
129+
const resolved = result.resolveId('test', path.resolve(DIRNAME, './files/index.js'));
130+
131+
t.is(resolved, paltformPath.resolve('./files/aliasMe.js'));
132+
});
133+
134+
// this test with old behaviour will fail on windows and Uinx-Like platforms
135+
test('Windows absolute path aliasing', t => {
136+
const result = alias({
137+
resolve: 'E:\\react\\node_modules\\fbjs\\lib\\warning',
138+
});
139+
140+
const resolved = result.resolveId('resolve', path.resolve(DIRNAME, './files/index.js'));
141+
142+
t.is(
143+
normalizePath(resolved),
144+
normalizePath('E:\\react\\node_modules\\fbjs\\lib\\warning.js')
145+
);
146+
});
147+
148+
test('Platform path.resolve(\'file-with.ext\') aliasing', t => {
149+
const result = alias({
150+
test: paltformPath.resolve('./files/folder/hipster.jsx'),
151+
resolve: ['.js', '.jsx'],
152+
});
153+
154+
const resolved = result.resolveId('test', path.resolve(DIRNAME, './files/index.js'));
155+
156+
t.is(resolved, paltformPath.resolve('./files/folder/hipster.jsx'));
157+
});
158+
121159
// Tests in Rollup
122160
test(t =>
123161
rollup({

0 commit comments

Comments
 (0)