Skip to content
Permalink
Browse files

fix(gatsby-ssr): can't export a function unless it's in the API, so t…

…o utilities checkPathExclusion
  • Loading branch information
wmontgomery committed Jul 22, 2019
1 parent b9721f8 commit d38981e547d5a4f323c153c5d9691781a80b859a
Showing with 29 additions and 17 deletions.
  1. +1 −11 src/gatsby-ssr.spec.ts
  2. +1 −6 src/gatsby-ssr.ts
  3. +11 −0 src/utilities.spec.ts
  4. +7 −0 src/utilities.ts
  5. +9 −0 utilities.js
@@ -1,4 +1,4 @@
import { onPreRenderHTML, onRenderBody, checkPathExclusion } from './gatsby-ssr'
import { onPreRenderHTML, onRenderBody } from './gatsby-ssr'
import Spy = jasmine.Spy
import { headComponentsData, postBodyComponentsData, scriptsData } from './fake-data.spec'

@@ -208,14 +208,4 @@ describe('gatsby-ssr.js', () => {
expect(replacePostBodyComponentsSpy).toHaveBeenCalledTimes(0)
})
})

describe('checkPathExclusion', () => {
it('does the pathname match any of the exclusions', () => {
expect(checkPathExclusion('/client/omegablerns', { excludePaths: /\/client/ })).toBeTruthy()
expect(checkPathExclusion('/my-cool-page', { excludePaths: /\/my-cool-page/ })).toBeTruthy()
expect(checkPathExclusion('/about/blerns', { excludePaths: /(\/client)|(\/tacos)/ })).toBeFalsy()
expect(checkPathExclusion('/about/tacos', { excludePaths: /(\/client)|(\/about\/tacos)/ })).toBeTruthy()
expect(checkPathExclusion('/blerkstorm', {})).toBeFalsy()
})
})
})
@@ -1,4 +1,5 @@
import { ReactElement, ReactNode } from 'react'
import { checkPathExclusion } from './utilities'

export interface OnRenderBodyArgs {
scripts?: Script[]
@@ -49,12 +50,6 @@ export function onPreRenderHTML ({ getHeadComponents, pathname, replaceHeadCompo
replacePostBodyComponents(getPostBodyComponentsNoJS(getPostBodyComponents(), pluginOptions))
}

export function checkPathExclusion (pathname: string, pluginOptions: PluginOptions): boolean {
if (!pluginOptions.excludePaths) return false

return RegExp(pluginOptions.excludePaths).test(pathname)
}

function getHeadComponentsNoJS (headComponents: ReactNode[], pluginOptions: PluginOptions): ReactNode[] {
return headComponents.filter((headComponent) => {
// Not a react component and therefore not a <script>.
@@ -0,0 +1,11 @@
import { checkPathExclusion } from './utilities'

describe('checkPathExclusion', () => {
it('does the pathname match any of the exclusions', () => {
expect(checkPathExclusion('/client/omegablerns', { excludePaths: /\/client/ })).toBeTruthy()
expect(checkPathExclusion('/my-cool-page', { excludePaths: /\/my-cool-page/ })).toBeTruthy()
expect(checkPathExclusion('/about/blerns', { excludePaths: /(\/client)|(\/tacos)/ })).toBeFalsy()
expect(checkPathExclusion('/about/tacos', { excludePaths: /(\/client)|(\/about\/tacos)/ })).toBeTruthy()
expect(checkPathExclusion('/blerkstorm', {})).toBeFalsy()
})
})
@@ -0,0 +1,7 @@
import { PluginOptions } from './gatsby-ssr'

export function checkPathExclusion (pathname: string, pluginOptions: PluginOptions): boolean {
if (!pluginOptions.excludePaths) return false

return RegExp(pluginOptions.excludePaths).test(pathname)
}

Some generated files are not rendered by default. Learn more.

0 comments on commit d38981e

Please sign in to comment.
You can’t perform that action at this time.