Skip to content

Commit

Permalink
fixed failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
parthverma1 committed Jun 5, 2024
1 parent 0e0c1fa commit cc41047
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 34 deletions.
21 changes: 3 additions & 18 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,8 @@ jobs:
strategy:
fail-fast: false
matrix:
node-version: [6, 8]
include:
- node-version: 10
# todo: enable coverage after figuring out why test-cov step is failing
coverage: false
- node-version: 16
legacy-peer-deps: true

node-version: [16]

steps:
- name: Checkout repository
uses: actions/checkout@v3
Expand All @@ -72,21 +66,12 @@ jobs:
with:
node-version: ${{ matrix.node-version }}

- if: ${{ matrix.legacy-peer-deps }}
name: Install with legacy peer deps
- name: Install with legacy peer deps
run: npm install --legacy-peer-deps

- if: ${{ !matrix.legacy-peer-deps }}
name: Install
run: npm install

- name: Compile TS
run: tsc lib/**/*.ts

- if: ${{ ! matrix.coverage }}
name: Run tests
run: npm run test-ci

- if: ${{ matrix.coverage }}
name: Run tests and upload coverage
run: npm run test-cov && npx codecov && cat ./coverage/lcov.info | npx coveralls
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function initParams (uri, options, callback) {
callback = options
}

var params = {httpVersion: 'http1'}
var params = {protocolVersion: 'http1'}
if (options !== null && typeof options === 'object') {
extend(params, options, {uri: uri})
} else if (typeof uri === 'string') {
Expand Down
2 changes: 1 addition & 1 deletion lib/autohttp/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as https from "https";
import {RequestOptions} from "../http2/request";
import {MultiProtocolRequest} from "./request";
import * as tls from "tls";
import {EventEmitter} from "node:events";
import {EventEmitter} from "events";


interface AgentOptions extends Http2AgentOptions {
Expand Down
4 changes: 2 additions & 2 deletions lib/autohttp/request.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import * as http from "http";
import * as http2 from "http2";
import {EventEmitter} from "node:events";
import {EventEmitter} from "events";
import { RequestOptions, Request as HTTP2Request} from '../../lib/http2/request'
import {AutoHttp2Agent} from "./agent";
import {ClientRequest} from "node:http";
import {ClientRequest} from "http";



Expand Down
2 changes: 1 addition & 1 deletion lib/http2/http2Agent.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {EventEmitter} from "node:events";
import {EventEmitter} from "events";
import * as http2 from "http2";
import * as tls from "tls";
import {RequestOptions} from "./request";
Expand Down
4 changes: 2 additions & 2 deletions lib/http2/request.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {URL} from "node:url";
import {URL} from "url";
import * as http from "http";
import * as http2 from 'http2';
import {EventEmitter} from "node:events";
import {EventEmitter} from "events";
import {Http2Agent} from "./http2Agent";

export interface RequestOptions {
Expand Down
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
},
"license": "Apache-2.0",
"engines": {
"node": ">= 6"
"node": ">= 16"
},
"main": "index.js",
"files": [
Expand Down Expand Up @@ -76,8 +76,7 @@
"server-destroy": "^1.0.1",
"standard": "^9.0.0",
"tape": "^4.6.0",
"taper": "^0.5.0",
"typescript": "^5.4.5"
"taper": "^0.5.0"
},
"greenkeeper": {
"ignore": [
Expand Down
4 changes: 2 additions & 2 deletions request.js
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ Request.prototype.init = function (options) {

// If user defines httpModules, respect if they have different httpModules for different http versions, else use the tls specific http module
// If the user defines nothing, revert to default modules
self.httpModule = httpModules[protocol]?.[options.httpVersion] || httpModules[protocol] || defaultModules[protocol][options.httpVersion]
self.httpModule = httpModules[protocol]?.[options.protocolVersion] || httpModules[protocol] || defaultModules[protocol][options.protocolVersion]

if (!self.httpModule) {
return self.emit('error', new Error('Invalid protocol: ' + protocol))
Expand Down Expand Up @@ -891,7 +891,7 @@ Request.prototype.getNewAgent = function () {
}

// we're using a stored agent. Make sure it's protocol-specific
poolKey = self.httpVersion + ':' + self.uri.protocol + poolKey
poolKey = self.protocolVersion + ':' + self.uri.protocol + poolKey

// generate a new agent for this setting if none yet exists
if (!self.pool[poolKey]) {
Expand Down
7 changes: 4 additions & 3 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ const TEST_URL = "https://postman-echo.com/get";
const httpsurl = 'https://localhost:443'
const http2url = 'https://localhost:3000/h2'
const pool = {};
const proto = 'auto';
const proto = 'h2';
const r = request(TEST_URL,{
httpVersion: proto,
protocolVersion: proto,
timing:true,
strictSSL:true,
gzip:true,
Expand All @@ -24,7 +24,7 @@ const r = request(TEST_URL,{
}, (err, resp, body)=> {
console.log(resp?.timings, err, body);
request(TEST_URL,{
httpVersion: proto,
protocolVersion: proto,
timing:true,
strictSSL:true,
gzip:true,
Expand All @@ -38,6 +38,7 @@ const r = request(TEST_URL,{
// cert: fs.readFileSync('/Users/parth.verma@postman.com/temp/t/cert.pem')
}, (err, resp, body)=> {
console.log(resp?.timings)
console.log(resp.httpVersion )
// console.log({body});
//
})
Expand Down
2 changes: 1 addition & 1 deletion tests/test-node-debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ tape('a simple request should not fail with debugging enabled', function (t) {
t.ok(stderr.length, 'stderr has some messages')
var url = s.url.replace(/\//g, '\\/')
var patterns = [
/^REQUEST { uri: /,
/^REQUEST {\n protocolVersion: /,
new RegExp('^REQUEST make request ' + url + '/\n$'),
/^REQUEST onRequestResponse /,
/^REQUEST finish init /,
Expand Down

0 comments on commit cc41047

Please sign in to comment.