@@ -2,77 +2,105 @@ const validatePath = require(`../validate-path`)
2
2
const createPath = require ( `../create-path` )
3
3
4
4
describe ( `JavaScript page creator` , ( ) => {
5
+ it ( `includes the correct file types` , ( ) => {
6
+ const validFiles = [
7
+ { path : `test1.js` } ,
8
+ { path : `somedir/test1.js` } ,
9
+ { path : `somedir/test2.ts` } ,
10
+ { path : `somedir/dir2/test1.js` } ,
11
+ ]
12
+
13
+ expect ( validFiles . filter ( file => validatePath ( file . path ) ) . length ) . toEqual ( validFiles . length )
14
+ } )
15
+
5
16
it ( `filters out files that start with underscores` , ( ) => {
6
- const files = [
7
- {
8
- path : `something/blah.js` ,
9
- } ,
10
- {
11
- path : `something/_blah.js` ,
12
- } ,
13
- {
14
- path : `_blah.js` ,
15
- } ,
17
+ const validFiles = [
18
+ { path : `something/blah.js` } ,
19
+ { path : `test1.js` } ,
20
+ ]
21
+
22
+ const testFiles = validFiles . concat ( [
23
+ { path : `something/_foo.js` } ,
24
+ { path : `_blah.js` } ,
25
+ ] )
26
+
27
+ expect ( testFiles . filter ( file => validatePath ( file . path ) ) . length ) . toEqual ( validFiles . length )
28
+ } )
29
+
30
+ it ( `filters out files that start with dot` , ( ) => {
31
+ const validFiles = [
32
+ { path : `something/blah.js` } ,
33
+ { path : `test1.ts` } ,
16
34
]
17
35
18
- expect ( files . filter ( file => validatePath ( file . path ) ) . length ) . toEqual ( 1 )
36
+ const testFiles = validFiles . concat ( [
37
+ { path : `.eslintrc` } ,
38
+ { path : `something/.eslintrc` } ,
39
+ { path : `something/.eslintrc.js` } ,
40
+ { path : `.markdownlint.json` } ,
41
+ { path : `something/.markdownlint.json` } ,
42
+ ] )
43
+
44
+ expect ( testFiles . filter ( file => validatePath ( file . path ) ) . length ) . toEqual ( validFiles . length )
45
+ } )
46
+
47
+ it ( `filters out json and yaml files` , ( ) => {
48
+ const validFiles = [
49
+ { path : `somefile.js` } ,
50
+ { path : `something/blah.js` } ,
51
+ ]
52
+
53
+ const testFiles = validFiles . concat ( [
54
+ { path : `something/otherConfig.yml` } ,
55
+ { path : `config.yaml` } ,
56
+ { path : `somefile.json` } ,
57
+ { path : `dir1/file.json` } ,
58
+ { path : `dir1/dir2/file.json` } ,
59
+ ] )
60
+
61
+ expect ( testFiles . filter ( file => validatePath ( file . path ) ) . length ) . toEqual ( validFiles . length )
19
62
} )
20
63
21
64
it ( `filters out files that start with template-*` , ( ) => {
22
- const files = [
23
- {
24
- path : `something/blah.js` ,
25
- } ,
26
- {
27
- path : `something/template-cool-page-type.js` ,
28
- } ,
29
- {
30
- path : `template-cool-page-type.js` ,
31
- } ,
65
+ const validFiles = [
66
+ { path : `something/blah.js` } ,
67
+ { path : `file1.js` } ,
32
68
]
33
69
34
- expect ( files . filter ( file => validatePath ( file . path ) ) . length ) . toEqual ( 1 )
70
+ const testFiles = validFiles . concat ( [
71
+ { path : `template-cool-page-type.js` } ,
72
+ ] )
73
+
74
+ expect ( testFiles . filter ( file => validatePath ( file . path ) ) . length ) . toEqual ( validFiles . length )
35
75
} )
36
76
37
77
it ( `filters out files that have TypeScript declaration extensions` , ( ) => {
38
- const files = [
39
- {
40
- path : `something/foo.ts` ,
41
- } ,
42
- {
43
- path : `something/bar.tsx` ,
44
- } ,
45
- {
46
- path : `something/declaration-file.d.ts` ,
47
- } ,
48
- {
49
- path : `something-else/other-declaration-file.d.tsx` ,
50
- } ,
78
+ const validFiles = [
79
+ { path : `something/foo.ts` } ,
80
+ { path : `something/bar.tsx` } ,
51
81
]
52
82
53
- expect ( files . filter ( file => validatePath ( file . path ) ) . length ) . toEqual ( 2 )
83
+ const testFiles = validFiles . concat ( [
84
+ { path : `something/declaration-file.d.ts` } ,
85
+ { path : `something-else/other-declaration-file.d.tsx` } ,
86
+ ] )
87
+
88
+ expect ( testFiles . filter ( file => validatePath ( file . path ) ) . length ) . toEqual ( validFiles . length )
54
89
} )
55
90
56
91
it ( `filters out test files` , ( ) => {
57
- const files = [
58
- {
59
- path : `__tests__/something.test.js` ,
60
- } ,
61
- {
62
- path : `foo.spec.js` ,
63
- } ,
64
- {
65
- path : `bar.test.js` ,
66
- } ,
67
- {
68
- path : `page.js` ,
69
- } ,
70
- {
71
- path : `page.jsx` ,
72
- } ,
92
+ const validFiles = [
93
+ { path : `page.js` } ,
94
+ { path : `page.jsx` } ,
73
95
]
74
96
75
- expect ( files . filter ( file => validatePath ( file . path ) ) . length ) . toEqual ( 2 )
97
+ const testFiles = validFiles . concat ( [
98
+ { path : `__tests__/something.test.js` } ,
99
+ { path : `foo.spec.js` } ,
100
+ { path : `bar.test.js` } ,
101
+ ] )
102
+
103
+ expect ( testFiles . filter ( file => validatePath ( file . path ) ) . length ) . toEqual ( validFiles . length )
76
104
} )
77
105
78
106
describe ( `create-path` , ( ) => {
0 commit comments