Skip to content

Commit

Permalink
fix: fix uriTemplate error
Browse files Browse the repository at this point in the history
  • Loading branch information
kelp404 committed Apr 5, 2020
1 parent 3b79e22 commit b4ca8e5
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 32 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
.DS_Store

# tests
__tests__/**/*.js
coverage/

# node modules
Expand Down
29 changes: 0 additions & 29 deletions __tests__/route.coffee

This file was deleted.

27 changes: 27 additions & 0 deletions __tests__/route.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const React = require('react');
const Route = require('../lib/route');

test('Initial Route without a parent.', () => {
const route = new Route({
name: 'web',
uri: '/users/{userId:[\\w-]{20}}/projects?index',
resolve: {
user: ({userId}) => ({id: userId, name: 'User'}),
projects: () => ([
{id: 'AWgrmJp1SjjuUM2bzZXM', title: 'Project'}
])
},
component: () => <div/>
});
expect(route).toMatchSnapshot();
});

test('Initial Route with a parent.', () => {
const parent = new Route({name: 'web', uri: '/'});
const route = new Route({
name: 'web.dashboard',
uri: 'dashboard',
parent
});
expect(route).toMatchSnapshot();
});
3 changes: 3 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
presets: ['@babel/preset-env', '@babel/preset-react']
};
2 changes: 1 addition & 1 deletion lib/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ module.exports = class Route {
// The match is like ['{projectId:[w-]{20}}', 'projectId', '[w-]{20}', ...].
this.uriParamKeys.push(match[1]);
uriPattern = uriPattern.replace(uriParamPattern, `(${match[2]})`);
uriTemplate = uriTemplate.replace(uriParamPattern, `{${match[1]}`);
uriTemplate = uriTemplate.replace(uriParamPattern, `{${match[1]}}`);
});
(this.uri.match(/\?[\w-]+/g) || []).forEach(uriQueryString => {
uriPattern = uriPattern.replace(uriQueryString, '');
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "index.js",
"scripts": {
"start": "concurrently --kill-others \"node_modules/nodemon/bin/nodemon.js example/server.js --watch example/server.js\" \"node_modules/webpack-dev-server/bin/webpack-dev-server.js\"",
"eslint": "./node_modules/eslint/bin/eslint.js index.js lib config example/pages example/app.js example/router.js example/server.js",
"eslint": "./node_modules/eslint/bin/eslint.js index.js lib __tests__ config example/pages example/app.js example/router.js example/server.js",
"build": "./node_modules/webpack/bin/webpack.js --mode=production",
"changelog": "node_modules/conventional-changelog-cli/cli.js -p angular",
"ncu": "./node_modules/npm-check-updates/bin/ncu",
Expand Down

0 comments on commit b4ca8e5

Please sign in to comment.