@@ -20,7 +20,7 @@ function testManyCases(filename, chosenCases, errorMessage) {
20
20
21
21
function testCaseWithOptions ( filename , errorMessage , options = [ ] ) {
22
22
return {
23
- code : 'foo()' ,
23
+ code : `/* Filename ${ filename } */` ,
24
24
filename,
25
25
options,
26
26
errors : errorMessage && [
@@ -37,22 +37,30 @@ test({
37
37
testCase ( 'src/foo/fooBar.js' , 'camelCase' ) ,
38
38
testCase ( 'src/foo/bar.test.js' , 'camelCase' ) ,
39
39
testCase ( 'src/foo/fooBar.test.js' , 'camelCase' ) ,
40
- testCase ( 'src/foo/fooBar.testUtils.js' , 'camelCase' ) ,
40
+ testCase ( 'src/foo/fooBar.test-utils.js' , 'camelCase' ) ,
41
+ testCase ( 'src/foo/fooBar.test_utils.js' , 'camelCase' ) ,
42
+ testCase ( 'src/foo/.test_utils.js' , 'camelCase' ) ,
41
43
testCase ( 'src/foo/foo.js' , 'snakeCase' ) ,
42
44
testCase ( 'src/foo/foo_bar.js' , 'snakeCase' ) ,
43
45
testCase ( 'src/foo/foo.test.js' , 'snakeCase' ) ,
44
46
testCase ( 'src/foo/foo_bar.test.js' , 'snakeCase' ) ,
45
47
testCase ( 'src/foo/foo_bar.test_utils.js' , 'snakeCase' ) ,
48
+ testCase ( 'src/foo/foo_bar.test-utils.js' , 'snakeCase' ) ,
49
+ testCase ( 'src/foo/.test-utils.js' , 'snakeCase' ) ,
46
50
testCase ( 'src/foo/foo.js' , 'kebabCase' ) ,
47
51
testCase ( 'src/foo/foo-bar.js' , 'kebabCase' ) ,
48
52
testCase ( 'src/foo/foo.test.js' , 'kebabCase' ) ,
49
53
testCase ( 'src/foo/foo-bar.test.js' , 'kebabCase' ) ,
50
54
testCase ( 'src/foo/foo-bar.test-utils.js' , 'kebabCase' ) ,
55
+ testCase ( 'src/foo/foo-bar.test_utils.js' , 'kebabCase' ) ,
56
+ testCase ( 'src/foo/.test_utils.js' , 'kebabCase' ) ,
51
57
testCase ( 'src/foo/Foo.js' , 'pascalCase' ) ,
52
58
testCase ( 'src/foo/FooBar.js' , 'pascalCase' ) ,
53
- testCase ( 'src/foo/Foo.Test.js' , 'pascalCase' ) ,
54
- testCase ( 'src/foo/FooBar.Test.js' , 'pascalCase' ) ,
55
- testCase ( 'src/foo/FooBar.TestUtils.js' , 'pascalCase' ) ,
59
+ testCase ( 'src/foo/Foo.test.js' , 'pascalCase' ) ,
60
+ testCase ( 'src/foo/FooBar.test.js' , 'pascalCase' ) ,
61
+ testCase ( 'src/foo/FooBar.test-utils.js' , 'pascalCase' ) ,
62
+ testCase ( 'src/foo/FooBar.test_utils.js' , 'pascalCase' ) ,
63
+ testCase ( 'src/foo/.test_utils.js' , 'pascalCase' ) ,
56
64
testCase ( 'spec/iss47Spec.js' , 'camelCase' ) ,
57
65
testCase ( 'spec/iss47Spec100.js' , 'camelCase' ) ,
58
66
testCase ( 'spec/i18n.js' , 'camelCase' ) ,
65
73
testCase ( 'spec/iss47_100spec.js' , 'snakeCase' ) ,
66
74
testCase ( 'spec/i18n.js' , 'snakeCase' ) ,
67
75
testCase ( 'spec/Iss47Spec.js' , 'pascalCase' ) ,
68
- testCase ( 'spec/Iss47.100Spec .js' , 'pascalCase' ) ,
76
+ testCase ( 'spec/Iss47.100spec .js' , 'pascalCase' ) ,
69
77
testCase ( 'spec/I18n.js' , 'pascalCase' ) ,
70
78
testCase ( undefined , 'camelCase' ) ,
71
79
testCase ( undefined , 'snakeCase' ) ,
@@ -238,6 +246,31 @@ test({
238
246
...[ 'index.js' , 'index.mjs' , 'index.cjs' , 'index.ts' , 'index.tsx' , 'index.vue' ] . flatMap (
239
247
filename => [ 'camelCase' , 'snakeCase' , 'kebabCase' , 'pascalCase' ] . map ( chosenCase => testCase ( filename , chosenCase ) ) ,
240
248
) ,
249
+ testCaseWithOptions ( 'index.tsx' , undefined , [ { case : 'pascalCase' , multipleFileExtensions : false } ] ) ,
250
+ testCaseWithOptions ( 'src/index.tsx' , undefined , [ { case : 'pascalCase' , multipleFileExtensions : false } ] ) ,
251
+ testCaseWithOptions ( 'src/foo/fooBar.test.js' , undefined , [ { case : 'camelCase' , multipleFileExtensions : false } ] ) ,
252
+ testCaseWithOptions ( 'src/foo/fooBar.testUtils.js' , undefined , [ { case : 'camelCase' , multipleFileExtensions : false } ] ) ,
253
+ testCaseWithOptions ( 'src/foo/foo_bar.test_utils.js' , undefined , [ { case : 'snakeCase' , multipleFileExtensions : false } ] ) ,
254
+ testCaseWithOptions ( 'src/foo/foo.test.js' , undefined , [ { case : 'kebabCase' , multipleFileExtensions : false } ] ) ,
255
+ testCaseWithOptions ( 'src/foo/foo-bar.test.js' , undefined , [ { case : 'kebabCase' , multipleFileExtensions : false } ] ) ,
256
+ testCaseWithOptions ( 'src/foo/foo-bar.test-utils.js' , undefined , [ { case : 'kebabCase' , multipleFileExtensions : false } ] ) ,
257
+ testCaseWithOptions ( 'src/foo/Foo.Test.js' , undefined , [ { case : 'pascalCase' , multipleFileExtensions : false } ] ) ,
258
+ testCaseWithOptions ( 'src/foo/FooBar.Test.js' , undefined , [ { case : 'pascalCase' , multipleFileExtensions : false } ] ) ,
259
+ testCaseWithOptions ( 'src/foo/FooBar.TestUtils.js' , undefined , [ { case : 'pascalCase' , multipleFileExtensions : false } ] ) ,
260
+ testCaseWithOptions ( 'spec/Iss47.100Spec.js' , undefined , [ { case : 'pascalCase' , multipleFileExtensions : false } ] ) ,
261
+ // Multiple filename parts - multiple file extensions
262
+ testCaseWithOptions ( 'src/foo/fooBar.Test.js' , undefined , [ { case : 'camelCase' } ] ) ,
263
+ testCaseWithOptions ( 'test/foo/fooBar.testUtils.js' , undefined , [ { case : 'camelCase' } ] ) ,
264
+ testCaseWithOptions ( 'test/foo/.testUtils.js' , undefined , [ { case : 'camelCase' } ] ) ,
265
+ testCaseWithOptions ( 'test/foo/foo_bar.Test.js' , undefined , [ { case : 'snakeCase' } ] ) ,
266
+ testCaseWithOptions ( 'test/foo/foo_bar.Test_Utils.js' , undefined , [ { case : 'snakeCase' } ] ) ,
267
+ testCaseWithOptions ( 'test/foo/.Test_Utils.js' , undefined , [ { case : 'snakeCase' } ] ) ,
268
+ testCaseWithOptions ( 'test/foo/foo-bar.Test.js' , undefined , [ { case : 'kebabCase' } ] ) ,
269
+ testCaseWithOptions ( 'test/foo/foo-bar.Test-Utils.js' , undefined , [ { case : 'kebabCase' } ] ) ,
270
+ testCaseWithOptions ( 'test/foo/.Test-Utils.js' , undefined , [ { case : 'kebabCase' } ] ) ,
271
+ testCaseWithOptions ( 'test/foo/FooBar.Test.js' , undefined , [ { case : 'pascalCase' } ] ) ,
272
+ testCaseWithOptions ( 'test/foo/FooBar.TestUtils.js' , undefined , [ { case : 'pascalCase' } ] ) ,
273
+ testCaseWithOptions ( 'test/foo/.TestUtils.js' , undefined , [ { case : 'pascalCase' } ] ) ,
241
274
] ,
242
275
invalid : [
243
276
testCase (
@@ -258,7 +291,7 @@ test({
258
291
testCase (
259
292
'test/foo/foo_bar.test_utils.js' ,
260
293
'camelCase' ,
261
- 'Filename is not in camel case. Rename it to `fooBar.testUtils .js`.' ,
294
+ 'Filename is not in camel case. Rename it to `fooBar.test_utils .js`.' ,
262
295
) ,
263
296
testCase (
264
297
'test/foo/fooBar.js' ,
@@ -273,7 +306,7 @@ test({
273
306
testCase (
274
307
'test/foo/fooBar.testUtils.js' ,
275
308
'snakeCase' ,
276
- 'Filename is not in snake case. Rename it to `foo_bar.test_utils .js`.' ,
309
+ 'Filename is not in snake case. Rename it to `foo_bar.testUtils .js`.' ,
277
310
) ,
278
311
testCase (
279
312
'test/foo/fooBar.js' ,
@@ -288,7 +321,7 @@ test({
288
321
testCase (
289
322
'test/foo/fooBar.testUtils.js' ,
290
323
'kebabCase' ,
291
- 'Filename is not in kebab case. Rename it to `foo-bar.test-utils .js`.' ,
324
+ 'Filename is not in kebab case. Rename it to `foo-bar.testUtils .js`.' ,
292
325
) ,
293
326
testCase (
294
327
'test/foo/fooBar.js' ,
@@ -298,12 +331,12 @@ test({
298
331
testCase (
299
332
'test/foo/foo_bar.test.js' ,
300
333
'pascalCase' ,
301
- 'Filename is not in pascal case. Rename it to `FooBar.Test .js`.' ,
334
+ 'Filename is not in pascal case. Rename it to `FooBar.test .js`.' ,
302
335
) ,
303
336
testCase (
304
337
'test/foo/foo-bar.test-utils.js' ,
305
338
'pascalCase' ,
306
- 'Filename is not in pascal case. Rename it to `FooBar.TestUtils .js`.' ,
339
+ 'Filename is not in pascal case. Rename it to `FooBar.test-utils .js`.' ,
307
340
) ,
308
341
testCase (
309
342
'src/foo/_FOO-BAR.js' ,
@@ -547,14 +580,59 @@ test({
547
580
} ,
548
581
'Filename is not in camel case, pascal case, or kebab case. Rename it to `1.js`.' ,
549
582
) ,
583
+ // Multiple filename parts - single file extension
584
+ testCaseWithOptions (
585
+ 'src/foo/foo_bar.test.js' ,
586
+ 'Filename is not in camel case. Rename it to `fooBar.test.js`.' ,
587
+ [ { case : 'camelCase' , multipleFileExtensions : false } ] ,
588
+ ) ,
589
+ testCaseWithOptions (
590
+ 'test/foo/foo_bar.test_utils.js' ,
591
+ 'Filename is not in camel case. Rename it to `fooBar.testUtils.js`.' ,
592
+ [ { case : 'camelCase' , multipleFileExtensions : false } ] ,
593
+ ) ,
594
+ testCaseWithOptions (
595
+ 'test/foo/fooBar.test.js' ,
596
+ 'Filename is not in snake case. Rename it to `foo_bar.test.js`.' ,
597
+ [ { case : 'snakeCase' , multipleFileExtensions : false } ] ,
598
+ ) ,
599
+ testCaseWithOptions (
600
+ 'test/foo/fooBar.testUtils.js' ,
601
+ 'Filename is not in snake case. Rename it to `foo_bar.test_utils.js`.' ,
602
+ [ { case : 'snakeCase' , multipleFileExtensions : false } ] ,
603
+ ) ,
604
+ testCaseWithOptions (
605
+ 'test/foo/fooBar.test.js' ,
606
+ 'Filename is not in kebab case. Rename it to `foo-bar.test.js`.' ,
607
+ [ { case : 'kebabCase' , multipleFileExtensions : false } ] ,
608
+ ) ,
609
+ testCaseWithOptions (
610
+ 'test/foo/fooBar.testUtils.js' ,
611
+ 'Filename is not in kebab case. Rename it to `foo-bar.test-utils.js`.' ,
612
+ [ { case : 'kebabCase' , multipleFileExtensions : false } ] ,
613
+ ) ,
614
+ testCaseWithOptions (
615
+ 'test/foo/foo_bar.test.js' ,
616
+ 'Filename is not in pascal case. Rename it to `FooBar.Test.js`.' ,
617
+ [ { case : 'pascalCase' , multipleFileExtensions : false } ] ,
618
+ ) ,
619
+ testCaseWithOptions (
620
+ 'test/foo/foo-bar.test-utils.js' ,
621
+ 'Filename is not in pascal case. Rename it to `FooBar.TestUtils.js`.' ,
622
+ [ { case : 'pascalCase' , multipleFileExtensions : false } ] ,
623
+ ) ,
550
624
] ,
551
625
} ) ;
552
626
553
627
test . snapshot ( {
554
628
valid : [
555
629
undefined ,
556
630
'src/foo.JS/bar.js' ,
631
+ 'src/foo.JS/bar.spec.js' ,
632
+ 'src/foo.JS/.spec.js' ,
557
633
'src/foo.JS/bar' ,
634
+ 'foo.SPEC.js' ,
635
+ '.SPEC.js' ,
558
636
] . map ( filename => ( { code : `const filename = ${ JSON . stringify ( filename ) } ;` , filename} ) ) ,
559
637
invalid : [
560
638
{
@@ -575,6 +653,6 @@ test.snapshot({
575
653
'foo.jS' ,
576
654
'index.JS' ,
577
655
'foo..JS' ,
578
- ] . map ( filename => ( { code : `const filename = ${ JSON . stringify ( filename ) } ; ` , filename} ) ) ,
656
+ ] . map ( filename => ( { code : `/* Filename ${ filename } */ ` , filename} ) ) ,
579
657
] ,
580
658
} ) ;
0 commit comments