@@ -3,7 +3,7 @@ import * as path from 'path'
3
3
4
4
import importType from 'core/importType'
5
5
6
- import { testContext } from '../utils'
6
+ import { testContext , testFilePath } from '../utils'
7
7
8
8
describe ( 'importType(name)' , function ( ) {
9
9
const context = testContext ( )
@@ -145,4 +145,92 @@ describe('importType(name)', function () {
145
145
const foldersContext = testContext ( { 'import/external-module-folders' : [ 'node_modules' ] } )
146
146
expect ( importType ( 'resolve' , foldersContext ) ) . to . equal ( 'external' )
147
147
} )
148
+
149
+ it ( "should return 'external' for a scoped symlinked module" , function ( ) {
150
+ const foldersContext = testContext ( {
151
+ 'import/resolver' : 'node' ,
152
+ 'import/external-module-folders' : [ 'node_modules' ] ,
153
+ } )
154
+ expect ( importType ( '@test-scope/some-module' , foldersContext ) ) . to . equal ( 'external' )
155
+ } )
156
+
157
+ // We're using Webpack resolver here since it resolves all symlinks, which means that
158
+ // directory path will not contain node_modules/<package-name> but will point to the
159
+ // actual directory inside 'files' instead
160
+ it ( "should return 'external' for a scoped module from a symlinked directory which name " +
161
+ "is contained in 'external-module-folders' (webpack resolver)" , function ( ) {
162
+ const foldersContext = testContext ( {
163
+ 'import/resolver' : 'webpack' ,
164
+ 'import/external-module-folders' : [ 'symlinked-module' ] ,
165
+ } )
166
+ expect ( importType ( '@test-scope/some-module' , foldersContext ) ) . to . equal ( 'external' )
167
+ } )
168
+
169
+ it ( "should return 'internal' for a scoped module from a symlinked directory which incomplete " +
170
+ "name is contained in 'external-module-folders' (webpack resolver)" , function ( ) {
171
+ const foldersContext_1 = testContext ( {
172
+ 'import/resolver' : 'webpack' ,
173
+ 'import/external-module-folders' : [ 'symlinked-mod' ] ,
174
+ } )
175
+ expect ( importType ( '@test-scope/some-module' , foldersContext_1 ) ) . to . equal ( 'internal' )
176
+
177
+ const foldersContext_2 = testContext ( {
178
+ 'import/resolver' : 'webpack' ,
179
+ 'import/external-module-folders' : [ 'linked-module' ] ,
180
+ } )
181
+ expect ( importType ( '@test-scope/some-module' , foldersContext_1 ) ) . to . equal ( 'internal' )
182
+ } )
183
+
184
+ it ( "should return 'external' for a scoped module from a symlinked directory which partial path " +
185
+ "is contained in 'external-module-folders' (webpack resolver)" , function ( ) {
186
+ const foldersContext = testContext ( {
187
+ 'import/resolver' : 'webpack' ,
188
+ 'import/external-module-folders' : [ 'files/symlinked-module' ] ,
189
+ } )
190
+ expect ( importType ( '@test-scope/some-module' , foldersContext ) ) . to . equal ( 'external' )
191
+ } )
192
+
193
+ it ( "should return 'internal' for a scoped module from a symlinked directory which partial path " +
194
+ "w/ incomplete segment is contained in 'external-module-folders' " +
195
+ "(webpack resolver)" , function ( ) {
196
+ const foldersContext_1 = testContext ( {
197
+ 'import/resolver' : 'webpack' ,
198
+ 'import/external-module-folders' : [ 'files/symlinked-mod' ] ,
199
+ } )
200
+ expect ( importType ( '@test-scope/some-module' , foldersContext_1 ) ) . to . equal ( 'internal' )
201
+
202
+ const foldersContext_2 = testContext ( {
203
+ 'import/resolver' : 'webpack' ,
204
+ 'import/external-module-folders' : [ 'les/symlinked-module' ] ,
205
+ } )
206
+ expect ( importType ( '@test-scope/some-module' , foldersContext_2 ) ) . to . equal ( 'internal' )
207
+ } )
208
+
209
+ it ( "should return 'external' for a scoped module from a symlinked directory which partial path " +
210
+ "ending w/ slash is contained in 'external-module-folders' (webpack resolver)" , function ( ) {
211
+ const foldersContext = testContext ( {
212
+ 'import/resolver' : 'webpack' ,
213
+ 'import/external-module-folders' : [ 'files/symlinked-module/' ] ,
214
+ } )
215
+ expect ( importType ( '@test-scope/some-module' , foldersContext ) ) . to . equal ( 'external' )
216
+ } )
217
+
218
+ it ( "should return 'internal' for a scoped module from a symlinked directory when " +
219
+ "'external-module-folders' contains an absolute path resembling directory's relative " +
220
+ "path (webpack resolver)" , function ( ) {
221
+ const foldersContext = testContext ( {
222
+ 'import/resolver' : 'webpack' ,
223
+ 'import/external-module-folders' : [ '/files/symlinked-module' ] ,
224
+ } )
225
+ expect ( importType ( '@test-scope/some-module' , foldersContext ) ) . to . equal ( 'internal' )
226
+ } )
227
+
228
+ it ( "should return 'external' for a scoped module from a symlinked directory which absolute " +
229
+ "path is contained in 'external-module-folders' (webpack resolver)" , function ( ) {
230
+ const foldersContext = testContext ( {
231
+ 'import/resolver' : 'webpack' ,
232
+ 'import/external-module-folders' : [ testFilePath ( 'symlinked-module' ) ] ,
233
+ } )
234
+ expect ( importType ( '@test-scope/some-module' , foldersContext ) ) . to . equal ( 'external' )
235
+ } )
148
236
} )
0 commit comments