Skip to content

Commit

Permalink
Merge pull request #114 from BedrockStreaming/update-superagent
Browse files Browse the repository at this point in the history
chore(superagent): Update superagent version
  • Loading branch information
Tetsu9901 committed Aug 1, 2023
2 parents b9a1d5e + f4fe7db commit 19d6415
Show file tree
Hide file tree
Showing 6 changed files with 1,574 additions and 1,714 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [10.x, 12.x, 14.x, 15.x]
superagent-version: [3.6.0,3.7.0,3.8.0,4.1.0]
node-version: [16.x, 18.x]
superagent-version: [8.0.9]

steps:
- uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 12
node-version: 18.x
registry-url: https://registry.npmjs.org/
- run: yarn install
- run: yarn publish
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
"url": "https://github.com/M6Web/superagent-mock"
},
"engines": {
"node": ">=10"
"node": ">=16.0.0"
},
"peerDependencies": {
"superagent": ">=3.6.0"
"superagent": ">=8.0.9"
},
"devDependencies": {
"@babel/cli": "^7.7.4",
Expand All @@ -29,7 +29,7 @@
"eslint": "^7.22.0",
"jest": "^26.6.3",
"rimraf": "^3.0.0",
"superagent": "^3.6.0"
"superagent": "8.0.9"
},
"scripts": {
"ci": "yarn clean && yarn lint && yarn build && yarn test",
Expand Down
6 changes: 5 additions & 1 deletion src/superagent-mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ module.exports = function (superagent, config, logger) {
var lengthComputable = progress.lengthComputable !== false; // default is true
var event = ProgressEvent.initProgressEvent
? ProgressEvent.initProgressEvent('', true, false, lengthComputable, loaded, total) // IE10+
: new ProgressEvent('', {lengthComputable: lengthComputable, loaded: loaded, total: total});
: new ProgressEvent('', {
lengthComputable: lengthComputable,
loaded: loaded,
total: total,
});

if (event.total > 0) {
event.percent = (event.loaded / event.total) * 100;
Expand Down
16 changes: 5 additions & 11 deletions tests/support/expectations.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ module.exports = function (request, config, isServer) {
currentLog = log;
};
var superagentPackage = require('superagent/package.json');
var superagentUserAgentHeader = isServer ? {'User-Agent': 'node-superagent/' + superagentPackage.version} : {};
var originalSetTimeout = setTimeout;

beforeEach(function (go) {
Expand All @@ -22,7 +21,7 @@ module.exports = function (request, config, isServer) {
var oldSet = request.Request.prototype.set;
request.Request.prototype.set = function (field, value) {
if (typeof field === 'object') {
// spy on set to collect the used arguments
// spy on set to collect the used arguments
headers = field;
}

Expand Down Expand Up @@ -739,7 +738,7 @@ module.exports = function (request, config, isServer) {
.end(function (err, result) {});

expect(requestObject.url).toBe('https://domain.example/test');
expect(requestObject.header).toEqual(Object.assign({header: 'value'}, superagentUserAgentHeader));
expect(requestObject.header).toEqual(Object.assign({header: 'value'}));
done();
});

Expand Down Expand Up @@ -886,7 +885,6 @@ module.exports = function (request, config, isServer) {
expect(currentLog.mocked).toBe(true);
expect(currentLog.url).toBe('https://domain.example/666');
expect(currentLog.method).toBe('GET');
expect(currentLog.headers).toEqual(superagentUserAgentHeader);
done();
});
});
Expand All @@ -899,7 +897,6 @@ module.exports = function (request, config, isServer) {
expect(currentLog.mocked).toBe(true);
expect(currentLog.url).toBe('https://domain.example/666');
expect(currentLog.method).toBe('PUT');
expect(currentLog.headers).toEqual(superagentUserAgentHeader);
done();
});
});
Expand All @@ -912,8 +909,7 @@ module.exports = function (request, config, isServer) {
expect(currentLog.mocked).toBe(true);
expect(currentLog.url).toBe('https://domain.example/666');
expect(currentLog.method).toBe('POST');
expect(currentLog.headers).toEqual(
Object.assign({'Content-Type': 'application/x-www-form-urlencoded'}, superagentUserAgentHeader));
expect(currentLog.headers).toEqual(Object.assign({'Content-Type': 'application/x-www-form-urlencoded'}));
done();
});
});
Expand All @@ -929,8 +925,7 @@ module.exports = function (request, config, isServer) {
expect(currentLog.mocked).toBe(true);
expect(currentLog.url).toBe('https://authorized.example/');
expect(currentLog.method).toBe('PUT');
expect(currentLog.headers).toEqual(
Object.assign({Authorization: 'valid_token', 'x-6play': 1}, superagentUserAgentHeader));
expect(currentLog.headers).toEqual(Object.assign({Authorization: 'valid_token', 'x-6play': 1}));
done();
});
});
Expand All @@ -947,8 +942,7 @@ module.exports = function (request, config, isServer) {
expect(currentLog.mocked).toBe(true);
expect(currentLog.url).toBe('https://authorized.example/');
expect(currentLog.method).toBe('PUT');
expect(currentLog.headers).toEqual(
Object.assign({Authorization: 'valid_token', 'x-6play': 1}, superagentUserAgentHeader));
expect(currentLog.headers).toEqual(Object.assign({Authorization: 'valid_token', 'x-6play': 1}));
done();
});
});
Expand Down
Loading

0 comments on commit 19d6415

Please sign in to comment.