Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(esm): main resolution extension required #333

Merged
merged 5 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
43081j marked this conversation as resolved.
Show resolved Hide resolved
{
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",
TobiTenno marked this conversation as resolved.
Show resolved Hide resolved
"@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