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

move to ESM (Chai 5) #310

Merged
merged 11 commits into from
May 22, 2024
Next Next commit
feat: change project to ESM loader
Move from CJs to ESModule
  • Loading branch information
Trickfilm400 committed May 22, 2024
commit a24cf98989b99c2c26145342a8290f58e426e1d1
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
module.exports = require('./lib/http');
import fn from "./lib/http.js";
export default fn;
26 changes: 16 additions & 10 deletions lib/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,23 @@
* for the `expect` and `should` interfaces.
*/

module.exports = function (chai, _) {
/*!
* Module dependencies.
*/
import net from "net"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the formatting should really be consistent (i.e. missing semi here) but i wonder if we should just do a follow up prettier PR if we don't already have it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, setting up prettier would help a lot

We can create these follow-up PRs and then create the v5 release if this is finished (I didn't want to create all of this in this PR, as it would be too much I think)

import url from "url"
import Cookie from "cookiejar"
import charset from "charset"
import qs from "qs"
import * as _request from "./request.js"

/*!
* Module dependencies.
*/

var net = require('net');
var qs = require('qs');
var url = require('url');
var Cookie = require('cookiejar');
var charset = require("charset");
/**
*
* @param {ChaiStatic} chai
* @param {ChaiUtils} _
*/
export default function (chai, _) {

/*!
* Aliases.
Expand All @@ -34,7 +40,7 @@ module.exports = function (chai, _) {
* Expose request builder
*/

chai.request = require('./request');
chai.request = _request.Test;

/*!
* Content types hash. Used to
Expand Down
2 changes: 1 addition & 1 deletion lib/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/*!
* net.isIP shim for browsers
*/
var isIP = require('is-ip');
import isIP from 'is-ip';

exports.isIP = isIP;
exports.isIPv4 = isIP.v4;
Expand Down
30 changes: 18 additions & 12 deletions lib/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@
/*!
* Module dependancies
*/
import superagent from "superagent"
import http from "http"
import https from "https"
import methods from "methods"
import util from "util"

var http = require('http')
, https = require('https')
, methods = require('methods')
, superagent = require('superagent')
, Agent = superagent.agent
, Request = superagent.Request
, util = require('util');
var Agent = superagent.agent, Request = superagent.Request;
Trickfilm400 marked this conversation as resolved.
Show resolved Hide resolved

/**
* ## Integration Testing
Expand Down Expand Up @@ -202,7 +201,12 @@ var http = require('http')
*
*/

module.exports = function (app) {
/**
*
* @param {ChaiHttpRequest} app
* @returns {ChaiHttp.Agent}
*/
export default function (app) {

/*!
* @param {Mixed} function or server
Expand Down Expand Up @@ -248,10 +252,6 @@ module.exports = function (app) {
return obj;
};

module.exports.Test = Test;
module.exports.Request = Test;
module.exports.agent = TestAgent;

/*!
* Test
*
Expand Down Expand Up @@ -352,3 +352,9 @@ methods.forEach(function(method){
});

TestAgent.prototype.del = TestAgent.prototype.delete;

export {
Test,
Test as Request,
TestAgent as agent
}