@gjsify/querystring 0.0.4 → 0.1.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.
- package/README.md +30 -3
- package/lib/esm/index.js +19 -21
- package/lib/types/error.d.ts +12 -0
- package/lib/types/index.d.ts +86 -0
- package/package.json +13 -19
- package/src/error.ts +2 -0
- package/src/index.spec.ts +568 -47
- package/src/index.ts +18 -14
- package/tsconfig.json +22 -10
- package/tsconfig.tsbuildinfo +1 -0
- package/lib/cjs/error.js +0 -25
- package/lib/cjs/index.js +0 -1035
- package/test.gjs.js +0 -33178
- package/test.gjs.mjs +0 -35769
- package/test.gjs.mjs.meta.json +0 -1
- package/test.node.js +0 -231
- package/test.node.mjs +0 -353
- package/tsconfig.types.json +0 -8
package/test.node.js
DELETED
|
@@ -1,231 +0,0 @@
|
|
|
1
|
-
// ../../gjs/unit/dist/index.cjs
|
|
2
|
-
import { versions } from "process";
|
|
3
|
-
var _a;
|
|
4
|
-
var mainloop = (_a = globalThis == null ? void 0 : globalThis.imports) == null ? void 0 : _a.mainloop;
|
|
5
|
-
var countTestsOverall = 0;
|
|
6
|
-
var countTestsFailed = 0;
|
|
7
|
-
var print = globalThis.print || console.log;
|
|
8
|
-
var MatcherFactory = class {
|
|
9
|
-
constructor(actualValue, positive, withOpposite = true) {
|
|
10
|
-
this.actualValue = actualValue;
|
|
11
|
-
this.positive = positive;
|
|
12
|
-
if (withOpposite) {
|
|
13
|
-
this.not = new MatcherFactory(actualValue, !positive, false);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
triggerResult(success, msg) {
|
|
17
|
-
if (success && !this.positive || !success && this.positive) {
|
|
18
|
-
++countTestsFailed;
|
|
19
|
-
throw new Error(msg);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
to(callback) {
|
|
23
|
-
this.triggerResult(
|
|
24
|
-
callback(this.actualValue),
|
|
25
|
-
" Expected callback to validate"
|
|
26
|
-
);
|
|
27
|
-
}
|
|
28
|
-
toBe(expectedValue) {
|
|
29
|
-
this.triggerResult(
|
|
30
|
-
this.actualValue === expectedValue,
|
|
31
|
-
" Expected values to match using ===\n Expected: " + expectedValue + "\n Actual: " + this.actualValue
|
|
32
|
-
);
|
|
33
|
-
}
|
|
34
|
-
toEqual(expectedValue) {
|
|
35
|
-
this.triggerResult(
|
|
36
|
-
this.actualValue == expectedValue,
|
|
37
|
-
" Expected values to match using ==\n Expected: " + expectedValue + "\n Actual: " + this.actualValue
|
|
38
|
-
);
|
|
39
|
-
}
|
|
40
|
-
toMatch(expectedValue) {
|
|
41
|
-
if (typeof this.actualValue.match !== "function") {
|
|
42
|
-
throw new Error(`You can not use toMatch on type ${typeof this.actualValue}`);
|
|
43
|
-
}
|
|
44
|
-
this.triggerResult(
|
|
45
|
-
!!this.actualValue.match(expectedValue),
|
|
46
|
-
" Expected values to match using regular expression\n Expression: " + expectedValue + "\n Actual: " + this.actualValue
|
|
47
|
-
);
|
|
48
|
-
}
|
|
49
|
-
toBeDefined() {
|
|
50
|
-
this.triggerResult(
|
|
51
|
-
typeof this.actualValue !== "undefined",
|
|
52
|
-
" Expected value to be defined"
|
|
53
|
-
);
|
|
54
|
-
}
|
|
55
|
-
toBeUndefined() {
|
|
56
|
-
this.triggerResult(
|
|
57
|
-
typeof this.actualValue === "undefined",
|
|
58
|
-
" Expected value to be undefined"
|
|
59
|
-
);
|
|
60
|
-
}
|
|
61
|
-
toBeNull() {
|
|
62
|
-
this.triggerResult(
|
|
63
|
-
this.actualValue === null,
|
|
64
|
-
" Expected value to be null"
|
|
65
|
-
);
|
|
66
|
-
}
|
|
67
|
-
toBeTruthy() {
|
|
68
|
-
this.triggerResult(
|
|
69
|
-
this.actualValue,
|
|
70
|
-
" Expected value to be truthy"
|
|
71
|
-
);
|
|
72
|
-
}
|
|
73
|
-
toBeFalsy() {
|
|
74
|
-
this.triggerResult(
|
|
75
|
-
!this.actualValue,
|
|
76
|
-
" Expected value to be falsy"
|
|
77
|
-
);
|
|
78
|
-
}
|
|
79
|
-
toContain(needle) {
|
|
80
|
-
this.triggerResult(
|
|
81
|
-
this.actualValue instanceof Array && this.actualValue.indexOf(needle) !== -1,
|
|
82
|
-
" Expected " + this.actualValue + " to contain " + needle
|
|
83
|
-
);
|
|
84
|
-
}
|
|
85
|
-
toBeLessThan(greaterValue) {
|
|
86
|
-
this.triggerResult(
|
|
87
|
-
this.actualValue < greaterValue,
|
|
88
|
-
" Expected " + this.actualValue + " to be less than " + greaterValue
|
|
89
|
-
);
|
|
90
|
-
}
|
|
91
|
-
toBeGreaterThan(smallerValue) {
|
|
92
|
-
this.triggerResult(
|
|
93
|
-
this.actualValue > smallerValue,
|
|
94
|
-
" Expected " + this.actualValue + " to be greater than " + smallerValue
|
|
95
|
-
);
|
|
96
|
-
}
|
|
97
|
-
toBeCloseTo(expectedValue, precision) {
|
|
98
|
-
var shiftHelper = Math.pow(10, precision);
|
|
99
|
-
this.triggerResult(
|
|
100
|
-
Math.round(this.actualValue * shiftHelper) / shiftHelper === Math.round(expectedValue * shiftHelper) / shiftHelper,
|
|
101
|
-
" Expected " + this.actualValue + " with precision " + precision + " to be close to " + expectedValue
|
|
102
|
-
);
|
|
103
|
-
}
|
|
104
|
-
toThrow() {
|
|
105
|
-
let errorMessage = "";
|
|
106
|
-
var didThrow = false;
|
|
107
|
-
try {
|
|
108
|
-
this.actualValue();
|
|
109
|
-
didThrow = false;
|
|
110
|
-
} catch (e) {
|
|
111
|
-
errorMessage = e.message || "";
|
|
112
|
-
didThrow = true;
|
|
113
|
-
}
|
|
114
|
-
const functionName = this.actualValue.name || typeof this.actualValue === "function" ? "[anonymous function]" : this.actualValue.toString();
|
|
115
|
-
this.triggerResult(
|
|
116
|
-
didThrow,
|
|
117
|
-
` Expected ${functionName} to ${this.positive ? "throw" : "not throw"} an exception ${!this.positive && errorMessage ? `, but an error with the message "${errorMessage}" was thrown` : ""}`
|
|
118
|
-
);
|
|
119
|
-
}
|
|
120
|
-
};
|
|
121
|
-
var describe = async function(moduleName, callback) {
|
|
122
|
-
print("\n" + moduleName);
|
|
123
|
-
await callback();
|
|
124
|
-
};
|
|
125
|
-
var it = async function(expectation, callback) {
|
|
126
|
-
try {
|
|
127
|
-
await callback();
|
|
128
|
-
print(" \x1B[32m\u2714\x1B[39m \x1B[90m" + expectation + "\x1B[39m");
|
|
129
|
-
} catch (e) {
|
|
130
|
-
print(" \x1B[31m\u274C\x1B[39m \x1B[90m" + expectation + "\x1B[39m");
|
|
131
|
-
print("\x1B[31m" + e.message + "\x1B[39m");
|
|
132
|
-
}
|
|
133
|
-
};
|
|
134
|
-
var expect = function(actualValue) {
|
|
135
|
-
++countTestsOverall;
|
|
136
|
-
var expecter = new MatcherFactory(actualValue, true);
|
|
137
|
-
return expecter;
|
|
138
|
-
};
|
|
139
|
-
var runTests = async function(namespaces) {
|
|
140
|
-
for (var subNamespace in namespaces) {
|
|
141
|
-
const namespace = namespaces[subNamespace];
|
|
142
|
-
if (typeof namespace === "function") {
|
|
143
|
-
await namespace();
|
|
144
|
-
} else if (typeof namespace === "object") {
|
|
145
|
-
await runTests(namespace);
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
};
|
|
149
|
-
var printResult = () => {
|
|
150
|
-
if (countTestsFailed) {
|
|
151
|
-
print("\n\x1B[31m\u274C " + countTestsFailed + " of " + countTestsOverall + " tests failed\x1B[39m");
|
|
152
|
-
} else {
|
|
153
|
-
print("\n\x1B[32m\u2714 " + countTestsOverall + " completed\x1B[39m");
|
|
154
|
-
}
|
|
155
|
-
};
|
|
156
|
-
var printRuntime = () => {
|
|
157
|
-
if (versions.gjs) {
|
|
158
|
-
print(`Running on Gjs ${versions.gjs}`);
|
|
159
|
-
} else if (versions.node) {
|
|
160
|
-
print(`Running on Node.js ${versions.node}`);
|
|
161
|
-
} else {
|
|
162
|
-
print(`Running on unknown runtime`);
|
|
163
|
-
}
|
|
164
|
-
};
|
|
165
|
-
var run = function(namespaces) {
|
|
166
|
-
printRuntime();
|
|
167
|
-
runTests(namespaces).then(() => {
|
|
168
|
-
printResult();
|
|
169
|
-
print();
|
|
170
|
-
mainloop == null ? void 0 : mainloop.quit();
|
|
171
|
-
});
|
|
172
|
-
mainloop == null ? void 0 : mainloop.run();
|
|
173
|
-
};
|
|
174
|
-
|
|
175
|
-
// src/index.spec.ts
|
|
176
|
-
import * as qs from "querystring";
|
|
177
|
-
var index_spec_default = async () => {
|
|
178
|
-
await describe("querystring", async () => {
|
|
179
|
-
await it("performs basic parsing", async () => {
|
|
180
|
-
expect(qs.parse("id=918854443121279438895193").id).toBe("918854443121279438895193");
|
|
181
|
-
});
|
|
182
|
-
});
|
|
183
|
-
await it("test stringifying invalid surrogate pair throws URIError", async () => {
|
|
184
|
-
expect(() => {
|
|
185
|
-
qs.stringify({ foo: "\uDC00" });
|
|
186
|
-
}).toThrow();
|
|
187
|
-
try {
|
|
188
|
-
qs.stringify({ foo: "\uDC00" });
|
|
189
|
-
} catch (error) {
|
|
190
|
-
expect(error instanceof URIError).toBeTruthy();
|
|
191
|
-
}
|
|
192
|
-
});
|
|
193
|
-
await it("test stringifying coerce numbers to string", async () => {
|
|
194
|
-
expect("foo=0").toBe(qs.stringify({ foo: 0 }));
|
|
195
|
-
expect("foo=0").toBe(qs.stringify({ foo: -0 }));
|
|
196
|
-
expect("foo=3").toBe(qs.stringify({ foo: 3 }));
|
|
197
|
-
expect("foo=-72.42").toBe(qs.stringify({ foo: -72.42 }));
|
|
198
|
-
expect("foo=").toBe(qs.stringify({ foo: NaN }));
|
|
199
|
-
expect("foo=").toBe(qs.stringify({ foo: Infinity }));
|
|
200
|
-
});
|
|
201
|
-
await it("test stringifying nested", async () => {
|
|
202
|
-
const f = qs.stringify({
|
|
203
|
-
a: "b",
|
|
204
|
-
q: qs.stringify({
|
|
205
|
-
x: "y",
|
|
206
|
-
y: "z"
|
|
207
|
-
})
|
|
208
|
-
});
|
|
209
|
-
expect(f).toBe("a=b&q=x%3Dy%26y%3Dz");
|
|
210
|
-
});
|
|
211
|
-
await it("test stringifying nested in colon", async () => {
|
|
212
|
-
const f = qs.stringify({
|
|
213
|
-
a: "b",
|
|
214
|
-
q: qs.stringify({
|
|
215
|
-
x: "y",
|
|
216
|
-
y: "z"
|
|
217
|
-
}, ";", ":")
|
|
218
|
-
}, ";", ":");
|
|
219
|
-
expect(f).toBe("a:b;q:x%3Ay%3By%3Az");
|
|
220
|
-
});
|
|
221
|
-
await it("test stringifying empty string", async () => {
|
|
222
|
-
expect(qs.stringify()).toBe("");
|
|
223
|
-
expect(qs.stringify(0)).toBe("");
|
|
224
|
-
expect(qs.stringify([])).toBe("");
|
|
225
|
-
expect(qs.stringify(null)).toBe("");
|
|
226
|
-
expect(qs.stringify(true)).toBe("");
|
|
227
|
-
});
|
|
228
|
-
};
|
|
229
|
-
|
|
230
|
-
// src/test.ts
|
|
231
|
-
run({ testSuite: index_spec_default });
|
package/test.node.mjs
DELETED
|
@@ -1,353 +0,0 @@
|
|
|
1
|
-
// ../../../node_modules/@girs/gjs/gjs.js
|
|
2
|
-
var imports = globalThis.imports || {};
|
|
3
|
-
|
|
4
|
-
// ../../gjs/unit/lib/esm/index.js
|
|
5
|
-
import nodeAssert from "assert";
|
|
6
|
-
var mainloop = globalThis?.imports?.mainloop;
|
|
7
|
-
var countTestsOverall = 0;
|
|
8
|
-
var countTestsFailed = 0;
|
|
9
|
-
var countTestsIgnored = 0;
|
|
10
|
-
var runtime = "";
|
|
11
|
-
var RED = "\x1B[31m";
|
|
12
|
-
var GREEN = "\x1B[32m";
|
|
13
|
-
var BLUE = "\x1B[34m";
|
|
14
|
-
var GRAY = "\x1B[90m";
|
|
15
|
-
var RESET = "\x1B[39m";
|
|
16
|
-
var print = globalThis.print || console.log;
|
|
17
|
-
var MatcherFactory = class _MatcherFactory {
|
|
18
|
-
constructor(actualValue, positive, negated) {
|
|
19
|
-
this.actualValue = actualValue;
|
|
20
|
-
this.positive = positive;
|
|
21
|
-
if (negated) {
|
|
22
|
-
this.not = negated;
|
|
23
|
-
} else {
|
|
24
|
-
this.not = new _MatcherFactory(actualValue, !positive, this);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
not;
|
|
28
|
-
triggerResult(success, msg) {
|
|
29
|
-
if (success && !this.positive || !success && this.positive) {
|
|
30
|
-
++countTestsFailed;
|
|
31
|
-
throw new Error(msg);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
to(callback) {
|
|
35
|
-
this.triggerResult(
|
|
36
|
-
callback(this.actualValue),
|
|
37
|
-
` Expected callback to validate`
|
|
38
|
-
);
|
|
39
|
-
}
|
|
40
|
-
toBe(expectedValue) {
|
|
41
|
-
this.triggerResult(
|
|
42
|
-
this.actualValue === expectedValue,
|
|
43
|
-
` Expected values to match using ===
|
|
44
|
-
Expected: ${expectedValue} (${typeof expectedValue})
|
|
45
|
-
Actual: ${this.actualValue} (${typeof this.actualValue})`
|
|
46
|
-
);
|
|
47
|
-
}
|
|
48
|
-
toEqual(expectedValue) {
|
|
49
|
-
this.triggerResult(
|
|
50
|
-
this.actualValue == expectedValue,
|
|
51
|
-
` Expected values to match using ==
|
|
52
|
-
Expected: ${expectedValue} (${typeof expectedValue})
|
|
53
|
-
Actual: ${this.actualValue} (${typeof this.actualValue})`
|
|
54
|
-
);
|
|
55
|
-
}
|
|
56
|
-
toEqualArray(expectedValue) {
|
|
57
|
-
let success = Array.isArray(this.actualValue) && Array.isArray(expectedValue) && this.actualValue.length === expectedValue.length;
|
|
58
|
-
for (let i = 0; i < this.actualValue.length; i++) {
|
|
59
|
-
const actualVal = this.actualValue[i];
|
|
60
|
-
const expectedVal = expectedValue[i];
|
|
61
|
-
success = actualVal == expectedVal;
|
|
62
|
-
if (!success)
|
|
63
|
-
break;
|
|
64
|
-
}
|
|
65
|
-
this.triggerResult(
|
|
66
|
-
success,
|
|
67
|
-
` Expected array items to match using ==
|
|
68
|
-
Expected: ${expectedValue} (${typeof expectedValue})
|
|
69
|
-
Actual: ${this.actualValue} (${typeof this.actualValue})`
|
|
70
|
-
);
|
|
71
|
-
}
|
|
72
|
-
toMatch(expectedValue) {
|
|
73
|
-
if (typeof this.actualValue.match !== "function") {
|
|
74
|
-
throw new Error(`You can not use toMatch on type ${typeof this.actualValue}`);
|
|
75
|
-
}
|
|
76
|
-
this.triggerResult(
|
|
77
|
-
!!this.actualValue.match(expectedValue),
|
|
78
|
-
" Expected values to match using regular expression\n Expression: " + expectedValue + "\n Actual: " + this.actualValue
|
|
79
|
-
);
|
|
80
|
-
}
|
|
81
|
-
toBeDefined() {
|
|
82
|
-
this.triggerResult(
|
|
83
|
-
typeof this.actualValue !== "undefined",
|
|
84
|
-
` Expected value to be defined`
|
|
85
|
-
);
|
|
86
|
-
}
|
|
87
|
-
toBeUndefined() {
|
|
88
|
-
this.triggerResult(
|
|
89
|
-
typeof this.actualValue === "undefined",
|
|
90
|
-
` Expected value to be undefined`
|
|
91
|
-
);
|
|
92
|
-
}
|
|
93
|
-
toBeNull() {
|
|
94
|
-
this.triggerResult(
|
|
95
|
-
this.actualValue === null,
|
|
96
|
-
` Expected value to be null`
|
|
97
|
-
);
|
|
98
|
-
}
|
|
99
|
-
toBeTruthy() {
|
|
100
|
-
this.triggerResult(
|
|
101
|
-
this.actualValue,
|
|
102
|
-
` Expected value to be truthy`
|
|
103
|
-
);
|
|
104
|
-
}
|
|
105
|
-
toBeFalsy() {
|
|
106
|
-
this.triggerResult(
|
|
107
|
-
!this.actualValue,
|
|
108
|
-
` Expected value to be falsy`
|
|
109
|
-
);
|
|
110
|
-
}
|
|
111
|
-
toContain(needle) {
|
|
112
|
-
this.triggerResult(
|
|
113
|
-
this.actualValue instanceof Array && this.actualValue.indexOf(needle) !== -1,
|
|
114
|
-
` Expected ` + this.actualValue + ` to contain ` + needle
|
|
115
|
-
);
|
|
116
|
-
}
|
|
117
|
-
toBeLessThan(greaterValue) {
|
|
118
|
-
this.triggerResult(
|
|
119
|
-
this.actualValue < greaterValue,
|
|
120
|
-
` Expected ` + this.actualValue + ` to be less than ` + greaterValue
|
|
121
|
-
);
|
|
122
|
-
}
|
|
123
|
-
toBeGreaterThan(smallerValue) {
|
|
124
|
-
this.triggerResult(
|
|
125
|
-
this.actualValue > smallerValue,
|
|
126
|
-
` Expected ` + this.actualValue + ` to be greater than ` + smallerValue
|
|
127
|
-
);
|
|
128
|
-
}
|
|
129
|
-
toBeCloseTo(expectedValue, precision) {
|
|
130
|
-
const shiftHelper = Math.pow(10, precision);
|
|
131
|
-
this.triggerResult(
|
|
132
|
-
Math.round(this.actualValue * shiftHelper) / shiftHelper === Math.round(expectedValue * shiftHelper) / shiftHelper,
|
|
133
|
-
` Expected ` + this.actualValue + ` with precision ` + precision + ` to be close to ` + expectedValue
|
|
134
|
-
);
|
|
135
|
-
}
|
|
136
|
-
toThrow(ErrorType) {
|
|
137
|
-
let errorMessage = "";
|
|
138
|
-
let didThrow = false;
|
|
139
|
-
let typeMatch = true;
|
|
140
|
-
try {
|
|
141
|
-
this.actualValue();
|
|
142
|
-
didThrow = false;
|
|
143
|
-
} catch (e) {
|
|
144
|
-
errorMessage = e.message || "";
|
|
145
|
-
didThrow = true;
|
|
146
|
-
if (ErrorType) {
|
|
147
|
-
typeMatch = e instanceof ErrorType;
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
const functionName = this.actualValue.name || typeof this.actualValue === "function" ? "[anonymous function]" : this.actualValue.toString();
|
|
151
|
-
this.triggerResult(
|
|
152
|
-
didThrow,
|
|
153
|
-
` Expected ${functionName} to ${this.positive ? "throw" : "not throw"} an exception ${!this.positive && errorMessage ? `, but an error with the message "${errorMessage}" was thrown` : ""}`
|
|
154
|
-
);
|
|
155
|
-
if (ErrorType) {
|
|
156
|
-
this.triggerResult(
|
|
157
|
-
typeMatch,
|
|
158
|
-
` Expected Error type '${ErrorType.name}', but the error is not an instance of it`
|
|
159
|
-
);
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
};
|
|
163
|
-
var describe = async function(moduleName, callback) {
|
|
164
|
-
print("\n" + moduleName);
|
|
165
|
-
await callback();
|
|
166
|
-
beforeEachCb = null;
|
|
167
|
-
afterEachCb = null;
|
|
168
|
-
};
|
|
169
|
-
var beforeEachCb;
|
|
170
|
-
var afterEachCb;
|
|
171
|
-
var it = async function(expectation, callback) {
|
|
172
|
-
try {
|
|
173
|
-
if (typeof beforeEachCb === "function") {
|
|
174
|
-
await beforeEachCb();
|
|
175
|
-
}
|
|
176
|
-
await callback();
|
|
177
|
-
if (typeof afterEachCb === "function") {
|
|
178
|
-
await afterEachCb();
|
|
179
|
-
}
|
|
180
|
-
print(` ${GREEN}\u2714${RESET} ${GRAY}${expectation}${RESET}`);
|
|
181
|
-
} catch (e) {
|
|
182
|
-
print(` ${RED}\u274C${RESET} ${GRAY}${expectation}${RESET}`);
|
|
183
|
-
print(`${RED}${e.message}${RESET}`);
|
|
184
|
-
if (e.stack)
|
|
185
|
-
print(e.stack);
|
|
186
|
-
}
|
|
187
|
-
};
|
|
188
|
-
var expect = function(actualValue) {
|
|
189
|
-
++countTestsOverall;
|
|
190
|
-
const expecter = new MatcherFactory(actualValue, true);
|
|
191
|
-
return expecter;
|
|
192
|
-
};
|
|
193
|
-
var assert = function(success, message) {
|
|
194
|
-
++countTestsOverall;
|
|
195
|
-
if (!success) {
|
|
196
|
-
++countTestsFailed;
|
|
197
|
-
}
|
|
198
|
-
nodeAssert(success, message);
|
|
199
|
-
};
|
|
200
|
-
assert.strictEqual = function(actual, expected, message) {
|
|
201
|
-
++countTestsOverall;
|
|
202
|
-
try {
|
|
203
|
-
nodeAssert.strictEqual(actual, expected, message);
|
|
204
|
-
} catch (error) {
|
|
205
|
-
++countTestsFailed;
|
|
206
|
-
throw error;
|
|
207
|
-
}
|
|
208
|
-
};
|
|
209
|
-
assert.throws = function(promiseFn, ...args) {
|
|
210
|
-
++countTestsOverall;
|
|
211
|
-
let error;
|
|
212
|
-
try {
|
|
213
|
-
promiseFn();
|
|
214
|
-
} catch (e) {
|
|
215
|
-
error = e;
|
|
216
|
-
}
|
|
217
|
-
if (!error)
|
|
218
|
-
++countTestsFailed;
|
|
219
|
-
nodeAssert.throws(() => {
|
|
220
|
-
if (error)
|
|
221
|
-
throw error;
|
|
222
|
-
}, args[0], args[1]);
|
|
223
|
-
};
|
|
224
|
-
assert.deepStrictEqual = function(actual, expected, message) {
|
|
225
|
-
++countTestsOverall;
|
|
226
|
-
try {
|
|
227
|
-
nodeAssert.deepStrictEqual(actual, expected, message);
|
|
228
|
-
} catch (error) {
|
|
229
|
-
++countTestsFailed;
|
|
230
|
-
throw error;
|
|
231
|
-
}
|
|
232
|
-
};
|
|
233
|
-
var runTests = async function(namespaces) {
|
|
234
|
-
for (const subNamespace in namespaces) {
|
|
235
|
-
const namespace = namespaces[subNamespace];
|
|
236
|
-
if (typeof namespace === "function") {
|
|
237
|
-
await namespace();
|
|
238
|
-
} else if (typeof namespace === "object") {
|
|
239
|
-
await runTests(namespace);
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
};
|
|
243
|
-
var printResult = () => {
|
|
244
|
-
if (countTestsIgnored) {
|
|
245
|
-
print(`
|
|
246
|
-
${BLUE}\u2714 ${countTestsIgnored} ignored test${countTestsIgnored > 1 ? "s" : ""}${RESET}`);
|
|
247
|
-
}
|
|
248
|
-
if (countTestsFailed) {
|
|
249
|
-
print(`
|
|
250
|
-
${RED}\u274C ${countTestsFailed} of ${countTestsOverall} tests failed${RESET}`);
|
|
251
|
-
} else {
|
|
252
|
-
print(`
|
|
253
|
-
${GREEN}\u2714 ${countTestsOverall} completed${RESET}`);
|
|
254
|
-
}
|
|
255
|
-
};
|
|
256
|
-
var getRuntime = async () => {
|
|
257
|
-
if (runtime && runtime !== "Unknown") {
|
|
258
|
-
return runtime;
|
|
259
|
-
}
|
|
260
|
-
if (globalThis.Deno?.version?.deno) {
|
|
261
|
-
return "Deno " + globalThis.Deno?.version?.deno;
|
|
262
|
-
} else {
|
|
263
|
-
let process = globalThis.process;
|
|
264
|
-
if (!process) {
|
|
265
|
-
try {
|
|
266
|
-
process = await import("process");
|
|
267
|
-
} catch (error) {
|
|
268
|
-
console.error(error);
|
|
269
|
-
console.warn(error.message);
|
|
270
|
-
runtime = "Unknown";
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
if (process?.versions?.gjs) {
|
|
274
|
-
runtime = "Gjs " + process.versions.gjs;
|
|
275
|
-
} else if (process?.versions?.node) {
|
|
276
|
-
runtime = "Node.js " + process.versions.node;
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
return runtime || "Unknown";
|
|
280
|
-
};
|
|
281
|
-
var printRuntime = async () => {
|
|
282
|
-
const runtime2 = await getRuntime();
|
|
283
|
-
print(`
|
|
284
|
-
Running on ${runtime2}`);
|
|
285
|
-
};
|
|
286
|
-
var run = async (namespaces) => {
|
|
287
|
-
printRuntime().then(async () => {
|
|
288
|
-
return runTests(namespaces).then(() => {
|
|
289
|
-
printResult();
|
|
290
|
-
print();
|
|
291
|
-
mainloop?.quit();
|
|
292
|
-
});
|
|
293
|
-
});
|
|
294
|
-
mainloop?.run();
|
|
295
|
-
};
|
|
296
|
-
|
|
297
|
-
// src/index.spec.ts
|
|
298
|
-
import * as qs from "querystring";
|
|
299
|
-
var index_spec_default = async () => {
|
|
300
|
-
await describe("querystring", async () => {
|
|
301
|
-
await it("performs basic parsing", async () => {
|
|
302
|
-
expect(qs.parse("id=918854443121279438895193").id).toBe("918854443121279438895193");
|
|
303
|
-
});
|
|
304
|
-
});
|
|
305
|
-
await it("test stringifying invalid surrogate pair throws URIError", async () => {
|
|
306
|
-
expect(() => {
|
|
307
|
-
qs.stringify({ foo: "\uDC00" });
|
|
308
|
-
}).toThrow();
|
|
309
|
-
try {
|
|
310
|
-
qs.stringify({ foo: "\uDC00" });
|
|
311
|
-
} catch (error) {
|
|
312
|
-
expect(error instanceof URIError).toBeTruthy();
|
|
313
|
-
}
|
|
314
|
-
});
|
|
315
|
-
await it("test stringifying coerce numbers to string", async () => {
|
|
316
|
-
expect("foo=0").toBe(qs.stringify({ foo: 0 }));
|
|
317
|
-
expect("foo=0").toBe(qs.stringify({ foo: -0 }));
|
|
318
|
-
expect("foo=3").toBe(qs.stringify({ foo: 3 }));
|
|
319
|
-
expect("foo=-72.42").toBe(qs.stringify({ foo: -72.42 }));
|
|
320
|
-
expect("foo=").toBe(qs.stringify({ foo: NaN }));
|
|
321
|
-
expect("foo=").toBe(qs.stringify({ foo: Infinity }));
|
|
322
|
-
});
|
|
323
|
-
await it("test stringifying nested", async () => {
|
|
324
|
-
const f = qs.stringify({
|
|
325
|
-
a: "b",
|
|
326
|
-
q: qs.stringify({
|
|
327
|
-
x: "y",
|
|
328
|
-
y: "z"
|
|
329
|
-
})
|
|
330
|
-
});
|
|
331
|
-
expect(f).toBe("a=b&q=x%3Dy%26y%3Dz");
|
|
332
|
-
});
|
|
333
|
-
await it("test stringifying nested in colon", async () => {
|
|
334
|
-
const f = qs.stringify({
|
|
335
|
-
a: "b",
|
|
336
|
-
q: qs.stringify({
|
|
337
|
-
x: "y",
|
|
338
|
-
y: "z"
|
|
339
|
-
}, ";", ":")
|
|
340
|
-
}, ";", ":");
|
|
341
|
-
expect(f).toBe("a:b;q:x%3Ay%3By%3Az");
|
|
342
|
-
});
|
|
343
|
-
await it("test stringifying empty string", async () => {
|
|
344
|
-
expect(qs.stringify()).toBe("");
|
|
345
|
-
expect(qs.stringify(0)).toBe("");
|
|
346
|
-
expect(qs.stringify([])).toBe("");
|
|
347
|
-
expect(qs.stringify(null)).toBe("");
|
|
348
|
-
expect(qs.stringify(true)).toBe("");
|
|
349
|
-
});
|
|
350
|
-
};
|
|
351
|
-
|
|
352
|
-
// src/test.mts
|
|
353
|
-
run({ testSuite: index_spec_default });
|