11/* eslint-env mocha */
2+ /* eslint-disable prefer-arrow-callback */
3+ /* eslint-disable func-names */
24import assert from 'assert' ;
35import { transform } from 'babel-core' ; // eslint-disable-line import/no-extraneous-dependencies
46import plugin from '../src' ;
57
68function testRequireImport ( source , output , transformerOpts ) {
7- it ( 'with a require statement' , ( ) => {
9+ it ( 'with a require statement' , function ( ) {
810 const code = `var something = require("${ source } ");` ;
911 const result = transform ( code , transformerOpts ) ;
1012
1113 assert . strictEqual ( result . code , `var something = require("${ output } ");` ) ;
1214 } ) ;
1315
14- it ( 'with an import statement' , ( ) => {
16+ it ( 'with an import statement' , function ( ) {
1517 const code = `import something from "${ source } ";` ;
1618 const result = transform ( code , transformerOpts ) ;
1719
1820 assert . strictEqual ( result . code , `import something from "${ output } ";` ) ;
1921 } ) ;
2022}
2123
22- describe ( 'root' , ( ) => {
24+ describe ( 'root' , function ( ) {
2325 const transformerOpts = {
2426 plugins : [
2527 [ plugin , {
@@ -28,48 +30,64 @@ describe('root', () => {
2830 ]
2931 } ;
3032
31- describe ( 'should rewrite the file path inside a root directory' , ( ) => {
33+ const transformerOptsGlob = {
34+ plugins : [
35+ [ plugin , {
36+ root : [ './test/**/components' ]
37+ } ]
38+ ]
39+ } ;
40+
41+ describe ( 'should rewrite the file path inside a root directory' , function ( ) {
3242 testRequireImport (
3343 'c1' ,
3444 './test/examples/components/c1' ,
3545 transformerOpts
3646 ) ;
3747 } ) ;
3848
39- describe ( 'should rewrite the sub file path inside a root directory' , ( ) => {
49+ describe ( 'should rewrite the sub file path inside a root directory' , function ( ) {
4050 testRequireImport (
4151 'sub/sub1' ,
4252 './test/examples/components/sub/sub1' ,
4353 transformerOpts
4454 ) ;
4555 } ) ;
4656
47- describe ( 'should rewrite the file while keeping the extension' , ( ) => {
57+ describe ( 'should rewrite the file while keeping the extension' , function ( ) {
4858 testRequireImport (
4959 'sub/sub1.css' ,
5060 './test/examples/components/sub/sub1.css' ,
5161 transformerOpts
5262 ) ;
5363 } ) ;
5464
55- describe ( 'should rewrite the file with a filename containing a dot' , ( ) => {
65+ describe ( 'should rewrite the file with a filename containing a dot' , function ( ) {
5666 testRequireImport (
5767 'sub/custom.modernizr3' ,
5868 './test/examples/components/sub/custom.modernizr3' ,
5969 transformerOpts
6070 ) ;
6171 } ) ;
6272
63- describe ( 'should not rewrite a path outisde of the root directory' , ( ) => {
73+ describe ( 'should not rewrite a path outisde of the root directory' , function ( ) {
6474 testRequireImport (
6575 'example-file' ,
6676 'example-file' ,
6777 transformerOpts
6878 ) ;
6979 } ) ;
80+
81+ describe ( 'should rewrite the file path inside a root directory according to glob' , function ( ) {
82+ testRequireImport (
83+ 'c1' ,
84+ './test/examples/components/c1' ,
85+ transformerOptsGlob
86+ ) ;
87+ } ) ;
7088} ) ;
7189
72- describe ( 'alias' , ( ) => {
90+ describe ( 'alias' , function ( ) {
7391 const transformerOpts = {
7492 plugins : [
7593 [ plugin , {
@@ -83,17 +101,17 @@ describe('alias', () => {
83101 ]
84102 } ;
85103
86- describe ( 'should alias a known path' , ( ) => {
87- describe ( 'using a simple exposed name' , ( ) => {
88- describe ( 'when requiring the exact name' , ( ) => {
104+ describe ( 'should alias a known path' , function ( ) {
105+ describe ( 'using a simple exposed name' , function ( ) {
106+ describe ( 'when requiring the exact name' , function ( ) {
89107 testRequireImport (
90108 'utils' ,
91109 './src/mylib/subfolder/utils' ,
92110 transformerOpts
93111 ) ;
94112 } ) ;
95113
96- describe ( 'when requiring a sub file of the exposed name' , ( ) => {
114+ describe ( 'when requiring a sub file of the exposed name' , function ( ) {
97115 testRequireImport (
98116 'utils/my-util-file' ,
99117 './src/mylib/subfolder/utils/my-util-file' ,
@@ -102,16 +120,16 @@ describe('alias', () => {
102120 } ) ;
103121 } ) ;
104122
105- describe ( 'using a "complex" exposed name' , ( ) => {
106- describe ( 'when requiring the exact name' , ( ) => {
123+ describe ( 'using a "complex" exposed name' , function ( ) {
124+ describe ( 'when requiring the exact name' , function ( ) {
107125 testRequireImport (
108126 'awesome/components' ,
109127 './src/components' ,
110128 transformerOpts
111129 ) ;
112130 } ) ;
113131
114- describe ( 'when requiring a sub file of the exposed name' , ( ) => {
132+ describe ( 'when requiring a sub file of the exposed name' , function ( ) {
115133 testRequireImport (
116134 'awesome/components/my-comp' ,
117135 './src/components/my-comp' ,
@@ -120,7 +138,7 @@ describe('alias', () => {
120138 } ) ;
121139 } ) ;
122140
123- describe ( 'with a dot in the filename' , ( ) => {
141+ describe ( 'with a dot in the filename' , function ( ) {
124142 testRequireImport (
125143 'utils/custom.modernizr3' ,
126144 './src/mylib/subfolder/utils/custom.modernizr3' ,
@@ -129,24 +147,24 @@ describe('alias', () => {
129147 } ) ;
130148 } ) ;
131149
132- describe ( 'should alias the path with its extension' , ( ) => {
150+ describe ( 'should alias the path with its extension' , function ( ) {
133151 testRequireImport (
134152 'awesome/components/my-comp.css' ,
135153 './src/components/my-comp.css' ,
136154 transformerOpts
137155 ) ;
138156 } ) ;
139157
140- describe ( 'should not alias a unknown path' , ( ) => {
141- describe ( 'when requiring a node module' , ( ) => {
158+ describe ( 'should not alias a unknown path' , function ( ) {
159+ describe ( 'when requiring a node module' , function ( ) {
142160 testRequireImport (
143161 'other-lib' ,
144162 'other-lib' ,
145163 transformerOpts
146164 ) ;
147165 } ) ;
148166
149- describe ( 'when requiring a specific un-mapped file' , ( ) => {
167+ describe ( 'when requiring a specific un-mapped file' , function ( ) {
150168 testRequireImport (
151169 './l/otherLib' ,
152170 './l/otherLib' ,
@@ -155,15 +173,15 @@ describe('alias', () => {
155173 } ) ;
156174 } ) ;
157175
158- describe ( '(legacy) should support aliasing a node module with "npm:"' , ( ) => {
176+ describe ( '(legacy) should support aliasing a node module with "npm:"' , function ( ) {
159177 testRequireImport (
160178 'abstract/thing' ,
161179 'concrete/thing' ,
162180 transformerOpts
163181 ) ;
164182 } ) ;
165183
166- describe ( 'should support aliasing a node modules' , ( ) => {
184+ describe ( 'should support aliasing a node modules' , function ( ) {
167185 testRequireImport (
168186 'underscore/map' ,
169187 'lodash/map' ,
0 commit comments