chai 5.1.2 → 5.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -42,49 +42,48 @@ import {transferFlags} from './transferFlags.js';
42
42
  * @public
43
43
  */
44
44
  export function overwriteProperty(ctx, name, getter) {
45
- var _get = Object.getOwnPropertyDescriptor(ctx, name)
46
- , _super = function () {};
45
+ var _get = Object.getOwnPropertyDescriptor(ctx, name),
46
+ _super = function () {};
47
47
 
48
- if (_get && 'function' === typeof _get.get)
49
- _super = _get.get
48
+ if (_get && 'function' === typeof _get.get) _super = _get.get;
50
49
 
51
- Object.defineProperty(ctx, name,
52
- { get: function overwritingPropertyGetter() {
53
- // Setting the `ssfi` flag to `overwritingPropertyGetter` causes this
54
- // function to be the starting point for removing implementation frames
55
- // from the stack trace of a failed assertion.
56
- //
57
- // However, we only want to use this function as the starting point if
58
- // the `lockSsfi` flag isn't set and proxy protection is disabled.
59
- //
60
- // If the `lockSsfi` flag is set, then either this assertion has been
61
- // overwritten by another assertion, or this assertion is being invoked
62
- // from inside of another assertion. In the first case, the `ssfi` flag
63
- // has already been set by the overwriting assertion. In the second
64
- // case, the `ssfi` flag has already been set by the outer assertion.
65
- //
66
- // If proxy protection is enabled, then the `ssfi` flag has already been
67
- // set by the proxy getter.
68
- if (!isProxyEnabled() && !flag(this, 'lockSsfi')) {
69
- flag(this, 'ssfi', overwritingPropertyGetter);
70
- }
71
-
72
- // Setting the `lockSsfi` flag to `true` prevents the overwritten
73
- // assertion from changing the `ssfi` flag. By this point, the `ssfi`
74
- // flag is already set to the correct starting point for this assertion.
75
- var origLockSsfi = flag(this, 'lockSsfi');
76
- flag(this, 'lockSsfi', true);
77
- var result = getter(_super).call(this);
78
- flag(this, 'lockSsfi', origLockSsfi);
50
+ Object.defineProperty(ctx, name, {
51
+ get: function overwritingPropertyGetter() {
52
+ // Setting the `ssfi` flag to `overwritingPropertyGetter` causes this
53
+ // function to be the starting point for removing implementation frames
54
+ // from the stack trace of a failed assertion.
55
+ //
56
+ // However, we only want to use this function as the starting point if
57
+ // the `lockSsfi` flag isn't set and proxy protection is disabled.
58
+ //
59
+ // If the `lockSsfi` flag is set, then either this assertion has been
60
+ // overwritten by another assertion, or this assertion is being invoked
61
+ // from inside of another assertion. In the first case, the `ssfi` flag
62
+ // has already been set by the overwriting assertion. In the second
63
+ // case, the `ssfi` flag has already been set by the outer assertion.
64
+ //
65
+ // If proxy protection is enabled, then the `ssfi` flag has already been
66
+ // set by the proxy getter.
67
+ if (!isProxyEnabled() && !flag(this, 'lockSsfi')) {
68
+ flag(this, 'ssfi', overwritingPropertyGetter);
69
+ }
79
70
 
80
- if (result !== undefined) {
81
- return result;
82
- }
71
+ // Setting the `lockSsfi` flag to `true` prevents the overwritten
72
+ // assertion from changing the `ssfi` flag. By this point, the `ssfi`
73
+ // flag is already set to the correct starting point for this assertion.
74
+ var origLockSsfi = flag(this, 'lockSsfi');
75
+ flag(this, 'lockSsfi', true);
76
+ var result = getter(_super).call(this);
77
+ flag(this, 'lockSsfi', origLockSsfi);
83
78
 
84
- var newAssertion = new Assertion();
85
- transferFlags(this, newAssertion);
86
- return newAssertion;
79
+ if (result !== undefined) {
80
+ return result;
87
81
  }
88
- , configurable: true
82
+
83
+ var newAssertion = new Assertion();
84
+ transferFlags(this, newAssertion);
85
+ return newAssertion;
86
+ },
87
+ configurable: true
89
88
  });
90
89
  }
@@ -30,7 +30,7 @@ const builtins = ['__flags', '__methods', '_obj', 'assert'];
30
30
  * @namespace Utils
31
31
  * @name proxify
32
32
  */
33
- export function proxify(obj ,nonChainableMethodName) {
33
+ export function proxify(obj, nonChainableMethodName) {
34
34
  if (!isProxyEnabled()) return obj;
35
35
 
36
36
  return new Proxy(obj, {
@@ -39,14 +39,22 @@ export function proxify(obj ,nonChainableMethodName) {
39
39
  // such as `Symbol.toStringTag`.
40
40
  // The values for which an error should be thrown can be configured using
41
41
  // the `config.proxyExcludedKeys` setting.
42
- if (typeof property === 'string' &&
43
- config.proxyExcludedKeys.indexOf(property) === -1 &&
44
- !Reflect.has(target, property)) {
42
+ if (
43
+ typeof property === 'string' &&
44
+ config.proxyExcludedKeys.indexOf(property) === -1 &&
45
+ !Reflect.has(target, property)
46
+ ) {
45
47
  // Special message for invalid property access of non-chainable methods.
46
48
  if (nonChainableMethodName) {
47
- throw Error('Invalid Chai property: ' + nonChainableMethodName + '.' +
48
- property + '. See docs for proper usage of "' +
49
- nonChainableMethodName + '".');
49
+ throw Error(
50
+ 'Invalid Chai property: ' +
51
+ nonChainableMethodName +
52
+ '.' +
53
+ property +
54
+ '. See docs for proper usage of "' +
55
+ nonChainableMethodName +
56
+ '".'
57
+ );
50
58
  }
51
59
 
52
60
  // If the property is reasonably close to an existing Chai property,
@@ -54,16 +62,14 @@ export function proxify(obj ,nonChainableMethodName) {
54
62
  // distance less than 4.
55
63
  var suggestion = null;
56
64
  var suggestionDistance = 4;
57
- getProperties(target).forEach(function(prop) {
65
+ getProperties(target).forEach(function (prop) {
58
66
  if (
67
+ // we actually mean to check `Object.prototype` here
68
+ // eslint-disable-next-line no-prototype-builtins
59
69
  !Object.prototype.hasOwnProperty(prop) &&
60
70
  builtins.indexOf(prop) === -1
61
71
  ) {
62
- var dist = stringDistanceCapped(
63
- property,
64
- prop,
65
- suggestionDistance
66
- );
72
+ var dist = stringDistanceCapped(property, prop, suggestionDistance);
67
73
  if (dist < suggestionDistance) {
68
74
  suggestion = prop;
69
75
  suggestionDistance = dist;
@@ -72,8 +78,13 @@ export function proxify(obj ,nonChainableMethodName) {
72
78
  });
73
79
 
74
80
  if (suggestion !== null) {
75
- throw Error('Invalid Chai property: ' + property +
76
- '. Did you mean "' + suggestion + '"?');
81
+ throw Error(
82
+ 'Invalid Chai property: ' +
83
+ property +
84
+ '. Did you mean "' +
85
+ suggestion +
86
+ '"?'
87
+ );
77
88
  } else {
78
89
  throw Error('Invalid Chai property: ' + property);
79
90
  }
@@ -119,17 +130,17 @@ function stringDistanceCapped(strA, strB, cap) {
119
130
  // `memo` is a two-dimensional array containing distances.
120
131
  // memo[i][j] is the distance between strA.slice(0, i) and
121
132
  // strB.slice(0, j).
122
- for (var i = 0; i <= strA.length; i++) {
133
+ for (let i = 0; i <= strA.length; i++) {
123
134
  memo[i] = Array(strB.length + 1).fill(0);
124
135
  memo[i][0] = i;
125
136
  }
126
- for (var j = 0; j < strB.length; j++) {
137
+ for (let j = 0; j < strB.length; j++) {
127
138
  memo[0][j] = j;
128
139
  }
129
140
 
130
- for (var i = 1; i <= strA.length; i++) {
141
+ for (let i = 1; i <= strA.length; i++) {
131
142
  var ch = strA.charCodeAt(i - 1);
132
- for (var j = 1; j <= strB.length; j++) {
143
+ for (let j = 1; j <= strB.length; j++) {
133
144
  if (Math.abs(i - j) >= cap) {
134
145
  memo[i][j] = cap;
135
146
  continue;
@@ -137,8 +148,7 @@ function stringDistanceCapped(strA, strB, cap) {
137
148
  memo[i][j] = Math.min(
138
149
  memo[i - 1][j] + 1,
139
150
  memo[i][j - 1] + 1,
140
- memo[i - 1][j - 1] +
141
- (ch === strB.charCodeAt(j - 1) ? 0 : 1)
151
+ memo[i - 1][j - 1] + (ch === strB.charCodeAt(j - 1) ? 0 : 1)
142
152
  );
143
153
  }
144
154
  }
@@ -18,7 +18,7 @@ import {flag} from './flag.js';
18
18
  * @name test
19
19
  */
20
20
  export function test(obj, args) {
21
- var negate = flag(obj, 'negate')
22
- , expr = args[0];
21
+ var negate = flag(obj, 'negate'),
22
+ expr = args[0];
23
23
  return negate ? !expr : expr;
24
24
  }
@@ -35,8 +35,13 @@ export function transferFlags(assertion, object, includeAll) {
35
35
  includeAll = arguments.length === 3 ? includeAll : true;
36
36
 
37
37
  for (var flag in flags) {
38
- if (includeAll ||
39
- (flag !== 'object' && flag !== 'ssfi' && flag !== 'lockSsfi' && flag != 'message')) {
38
+ if (
39
+ includeAll ||
40
+ (flag !== 'object' &&
41
+ flag !== 'ssfi' &&
42
+ flag !== 'lockSsfi' &&
43
+ flag != 'message')
44
+ ) {
40
45
  object.__flags[flag] = flags[flag];
41
46
  }
42
47
  }
@@ -6,7 +6,7 @@ export function type(obj) {
6
6
  if (typeof obj === 'undefined') {
7
7
  return 'undefined';
8
8
  }
9
-
9
+
10
10
  if (obj === null) {
11
11
  return 'null';
12
12
  }
package/lib/chai.js CHANGED
@@ -29,6 +29,7 @@ export {AssertionError};
29
29
  */
30
30
  export function use(fn) {
31
31
  const exports = {
32
+ use,
32
33
  AssertionError,
33
34
  util,
34
35
  config,
@@ -44,7 +45,7 @@ export function use(fn) {
44
45
  }
45
46
 
46
47
  return exports;
47
- };
48
+ }
48
49
 
49
50
  // Utility Functions
50
51
  export {util};
package/package.json CHANGED
@@ -18,7 +18,7 @@
18
18
  "Veselin Todorov <hi@vesln.com>",
19
19
  "John Firebaugh <john.firebaugh@gmail.com>"
20
20
  ],
21
- "version": "5.1.2",
21
+ "version": "5.2.0",
22
22
  "repository": {
23
23
  "type": "git",
24
24
  "url": "https://github.com/chaijs/chai"
@@ -31,12 +31,15 @@
31
31
  "prebuild": "npm run clean",
32
32
  "build": "npm run build:esm",
33
33
  "build:esm": "esbuild --bundle --format=esm --keep-names --outfile=chai.js index.js",
34
+ "format": "prettier --write lib",
34
35
  "pretest": "npm run lint && npm run build",
35
36
  "test": "npm run test-node && npm run test-chrome",
36
- "test-node": "mocha --require ./test/bootstrap/index.js --reporter dot test/*.js",
37
+ "test-node": "c8 --99 --check-coverage mocha --require ./test/bootstrap/index.js test/*.js",
37
38
  "test-chrome": "web-test-runner --playwright",
38
- "lint": "eslint lib/",
39
- "clean": "rm -f chai.js coverage"
39
+ "lint": "npm run lint:js && npm run lint:format",
40
+ "lint:js": "eslint lib/",
41
+ "lint:format": "prettier --check lib",
42
+ "clean": "rm -rf chai.js coverage/"
40
43
  },
41
44
  "engines": {
42
45
  "node": ">=12"
@@ -49,13 +52,16 @@
49
52
  "pathval": "^2.0.0"
50
53
  },
51
54
  "devDependencies": {
55
+ "@eslint/js": "^9.17.0",
52
56
  "@rollup/plugin-commonjs": "^25.0.7",
53
57
  "@web/dev-server-rollup": "^0.6.1",
54
58
  "@web/test-runner": "^0.18.0",
55
59
  "@web/test-runner-playwright": "^0.11.0",
60
+ "c8": "^10.1.3",
56
61
  "esbuild": "^0.19.10",
57
62
  "eslint": "^8.56.0",
58
63
  "eslint-plugin-jsdoc": "^48.0.4",
59
- "mocha": "^10.2.0"
64
+ "mocha": "^10.2.0",
65
+ "prettier": "^3.4.2"
60
66
  }
61
67
  }
@@ -1,25 +0,0 @@
1
- /*!
2
- * Chai - getEnumerableProperties utility
3
- * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
4
- * MIT Licensed
5
- */
6
-
7
- /**
8
- * ### .getEnumerableProperties(object)
9
- *
10
- * This allows the retrieval of enumerable property names of an object,
11
- * inherited or not.
12
- *
13
- * @param {object} object
14
- * @returns {Array}
15
- * @namespace Utils
16
- * @name getEnumerableProperties
17
- * @public
18
- */
19
- module.exports = function getEnumerableProperties(object) {
20
- var result = [];
21
- for (var name in object) {
22
- result.push(name);
23
- }
24
- return result;
25
- };
@@ -1,3 +0,0 @@
1
- const {assert} = require('./chai.cjs');
2
-
3
- globalThis.assert = assert;
@@ -1,3 +0,0 @@
1
- const {expect} = require('./chai.cjs');
2
-
3
- globalThis.expect = expect;
@@ -1,3 +0,0 @@
1
- const {should} = require('./chai.cjs');
2
-
3
- globalThis.should = should();