From aa205ee8c9ca5b9bee153220673e6c0b068d9b29 Mon Sep 17 00:00:00 2001 From: Matt <7128721+TobiTenno@users.noreply.github.com> Date: Thu, 27 Jun 2024 04:35:34 -0500 Subject: [PATCH] fix(esm): main resolution extension required (#333) Fixes the `main` and `exports` of the package to include the file extension --- eslint.config.mjs | 16 +++++++++++++++- index.js | 2 ++ lib/http.js | 2 +- package-lock.json | 8 ++++---- package.json | 10 ++++++++-- test/bootstrap/index.js | 5 ++++- test/http.js | 20 ++++++++++---------- test/request.js | 7 +++---- 8 files changed, 47 insertions(+), 23 deletions(-) diff --git a/eslint.config.mjs b/eslint.config.mjs index 703dffe..1d405af 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -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'] - } + }, + ]; diff --git a/index.js b/index.js index c134387..aa7e123 100644 --- a/index.js +++ b/index.js @@ -1,2 +1,4 @@ import fn from './lib/http.js'; export default fn; + +export * as request from './lib/request.js'; diff --git a/lib/http.js b/lib/http.js index 4c05aab..ce7bdff 100644 --- a/lib/http.js +++ b/lib/http.js @@ -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); diff --git a/package-lock.json b/package-lock.json index 93b6a8e..5ad4a6c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -18,7 +18,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", @@ -770,9 +770,9 @@ } }, "node_modules/@types/chai": { - "version": "4.3.15", - "resolved": "https://registry.npmjs.org/@types/chai/-/chai-4.3.15.tgz", - "integrity": "sha512-PYVSvyeZqy9++MoSegq88PxoPndWDDLGbJmE/OZnzUk3D4cCRTmA4N6EX3g0GgLVA+vtys7bj4luhkVCglGTkQ==", + "version": "4.3.16", + "resolved": "https://registry.npmjs.org/@types/chai/-/chai-4.3.16.tgz", + "integrity": "sha512-PatH4iOdyh3MyWtmHVFXLWCCIhUbopaltqddG9BzB+gMIzee2MJrvd+jouii9Z3wzQJruGWAm7WOMjgfG8hQlQ==", "dev": true }, "node_modules/@types/cookiejar": { diff --git a/package.json b/package.json index c124c07..40f5d36 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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", diff --git a/test/bootstrap/index.js b/test/bootstrap/index.js index 52b0f9f..8c890b6 100644 --- a/test/bootstrap/index.js +++ b/test/bootstrap/index.js @@ -1,6 +1,7 @@ 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; @@ -8,3 +9,5 @@ global.should = originalChai.should(); global.expect = originalChai.expect; global['chai'] = originalChai.use(project); + +global.request = request; diff --git a/test/http.js b/test/http.js index 9c45f9f..8af0611 100644 --- a/test/http.js +++ b/test/http.js @@ -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'; } }; @@ -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'; } }; @@ -105,7 +105,7 @@ describe('assertions', function () { it('#headers', function () { const req = {headers: {foo: 'bar'}}; const res = { - getHeader: function (key) { + getHeader: function () { return 'foo'; } }; @@ -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'; } }; @@ -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'; } }; @@ -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'; } }; @@ -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 () { @@ -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'/ ); }); diff --git a/test/request.js b/test/request.js index 27b8734..1d2be68 100644 --- a/test/request.js +++ b/test/request.js @@ -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 () { @@ -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); }); @@ -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(); });