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

Commit 91e2581

Browse files
committed
refactor: simplify test changes
1 parent ad7220b commit 91e2581

File tree

2 files changed

+11
-29
lines changed

2 files changed

+11
-29
lines changed

src/index.js

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,6 @@ const exists = uri => {
3030
}
3131
};
3232

33-
const getVolume = id => {
34-
let volume = '';
35-
36-
if (IS_WINDOWS && typeof id === 'string') {
37-
[volume] = id.match(VOLUME) || [''];
38-
}
39-
40-
return volume;
41-
};
42-
4333
const normalizeId = id => {
4434
if (IS_WINDOWS && typeof id === 'string') {
4535
return slash(id.replace(VOLUME, ''));
@@ -63,7 +53,6 @@ export default function alias(options = {}) {
6353

6454
return {
6555
resolveId(importee, importer) {
66-
const volume = getVolume(importee) || getVolume(importer);
6756
const importeeId = normalizeId(importee);
6857
const importerId = normalizeId(importer);
6958

@@ -87,19 +76,19 @@ export default function alias(options = {}) {
8776
.find(exists);
8877

8978
if (match) {
90-
return path.join(volume, match);
79+
return match;
9180
}
9281

9382
// To keep the previous behaviour we simply return the file path
9483
// with extension
9584
if (endsWith('.js', filePath)) {
96-
return path.join(volume, filePath);
85+
return filePath;
9786
}
9887

99-
return path.join(volume, filePath + '.js');
88+
return filePath + '.js';
10089
}
10190

102-
return path.join(volume, updatedId);
91+
return updatedId;
10392
},
10493
};
10594
}

test/index.js

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import test from 'ava';
2-
import path from 'path';
2+
import { 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]:)/, ''));
8+
79
test(t => {
810
t.is(typeof alias, 'function');
911
});
@@ -91,12 +93,9 @@ test('Test for the resolve property', t => {
9193
resolve: ['.js', '.jsx'],
9294
});
9395

94-
const resolved = result.resolveId(
95-
'ember',
96-
slash(path.resolve(__dirname, './files/index.js'))
97-
);
96+
const resolved = result.resolveId('ember', path.resolve(DIRNAME, './files/index.js'));
9897

99-
t.is(resolved, slash(path.resolve(__dirname, './files/folder/hipster.jsx')));
98+
t.is(resolved, path.resolve(DIRNAME, './files/folder/hipster.jsx'));
10099
});
101100

102101
test(t => {
@@ -114,15 +113,9 @@ test(t => {
114113
resolve: './i/am/a/local/file',
115114
});
116115

117-
const resolved = result.resolveId(
118-
'resolve',
119-
slash(path.resolve(__dirname, './files/index.js'))
120-
);
116+
const resolved = result.resolveId('resolve', path.resolve(DIRNAME, './files/index.js'));
121117

122-
t.is(
123-
resolved,
124-
slash(path.resolve(__dirname, './files/i/am/a/local/file.js'))
125-
);
118+
t.is(resolved, path.resolve(DIRNAME, './files/i/am/a/local/file.js'));
126119
});
127120

128121
// Tests in Rollup

0 commit comments

Comments
 (0)