Skip to content

Commit

Permalink
fix: fixes regression with pathPrefix and gatsby-link
Browse files Browse the repository at this point in the history
Note: this is not done! Want to get the tests actually working
  • Loading branch information
DSchau committed Jul 20, 2017
1 parent adedf93 commit 26c2d78
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
3 changes: 3 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ module.exports = {
roots: pkgs,
modulePathIgnorePatterns: distDirs,
coveragePathIgnorePatterns: distDirs,
globals: {
__PREFIX_PATHS__: false
},
testPathIgnorePatterns: [
`/examples/`,
`/www/`,
Expand Down
26 changes: 26 additions & 0 deletions packages/gatsby-link/src/__tests__/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import React from 'react';

const getInstance = (to, pathPrefix = '') => {
if (pathPrefix) {
global.__PREFIX_PATHS__ = true;
global.__PATH_PREFIX__ = pathPrefix;
} else {
global.__PREFIX_PATHS__ = false;
}
const Link = require('../').default;
return new Link({
to
});
};

test('it does not prefix paths by default', () => {
const instance = getInstance('/some-path');

expect(instance.state.to).toBe('/some-path');
});

test.skip('it prefixes paths if __PREFIX_PATHS__ and __PATH_PREFIX__ are defined', () => {
const instance = getInstance('/some-path', '/blog');

expect(instance.state.to).toBe('/blog/some-path');
});
2 changes: 1 addition & 1 deletion packages/gatsby-link/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import PropTypes from "prop-types"

let pathPrefix = ``
if (__PREFIX_PATHS__) {
pathPrefix = `${__PATH_PREFIX__}/`
pathPrefix = __PATH_PREFIX__;
}

class GatsbyLink extends React.Component {
Expand Down

0 comments on commit 26c2d78

Please sign in to comment.