prodatakey / dirty-chai

Extends Chai with lint-friendly terminating assertions
225 stars 18 forks source link

Support for chai v5 #54

Open attekemppila opened 10 months ago

attekemppila commented 10 months ago

node v18.19.0 npm v10.2.3

Current peerDependency doesn't include chai v5:

https://github.com/prodatakey/dirty-chai/blob/bb5d007b40a57080205afb81f7405cd1e8b89e84/package.json#L39-L41

npm install fails because of that.

Does anything else need chaning in the code. I didn't test yet myself.

perrin4869 commented 3 months ago

I started looking into this, the main problem right now is that we cannot monkey-patch the utils object anymore, since it is a non-configurable getter, so in chai v5 this will throw. The solution is to remove the 3 money patches and expect users to install dirty-chai as the last plugin, or to make the getter configurable in chai@5. @keithamus any opinions? @joshperry do you still have write permissions to this repo?

keithamus commented 3 months ago

Happy to make getters configurable in chai. Please file an issue with the explanation on the chai issue tracker so we can track the work there (or better yet, please file a PR :wink:).

lehni commented 3 months ago

I just looked into it. These getters are not produced by chai's own code, but by the esbuild command. I don't think there's an easy way to make them configurable through esbuild:

var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};

// (disabled):util
var require_util = __commonJS({
  "(disabled):util"() {
  }
});

// lib/chai/utils/index.js
var utils_exports = {};
__export(utils_exports, {
  addChainableMethod: () => addChainableMethod,
  addLengthGuard: () => addLengthGuard,
  addMethod: () => addMethod,
  addProperty: () => addProperty,
  checkError: () => check_error_exports,
  compareByInspect: () => compareByInspect,
  eql: () => deep_eql_default,
  expectTypes: () => expectTypes,
  flag: () => flag,
  getActual: () => getActual,
  getMessage: () => getMessage2,
  getName: () => getName,
  getOperator: () => getOperator,
  getOwnEnumerableProperties: () => getOwnEnumerableProperties,
  getOwnEnumerablePropertySymbols: () => getOwnEnumerablePropertySymbols,
  getPathInfo: () => getPathInfo,
  hasProperty: () => hasProperty,
  inspect: () => inspect2,
  isNaN: () => isNaN2,
  isProxyEnabled: () => isProxyEnabled,
  isRegExp: () => isRegExp2,
  objDisplay: () => objDisplay,
  overwriteChainableMethod: () => overwriteChainableMethod,
  overwriteMethod: () => overwriteMethod,
  overwriteProperty: () => overwriteProperty,
  proxify: () => proxify,
  test: () => test,
  transferFlags: () => transferFlags,
  type: () => type
});
keithamus commented 3 months ago

We could also look into providing hooks into this to allow plugins like this one to do what it does, perhaps an onChainableMethodAdded() function or something?

lehni commented 3 months ago

Yes I was thinking about this too. It would need to cover these hooks:

https://github.com/prodatakey/dirty-chai/blob/bb5d007b40a57080205afb81f7405cd1e8b89e84/lib/dirty-chai.js#L168-L214