Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[path-to-regexp_v2.x.x] Convert module from ESM to CommonJS (#3275)
- Loading branch information
1 parent
8907099
commit 256ef26
Showing
2 changed files
with
85 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 52 additions & 17 deletions
69
definitions/npm/path-to-regexp_v2.x.x/test_path-to-regexp_v2.x.x.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,78 @@ | ||
// @flow | ||
import { describe, it } from 'flow-typed-test'; | ||
const pathToRegexp = require('path-to-regexp'); | ||
|
||
import { describe, it } from "flow-typed-test"; | ||
const { parse, compile, tokensToFunction, tokensToRegExp } = pathToRegexp; | ||
|
||
import { parse, compile, tokensToFunction, tokensToRegExp } from "path-to-regexp"; | ||
|
||
describe("path-to-regexp", () => { | ||
const url = "/test/url/:with/param"; | ||
describe('path-to-regexp', () => { | ||
const url = '/test/url/:with/param'; | ||
const tokens = [ | ||
"/test", | ||
"/url", | ||
{name: "with", prefix: "/", delimiter: "/", optional: false, repeat: false, partial: false, pattern: "[^\\/]+?"}, | ||
"/param" | ||
'/test', | ||
'/url', | ||
{ | ||
name: 'with', | ||
prefix: '/', | ||
delimiter: '/', | ||
optional: false, | ||
repeat: false, | ||
partial: false, | ||
pattern: '[^\\/]+?', | ||
}, | ||
'/param', | ||
]; | ||
const badTokens = [ | ||
"/test", | ||
"/url", | ||
{prefix: "/", delimiter: "/", optional: false, repeat: false, partial: false, pattern: "[^\\/]+?"}, | ||
"/param" | ||
'/test', | ||
'/url', | ||
{ | ||
prefix: '/', | ||
delimiter: '/', | ||
optional: false, | ||
repeat: false, | ||
partial: false, | ||
pattern: '[^\\/]+?', | ||
}, | ||
'/param', | ||
]; | ||
|
||
it("parse", () => { | ||
it('parse', () => { | ||
parse(url); | ||
}); | ||
|
||
it("compile", () => { | ||
it('compile', () => { | ||
compile(url); | ||
}); | ||
|
||
it("tokensToFunction", () => { | ||
it('tokensToFunction', () => { | ||
tokensToFunction(tokens); | ||
|
||
// $ExpectError | ||
tokensToFunction(badTokens); | ||
}); | ||
|
||
it("tokensToRegExp", () => { | ||
it('tokensToRegExp', () => { | ||
tokensToRegExp(tokens); | ||
|
||
// $ExpectError | ||
tokensToRegExp(badTokens); | ||
}); | ||
|
||
describe('pathToRegexp', () => { | ||
it('should return regexp when call with one required argument', () => { | ||
const path = 'string'; | ||
|
||
(pathToRegexp(path): RegExp); | ||
}); | ||
|
||
it('should raises an error when call without argument', () => { | ||
// $ExpectError: path is required argument | ||
pathToRegexp(); | ||
}); | ||
|
||
it('should raises an error when pass path with invalid type', () => { | ||
const path = true; | ||
|
||
// $ExpectError: path must be `string` or `RegExp` or `Array<string or RegExp>` | ||
pathToRegexp(path); | ||
}); | ||
}); | ||
}); |