@gjsify/abort-controller 0.0.2
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 +4 -0
- package/lib/cjs/index.js +18 -0
- package/lib/esm/index.js +2 -0
- package/lib/types/index.d.ts +2 -0
- package/package.json +50 -0
- package/src/abort-controller.spec.ts +169 -0
- package/src/abort-signal.spec.ts +25 -0
- package/src/index.ts +2 -0
- package/src/test.mts +6 -0
- package/test.gjs.js +34758 -0
- package/test.gjs.mjs +34848 -0
- package/test.gjs.mjs.meta.json +1 -0
- package/test.node.js +1226 -0
- package/test.node.mjs +8748 -0
- package/tsconfig.json +19 -0
- package/tsconfig.types.json +8 -0
- package/tsconfig.types.tsbuildinfo +1 -0
package/README.md
ADDED
package/lib/cjs/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __copyProps = (to, from, except, desc) => {
|
|
6
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
|
+
for (let key of __getOwnPropNames(from))
|
|
8
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
9
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
10
|
+
}
|
|
11
|
+
return to;
|
|
12
|
+
};
|
|
13
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
var src_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(src_exports);
|
|
17
|
+
var import_dom_events = require("@gjsify/dom-events");
|
|
18
|
+
__reExport(src_exports, require("@gjsify/deno-runtime/ext/web/03_abort_signal"), module.exports);
|
package/lib/esm/index.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@gjsify/abort-controller",
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"description": "Web AbortController module for Gjs",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "lib/cjs/index.js",
|
|
7
|
+
"module": "lib/esm/index.js",
|
|
8
|
+
"types": "lib/types/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": {
|
|
12
|
+
"types": "./lib/types/index.d.ts",
|
|
13
|
+
"default": "./lib/esm/index.js"
|
|
14
|
+
},
|
|
15
|
+
"require": {
|
|
16
|
+
"types": "./lib/types/index.d.ts",
|
|
17
|
+
"default": "./lib/cjs/index.js"
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"scripts": {
|
|
22
|
+
"clear": "rm -rf lib tsconfig.tsbuildinfo tsconfig.types.tsbuildinfo || exit 0",
|
|
23
|
+
"print:name": "echo '@gjsify/abort-controller'",
|
|
24
|
+
"build": "yarn print:name && yarn build:gjsify && yarn build:types",
|
|
25
|
+
"build:gjsify": "gjsify build --library 'src/**/*.{ts,js}' --exclude 'src/**/*.spec.{mts,ts}' 'src/test.{mts,ts}'",
|
|
26
|
+
"build:types": "tsc --project tsconfig.types.json || exit 0",
|
|
27
|
+
"build:test": "yarn build:test:gjs && yarn build:test:node",
|
|
28
|
+
"build:test:gjs": "gjsify build src/test.mts --app gjs --outfile test.gjs.mjs",
|
|
29
|
+
"build:test:node": "gjsify build src/test.mts --app node --outfile test.node.mjs",
|
|
30
|
+
"test": "yarn print:name && yarn build:gjsify && yarn build:test && yarn test:gjs",
|
|
31
|
+
"test:gjs": "gjs -m test.gjs.mjs",
|
|
32
|
+
"test:node": "node test.node.mjs"
|
|
33
|
+
},
|
|
34
|
+
"keywords": [
|
|
35
|
+
"gjs",
|
|
36
|
+
"node",
|
|
37
|
+
"buffer"
|
|
38
|
+
],
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"@gjsify/cli": "^0.0.2",
|
|
41
|
+
"@gjsify/unit": "^0.0.2",
|
|
42
|
+
"@types/node": "^20.3.1",
|
|
43
|
+
"typescript": "^5.1.3"
|
|
44
|
+
},
|
|
45
|
+
"dependencies": {
|
|
46
|
+
"@gjsify/deno-runtime": "^0.0.2",
|
|
47
|
+
"@gjsify/deno_std": "^0.0.2",
|
|
48
|
+
"@gjsify/dom-events": "^0.0.2"
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { describe, it, expect, assert } from '@gjsify/unit';
|
|
2
|
+
|
|
3
|
+
// TODO add a fake module for node and deno to run this tests also in his runtime?
|
|
4
|
+
import { AbortController, AbortSignal } from '@gjsify/abort-controller';
|
|
5
|
+
|
|
6
|
+
const HAS_EVENT_TARGET_INTERFACE = typeof EventTarget !== "undefined"
|
|
7
|
+
|
|
8
|
+
export default async () => {
|
|
9
|
+
|
|
10
|
+
// Credits https://github.com/mysticatea/abort-controller/tree/master/test
|
|
11
|
+
|
|
12
|
+
await describe('AbortController', async () => {
|
|
13
|
+
await it('should have a callable constructor', async () => {
|
|
14
|
+
expect(() => {
|
|
15
|
+
new AbortController();
|
|
16
|
+
}).not.toThrow();
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
await it('should not be callable', async () => {
|
|
20
|
+
expect(AbortController).toThrow();
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
await it('should have 2 properties', async () => {
|
|
24
|
+
const controller = new AbortController();
|
|
25
|
+
|
|
26
|
+
const keys = new Set()
|
|
27
|
+
keys.add("signal")
|
|
28
|
+
keys.add("abort")
|
|
29
|
+
|
|
30
|
+
for (const key in controller) {
|
|
31
|
+
assert(keys.has(key), `'${key}' found, but should not have it`);
|
|
32
|
+
keys.delete(key)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
keys.forEach((key) => {
|
|
36
|
+
assert(false, `'${key}' not found`);
|
|
37
|
+
})
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
// TODO
|
|
41
|
+
// await it('should be stringified as [object AbortController]', async () => {
|
|
42
|
+
// const controller = new AbortController();
|
|
43
|
+
// expect(controller.toString()).toBe("[object AbortController]")
|
|
44
|
+
// });
|
|
45
|
+
|
|
46
|
+
await describe("'signal' property", async () => {
|
|
47
|
+
const controller = new AbortController();
|
|
48
|
+
const signal = controller.signal
|
|
49
|
+
|
|
50
|
+
await it("should return the same instance always", async () => {
|
|
51
|
+
expect(signal === controller.signal).toBeTruthy()
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
await it("should be a AbortSignal object", async () => {
|
|
55
|
+
expect(signal instanceof AbortSignal).toBeTruthy()
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
if(HAS_EVENT_TARGET_INTERFACE) {
|
|
59
|
+
await it("should be a EventTarget object", async () => {
|
|
60
|
+
expect(signal instanceof EventTarget).toBeTruthy()
|
|
61
|
+
})
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
await it("should have 5 properties", async () => {
|
|
65
|
+
const keys = new Set<string>()
|
|
66
|
+
keys.add("addEventListener")
|
|
67
|
+
keys.add("removeEventListener")
|
|
68
|
+
keys.add("dispatchEvent")
|
|
69
|
+
keys.add("aborted")
|
|
70
|
+
keys.add("onabort")
|
|
71
|
+
|
|
72
|
+
// TODO
|
|
73
|
+
// for (const key in signal) {
|
|
74
|
+
// assert(keys.has(key), `'${key}' found, but should not have it`);
|
|
75
|
+
// keys.delete(key)
|
|
76
|
+
// }
|
|
77
|
+
|
|
78
|
+
keys.forEach(key => {
|
|
79
|
+
// WORKAROUND for getter / setter
|
|
80
|
+
const exists = (signal as any)[key] !== undefined;
|
|
81
|
+
|
|
82
|
+
assert(exists, `'${key}' not found, but should have it: `);
|
|
83
|
+
})
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
await it("should have 'aborted' property which is false by default", async () => {
|
|
87
|
+
expect(signal.aborted).toBeFalsy();
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
await it("should have 'onabort' property which is null by default", async () => {
|
|
91
|
+
// TODO:
|
|
92
|
+
expect((signal as any).onabort).toBeNull()
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
await it("should throw a TypeError if 'signal.aborted' getter is called with non AbortSignal object", async () => {
|
|
96
|
+
const getAborted = Object.getOwnPropertyDescriptor(
|
|
97
|
+
(signal as any).__proto__,
|
|
98
|
+
"aborted",
|
|
99
|
+
)!.get
|
|
100
|
+
|
|
101
|
+
expect(() => {
|
|
102
|
+
getAborted!.call({})
|
|
103
|
+
}).toThrow(TypeError);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
await it("should be stringified as [object AbortSignal]", async () => {
|
|
107
|
+
expect(signal.toString()).toBe("[object AbortSignal]")
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
await describe("'abort' method", async () => {
|
|
112
|
+
|
|
113
|
+
await it("should set true to 'signal.aborted' property", async () => {
|
|
114
|
+
const controller = new AbortController();
|
|
115
|
+
|
|
116
|
+
controller.abort()
|
|
117
|
+
assert(controller.signal.aborted)
|
|
118
|
+
})
|
|
119
|
+
|
|
120
|
+
await it("should fire 'abort' event on 'signal' (addEventListener)", async () => {
|
|
121
|
+
const controller = new AbortController();
|
|
122
|
+
|
|
123
|
+
let calls = 0;
|
|
124
|
+
controller.signal.addEventListener("abort", () => {
|
|
125
|
+
++calls;
|
|
126
|
+
});
|
|
127
|
+
controller.abort()
|
|
128
|
+
|
|
129
|
+
assert(calls === 1)
|
|
130
|
+
})
|
|
131
|
+
|
|
132
|
+
await it("should fire 'abort' event on 'signal' (onabort)", async () => {
|
|
133
|
+
const controller = new AbortController();
|
|
134
|
+
|
|
135
|
+
let calls = 0;
|
|
136
|
+
// TODO:
|
|
137
|
+
(controller.signal as any).onabort = () => {
|
|
138
|
+
++calls;
|
|
139
|
+
}
|
|
140
|
+
controller.abort()
|
|
141
|
+
|
|
142
|
+
assert(calls === 1)
|
|
143
|
+
})
|
|
144
|
+
|
|
145
|
+
await it("should not fire 'abort' event twice", async () => {
|
|
146
|
+
const controller = new AbortController();
|
|
147
|
+
|
|
148
|
+
let calls = 0;
|
|
149
|
+
controller.signal.addEventListener("abort", () => {
|
|
150
|
+
++calls;
|
|
151
|
+
});
|
|
152
|
+
controller.abort()
|
|
153
|
+
controller.abort()
|
|
154
|
+
controller.abort()
|
|
155
|
+
|
|
156
|
+
assert(calls === 1)
|
|
157
|
+
})
|
|
158
|
+
|
|
159
|
+
await it("should throw a TypeError if 'this' is not an AbortController object", async () => {
|
|
160
|
+
const controller = new AbortController();
|
|
161
|
+
|
|
162
|
+
expect(() => {
|
|
163
|
+
controller.abort.call({})
|
|
164
|
+
}).toThrow(TypeError)
|
|
165
|
+
})
|
|
166
|
+
})
|
|
167
|
+
|
|
168
|
+
});
|
|
169
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { describe, it, expect } from '@gjsify/unit';
|
|
2
|
+
|
|
3
|
+
import { AbortSignal } from '@gjsify/abort-controller';
|
|
4
|
+
|
|
5
|
+
// Use build in AbortSignal on Node.js tests and the custom implementation on Gjs
|
|
6
|
+
// export const AbortSignal = globalThis.AbortSignal || GjsifyAbortSignal;
|
|
7
|
+
|
|
8
|
+
export default async () => {
|
|
9
|
+
|
|
10
|
+
// Credits https://github.com/mysticatea/abort-controller/tree/master/test
|
|
11
|
+
|
|
12
|
+
await describe("AbortSignal", async () => {
|
|
13
|
+
await it("should not be callable", async () => {
|
|
14
|
+
expect(() => {
|
|
15
|
+
(AbortSignal as any)()
|
|
16
|
+
}).toThrow(TypeError);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
await it("should throw a TypeError when it's constructed directly", async () => {
|
|
20
|
+
expect(() => {
|
|
21
|
+
new AbortSignal()
|
|
22
|
+
}).toThrow(TypeError);
|
|
23
|
+
});
|
|
24
|
+
})
|
|
25
|
+
}
|
package/src/index.ts
ADDED