Skip to content

Commit

Permalink
feat: support trace method request
Browse files Browse the repository at this point in the history
  • Loading branch information
fengmk2 committed Jan 17, 2025
1 parent 732b13c commit 0056ca2
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
"superagent": "^9.0.1"
},
"devDependencies": {
"@arethetypeswrong/cli": "^0.17.1",
"@arethetypeswrong/cli": "^0.17.3",
"@eggjs/bin": "7",
"@eggjs/tsconfig": "1",
"@types/body-parser": "^1.19.5",
"@types/cookie-parser": "^1.4.8",
Expand All @@ -37,7 +38,6 @@
"@types/node": "22",
"body-parser": "^1.20.3",
"cookie-parser": "^1.4.6",
"egg-bin": "6",
"eslint": "8",
"eslint-config-egg": "14",
"express": "^4.18.2",
Expand Down
3 changes: 3 additions & 0 deletions src/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ export class TestAgent extends Agent {
options(url: string) {
return this._testRequest('options', url);
}
trace(url: string) {
return this._testRequest('trace', url);
}
}

// allow keep use by `agent()`
Expand Down
3 changes: 3 additions & 0 deletions src/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,7 @@ export class Request {
options(url: string) {
return this._testRequest('options', url);
}
trace(url: string) {
return this._testRequest('trace', url);
}
}
23 changes: 23 additions & 0 deletions test/supertest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,18 @@ describe('request(app)', function() {
.expect('Hello', done);
});

it('should work on trace method', function(done) {
const app = express();

app.trace('/', function(_req, res) {
res.end('Hello');
});

request(app)
.trace('/')
.expect('Hello', done);
});

it('should default redirects to 0', function(done) {
const app = express();

Expand Down Expand Up @@ -1078,6 +1090,11 @@ describe('request.agent(app)', function() {
res.send();
});

app.trace('/', function(_req, res) {
res.cookie('cookie', 'hey');
res.send('trace method');
});

app.get('/return_cookies', function(req, res) {
if (req.cookies.cookie) res.send(req.cookies.cookie);
else res.send(':(');
Expand Down Expand Up @@ -1105,6 +1122,12 @@ describe('request.agent(app)', function() {
.get('/return_headers')
.expect('hey', done);
});

it('should trace method work', function(done) {
agent
.trace('/')
.expect('trace method', done);
});
});

describe('agent.host(host)', function() {
Expand Down

0 comments on commit 0056ca2

Please sign in to comment.