@gjsify/console 0.0.1 → 0.0.3

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/test.node.mjs ADDED
@@ -0,0 +1,308 @@
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 {
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 console2 from "console";
299
+ var index_spec_default = async () => {
300
+ await describe("Default import", async () => {
301
+ await it("should be an object", async () => {
302
+ expect(console2 instanceof Object).toBeTruthy();
303
+ });
304
+ });
305
+ };
306
+
307
+ // src/test.mts
308
+ run({ testSuite: index_spec_default });
package/tsconfig.json ADDED
@@ -0,0 +1,19 @@
1
+ {
2
+ "compilerOptions": {
3
+ "module": "ESNext",
4
+ "types": ["node"],
5
+ "target": "ESNext",
6
+ "experimentalDecorators": true,
7
+ "outDir": "lib",
8
+ "rootDir": "src",
9
+ "composite": true,
10
+ "moduleResolution": "bundler",
11
+ "allowImportingTsExtensions": true
12
+ },
13
+ "skipLibCheck": true,
14
+ "allowJs": true,
15
+ "checkJs": false,
16
+ "reflection": false,
17
+ "include": ["src/**/*.ts"],
18
+ "exclude": ["src/test.mts", "src/**/*.spec.ts"]
19
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "emitDeclarationOnly": true,
5
+ "declarationDir": "lib/types",
6
+ },
7
+ "exclude": ["src/test.ts", "src/test.mts", "src/**/*.spec.ts", "src/**/*.spec.mts"]
8
+ }
package/.testem.json DELETED
@@ -1,14 +0,0 @@
1
- {
2
- "launchers": {
3
- "node": {
4
- "command": "npm test"
5
- }
6
- },
7
- "src_files": [
8
- "./**/*.js"
9
- ],
10
- "before_tests": "npm run build",
11
- "on_exit": "rm test/static/bundle.js",
12
- "test_page": "test/static/index.html",
13
- "launch_in_dev": ["node", "phantomjs"]
14
- }
package/.travis.yml DELETED
@@ -1,11 +0,0 @@
1
- language: node_js
2
- node_js:
3
- - "stable"
4
- - "12"
5
- - "11"
6
- - "10"
7
- - "8"
8
- - "6"
9
- - "4"
10
- - "0.12"
11
- - "0.10"
package/CHANGELOG.md DELETED
@@ -1,10 +0,0 @@
1
- # console-browserify change log
2
-
3
- All notable changes to this project will be documented in this file.
4
-
5
- This project adheres to [Semantic Versioning](http://semver.org/).
6
-
7
- ## 1.2.0
8
- * Move to the browserify org.
9
- * Remove `date-now` dependency. ([@jakepusateri](https://github.com/jakepusateri) in [#10](https://github.com/browserify/console-browserify/pull/10))
10
- * Fix memory leak in `time`/`timeEnd`. ([@maxnordlund](https://github.com/maxnordlund) in [#11](https://github.com/browserify/console-browserify/pull/11))
package/LICENCE DELETED
@@ -1,19 +0,0 @@
1
- Copyright (c) 2012 Raynos.
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining a copy
4
- of this software and associated documentation files (the "Software"), to deal
5
- in the Software without restriction, including without limitation the rights
6
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- copies of the Software, and to permit persons to whom the Software is
8
- furnished to do so, subject to the following conditions:
9
-
10
- The above copyright notice and this permission notice shall be included in
11
- all copies or substantial portions of the Software.
12
-
13
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
- THE SOFTWARE.
package/index.js DELETED
@@ -1,108 +0,0 @@
1
- /*
2
- ┌─────────────┐
3
- │ Missing │
4
- └─────────────┘
5
- console.group
6
- console.groupCollapsed
7
- console.groupEnd()
8
- no Console constructor
9
- */
10
-
11
- /*global window, global*/
12
- var util = require("util")
13
- var assert = require("assert")
14
- function now() { return new Date().getTime() }
15
-
16
- var slice = Array.prototype.slice
17
- var console
18
- var times = {}
19
-
20
- if (typeof global !== "undefined" && global.console) {
21
- console = global.console
22
- } else if (typeof window !== "undefined" && window.console) {
23
- console = window.console
24
- } else if (typeof print === "function" && typeof printerr === "function") {
25
- // gjs runtime
26
- console = {
27
- log: print,
28
- warn: printerr,
29
- }
30
- } else {
31
- console = {}
32
- }
33
-
34
- var functions = [
35
- [log, "log"],
36
- [info, "info"],
37
- [debug, "debug"],
38
- [warn, "warn"],
39
- [error, "error"],
40
- [time, "time"],
41
- [timeEnd, "timeEnd"],
42
- [trace, "trace"],
43
- [dir, "dir"],
44
- [consoleAssert, "assert"]
45
- ]
46
-
47
- function log() {}
48
-
49
- function info() {
50
- console.log.apply(console, arguments)
51
- }
52
-
53
- function warn() {
54
- console.log.apply(console, arguments)
55
- }
56
-
57
- function debug() {
58
- console.log.apply(console, arguments)
59
- }
60
-
61
- function error() {
62
- console.warn.apply(console, arguments)
63
- }
64
-
65
- function time(label) {
66
- times[label] = now()
67
- }
68
-
69
- function timeEnd(label) {
70
- var time = times[label]
71
- if (!time) {
72
- throw new Error("No such label: " + label)
73
- }
74
-
75
- delete times[label]
76
- var duration = now() - time
77
- console.log(label + ": " + duration + "ms")
78
- }
79
-
80
- function trace() {
81
- var err = new Error()
82
- err.name = "Trace"
83
- err.message = util.format.apply(null, arguments)
84
- console.error(err.stack)
85
- }
86
-
87
- function dir(object) {
88
- console.log(util.inspect(object) + "\n")
89
- }
90
-
91
- function consoleAssert(expression) {
92
- if (!expression) {
93
- var arr = slice.call(arguments, 1)
94
- assert.ok(false, util.format.apply(null, arr))
95
- }
96
- }
97
-
98
- for (var i = 0; i < functions.length; i++) {
99
- var tuple = functions[i]
100
- var f = tuple[0]
101
- var name = tuple[1]
102
-
103
- if (!console[name]) {
104
- console[name] = f
105
- }
106
- }
107
-
108
- module.exports = console
package/test/index.js DELETED
@@ -1,67 +0,0 @@
1
- var console = require("../index")
2
- var test = require("tape")
3
-
4
- if (typeof window !== "undefined" && !window.JSON) {
5
- window.JSON = require("jsonify")
6
- }
7
-
8
- test("console has expected methods", function (assert) {
9
- assert.ok(console.log)
10
- assert.ok(console.info)
11
- assert.ok(console.warn)
12
- assert.ok(console.dir)
13
- assert.ok(console.time, "time")
14
- assert.ok(console.timeEnd, "timeEnd")
15
- assert.ok(console.trace, "trace")
16
- assert.ok(console.assert)
17
-
18
- assert.end()
19
- })
20
-
21
- test("invoke console.log", function (assert) {
22
- console.log("test-log")
23
-
24
- assert.end()
25
- })
26
-
27
- test("invoke console.info", function (assert) {
28
- console.info("test-info")
29
-
30
- assert.end()
31
- })
32
-
33
- test("invoke console.warn", function (assert) {
34
- console.warn("test-warn")
35
-
36
- assert.end()
37
- })
38
-
39
- test("invoke console.time", function (assert) {
40
- console.time("label")
41
-
42
- assert.end()
43
- })
44
-
45
- test("invoke console.trace", function (assert) {
46
- console.trace("test-trace")
47
-
48
- assert.end()
49
- })
50
-
51
- test("invoke console.assert", function (assert) {
52
- console.assert(true)
53
-
54
- assert.end()
55
- })
56
-
57
- test("invoke console.dir", function (assert) {
58
- console.dir("test-dir")
59
-
60
- assert.end()
61
- })
62
-
63
- test("invoke console.timeEnd", function (assert) {
64
- console.timeEnd("label")
65
-
66
- assert.end()
67
- })
@@ -1,12 +0,0 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <meta http-equiv="x-ua-compatible" content="IE=8" >
5
- <title>TAPE Example</title>
6
- <script src="/testem.js"></script>
7
- <script src="test-adapter.js"></script>
8
- <script src="bundle.js"></script>
9
- </head>
10
- <body>
11
- </body>
12
- </html>
@@ -1,53 +0,0 @@
1
- (function () {
2
- var Testem = window.Testem
3
- var regex = /^((?:not )?ok) (\d+) (.+)$/
4
-
5
- Testem.useCustomAdapter(tapAdapter)
6
-
7
- function tapAdapter(socket){
8
- var results = {
9
- failed: 0
10
- , passed: 0
11
- , total: 0
12
- , tests: []
13
- }
14
-
15
- socket.emit('tests-start')
16
-
17
- Testem.handleConsoleMessage = function(msg){
18
- var m = msg.match(regex)
19
- if (m) {
20
- var passed = m[1] === 'ok'
21
- var test = {
22
- passed: passed ? 1 : 0,
23
- failed: passed ? 0 : 1,
24
- total: 1,
25
- id: m[2],
26
- name: m[3],
27
- items: []
28
- }
29
-
30
- if (passed) {
31
- results.passed++
32
- } else {
33
- console.error("failure", m)
34
-
35
- results.failed++
36
- }
37
-
38
- results.total++
39
-
40
- // console.log("emitted test", test)
41
- socket.emit('test-result', test)
42
- results.tests.push(test)
43
- } else if (msg === '# ok' || msg.match(/^# tests \d+/)){
44
- // console.log("emitted all test")
45
- socket.emit('all-test-results', results)
46
- }
47
-
48
- // return false if you want to prevent the console message from
49
- // going to the console
50
- // return false
51
- }
52
- }
53
- }())