|
1 | 1 | import test from 'ava';
|
2 |
| -import { posix as path } from 'path'; |
| 2 | +import paltformPath, { posix as path } from 'path'; |
3 | 3 | import { rollup } from 'rollup';
|
4 | 4 | import alias from '../dist/rollup-plugin-alias';
|
5 | 5 | import slash from 'slash';
|
6 | 6 |
|
7 |
| -const DIRNAME = slash(__dirname.replace(/^([A-Z]:)/, '')); |
| 7 | +const normalizePath = (pathToNormalize) => slash(pathToNormalize.replace(/^([A-Z]:)/, '')); |
| 8 | +const DIRNAME = normalizePath(__dirname); |
8 | 9 |
|
9 | 10 | test(t => {
|
10 | 11 | t.is(typeof alias, 'function');
|
@@ -118,6 +119,43 @@ test(t => {
|
118 | 119 | t.is(resolved, path.resolve(DIRNAME, './files/i/am/a/local/file.js'));
|
119 | 120 | });
|
120 | 121 |
|
| 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 | + |
121 | 159 | // Tests in Rollup
|
122 | 160 | test(t =>
|
123 | 161 | rollup({
|
|
0 commit comments