Skip to content

Commit

Permalink
Don't create pages for test files (#3464)
Browse files Browse the repository at this point in the history
* Don't generate pages for test files

* Use parsedPath.base instead of path
  • Loading branch information
kpollich authored and KyleAMathews committed Jan 10, 2018
1 parent e1888a4 commit 57af380
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,28 @@ describe(`JavaScript page creator`, () => {
expect(files.filter(file => validatePath(file.path)).length).toEqual(2)
})

it(`filters out test files`, () => {
const files = [
{
path: `__tests__/something.test.js`,
},
{
path: `foo.spec.js`,
},
{
path: `bar.test.js`,
},
{
path: `page.js`,
},
{
path: `page.jsx`,
},
]

expect(files.filter(file => validatePath(file.path)).length).toEqual(2)
})

describe(`create-path`, () => {
it(`should create unix paths`, () => {
const basePath = `/a/`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ const systemPath = require(`path`)

const tsDeclarationExtTest = /\.d\.tsx?$/

function isTestFile(path) {
const testFileTest = new RegExp(`(/__tests__/.*|(\\.|/)(test|spec))\\.jsx?$`)
return path.match(testFileTest)
}

module.exports = path => {
// Disallow paths starting with an underscore
// and template-.
Expand All @@ -10,6 +15,7 @@ module.exports = path => {
return (
parsedPath.name.slice(0, 1) !== `_` &&
parsedPath.name.slice(0, 9) !== `template-` &&
!tsDeclarationExtTest.test(parsedPath.base)
!tsDeclarationExtTest.test(parsedPath.base) &&
!isTestFile(parsedPath.base)
)
}

0 comments on commit 57af380

Please sign in to comment.