New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

cyclic-router

Package Overview
Dependencies
Maintainers
3
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cyclic-router - npm Package Compare versions

Comparing version 4.0.7 to 5.0.0

lib/routerify.d.ts

9

CHANGELOG.md

@@ -0,1 +1,10 @@

# v5.0.0 (2017-08-08)
## Features
- **routerify:** Add option to omit history source
([4e42e6d1](https://github.com/git+https://github.com/cyclejs-community/cyclic-router.git/commits/4e42e6d1ac86c133ad88de3ee886212ac7a52e83))
# v4.0.7 (2017-08-04)

@@ -2,0 +11,0 @@

2

lib/index.d.ts

@@ -1,3 +0,3 @@

export * from './makeRouterDriver';
export * from './routerify';
export { RouterSource } from './RouterSource';
export * from './interfaces';

@@ -6,5 +6,5 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
__export(require("./makeRouterDriver"));
__export(require("./routerify"));
var RouterSource_1 = require("./RouterSource");
exports.RouterSource = RouterSource_1.RouterSource;
//# sourceMappingURL=index.js.map

@@ -25,11 +25,11 @@ "use strict";

/**
* Function used to create HREFs that are properly namespaced
* @typedef {createHref}
* @name createHref
* @method createHref
* @param {string} path - the HREF that will be appended to the current
* namespace
* @return {string} a fully qualified HREF composed from the current
* namespace and the path provided
*/
* Function used to create HREFs that are properly namespaced
* @typedef {createHref}
* @name createHref
* @method createHref
* @param {string} path - the HREF that will be appended to the current
* namespace
* @return {string} a fully qualified HREF composed from the current
* namespace and the path provided
*/
return function createHref(location) {

@@ -36,0 +36,0 @@ if (typeof location === 'object' && location !== null) {

{
"name": "cyclic-router",
"version": "4.0.7",
"version": "5.0.0",
"description": "A router driver built for Cycle.js",

@@ -29,8 +29,10 @@ "main": "lib/index.js",

"homepage": "https://github.com/cyclejs-community/cyclic-router#readme",
"peerDependencies": {
"@cycle/history": "*"
},
"dependencies": {
"@cycle/history": "^6.3.0",
"@cycle/run": "^3.1.0",
"history": "^4.6.3"
"@cycle/run": "^3.1.0"
},
"devDependencies": {
"@cycle/history": "^6.3.0",
"@cycle/rxjs-run": "^7.0.0",

@@ -49,2 +51,3 @@ "@types/history": "^4.6.0",

"mocha": "^3.4.2",
"prettier": "^1.5.3",
"rxjs": "^5.4.0",

@@ -61,6 +64,8 @@ "switch-path": "^1.2.0",

"ghooks": {
"commit-msg": "node ./node_modules/.bin/validate-commit-msg"
"commit-msg": "node ./node_modules/.bin/validate-commit-msg",
"pre-commit": "npm run format"
}
},
"scripts": {
"format": "prettier --tab-width 4 --single-quote --write '{src,test}/**/*.{js,ts,tsx}'",
"lint": "tslint -c tslint.json src/*.ts src/**/*.ts",

@@ -67,0 +72,0 @@ "test-node": "mocha -r babel-register test/index.js",

/* eslint max-nested-callbacks: 0 */
/*global describe, it */
import assert from 'assert'
import {run} from '@cycle/rxjs-run'
import {setAdapt} from '@cycle/run/lib/adapt'
import {Observable} from 'rxjs'
import {makeRouterDriver} from '../lib'
import {createMemoryHistory, MemoryHistoryBuildOptions} from 'history'
import switchPath from 'switch-path'
import assert from 'assert';
import { setAdapt, adapt } from '@cycle/run/lib/adapt';
import { Observable } from 'rxjs';
import { routerify } from '../lib';
import { makeServerHistoryDriver } from '@cycle/history';
import switchPath from 'switch-path';
describe('Cyclic Router - Rx 5', () => {
before(() => setAdapt(stream => Observable.from(stream)));
describe('makeRouterDriver', () => {
it('should throw if not given a history instance', () => {
assert.throws(() => {
makeRouterDriver(null)
}, Error,
/First argument to makeRouterDriver must be a valid history driver/i)
})
describe('Cyclic Router - RxJS 5', () => {
before(() => setAdapt(stream => Observable.from(stream)));
describe('routerify', () => {
it('should throw if not given a main function', () => {
assert.throws(
() => {
makeRouterDriver(null);
},
Error,
/First argument to routerify must be a valid cycle app/i
);
});
describe('routerDriver', () => {
it('should return an object with `path` `define` `observable` ' +
'`createHref` and `dispose`',
() => {
const history = createMemoryHistory()
const router = makeRouterDriver(history, switchPath)(Observable.of('/'))
assert.notStrictEqual(router.path, null)
assert.strictEqual(typeof router.path, 'function')
assert.notStrictEqual(router.define, null)
assert.strictEqual(typeof router.define, 'function')
assert.notStrictEqual(router.history$, null)
assert.strictEqual(typeof router.history$, 'object')
assert.strictEqual(typeof router.history$.subscribe, 'function')
assert.notStrictEqual(router.createHref, null)
assert.strictEqual(typeof router.createHref, 'function')
})
})
})
it('should return a function returning sinks', () => {
const app = () => ({ router: Observable.never() });
const augmentedApp = routerify(app, switchPath);
const sinks = augmentedApp({ history: Observable.never() });
assert.notStrictEqual(augmentedApp, null);
assert.strictEqual(typeof augmentedApp, 'function');
assert.notStrictEqual(sinks, null);
assert.strictEqual(typeof sinks, 'object');
assert.notStrictEqual(sinks.history, null);
assert.strictEqual(typeof sinks.history, 'object');
assert.strictEqual(typeof sinks.history.subscribe, 'function');
});
});
describe('path()', () => {
it('should return an object with `path` `define` `observable` ' +
'`createHref`',
() => {
const history = createMemoryHistory()
const router = makeRouterDriver(history, switchPath)(Observable.of('/'))
.path('/')
assert.notStrictEqual(router.path, null)
assert.strictEqual(typeof router.path, 'function')
assert.notStrictEqual(router.define, null)
assert.strictEqual(typeof router.define, 'function')
assert.notStrictEqual(router.history$, null)
assert.strictEqual(typeof router.history$, 'object')
assert.strictEqual(typeof router.history$.subscribe, 'function')
assert.notStrictEqual(router.createHref, null)
assert.strictEqual(typeof router.createHref, 'function')
})
describe('path()', () => {
it(
'should return an object with `path` `define` `observable` ' +
'`createHref` and `dispose`',
() => {
const app = ({ router }) => {
assert.notStrictEqual(router.path, null);
assert.strictEqual(typeof router.path, 'function');
assert.notStrictEqual(router.define, null);
assert.strictEqual(typeof router.define, 'function');
assert.notStrictEqual(router.history$, null);
assert.strictEqual(typeof router.history$, 'object');
assert.strictEqual(
typeof router.history$.subscribe,
'function'
);
assert.notStrictEqual(router.createHref, null);
assert.strictEqual(typeof router.createHref, 'function');
return {};
};
routerify(app, switchPath)({ history: Observable.never() });
}
);
it('should filter the history$', () => {
const routes = [
'/somewhere/else',
'/path/that/is/correct',
]
const history = createMemoryHistory()
const router = makeRouterDriver(history, switchPath)(Observable.never())
.path('/path')
it('should filter the history$', () => {
const routes = ['/somewhere/else', '/path/that/is/correct'];
router.history$.subscribe((location) => {
assert.notStrictEqual(location.pathname, '/somewhere/else')
assert.strictEqual(location.pathname, '/path/that/is/correct')
})
const app = sources => {
sources.router.path('/path').history$.subscribe(location => {
assert.notStrictEqual(location.pathname, '/somewhere/else');
assert.strictEqual(
location.pathname,
'/path/that/is/correct'
);
});
return {};
};
routerify(app, switchPath)({
history: adapt(
makeServerHistoryDriver()(Observable.from(routes))
)
});
});
routes.forEach(r => history.push(r))
})
it('multiple path()s should filter the history$', () => {
const routes = [
'/the/wrong/path',
'/some/really/really/deeply/nested/route/that/is/correct',
'/some/really/really/deeply/nested/incorrect/route'
];
it('multiple path()s should filter the history$', () => {
const routes = [
'/the/wrong/path',
'/some/really/really/deeply/nested/route/that/is/correct',
'/some/really/really/deeply/nested/incorrect/route',
]
const app = sources => {
sources.router
.path('/some')
.path('/really')
.path('/really')
.path('/deeply')
.path('/nested')
.path('/route')
.path('/that')
.history$.subscribe(({ pathname }) => {
assert.strictEqual(
pathname,
'/some/really/really/deeply/nested/route/that/is/correct'
);
});
return {};
};
routerify(app, switchPath)({
history: adapt(
makeServerHistoryDriver()(Observable.from(routes))
)
});
});
const history = createMemoryHistory()
const router = makeRouterDriver(history, switchPath)(Observable.never())
.path('/some').path('/really').path('/really').path('/deeply')
.path('/nested').path('/route').path('/that')
it('should create a proper path using createHref()', () => {
const routes = [
'/the/wrong/path',
'/some/really/really/deeply/nested/route/that/is/correct',
'/some/really/really/deeply/nested/incorrect/route'
];
router.history$.subscribe(({pathname}) => {
assert.strictEqual(pathname,
'/some/really/really/deeply/nested/route/that/is/correct')
})
const app = sources => {
sources.router
.path('/some')
.path('/really')
.path('/really')
.path('/deeply')
.path('/nested')
.path('/route')
.path('/that')
.history$.subscribe(({ pathname }) => {
assert.strictEqual(
pathname,
'/some/really/really/deeply/nested/route/that/is/correct'
);
assert.strictEqual(
router.createHref('/is/correct'),
'/some/really/really/deeply/nested/route/that/is/correct'
);
});
return {};
};
routerify(app, switchPath)({
history: adapt(
makeServerHistoryDriver()(Observable.from(routes))
)
});
});
});
routes.forEach(r => history.push(r))
})
describe('define()', () => {
it(
'should return an object with `path$` `value$` `fullPath$` ' +
'`createHref` and `dispose`',
() => {
const app = sources => {
const router = sources.router.define({});
assert.strictEqual(router instanceof Observable, true);
assert.strictEqual(typeof router.subscribe, 'function');
assert.notStrictEqual(router.createHref, null);
assert.strictEqual(typeof router.createHref, 'function');
return {};
};
routerify(app, switchPath)({ history: Observable.never() });
}
);
it('should create a proper path using createHref()', () => {
const routes = [
'/the/wrong/path',
'/some/really/really/deeply/nested/route/that/is/correct',
'/some/really/really/deeply/nested/incorrect/route',
]
it('should match routes against a definition object', done => {
const defintion = {
'/some': {
'/route': 123
}
};
const history = createMemoryHistory()
const router = makeRouterDriver(history, switchPath)(Observable.never())
.path('/some').path('/really').path('/really').path('/deeply')
.path('/nested').path('/route').path('/that')
const app = ({ router }) => {
const match$ = router.define(defintion);
match$.subscribe(({ path, value, location }) => {
assert.strictEqual(path, '/some/route');
assert.strictEqual(value, 123);
assert.strictEqual(location.pathname, '/some/route');
done();
});
return {};
};
routerify(app, switchPath)({
history: adapt(
makeServerHistoryDriver()(Observable.of('/some/route'))
)
});
});
it('should respect prior filtering by path()', done => {
const defintion = {
'/correct': {
'/route': 123
}
};
router.history$.subscribe(({pathname}) => {
assert.strictEqual(pathname,
'/some/really/really/deeply/nested/route/that/is/correct')
// assert.strictEqual(
// router.createHref('/is/correct'),
// '/some/really/really/deeply/nested/route/that/is/correct')
})
routes.forEach(r => history.push(r))
const routes = ['/some/nested/correct/route'];
})
})
const app = ({ router }) => {
const match$ = router
.path('/some')
.path('/nested')
.define(defintion);
match$.subscribe(({ path, value, location }) => {
assert.strictEqual(path, '/correct/route');
assert.strictEqual(value, 123);
assert.strictEqual(
location.pathname,
'/some/nested/correct/route'
);
done();
});
return {};
};
routerify(app, switchPath)({
history: adapt(
makeServerHistoryDriver()(
Observable.of(
'/wrong/path',
'/some/nested/correct/route'
).delay(0)
)
)
});
});
describe('define()', () => {
it('should return an object that is an Observable with createHref',
() => {
const history = createMemoryHistory()
const router = makeRouterDriver(history, switchPath)(Observable.of('/'))
.define({})
assert.strictEqual(router instanceof Observable, true)
assert.strictEqual(typeof router.subscribe, 'function')
assert.notStrictEqual(router.createHref, null)
assert.strictEqual(typeof router.createHref, 'function')
})
it('should match a default route if one is not found', done => {
const definition = {
'/correct': {
'/route': 123
},
'*': 999
};
it('should match routes against a definition object', done => {
const defintion = {
'/some': {
'/route': 123,
},
}
const app = ({ router }) => {
const match$ = router
.path('/some')
.path('/nested')
.define(definition);
match$.subscribe(({ path, value, location }) => {
assert.strictEqual(path, '/incorrect/route');
assert.strictEqual(value, 999);
assert.strictEqual(
location.pathname,
'/some/nested/incorrect/route'
);
done();
});
return { router: Observable.of('/wrong/path') };
};
routerify(app, switchPath)({
history: adapt(
makeServerHistoryDriver()(
Observable.of(
'/wrong/route',
'/some/nested/incorrect/route'
).delay(0)
)
)
});
});
const routes = [
'/some/route',
]
it('should create a proper href using createHref()', done => {
const definition = {
'/correct': {
'/route': 123
},
'*': 999
};
const history = createMemoryHistory()
const router = makeRouterDriver(history, switchPath)(Observable.never())
const match$ = router.define(defintion)
const app = ({ router }) => {
const match$ = router
.path('/some')
.path('/nested')
.define(definition);
match$.skip(1).subscribe(({path, value, location}) => {
assert.strictEqual(path, '/some/route')
assert.strictEqual(value, 123)
assert.strictEqual(location.pathname, '/some/route')
done()
})
routes.forEach(r => history.push(r))
})
assert(match$.createHref('/hello'), '/some/nested/hello');
match$.subscribe(({ path, value, location, createHref }) => {
assert.strictEqual(path, '/incorrect/route');
assert.strictEqual(value, 999);
assert.strictEqual(
location.pathname,
'/some/nested/incorrect/route'
);
//assert.strictEqual(location.pathname, createHref('/incorrect/route'))
done();
});
return { router: Observable.of('/wrong/path') };
};
routerify(app, switchPath)({
history: adapt(
makeServerHistoryDriver()(
Observable.of(
'/wrong/route',
'/some/nested/incorrect/route'
).delay(0)
)
)
});
});
it('should respect prior filtering by path()', done => {
const defintion = {
'/correct': {
'/route': 123,
},
}
it('should match partials', done => {
const defintion = {
'/correct': {
'/route': 123
},
'*': 999
};
const routes = [
'/wrong/path',
'/some/nested/correct/route',
]
const app = ({ router }) => {
const match$ = router
.path('/some')
.path('/nested')
.define(defintion);
match$.subscribe(
({ path, location: { pathname }, createHref }) => {
assert.strictEqual(path, '/correct/route');
assert.strictEqual(
pathname,
'/some/nested/correct/route/partial'
);
done();
}
);
const history = createMemoryHistory()
const router = makeRouterDriver(history, switchPath)(Observable.never())
const match$ = router.path('/some').path('/nested').define(defintion)
match$.subscribe(({path, value, location}) => {
assert.strictEqual(path, '/correct/route')
assert.strictEqual(value, 123)
assert.strictEqual(location.pathname, '/some/nested/correct/route')
done()
})
routes.forEach(r => history.push(r))
})
it('should match a default route if one is not found', done => {
const definition = {
'/correct': {
'/route': 123,
},
'*': 999,
}
const routes = [
'/wrong/path',
'/wrong/route',
'/some/nested/incorrect/route',
]
const history = createMemoryHistory()
const router = makeRouterDriver(history, switchPath)(Observable.never())
const match$ = router.path('/some').path('/nested').define(definition)
match$.subscribe(({path, value, location}) => {
assert.strictEqual(path, '/incorrect/route')
assert.strictEqual(value, 999)
assert.strictEqual(location.pathname, '/some/nested/incorrect/route')
done()
})
routes.forEach(r => history.push(r))
})
it('should create a proper href using createHref()', done => {
const defintion = {
'/correct': {
'/route': 123,
},
'*': 999,
}
const routes = [
'/wrong/path',
'/some/nested/correct/route',
]
const history = createMemoryHistory()
const router = makeRouterDriver(history, switchPath)(Observable.never())
const match$ = router
.path('/some').path('/nested').define(defintion)
match$.subscribe(({location: {pathname}, createHref}) => {
assert.strictEqual(pathname, '/some/nested/correct/route')
assert.strictEqual(createHref('/correct/route'), pathname)
done()
})
routes.forEach(r => history.push(r))
})
it('should match partials', done => {
const defintion = {
'/correct': {
'/route': 123,
},
'*': 999,
}
const routes = [
'/wrong/path',
'/some/nested/correct/route/partial',
]
const history = createMemoryHistory()
const router = makeRouterDriver(history, switchPath)(Observable.never())
const match$ = router
.path('/some').path('/nested').define(defintion)
match$.subscribe(({path, location: {pathname}}) => {
assert.strictEqual(path, '/correct/route')
assert.strictEqual(pathname, '/some/nested/correct/route/partial')
done()
})
routes.forEach(r => history.push(r))
})
})
})
return { router: Observable.of('/wrong/path') };
};
routerify(app, switchPath)({
history: adapt(
makeServerHistoryDriver()(
Observable.of(
'/some/nested/correct/route/partial'
).delay(0)
)
)
});
});
});
});
/* eslint max-nested-callbacks: 0 */
/*global describe, it */
import assert from 'assert'
import {run} from '@cycle/run'
import {setAdapt} from '@cycle/run/lib/adapt'
import xs from 'xstream'
import {makeRouterDriver} from '../lib'
import {createMemoryHistory, createBrowserHistory} from 'history'
import assert from 'assert';
import { setAdapt } from '@cycle/run/lib/adapt';
import xs from 'xstream';
import delay from 'xstream/extra/delay';
import { routerify } from '../lib';
import { makeServerHistoryDriver } from '@cycle/history';
import switchPath from 'switch-path';
describe('Cyclic Router - XStream', () => {
before(() => setAdapt(stream => stream));
describe('makeRouterDriver', () => {
it('should throw if not given a history instance', () => {
assert.throws(() => {
makeRouterDriver(null)
}, Error,
/First argument to makeRouterDriver must be a valid history driver/i)
})
before(() => setAdapt(stream => stream));
describe('routerify', () => {
it('should throw if not given a main function', () => {
assert.throws(
() => {
makeRouterDriver(null);
},
Error,
/First argument to routerify must be a valid cycle app/i
);
});
describe('routerDriver', () => {
it('should return an object with `path` `define` `observable` ' +
'`createHref` and `dispose`',
() => {
const history = createMemoryHistory()
const router = makeRouterDriver(history, switchPath)(xs.of('/'))
assert.notStrictEqual(router.path, null)
assert.strictEqual(typeof router.path, 'function')
assert.notStrictEqual(router.define, null)
assert.strictEqual(typeof router.define, 'function')
assert.notStrictEqual(router.history$, null)
assert.strictEqual(typeof router.history$, 'object')
assert.strictEqual(typeof router.history$.addListener, 'function')
assert.notStrictEqual(router.createHref, null)
assert.strictEqual(typeof router.createHref, 'function')
})
})
})
it('should return a function returning sinks', () => {
const app = () => ({ router: xs.never() });
const augmentedApp = routerify(app, switchPath);
const sinks = augmentedApp({ history: xs.never() });
assert.notStrictEqual(augmentedApp, null);
assert.strictEqual(typeof augmentedApp, 'function');
assert.notStrictEqual(sinks, null);
assert.strictEqual(typeof sinks, 'object');
assert.notStrictEqual(sinks.history, null);
assert.strictEqual(typeof sinks.history, 'object');
assert.strictEqual(typeof sinks.history.addListener, 'function');
});
});
describe('path()', () => {
it('should return an object with `path` `define` `observable` ' +
'`createHref` and `dispose`',
() => {
const history = createMemoryHistory()
const router = makeRouterDriver(history, switchPath)(xs.of('/'))
.path('/')
assert.notStrictEqual(router.path, null)
assert.strictEqual(typeof router.path, 'function')
assert.notStrictEqual(router.define, null)
assert.strictEqual(typeof router.define, 'function')
assert.notStrictEqual(router.history$, null)
assert.strictEqual(typeof router.history$, 'object')
assert.strictEqual(typeof router.history$.addListener, 'function')
assert.notStrictEqual(router.createHref, null)
assert.strictEqual(typeof router.createHref, 'function')
})
describe('path()', () => {
it(
'should return an object with `path` `define` `observable` ' +
'`createHref` and `dispose`',
() => {
const app = ({ router }) => {
assert.notStrictEqual(router.path, null);
assert.strictEqual(typeof router.path, 'function');
assert.notStrictEqual(router.define, null);
assert.strictEqual(typeof router.define, 'function');
assert.notStrictEqual(router.history$, null);
assert.strictEqual(typeof router.history$, 'object');
assert.strictEqual(
typeof router.history$.addListener,
'function'
);
assert.notStrictEqual(router.createHref, null);
assert.strictEqual(typeof router.createHref, 'function');
return {};
};
routerify(app, switchPath)({ history: xs.never() });
}
);
it('should filter the history$', () => {
const routes = [
'/somewhere/else',
'/path/that/is/correct',
]
it('should filter the history$', () => {
const routes = ['/somewhere/else', '/path/that/is/correct'];
const history = createMemoryHistory()
const router = makeRouterDriver(history, switchPath)(xs.fromArray(routes))
.path('/path')
const app = sources => {
sources.router.path('/path').history$.addListener({
next: location => {
assert.notStrictEqual(
location.pathname,
'/somewhere/else'
);
assert.strictEqual(
location.pathname,
'/path/that/is/correct'
);
},
error: () => {},
complete: () => {}
});
return {};
};
routerify(app, switchPath)({
history: makeServerHistoryDriver()(xs.fromArray(routes))
});
});
router.history$.addListener({
next: (location) => {
assert.notStrictEqual(location.pathname, '/somewhere/else')
assert.strictEqual(location.pathname, '/path/that/is/correct')
},
error: () => {},
complete: () => {}
})
})
it('multiple path()s should filter the history$', () => {
const routes = [
'/the/wrong/path',
'/some/really/really/deeply/nested/route/that/is/correct',
'/some/really/really/deeply/nested/incorrect/route'
];
it('multiple path()s should filter the history$', () => {
const routes = [
'/the/wrong/path',
'/some/really/really/deeply/nested/route/that/is/correct',
'/some/really/really/deeply/nested/incorrect/route',
]
const app = sources => {
sources.router
.path('/some')
.path('/really')
.path('/really')
.path('/deeply')
.path('/nested')
.path('/route')
.path('/that')
.history$.addListener({
next: ({ pathname }) => {
assert.strictEqual(
pathname,
'/some/really/really/deeply/nested/route/that/is/correct'
);
},
error: () => {},
complete: () => {}
});
return {};
};
routerify(app, switchPath)({
history: makeServerHistoryDriver()(xs.fromArray(routes))
});
});
const history = createMemoryHistory()
const router = makeRouterDriver(history, switchPath)(xs.fromArray(routes))
.path('/some').path('/really').path('/really').path('/deeply')
.path('/nested').path('/route').path('/that')
it('should create a proper path using createHref()', () => {
const routes = [
'/the/wrong/path',
'/some/really/really/deeply/nested/route/that/is/correct',
'/some/really/really/deeply/nested/incorrect/route'
];
router.history$.addListener({
next: ({pathname}) => {
assert.strictEqual(pathname,
'/some/really/really/deeply/nested/route/that/is/correct')
},
error: () => {},
complete: () => {},
})
})
const app = sources => {
sources.router
.path('/some')
.path('/really')
.path('/really')
.path('/deeply')
.path('/nested')
.path('/route')
.path('/that')
.history$.addListener({
next: ({ pathname }) => {
assert.strictEqual(
pathname,
'/some/really/really/deeply/nested/route/that/is/correct'
);
assert.strictEqual(
router.createHref('/is/correct'),
'/some/really/really/deeply/nested/route/that/is/correct'
);
},
error: () => {},
complete: () => {}
});
return {};
};
routerify(app, switchPath)({
history: makeServerHistoryDriver()(xs.fromArray(routes))
});
});
});
it('should create a proper path using createHref()', () => {
const routes = [
'/the/wrong/path',
'/some/really/really/deeply/nested/route/that/is/correct',
'/some/really/really/deeply/nested/incorrect/route',
]
describe('define()', () => {
it(
'should return an object with `path$` `value$` `fullPath$` ' +
'`createHref` and `dispose`',
() => {
const app = sources => {
const router = sources.router.define({});
assert.strictEqual(router instanceof xs, true);
assert.strictEqual(typeof router.addListener, 'function');
assert.notStrictEqual(router.createHref, null);
assert.strictEqual(typeof router.createHref, 'function');
return {};
};
routerify(app, switchPath)({ history: xs.never() });
}
);
const history = createMemoryHistory()
const router = makeRouterDriver(history, switchPath)(xs.fromArray(routes))
.path('/some').path('/really').path('/really').path('/deeply')
.path('/nested').path('/route').path('/that')
it('should match routes against a definition object', done => {
const defintion = {
'/some': {
'/route': 123
}
};
router.history$.addListener({
next: ({pathname}) => {
assert.strictEqual(pathname,
'/some/really/really/deeply/nested/route/that/is/correct')
assert.strictEqual(
router.createHref('/is/correct'),
'/some/really/really/deeply/nested/route/that/is/correct')
},
error: () => {},
complete: () => {},
})
})
})
const app = ({ router }) => {
const match$ = router.define(defintion);
match$.addListener({
next: ({ path, value, location }) => {
assert.strictEqual(path, '/some/route');
assert.strictEqual(value, 123);
assert.strictEqual(location.pathname, '/some/route');
done();
},
error: () => {},
complete: () => {}
});
return {};
};
routerify(app, switchPath)({
history: makeServerHistoryDriver()(xs.of('/some/route'))
});
});
describe('define()', () => {
it('should return an object with `path$` `value$` `fullPath$` ' +
'`createHref` and `dispose`',
() => {
const history = createMemoryHistory()
const router = makeRouterDriver(history, switchPath)(xs.merge(xs.never(), xs.of('/')))
.define({})
assert.strictEqual(router instanceof xs, true)
assert.strictEqual(typeof router.addListener, 'function')
assert.notStrictEqual(router.createHref, null)
assert.strictEqual(typeof router.createHref, 'function')
})
it('should respect prior filtering by path()', done => {
const defintion = {
'/correct': {
'/route': 123
}
};
it('should match routes against a definition object', done => {
const defintion = {
'/some': {
'/route': 123,
},
}
const routes = ['/some/nested/correct/route'];
const history = createMemoryHistory()
const router = makeRouterDriver(history, switchPath)(xs.of('/some/route'))
const match$ = router.define(defintion)
const app = ({ router }) => {
const match$ = router
.path('/some')
.path('/nested')
.define(defintion);
match$.addListener({
next: ({ path, value, location }) => {
assert.strictEqual(path, '/correct/route');
assert.strictEqual(value, 123);
assert.strictEqual(
location.pathname,
'/some/nested/correct/route'
);
done();
},
error: () => {},
complete: () => {}
});
return {};
};
routerify(app, switchPath)({
history: makeServerHistoryDriver()(
xs
.of('/wrong/path', '/some/nested/correct/route')
.compose(delay(0))
)
});
});
match$.addListener({
next: ({path, value, location}) => {
assert.strictEqual(path, '/some/route')
assert.strictEqual(value, 123)
assert.strictEqual(location.pathname, '/some/route')
done()
},
error: () => {},
complete: () => {},
})
})
it('should match a default route if one is not found', done => {
const definition = {
'/correct': {
'/route': 123
},
'*': 999
};
it('should respect prior filtering by path()', done => {
const defintion = {
'/correct': {
'/route': 123,
},
}
const app = ({ router }) => {
const match$ = router
.path('/some')
.path('/nested')
.define(definition);
match$.addListener({
next: ({ path, value, location }) => {
assert.strictEqual(path, '/incorrect/route');
assert.strictEqual(value, 999);
assert.strictEqual(
location.pathname,
'/some/nested/incorrect/route'
);
done();
},
error: () => {},
complete: () => {}
});
return { router: xs.of('/wrong/path') };
};
routerify(app, switchPath)({
history: makeServerHistoryDriver()(
xs
.of('/wrong/route', '/some/nested/incorrect/route')
.compose(delay(0))
)
});
});
const routes = [
'/some/nested/correct/route',
]
it('should create a proper href using createHref()', done => {
const definition = {
'/correct': {
'/route': 123
},
'*': 999
};
const history = createMemoryHistory()
const router = makeRouterDriver(history, switchPath)(xs.never())
const match$ = router.path('/some').path('/nested').define(defintion)
const app = ({ router }) => {
const match$ = router
.path('/some')
.path('/nested')
.define(definition);
match$.addListener({
next: ({path, value, location}) => {
assert.strictEqual(path, '/correct/route')
assert.strictEqual(value, 123)
assert.strictEqual(location.pathname, '/some/nested/correct/route')
done()
},
error: () => {},
complete: () => {},
})
assert(match$.createHref('/hello'), '/some/nested/hello');
match$.addListener({
next: ({ path, value, location, createHref }) => {
assert.strictEqual(path, '/incorrect/route');
assert.strictEqual(value, 999);
assert.strictEqual(
location.pathname,
'/some/nested/incorrect/route'
);
//assert.strictEqual(location.pathname, createHref('/incorrect/route'))
done();
},
error: () => {},
complete: () => {}
});
return { router: xs.of('/wrong/path') };
};
routerify(app, switchPath)({
history: makeServerHistoryDriver()(
xs
.of('/wrong/route', '/some/nested/incorrect/route')
.compose(delay(0))
)
});
});
setTimeout(() => {
history.push('/wrong/path')
history.push('/some/nested/correct/route')
})
})
it('should match partials', done => {
const defintion = {
'/correct': {
'/route': 123
},
'*': 999
};
it('should match a default route if one is not found', done => {
const definition = {
'/correct': {
'/route': 123,
},
'*': 999,
}
const app = ({ router }) => {
const match$ = router
.path('/some')
.path('/nested')
.define(defintion);
match$.addListener({
next: ({ path, location: { pathname }, createHref }) => {
assert.strictEqual(path, '/correct/route');
assert.strictEqual(
pathname,
'/some/nested/correct/route/partial'
);
done();
},
error: () => {},
complete: () => {}
});
const history = createMemoryHistory()
const router = makeRouterDriver(history, switchPath)(xs.of('/wrong/path'))
const match$ = router.path('/some').path('/nested').define(definition)
match$.addListener({
next: ({path, value, location}) => {
assert.strictEqual(path, '/incorrect/route')
assert.strictEqual(value, 999)
assert.strictEqual(location.pathname, '/some/nested/incorrect/route')
done()
},
error: () => {},
complete: () => {},
})
history.push('/wrong/route')
history.push('/some/nested/incorrect/route')
})
it('should create a proper href using createHref()', done => {
const definition = {
'/correct': {
'/route': 123,
},
'*': 999,
}
const history = createMemoryHistory()
const router = makeRouterDriver(history, switchPath)(xs.of('/wrong/path'))
const match$ = router.path('/some').path('/nested').define(definition)
match$.addListener({
next: ({path, value, location, createHref}) => {
assert.strictEqual(path, '/incorrect/route')
assert.strictEqual(value, 999)
assert.strictEqual(location.pathname, '/some/nested/incorrect/route')
//assert.strictEqual(location.pathname, createHref('/incorrect/route'))
done()
},
error: () => {},
complete: () => {},
})
assert(match$.createHref('/hello'), '/some/nested/hello')
history.push('/wrong/route')
history.push('/some/nested/incorrect/route')
})
it('should match partials', done => {
const defintion = {
'/correct': {
'/route': 123,
},
'*': 999,
}
const history = createMemoryHistory()
const router = makeRouterDriver(history, switchPath)(xs.of('/wrong/path'))
const match$ = router
.path('/some').path('/nested').define(defintion)
match$.addListener({
next: ({path, location: {pathname}, createHref}) => {
assert.strictEqual(path, '/correct/route')
assert.strictEqual(pathname, '/some/nested/correct/route/partial')
done()
},
error: () => {},
complete: () => {},
})
history.push('/some/nested/correct/route/partial')
})
})
})
return { router: xs.of('/wrong/path') };
};
routerify(app, switchPath)({
history: makeServerHistoryDriver()(
xs
.of('/some/nested/correct/route/partial')
.compose(delay(0))
)
});
});
});
});

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc