Skip to content

Commit

Permalink
fix(esm): main resolution extension required (#333)
Browse files Browse the repository at this point in the history
Fixes the `main` and `exports` of the package to include the file extension
  • Loading branch information
TobiTenno authored Jun 27, 2024
1 parent 3d1c5d1 commit aa205ee
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 23 deletions.
16 changes: 15 additions & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,22 @@ import js from '@eslint/js';
import mocha from 'eslint-plugin-mocha';
export default [
mocha.configs.flat.recommended,
{
files: ['test/**/*.js'],
languageOptions: {
globals: {
http: 'readonly',
should: 'readonly',
expect: 'readonly',
chai: 'readonly',
global: 'writable',
request: 'readonly'
}
}
},
{
...js.configs.recommended,
files: ['**/*.js']
}
},

];
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
import fn from './lib/http.js';
export default fn;

export * as request from './lib/request.js';
2 changes: 1 addition & 1 deletion lib/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ export default function (chai, _) {
* @api public
*/

Assertion.addMethod('param', function (name, value) {
Assertion.addMethod('param', function () {
const assertion = new Assertion();
_.transferFlags(this, assertion);
assertion._obj = qs.parse(url.parse(this._obj.url).query);
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,13 @@
"index.js",
"types/index.d.ts"
],
"main": "./index",
"main": "./index.js",
"exports": {
".": {
"import": "./index.js",
"types": "./types/index.d.ts"
}
},
"types": "./types/index.d.ts",
"repository": {
"type": "git",
Expand Down Expand Up @@ -55,7 +61,7 @@
},
"devDependencies": {
"@eslint/js": "^9.3.0",
"@types/chai": "^4.3.15",
"@types/chai": "^4.3.16",
"@types/superagent": "^8.1.7",
"chai": "^5.1.0",
"coveralls": "^3.1.1",
Expand Down
5 changes: 4 additions & 1 deletion test/bootstrap/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import * as originalChai from 'chai';
import * as http from 'http';
import project from '../../index.js';
// this import is available from defining `imports` in package.json
import project, { request } from 'chai-http';

global.http = http;

global.should = originalChai.should();
global.expect = originalChai.expect;

global['chai'] = originalChai.use(project);

global.request = request;
20 changes: 10 additions & 10 deletions test/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ describe('assertions', function () {
it('#header test value', function () {
const req = {headers: {foo: 'bar'}};
const res = {
getHeader: function (key) {
getHeader: function () {
return 'foo';
}
};
Expand All @@ -91,7 +91,7 @@ describe('assertions', function () {
it('#header case insensitive', function () {
const req = {headers: {foo: 'bar'}};
const res = {
getHeader: function (key) {
getHeader: function () {
return 'foo';
}
};
Expand All @@ -105,7 +105,7 @@ describe('assertions', function () {
it('#headers', function () {
const req = {headers: {foo: 'bar'}};
const res = {
getHeader: function (key) {
getHeader: function () {
return 'foo';
}
};
Expand All @@ -129,7 +129,7 @@ describe('assertions', function () {
it('#json', function () {
const req = {headers: {'content-type': ['application/json']}};
const res = {
getHeader: function (key) {
getHeader: function () {
return 'application/json';
}
};
Expand All @@ -153,7 +153,7 @@ describe('assertions', function () {
it('#text', function () {
const req = {headers: {'content-type': ['text/plain']}};
const res = {
getHeader: function (key) {
getHeader: function () {
return 'text/plain';
}
};
Expand All @@ -173,7 +173,7 @@ describe('assertions', function () {
it('#html', function () {
const req = {headers: {'content-type': ['text/html']}};
const res = {
getHeader: function (key) {
getHeader: function () {
return 'text/html';
}
};
Expand Down Expand Up @@ -280,11 +280,11 @@ describe('assertions', function () {

(function () {
req.should.not.have.param('foo');
}).should.throw(/expected .* to not have property \'foo\'/);
}).should.throw(/expected .* to not have property 'foo'/);

(function () {
req.should.not.have.param('foo', 'bar');
}).should.throw(/expected .* to not have property \'foo\' of \'bar\'/);
}).should.throw(/expected .* to not have property 'foo' of 'bar'/);
});

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

(function () {
req.should.not.have.nested.param('form.name');
}).should.throw(/expected .* to not have nested property \'form.name\'/);
}).should.throw(/expected .* to not have nested property 'form.name'/);

(function () {
req.should.not.have.nested.param('form.lastName', 'bob');
}).should.throw(
/expected .* to not have nested property \'form.lastName\' of \'bob\'/
/expected .* to not have nested property 'form.lastName' of 'bob'/
);
});

Expand Down
7 changes: 3 additions & 4 deletions test/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import superagent from 'superagent';
describe('request', function () {
const isNode = typeof process === 'object';
const isBrowser = typeof window === 'object';
const request = chai.request;

describe('Browser and Node.js', function () {
it('is present on chai', function () {
Expand Down Expand Up @@ -273,8 +272,8 @@ describe('request', function () {
server.listen = function () {
throw new Error('listen was called when it shouldnt have been');
};
cachedRequest.get('/').end(function (err, res) {
cachedRequest.get('/').end(function (err2, res) {
cachedRequest.get('/').end(function (err) {
cachedRequest.get('/').end(function (err2) {
server.close(function () {
done(err || err2);
});
Expand All @@ -288,7 +287,7 @@ describe('request', function () {
res.end('hello world');
});
const cachedRequest = request.execute(server).keepOpen();
cachedRequest.close(function (err) {
cachedRequest.close(function () {
should.not.exist(server.address());
done();
});
Expand Down

0 comments on commit aa205ee

Please sign in to comment.