Skip to content
This repository was archived by the owner on Jun 27, 2022. It is now read-only.

Commit d94c857

Browse files
committed
Adheres to the specification
1 parent aaa235f commit d94c857

31 files changed

+1246
-698
lines changed

.circleci/config.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,9 @@ jobs:
2929
name: Build
3030
command: yarn build
3131
- run:
32-
name: Tests
32+
name: Unit tests
3333
command: yarn test
34+
35+
- run:
36+
name: Spefication tests
37+
command: yarn spec:all

.vscode/settings.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"cucumberautocomplete.steps": ["specification/support/steps.ts"],
3+
"cucumberautocomplete.strictGherkinCompletion": true
4+
}

cucumber.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const options = [
2+
'--require-module ts-node/register',
3+
'--require specification/support/*.ts',
4+
'--publish-quiet',
5+
]
6+
7+
module.exports = {
8+
default: ['./specification/**/*.feature', ...options].join(' '),
9+
only: options.join(' '),
10+
}

jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module.exports = {
22
transform: {
3-
'^.+\\.tsx?$': 'ts-jest',
3+
'^.+\\.ts$': 'ts-jest',
44
},
55
}

package.json

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,22 @@
2828
"scripts": {
2929
"test": "jest",
3030
"clean": "rimraf -rf lib",
31+
"spec": "cucumber-js -p only",
32+
"spec:all": "cucumber-js -p default",
33+
"spec:watch": "ts-node specification/scripts/run.ts",
3134
"build": "yarn clean && rollup -c rollup.config.js",
3235
"prepublishOnly": "yarn test && yarn build"
3336
},
3437
"devDependencies": {
3538
"@babel/core": "^7.13.10",
3639
"@babel/preset-env": "^7.13.12",
40+
"@cucumber/cucumber": "^7.3.1",
41+
"@types/chai": "^4.2.21",
42+
"@types/debug": "^4.1.7",
3743
"@types/jest": "^26.0.21",
44+
"chai": "^4.3.4",
45+
"chokidar": "^3.5.2",
46+
"debug": "^4.3.2",
3847
"jest": "^26.6.3",
3948
"rimraf": "^3.0.2",
4049
"rollup": "^2.42.3",
@@ -43,6 +52,8 @@
4352
"rollup-plugin-sourcemaps": "^0.6.3",
4453
"rollup-plugin-typescript2": "^0.30.0",
4554
"ts-jest": "^26.5.4",
55+
"ts-node": "^10.2.1",
4656
"typescript": "^4.2.3"
47-
}
57+
},
58+
"dependencies": {}
4859
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
Feature: Absolute URL
2+
3+
Background:
4+
Given the path is "https://api.github.com/graphql"
5+
6+
Scenario: Exact matching url
7+
When the url is "https://api.github.com/graphql"
8+
Then it matches
9+
But has no parameters
10+
11+
Scenario: Matching url with a trailing slash
12+
When the url is "https://api.github.com/graphql/"
13+
Then it matches
14+
But has no parameters
15+
16+
Scenario: Matching url with a hash
17+
When the url is "https://api.github.com/graphql"
18+
Then it matches
19+
But has no parameters
20+
21+
Scenario: Entirely different url
22+
When the url is "https://graphql.com"
23+
Then it doesn't match
24+
25+
Scenario: The same url with a nested path
26+
When the url is "https://api.github.com/graphql/query"
27+
Then it doesn't match
28+
29+
Scenario: The same path with a different hostname
30+
When the url is "https://arbitrary.com/graphql"
31+
Then it doesn't match
32+
33+
Scenario: Matching url with a different protocol
34+
When the url is "http://api.github.com/graphql"
35+
Then it doesn't match
36+
37+
When the url is "chrome-extension://api.github.com/graphql"
38+
Then it doesn't match
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
Feature: Leading path parameter
2+
3+
# Scenario: All-capturing parameter
4+
# Given the path is ":service"
5+
# When the url is "/user/1/messages"
6+
# Then it matches
7+
# And has the "service" parameter equal to "/user/1/messages"
8+
9+
Scenario: Single leading parameter
10+
Given the path is ":service/user"
11+
When the url is "payments/user"
12+
Then it matches
13+
And has the "service" parameter equal to "payments"
14+
15+
When the url is "payments/user/abc-123"
16+
Then it doesn't match
17+
18+
When the url is "payments/session/user"
19+
Then it doesn't match
20+
21+
Scenario: Multiple leading parameters
22+
Given the path is ":service/:session/user"
23+
When the url is "payments/abc-123/user"
24+
Then it matches
25+
And has the "service" parameter equal to "payments"
26+
And has the "session" parameter equal to "abc-123"
27+
28+
When the url is "payments/user"
29+
Then it doesn't match
30+
31+
When the url is "payments/abc-123/user/messages"
32+
Then it doesn't match
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
Feature: One-or-more (+) path parameter
2+
x
3+
Background:
4+
Given the path is "/:service+"
5+
6+
Scenario: Single matching segment
7+
When the url is "/payments"
8+
Then it matches
9+
And has the "service" parameter equal to "payments"
10+
11+
When the url is "/payments/"
12+
Then it matches
13+
And has the "service" parameter equal to "payments"
14+
15+
Scenario: Multiple matching segments
16+
When the url is "/payments/recent"
17+
Then it matches
18+
And has the "service" parameter equal to "payments, recent"
19+
20+
When the url is "/payments/recent/"
21+
Then it matches
22+
And has the "service" parameter equal to "payments, recent"
23+
24+
Scenario: No matching segments
25+
When the url is "/"
26+
Then it doesn't match
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
Feature: Optional (?) path parameter
2+
3+
Scenario: Matching segment
4+
Given the path is "/:id?"
5+
When the url is "/abc-123"
6+
Then it matches
7+
And has the "id" parameter equal to "abc-123"
8+
9+
Scenario: No matching segments
10+
Given the path is "/:id?"
11+
When the url is "/"
12+
Then it matches
13+
But has no parameters
14+
15+
Scenario: Matching segment for a leading parameter
16+
Given the path is "/:id?/user"
17+
When the url is "/abc-123/user"
18+
Then it matches
19+
And has the "id" parameter equal to "abc-123"
20+
21+
When the url is "/abc-123/user/"
22+
Then it matches
23+
And has the "id" parameter equal to "abc-123"
24+
25+
Scenario: No matching segments for a leading parameter
26+
Given the path is "/:id?/user"
27+
When the url is "/user"
28+
Then it doesn't match
29+
30+
When the url is "/user/"
31+
Then it doesn't match
32+
33+
Scenario: Matching segment for a trailing parameter
34+
Given the path is "/user/:id?"
35+
When the url is "/user/1"
36+
Then it matches
37+
And has the "id" parameter equal to "1"
38+
39+
When the url is "/user/1/"
40+
Then it matches
41+
And has the "id" parameter equal to "1"
42+
43+
Scenario: No matching segments for a trailing parameter
44+
Given the path is "/user/:id?"
45+
When the url is "/user/"
46+
Then it matches
47+
But has no parameters
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Feature: Trailing path parameters
2+
3+
Scenario: Single trailing parameter
4+
Given the path is "/user/:id"
5+
When the url is "/user/1"
6+
Then it matches
7+
And has the "id" parameter equal to "1"
8+
9+
Scenario: Multiple trailing parameters
10+
Given the path is "/user/:id/:messageId"
11+
When the url is "/user/abc-123/1"
12+
Then it matches
13+
And has the "id" parameter equal to "abc-123"
14+
And has the "messageId" parameter equal to "1"

0 commit comments

Comments
 (0)