@@ -5,11 +5,16 @@ const {test} = require('tap');
55const { load} = require ( '../eslint-plugin-helper' ) ;
66
77const projectDir = path . join ( __dirname , 'fixture/eslint-plugin-helper' ) ;
8+ const overrideDir = path . join ( __dirname , 'fixture/eslint-plugin-helper/for-overriding' ) ;
89
910test ( 'caches loaded configuration' , t => {
1011 const expected = load ( projectDir ) ;
11- const actual = load ( projectDir ) ;
12- t . is ( expected , actual ) ;
12+ t . is ( expected , load ( projectDir ) ) ;
13+
14+ const withOverride = load ( projectDir , { } ) ;
15+ t . not ( expected , withOverride ) ;
16+ t . is ( withOverride , load ( projectDir , { } ) ) ;
17+
1318 t . end ( ) ;
1419} ) ;
1520
@@ -43,6 +48,41 @@ test('classifies files according to the configuration', t => {
4348 t . end ( ) ;
4449} ) ;
4550
51+ test ( 'classifies files according to configuration override' , t => {
52+ const helper = load ( overrideDir , {
53+ extensions : [ 'foo' ] ,
54+ files : [ 'tests/**/*' ] ,
55+ helpers : [ 'helpers/*' ] ,
56+ sources : [ 'source.*' ]
57+ } ) ;
58+ t . deepEqual ( helper . classifyFile ( path . join ( overrideDir , 'tests/test.foo' ) ) , {
59+ isHelper : false ,
60+ isSource : false ,
61+ isTest : true
62+ } ) ;
63+ t . deepEqual ( helper . classifyFile ( path . join ( overrideDir , 'tests/_helper.foo' ) ) , {
64+ isHelper : true ,
65+ isSource : false ,
66+ isTest : false
67+ } ) ;
68+ t . deepEqual ( helper . classifyFile ( path . join ( overrideDir , 'helpers/helper.foo' ) ) , {
69+ isHelper : true ,
70+ isSource : false ,
71+ isTest : false
72+ } ) ;
73+ t . deepEqual ( helper . classifyFile ( path . join ( overrideDir , 'source.foo' ) ) , {
74+ isHelper : false ,
75+ isSource : true ,
76+ isTest : false
77+ } ) ;
78+ t . deepEqual ( helper . classifyFile ( path . join ( overrideDir , 'tests/test.js' ) ) , {
79+ isHelper : false ,
80+ isSource : false ,
81+ isTest : false
82+ } ) ;
83+ t . end ( ) ;
84+ } ) ;
85+
4686test ( 'classifies imports with extension according to the configuration' , t => {
4787 const helper = load ( projectDir ) ;
4888 t . deepEqual ( helper . classifyImport ( path . join ( projectDir , 'tests/test.foo' ) ) , {
@@ -68,6 +108,36 @@ test('classifies imports with extension according to the configuration', t => {
68108 t . end ( ) ;
69109} ) ;
70110
111+ test ( 'classifies imports with extension according to the override' , t => {
112+ const helper = load ( overrideDir , {
113+ extensions : [ 'foo' ] ,
114+ files : [ 'tests/**/*' ] ,
115+ helpers : [ 'helpers/*' ] ,
116+ sources : [ 'source.*' ]
117+ } ) ;
118+ t . deepEqual ( helper . classifyImport ( path . join ( overrideDir , 'tests/test.foo' ) ) , {
119+ isHelper : false ,
120+ isSource : false ,
121+ isTest : true
122+ } ) ;
123+ t . deepEqual ( helper . classifyImport ( path . join ( overrideDir , 'tests/_helper.foo' ) ) , {
124+ isHelper : true ,
125+ isSource : false ,
126+ isTest : false
127+ } ) ;
128+ t . deepEqual ( helper . classifyImport ( path . join ( overrideDir , 'helpers/helper.foo' ) ) , {
129+ isHelper : true ,
130+ isSource : false ,
131+ isTest : false
132+ } ) ;
133+ t . deepEqual ( helper . classifyImport ( path . join ( overrideDir , 'source.foo' ) ) , {
134+ isHelper : false ,
135+ isSource : true ,
136+ isTest : false
137+ } ) ;
138+ t . end ( ) ;
139+ } ) ;
140+
71141test ( 'classifies imports without extension according to the configuration' , t => {
72142 const helper = load ( projectDir ) ;
73143 t . deepEqual ( helper . classifyImport ( path . join ( projectDir , 'tests/test' ) ) , {
@@ -92,3 +162,33 @@ test('classifies imports without extension according to the configuration', t =>
92162 } ) ;
93163 t . end ( ) ;
94164} ) ;
165+
166+ test ( 'classifies imports without extension according to the override' , t => {
167+ const helper = load ( overrideDir , {
168+ extensions : [ 'foo' ] ,
169+ files : [ 'tests/**/*' ] ,
170+ helpers : [ 'helpers/*' ] ,
171+ sources : [ 'source.*' ]
172+ } ) ;
173+ t . deepEqual ( helper . classifyImport ( path . join ( overrideDir , 'tests/test' ) ) , {
174+ isHelper : false ,
175+ isSource : false ,
176+ isTest : true
177+ } ) ;
178+ t . deepEqual ( helper . classifyImport ( path . join ( overrideDir , 'tests/_helper' ) ) , {
179+ isHelper : true ,
180+ isSource : false ,
181+ isTest : false
182+ } ) ;
183+ t . deepEqual ( helper . classifyImport ( path . join ( overrideDir , 'helpers/helper' ) ) , {
184+ isHelper : true ,
185+ isSource : false ,
186+ isTest : false
187+ } ) ;
188+ t . deepEqual ( helper . classifyImport ( path . join ( overrideDir , 'source' ) ) , {
189+ isHelper : false ,
190+ isSource : true ,
191+ isTest : false
192+ } ) ;
193+ t . end ( ) ;
194+ } ) ;
0 commit comments