chai 4.1.0 → 4.3.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.
@@ -18,7 +18,7 @@ var isProxyEnabled = require('./isProxyEnabled');
18
18
  * the list of existing properties. However, if a nonChainableMethodName is
19
19
  * provided, then the root cause is instead a failure to invoke a non-chainable
20
20
  * method prior to reading the non-existent property.
21
- *
21
+ *
22
22
  * If proxies are unsupported or disabled via the user's Chai config, then
23
23
  * return object without modification.
24
24
  *
@@ -49,19 +49,31 @@ module.exports = function proxify(obj, nonChainableMethodName) {
49
49
  nonChainableMethodName + '".');
50
50
  }
51
51
 
52
- var orderedProperties = getProperties(target).filter(function(property) {
53
- return !Object.prototype.hasOwnProperty(property) &&
54
- builtins.indexOf(property) === -1;
55
- }).sort(function(a, b) {
56
- return stringDistance(property, a) - stringDistance(property, b);
52
+ // If the property is reasonably close to an existing Chai property,
53
+ // suggest that property to the user. Only suggest properties with a
54
+ // distance less than 4.
55
+ var suggestion = null;
56
+ var suggestionDistance = 4;
57
+ getProperties(target).forEach(function(prop) {
58
+ if (
59
+ !Object.prototype.hasOwnProperty(prop) &&
60
+ builtins.indexOf(prop) === -1
61
+ ) {
62
+ var dist = stringDistanceCapped(
63
+ property,
64
+ prop,
65
+ suggestionDistance
66
+ );
67
+ if (dist < suggestionDistance) {
68
+ suggestion = prop;
69
+ suggestionDistance = dist;
70
+ }
71
+ }
57
72
  });
58
73
 
59
- if (orderedProperties.length &&
60
- stringDistance(orderedProperties[0], property) < 4) {
61
- // If the property is reasonably close to an existing Chai property,
62
- // suggest that property to the user.
74
+ if (suggestion !== null) {
63
75
  throw Error('Invalid Chai property: ' + property +
64
- '. Did you mean "' + orderedProperties[0] + '"?');
76
+ '. Did you mean "' + suggestion + '"?');
65
77
  } else {
66
78
  throw Error('Invalid Chai property: ' + property);
67
79
  }
@@ -89,34 +101,44 @@ module.exports = function proxify(obj, nonChainableMethodName) {
89
101
  };
90
102
 
91
103
  /**
92
- * # stringDistance(strA, strB)
93
- * Return the Levenshtein distance between two strings.
104
+ * # stringDistanceCapped(strA, strB, cap)
105
+ * Return the Levenshtein distance between two strings, but no more than cap.
94
106
  * @param {string} strA
95
107
  * @param {string} strB
96
- * @return {number} the string distance between strA and strB
108
+ * @param {number} number
109
+ * @return {number} min(string distance between strA and strB, cap)
97
110
  * @api private
98
111
  */
99
112
 
100
- function stringDistance(strA, strB, memo) {
101
- if (!memo) {
102
- // `memo` is a two-dimensional array containing a cache of distances
103
- // memo[i][j] is the distance between strA.slice(0, i) and
104
- // strB.slice(0, j).
105
- memo = [];
106
- for (var i = 0; i <= strA.length; i++) {
107
- memo[i] = [];
108
- }
113
+ function stringDistanceCapped(strA, strB, cap) {
114
+ if (Math.abs(strA.length - strB.length) >= cap) {
115
+ return cap;
116
+ }
117
+
118
+ var memo = [];
119
+ // `memo` is a two-dimensional array containing distances.
120
+ // memo[i][j] is the distance between strA.slice(0, i) and
121
+ // strB.slice(0, j).
122
+ for (var i = 0; i <= strA.length; i++) {
123
+ memo[i] = Array(strB.length + 1).fill(0);
124
+ memo[i][0] = i;
125
+ }
126
+ for (var j = 0; j < strB.length; j++) {
127
+ memo[0][j] = j;
109
128
  }
110
129
 
111
- if (!memo[strA.length] || !memo[strA.length][strB.length]) {
112
- if (strA.length === 0 || strB.length === 0) {
113
- memo[strA.length][strB.length] = Math.max(strA.length, strB.length);
114
- } else {
115
- memo[strA.length][strB.length] = Math.min(
116
- stringDistance(strA.slice(0, -1), strB, memo) + 1,
117
- stringDistance(strA, strB.slice(0, -1), memo) + 1,
118
- stringDistance(strA.slice(0, -1), strB.slice(0, -1), memo) +
119
- (strA.slice(-1) === strB.slice(-1) ? 0 : 1)
130
+ for (var i = 1; i <= strA.length; i++) {
131
+ var ch = strA.charCodeAt(i - 1);
132
+ for (var j = 1; j <= strB.length; j++) {
133
+ if (Math.abs(i - j) >= cap) {
134
+ memo[i][j] = cap;
135
+ continue;
136
+ }
137
+ memo[i][j] = Math.min(
138
+ memo[i - 1][j] + 1,
139
+ memo[i][j - 1] + 1,
140
+ memo[i - 1][j - 1] +
141
+ (ch === strB.charCodeAt(j - 1) ? 0 : 1)
120
142
  );
121
143
  }
122
144
  }
@@ -5,7 +5,7 @@
5
5
  */
6
6
 
7
7
  /*!
8
- * Module dependancies
8
+ * Module dependencies
9
9
  */
10
10
 
11
11
  var flag = require('./flag');
@@ -16,7 +16,7 @@
16
16
  * var newAssertion = new Assertion();
17
17
  * utils.transferFlags(assertion, newAssertion);
18
18
  *
19
- * var anotherAsseriton = new Assertion(myObj);
19
+ * var anotherAssertion = new Assertion(myObj);
20
20
  * utils.transferFlags(assertion, anotherAssertion, false);
21
21
  *
22
22
  * @param {Assertion} assertion the assertion to transfer the flags from
package/lib/chai.js CHANGED
@@ -10,7 +10,7 @@ var used = [];
10
10
  * Chai version
11
11
  */
12
12
 
13
- exports.version = '4.1.0';
13
+ exports.version = '4.3.0';
14
14
 
15
15
  /*!
16
16
  * Assertion Error
package/package.json CHANGED
@@ -17,7 +17,7 @@
17
17
  "Veselin Todorov <hi@vesln.com>",
18
18
  "John Firebaugh <john.firebaugh@gmail.com>"
19
19
  ],
20
- "version": "4.1.0",
20
+ "version": "4.3.0",
21
21
  "repository": {
22
22
  "type": "git",
23
23
  "url": "https://github.com/chaijs/chai"
@@ -26,29 +26,37 @@
26
26
  "url": "https://github.com/chaijs/chai/issues"
27
27
  },
28
28
  "main": "./index",
29
+ "exports": {
30
+ ".": {
31
+ "require": "./index.js",
32
+ "import": "./index.mjs"
33
+ },
34
+ "./": "./"
35
+ },
29
36
  "scripts": {
30
37
  "test": "make test"
31
38
  },
32
39
  "engines": {
33
- "node": ">=4"
40
+ "node": ">=8"
34
41
  },
35
42
  "dependencies": {
36
- "assertion-error": "^1.0.1",
37
- "check-error": "^1.0.1",
38
- "deep-eql": "^2.0.1",
43
+ "assertion-error": "^1.1.0",
44
+ "check-error": "^1.0.2",
45
+ "deep-eql": "^3.0.1",
39
46
  "get-func-name": "^2.0.0",
40
- "pathval": "^1.0.0",
41
- "type-detect": "^4.0.0"
47
+ "pathval": "^1.1.0",
48
+ "type-detect": "^4.0.5"
42
49
  },
43
50
  "devDependencies": {
44
- "browserify": "^14.4.0",
51
+ "browserify": "^16.2.3",
45
52
  "bump-cli": "^1.1.3",
53
+ "codecov": "^3.0.0",
46
54
  "istanbul": "^0.4.3",
47
- "karma": "^1.0.0",
55
+ "karma": "^2.0.0",
56
+ "karma-chrome-launcher": "^2.2.0",
48
57
  "karma-firefox-launcher": "^1.0.0",
49
58
  "karma-mocha": "^1.0.1",
50
- "karma-phantomjs-launcher": "^1.0.0",
51
- "karma-sauce-launcher": "^1.0.0",
52
- "mocha": "^3.0.0"
59
+ "karma-sauce-launcher": "^1.2.0",
60
+ "mocha": "^7.1.2"
53
61
  }
54
62
  }
package/sauce.browsers.js CHANGED
@@ -23,15 +23,6 @@ exports['SL_Chrome'] = {
23
23
  , version: 38
24
24
  };
25
25
 
26
- /*!
27
- * Opera
28
- */
29
-
30
- exports['SL_Opera'] = {
31
- base: 'SauceLabs'
32
- , browserName: 'opera'
33
- };
34
-
35
26
  /*!
36
27
  * Internet Explorer
37
28
  */
package/.npmignore DELETED
@@ -1,14 +0,0 @@
1
- .git*
2
- docs/
3
- test/
4
- support/
5
- component.json
6
- components/
7
- build/
8
- lib-cov/
9
- coverage/
10
- .travis.yml
11
- .mailmap
12
- Makefile
13
- *.swp
14
- .DS_Store