-
Notifications
You must be signed in to change notification settings - Fork 10.3k
/
gatsby-node.js
131 lines (107 loc) · 3.87 KB
/
gatsby-node.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
const validatePath = require(`../validate-path`)
const createPath = require(`../create-path`)
describe(`JavaScript page creator`, () => {
it(`includes the correct file types`, () => {
const validFiles = [
{ path: `test1.js` },
{ path: `somedir/test1.js` },
{ path: `somedir/test2.ts` },
{ path: `somedir/dir2/test1.js` },
]
expect(validFiles.filter(file => validatePath(file.path))).toEqual(
validFiles
)
})
it(`filters out files that start with underscores`, () => {
const validFiles = [{ path: `something/blah.js` }, { path: `test1.js` }]
const testFiles = validFiles.concat([
{ path: `something/_foo.js` },
{ path: `_blah.js` },
])
expect(testFiles.filter(file => validatePath(file.path))).toEqual(
validFiles
)
})
it(`filters out files that start with dot`, () => {
const validFiles = [{ path: `something/blah.js` }, { path: `test1.ts` }]
const testFiles = validFiles.concat([
{ path: `.eslintrc` },
{ path: `something/.eslintrc` },
{ path: `something/.eslintrc.js` },
{ path: `.markdownlint.json` },
{ path: `something/.markdownlint.json` },
])
expect(testFiles.filter(file => validatePath(file.path))).toEqual(
validFiles
)
})
it(`filters out json and yaml files`, () => {
const validFiles = [{ path: `somefile.js` }, { path: `something/blah.js` }]
const testFiles = validFiles.concat([
{ path: `something/otherConfig.yml` },
{ path: `config.yaml` },
{ path: `somefile.json` },
{ path: `dir1/file.json` },
{ path: `dir1/dir2/file.json` },
])
expect(testFiles.filter(file => validatePath(file.path))).toEqual(
validFiles
)
})
it(`filters out files that start with template-*`, () => {
const validFiles = [{ path: `something/blah.js` }, { path: `file1.js` }]
const testFiles = validFiles.concat([
{ path: `template-cool-page-type.js` },
])
expect(testFiles.filter(file => validatePath(file.path))).toEqual(
validFiles
)
})
it(`filters out files that have TypeScript declaration extensions`, () => {
const validFiles = [
{ path: `something/foo.ts` },
{ path: `something/bar.tsx` },
]
const testFiles = validFiles.concat([
{ path: `something/declaration-file.d.ts` },
{ path: `something-else/other-declaration-file.d.tsx` },
])
expect(testFiles.filter(file => validatePath(file.path))).toEqual(
validFiles
)
})
it(`filters out test files`, () => {
const validFiles = [{ path: `page.js` }, { path: `page.jsx` }]
const testFiles = validFiles.concat([
{ path: `src/pages/__tests__/something.test.js` },
{ path: `src/pages/__tests__/something.test.tsx` },
{ path: `src/pages/__tests__/something.js` },
{ path: `src/pages/__tests__/nested-directory/something.js` },
{ path: `src/pages/foo.spec.js` },
{ path: `src/pages/foo.spec.tsx` },
{ path: `src/pages/bar.test.js` },
{ path: `src/pages/bar.test.tsx` },
{ path: `src\\pages\\bar.test.js` },
{ path: `src\\pages\\__tests__\\nested-directory\\something.js` },
])
expect(testFiles.filter(file => validatePath(file.path))).toEqual(
validFiles
)
})
describe(`create-path`, () => {
it(`should create unix paths`, () => {
const basePath = `/a/`
const paths = [`/a/b/c/de`, `/a/bee`, `/a/b/d/c/`]
expect(paths.map(p => createPath(basePath, p))).toMatchSnapshot()
})
it(`should deal with windows paths`, () => {
const basePath = `D:/Projets/gatsby-starter/src/pages`
const paths = [
`D:\\Projets\\gatsby-starter\\src\\pages\\404.tsx`,
`D:\\Projets\\gatsby-starter\\src\\pages\\index.tsx`,
`D:\\Projets\\gatsby-starter\\src\\pages\\blog.tsx`,
]
expect(paths.map(p => createPath(basePath, p))).toMatchSnapshot()
})
})
})