Skip to content

Commit aa205ee

Browse files
authored
fix(esm): main resolution extension required (#333)
Fixes the `main` and `exports` of the package to include the file extension
1 parent 3d1c5d1 commit aa205ee

File tree

8 files changed

+47
-23
lines changed

8 files changed

+47
-23
lines changed

eslint.config.mjs

+15-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,22 @@ import js from '@eslint/js';
22
import mocha from 'eslint-plugin-mocha';
33
export default [
44
mocha.configs.flat.recommended,
5+
{
6+
files: ['test/**/*.js'],
7+
languageOptions: {
8+
globals: {
9+
http: 'readonly',
10+
should: 'readonly',
11+
expect: 'readonly',
12+
chai: 'readonly',
13+
global: 'writable',
14+
request: 'readonly'
15+
}
16+
}
17+
},
518
{
619
...js.configs.recommended,
720
files: ['**/*.js']
8-
}
21+
},
22+
923
];

index.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
import fn from './lib/http.js';
22
export default fn;
3+
4+
export * as request from './lib/request.js';

lib/http.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ export default function (chai, _) {
381381
* @api public
382382
*/
383383

384-
Assertion.addMethod('param', function (name, value) {
384+
Assertion.addMethod('param', function () {
385385
const assertion = new Assertion();
386386
_.transferFlags(this, assertion);
387387
assertion._obj = qs.parse(url.parse(this._obj.url).query);

package-lock.json

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+8-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,13 @@
2424
"index.js",
2525
"types/index.d.ts"
2626
],
27-
"main": "./index",
27+
"main": "./index.js",
28+
"exports": {
29+
".": {
30+
"import": "./index.js",
31+
"types": "./types/index.d.ts"
32+
}
33+
},
2834
"types": "./types/index.d.ts",
2935
"repository": {
3036
"type": "git",
@@ -55,7 +61,7 @@
5561
},
5662
"devDependencies": {
5763
"@eslint/js": "^9.3.0",
58-
"@types/chai": "^4.3.15",
64+
"@types/chai": "^4.3.16",
5965
"@types/superagent": "^8.1.7",
6066
"chai": "^5.1.0",
6167
"coveralls": "^3.1.1",

test/bootstrap/index.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import * as originalChai from 'chai';
22
import * as http from 'http';
3-
import project from '../../index.js';
3+
// this import is available from defining `imports` in package.json
4+
import project, { request } from 'chai-http';
45

56
global.http = http;
67

78
global.should = originalChai.should();
89
global.expect = originalChai.expect;
910

1011
global['chai'] = originalChai.use(project);
12+
13+
global.request = request;

test/http.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ describe('assertions', function () {
6565
it('#header test value', function () {
6666
const req = {headers: {foo: 'bar'}};
6767
const res = {
68-
getHeader: function (key) {
68+
getHeader: function () {
6969
return 'foo';
7070
}
7171
};
@@ -91,7 +91,7 @@ describe('assertions', function () {
9191
it('#header case insensitive', function () {
9292
const req = {headers: {foo: 'bar'}};
9393
const res = {
94-
getHeader: function (key) {
94+
getHeader: function () {
9595
return 'foo';
9696
}
9797
};
@@ -105,7 +105,7 @@ describe('assertions', function () {
105105
it('#headers', function () {
106106
const req = {headers: {foo: 'bar'}};
107107
const res = {
108-
getHeader: function (key) {
108+
getHeader: function () {
109109
return 'foo';
110110
}
111111
};
@@ -129,7 +129,7 @@ describe('assertions', function () {
129129
it('#json', function () {
130130
const req = {headers: {'content-type': ['application/json']}};
131131
const res = {
132-
getHeader: function (key) {
132+
getHeader: function () {
133133
return 'application/json';
134134
}
135135
};
@@ -153,7 +153,7 @@ describe('assertions', function () {
153153
it('#text', function () {
154154
const req = {headers: {'content-type': ['text/plain']}};
155155
const res = {
156-
getHeader: function (key) {
156+
getHeader: function () {
157157
return 'text/plain';
158158
}
159159
};
@@ -173,7 +173,7 @@ describe('assertions', function () {
173173
it('#html', function () {
174174
const req = {headers: {'content-type': ['text/html']}};
175175
const res = {
176-
getHeader: function (key) {
176+
getHeader: function () {
177177
return 'text/html';
178178
}
179179
};
@@ -280,11 +280,11 @@ describe('assertions', function () {
280280

281281
(function () {
282282
req.should.not.have.param('foo');
283-
}).should.throw(/expected .* to not have property \'foo\'/);
283+
}).should.throw(/expected .* to not have property 'foo'/);
284284

285285
(function () {
286286
req.should.not.have.param('foo', 'bar');
287-
}).should.throw(/expected .* to not have property \'foo\' of \'bar\'/);
287+
}).should.throw(/expected .* to not have property 'foo' of 'bar'/);
288288
});
289289

290290
it('#param (nested)', function () {
@@ -300,12 +300,12 @@ describe('assertions', function () {
300300

301301
(function () {
302302
req.should.not.have.nested.param('form.name');
303-
}).should.throw(/expected .* to not have nested property \'form.name\'/);
303+
}).should.throw(/expected .* to not have nested property 'form.name'/);
304304

305305
(function () {
306306
req.should.not.have.nested.param('form.lastName', 'bob');
307307
}).should.throw(
308-
/expected .* to not have nested property \'form.lastName\' of \'bob\'/
308+
/expected .* to not have nested property 'form.lastName' of 'bob'/
309309
);
310310
});
311311

test/request.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import superagent from 'superagent';
22
describe('request', function () {
33
const isNode = typeof process === 'object';
44
const isBrowser = typeof window === 'object';
5-
const request = chai.request;
65

76
describe('Browser and Node.js', function () {
87
it('is present on chai', function () {
@@ -273,8 +272,8 @@ describe('request', function () {
273272
server.listen = function () {
274273
throw new Error('listen was called when it shouldnt have been');
275274
};
276-
cachedRequest.get('/').end(function (err, res) {
277-
cachedRequest.get('/').end(function (err2, res) {
275+
cachedRequest.get('/').end(function (err) {
276+
cachedRequest.get('/').end(function (err2) {
278277
server.close(function () {
279278
done(err || err2);
280279
});
@@ -288,7 +287,7 @@ describe('request', function () {
288287
res.end('hello world');
289288
});
290289
const cachedRequest = request.execute(server).keepOpen();
291-
cachedRequest.close(function (err) {
290+
cachedRequest.close(function () {
292291
should.not.exist(server.address());
293292
done();
294293
});

0 commit comments

Comments
 (0)