From 1e237c9d53cc0527b3429eb226fa1e3747d2790c Mon Sep 17 00:00:00 2001 From: Joe Pea Date: Mon, 30 Oct 2023 16:54:15 -0700 Subject: [PATCH] infra: lume cli update: update tests to run in @web/test-runner (replaced Karma in lume cli), update GitHub Actions yml to run clean/build/test separately as they are no longer coupled in lume cli, update build output with changes from the updated target:esnext option in lume cli tsconfig. Note, the dev process in the repo, when standalone and not a git submodule in the lume repo, will not work for now and needs to be developed as part of the lume supermodule repo using the link script for bootstrapping and linking of packages. Once we finish the stage-3-decorators and classy-solid migration in Lume (soon) we will get the lume cli working in standalone repos again. --- .github/workflows/tests.yml | 4 + dist/BehaviorMap.js | 31 ++-- dist/BehaviorMap.js.map | 2 +- dist/BehaviorRegistry.js | 36 ++-- dist/BehaviorRegistry.js.map | 2 +- dist/HasAttribute.js | 31 +--- dist/HasAttribute.js.map | 2 +- dist/global.test.d.ts | 2 - dist/global.test.d.ts.map | 1 - dist/global.test.js | 2 - dist/global.test.js.map | 1 - dist/index.test.d.ts | 4 +- dist/index.test.d.ts.map | 2 +- dist/index.test.js | 222 +++++++++++++++++++++- dist/index.test.js.map | 2 +- dist/tests-shared.d.ts | 2 - dist/tests-shared.d.ts.map | 1 - dist/tests-shared.js | 225 ---------------------- dist/tests-shared.js.map | 1 - lume.config.cjs | 12 ++ package.json | 7 +- src/global.test.ts | 1 - src/index.test.ts | 348 ++++++++++++++++++++++++++++++++++- src/tests-shared.ts | 331 --------------------------------- 24 files changed, 629 insertions(+), 643 deletions(-) delete mode 100644 dist/global.test.d.ts delete mode 100644 dist/global.test.d.ts.map delete mode 100644 dist/global.test.js delete mode 100644 dist/global.test.js.map delete mode 100644 dist/tests-shared.d.ts delete mode 100644 dist/tests-shared.d.ts.map delete mode 100644 dist/tests-shared.js delete mode 100644 dist/tests-shared.js.map create mode 100644 lume.config.cjs delete mode 100644 src/global.test.ts delete mode 100644 src/tests-shared.ts diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 52ed0a7..1024ff5 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -21,6 +21,10 @@ jobs: - name: npm install, build, and test run: | npm i + npm run clean + npm run build npm test + - name: ensure no modifications + run: git add . && git diff --quiet && git diff --cached --quiet env: CI: true diff --git a/dist/BehaviorMap.js b/dist/BehaviorMap.js index 556b6c5..df1fc65 100644 --- a/dist/BehaviorMap.js +++ b/dist/BehaviorMap.js @@ -1,16 +1,11 @@ -var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { - if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); - if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); - return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); -}; -var _BehaviorMap_reactivityTriggerObject; import { $TRACK } from 'solid-js'; import { createMutable, modifyMutable, reconcile } from 'solid-js/store'; export class BehaviorMap extends Map { constructor() { super(...arguments); - _BehaviorMap_reactivityTriggerObject.set(this, createMutable({})); + this.#reactivityTriggerObject = createMutable({}); } + #reactivityTriggerObject; find(predicate) { let result = void undefined; for (const [name, behavior] of this) { @@ -22,50 +17,50 @@ export class BehaviorMap extends Map { return result; } get(key) { - __classPrivateFieldGet(this, _BehaviorMap_reactivityTriggerObject, "f")[key]; + this.#reactivityTriggerObject[key]; return super.get(key); } set(key, value) { queueMicrotask(() => { - __classPrivateFieldGet(this, _BehaviorMap_reactivityTriggerObject, "f")[key] = value; + this.#reactivityTriggerObject[key] = value; }); super.set(key, value); return this; } delete(key) { queueMicrotask(() => { - delete __classPrivateFieldGet(this, _BehaviorMap_reactivityTriggerObject, "f")[key]; + delete this.#reactivityTriggerObject[key]; }); return super.delete(key); } clear() { queueMicrotask(() => { - modifyMutable(__classPrivateFieldGet(this, _BehaviorMap_reactivityTriggerObject, "f"), reconcile({})); + modifyMutable(this.#reactivityTriggerObject, reconcile({})); }); super.clear(); } has(key) { - __classPrivateFieldGet(this, _BehaviorMap_reactivityTriggerObject, "f")[key]; + this.#reactivityTriggerObject[key]; return super.has(key); } entries() { - __classPrivateFieldGet(this, _BehaviorMap_reactivityTriggerObject, "f")[$TRACK]; + this.#reactivityTriggerObject[$TRACK]; return super.entries(); } - [(_BehaviorMap_reactivityTriggerObject = new WeakMap(), Symbol.iterator)]() { - __classPrivateFieldGet(this, _BehaviorMap_reactivityTriggerObject, "f")[$TRACK]; + [Symbol.iterator]() { + this.#reactivityTriggerObject[$TRACK]; return super[Symbol.iterator](); } forEach(callbackfn, thisArg) { - __classPrivateFieldGet(this, _BehaviorMap_reactivityTriggerObject, "f")[$TRACK]; + this.#reactivityTriggerObject[$TRACK]; super.forEach(callbackfn, thisArg); } keys() { - __classPrivateFieldGet(this, _BehaviorMap_reactivityTriggerObject, "f")[$TRACK]; + this.#reactivityTriggerObject[$TRACK]; return super.keys(); } get size() { - __classPrivateFieldGet(this, _BehaviorMap_reactivityTriggerObject, "f")[$TRACK]; + this.#reactivityTriggerObject[$TRACK]; return super.size; } set size(n) { diff --git a/dist/BehaviorMap.js.map b/dist/BehaviorMap.js.map index 6b0eaee..1cb31a4 100644 --- a/dist/BehaviorMap.js.map +++ b/dist/BehaviorMap.js.map @@ -1 +1 @@ -{"version":3,"file":"BehaviorMap.js","sourceRoot":"","sources":["../src/BehaviorMap.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAC,MAAM,EAAC,MAAM,UAAU,CAAA;AAC/B,OAAO,EAAC,aAAa,EAAE,aAAa,EAAE,SAAS,EAAC,MAAM,gBAAgB,CAAA;AAStE,MAAM,OAAO,WAAY,SAAQ,GAAqC;IAAtE;;QAKC,+CAA2B,aAAa,CAA2C,EAAE,CAAC,EAAA;IA6GvF,CAAC;IA3GA,IAAI,CAAC,SAAwE;QAC5E,IAAI,MAAM,GAAyC,KAAK,SAAS,CAAA;QAEjE,KAAK,MAAM,CAAC,IAAI,EAAE,QAAQ,CAAC,IAAI,IAAI,EAAE;YAC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Q,CAAC,EAAE,CAAA;IAChC,CAAC;IAEQ,OAAO,CACf,UAA8G,EAC9G,OAAa;QAIb,IAAI,CAAC,wBAAwB,CAAC,MAAM,CAAC,CAAA;QAErC,KAAK,CAAC,OAAO,CAAC,UAAU,EAAE,OAAO,CAAC,CAAA;IACnC,CAAC;IAEQ,IAAI;QAGZ,IAAI,CAAC,wBAAwB,CAAC,MAAM,CAAC,CAAA;QAErC,OAAO,KAAK,CAAC,IAAI,EAAE,CAAA;IACpB,CAAC;IAED,IAAa,IAAI;QAGhB,IAAI,CAAC,wBAAwB,CAAC,MAAM,CAAC,CAAA;QAErC,OAAO,KAAK,CAAC,IAAI,CAAA;IAClB,CAAC;IACD,IAAa,IAAI,CAAC,CAAS;QAI1B,KAAK,CAAC,IAAI,GAAG,CAAC,CAAA;IACf,CAAC;CACD"} \ No newline at end of file diff --git a/dist/BehaviorRegistry.js b/dist/BehaviorRegistry.js index 7e0a860..ccfc712 100644 --- a/dist/BehaviorRegistry.js +++ b/dist/BehaviorRegistry.js @@ -1,21 +1,16 @@ -var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { - if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); - if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); - return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); -}; -var _a; -var _BehaviorRegistry_definedBehaviors, _BehaviorRegistry_whenDefinedPromises; export class BehaviorRegistry { constructor() { - _BehaviorRegistry_definedBehaviors.set(this, new Map()); - _BehaviorRegistry_whenDefinedPromises.set(this, new Map()); + this.#definedBehaviors = new Map(); + this.#whenDefinedPromises = new Map(); } + #definedBehaviors; + #whenDefinedPromises; define(name, Behavior) { - if (!__classPrivateFieldGet(this, _BehaviorRegistry_definedBehaviors, "f").has(name)) { - __classPrivateFieldGet(this, _BehaviorRegistry_definedBehaviors, "f").set(name, Behavior); - if (__classPrivateFieldGet(this, _BehaviorRegistry_whenDefinedPromises, "f").has(name)) { - __classPrivateFieldGet(this, _BehaviorRegistry_whenDefinedPromises, "f").get(name).resolve(); - __classPrivateFieldGet(this, _BehaviorRegistry_whenDefinedPromises, "f").delete(name); + if (!this.#definedBehaviors.has(name)) { + this.#definedBehaviors.set(name, Behavior); + if (this.#whenDefinedPromises.has(name)) { + this.#whenDefinedPromises.get(name).resolve(); + this.#whenDefinedPromises.delete(name); } } else { @@ -23,25 +18,24 @@ export class BehaviorRegistry { } } get(name) { - return __classPrivateFieldGet(this, _BehaviorRegistry_definedBehaviors, "f").get(name); + return this.#definedBehaviors.get(name); } has(name) { - return __classPrivateFieldGet(this, _BehaviorRegistry_definedBehaviors, "f").has(name); + return this.#definedBehaviors.has(name); } whenDefined(name) { - if (__classPrivateFieldGet(this, _BehaviorRegistry_whenDefinedPromises, "f").has(name)) - return __classPrivateFieldGet(this, _BehaviorRegistry_whenDefinedPromises, "f").get(name).promise; + if (this.#whenDefinedPromises.has(name)) + return this.#whenDefinedPromises.get(name).promise; if (this.has(name)) return Promise.resolve(); let resolve; const promise = new Promise(r => (resolve = r)); - __classPrivateFieldGet(this, _BehaviorRegistry_whenDefinedPromises, "f").set(name, { promise, resolve }); + this.#whenDefinedPromises.set(name, { promise, resolve }); return promise; } } -_BehaviorRegistry_definedBehaviors = new WeakMap(), _BehaviorRegistry_whenDefinedPromises = new WeakMap(); export let elementBehaviors; -if ((_a = globalThis.window) === null || _a === void 0 ? void 0 : _a.document) { +if (globalThis.window?.document) { elementBehaviors = globalThis.elementBehaviors = new BehaviorRegistry(); } //# sourceMappingURL=BehaviorRegistry.js.map \ No newline at end of file diff --git a/dist/BehaviorRegistry.js.map b/dist/BehaviorRegistry.js.map index f7d1fb2..a11f46c 100644 --- a/dist/BehaviorRegistry.js.map +++ b/dist/BehaviorRegistry.js.map @@ -1 +1 @@ -{"version":3,"file":"BehaviorRegistry.js","sourceRoot":"","sources":["../src/BehaviorRegistry.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G,CAAC,IAAY;QACf,OAAO,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;IACxC,CAAC;IAOD,WAAW,CAAC,IAAY;QACvB,IAAI,IAAI,CAAC,oBAAoB,CAAC,GAAG,CAAC,IAAI,CAAC;YAAE,OAAO,IAAI,CAAC,oBAAoB,CAAC,GAAG,CAAC,IAAI,CAAE,CAAC,OAAO,CAAA;QAC5F,IAAI,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC;YAAE,OAAO,OAAO,CAAC,OAAO,EAAE,CAAA;QAE5C,IAAI,OAAoB,CAAA;QACxB,MAAM,OAAO,GAAG,IAAI,OAAO,CAAO,CAAC,CAAC,EAAE,CAAC,CAAC,OAAO,GAAG,CAAC,CAAC,CAAC,CAAA;QAErD,IAAI,CAAC,oBAAoB,CAAC,GAAG,CAAC,IAAI,EAAE,EAAC,OAAO,EAAE,OAAO,EAAC,CAAC,CAAA;QAEvD,OAAO,OAAO,CAAA;IACf,CAAC;CACD;AAED,MAAM,CAAC,IAAI,gBAAkC,CAAA;AAG7C,IAAI,UAAU,CAAC,MAAM,EAAE,QAAQ,EAAE;IAChC,gBAAgB,GAAG,UAAU,CAAC,gBAAgB,GAAG,IAAI,gBAAgB,EAAE,CAAA;CACvE"} \ No newline at end of file diff --git a/dist/HasAttribute.js b/dist/HasAttribute.js index 718c179..3b203fd 100644 --- a/dist/HasAttribute.js +++ b/dist/HasAttribute.js @@ -1,16 +1,3 @@ -var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) { - if (kind === "m") throw new TypeError("Private method is not writable"); - if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter"); - if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it"); - return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value; -}; -var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { - if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); - if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); - return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); -}; -var _a; -var _HasAttribute_skipConnectedCheck; import '@lume/custom-attributes/dist/index.js'; import { CancelablePromise, PromiseCancellation } from './CancelablePromise.js'; import { BehaviorMap } from './BehaviorMap.js'; @@ -19,7 +6,7 @@ export class HasAttribute { this.observers = new Map(); this.elementDefinedPromises = new Map(); this.isConnected = false; - _HasAttribute_skipConnectedCheck.set(this, false); + this.#skipConnectedCheck = false; } get behaviors() { return this.ownerElement.behaviors; @@ -30,12 +17,13 @@ export class HasAttribute { } disconnectedCallback() { this.isConnected = false; - __classPrivateFieldSet(this, _HasAttribute_skipConnectedCheck, true, "f"); + this.#skipConnectedCheck = true; this.changedCallback(this.value, ''); - __classPrivateFieldSet(this, _HasAttribute_skipConnectedCheck, false, "f"); + this.#skipConnectedCheck = false; } + #skipConnectedCheck; changedCallback(oldVal, newVal) { - if (!__classPrivateFieldGet(this, _HasAttribute_skipConnectedCheck, "f")) { + if (!this.#skipConnectedCheck) { if (!this.isConnected) return; } @@ -75,7 +63,6 @@ export class HasAttribute { this.connectBehavior(name); } async connectBehavior(name) { - var _a; let Behavior = elementBehaviors.get(name); if (!Behavior) { await elementBehaviors.whenDefined(name); @@ -99,7 +86,7 @@ export class HasAttribute { if (this.isConnected) { const behavior = new Behavior(this.ownerElement); this.behaviors.set(name, behavior); - (_a = behavior.connectedCallback) === null || _a === void 0 ? void 0 : _a.call(behavior, this.ownerElement); + behavior.connectedCallback?.(this.ownerElement); if (Array.isArray(observedAttributes) && observedAttributes.length) { this.fireInitialAttributeChangedCallbacks(behavior, observedAttributes); this.createAttributeObserver(behavior); @@ -112,7 +99,6 @@ export class HasAttribute { } } disconnectBehavior(name) { - var _a; const promiseId = name + '_' + this.ownerElement.tagName; const promise = this.elementDefinedPromises.get(promiseId); if (promise) { @@ -122,7 +108,7 @@ export class HasAttribute { const behavior = this.behaviors.get(name); if (!behavior) return; - (_a = behavior.disconnectedCallback) === null || _a === void 0 ? void 0 : _a.call(behavior, this.ownerElement); + behavior.disconnectedCallback?.(this.ownerElement); this.destroyAttributeObserver(behavior); this.behaviors.delete(name); } @@ -173,8 +159,7 @@ export class HasAttribute { } } } -_HasAttribute_skipConnectedCheck = new WeakMap(); -if ((_a = globalThis.window) === null || _a === void 0 ? void 0 : _a.document) { +if (globalThis.window?.document) { const behaviorMaps = new WeakMap(); Object.defineProperty(Element.prototype, 'behaviors', { get() { diff --git a/dist/HasAttribute.js.map b/dist/HasAttribute.js.map index 85831e9..2b86c55 100644 --- a/dist/HasAttribute.js.map +++ b/dist/HasAttribute.js.map @@ -1 +1 @@ -{"version":3,"file":"HasAttribute.js","sourceRoot":"","sources":["../src/HasAttribute.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,OAAO,uCAAuC,CAAA;AAE9C,OAAO,EAAC,iBAAiB,EAAE,mBAAmB,EAAC,MAAM,wBAAwB,CAAA;AAE7E,OAAO,EAAC,WAAW,EAAC,MAAM,kBAAkB,CAAA;AAU5C,MAAM,OAAO,YAAY;IAAzB;QAWC,cAAS,GAAG,IAAI,GAAG,EAA8C,CAAA;QACjE,2BAAsB,GAAG,IAAI,GAAG,EAAuD,CAAA;QAEvF,gBAAW,GAAG,KAAK,CAAA;QAkBnB,2CAAsB,KAAK,EAAA;IAyM5B,CAAC;IAlOA,IAAI,SAAS;QACZ,OAAO,IAAI,CAAC,YAAY,CAAC,SAAS,CAAA;IACnC,CAAC;IAWD,iBAAiB;QAChB,IAAI,CAAC,WAAW,GAAG,IAAI,CAAA;QACvB,IAAI,CAAC,eAAe,CAAC,EAAE,EAAE,IAAI,CAAC,KAAK,CAAC,CAAA;IACrC,CAAC;IAED,oBAAoB;QACnB,IAAI,CAAC,WAAW,GAAG,KAAK,CAAA;QACxB,uBAAA,I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ACJ,IAAI,EACJ,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,YAAY,CAAC,IAAI,CAAE,CAAC,KAAK,EACtD,IAAI,CAAC,YAAY,CACjB,CAAA;SACF;IACF,CAAC;CACD;AAGD,IAAI,UAAU,CAAC,MAAM,EAAE,QAAQ,EAAE;IAEhC,MAAM,YAAY,GAAG,IAAI,OAAO,EAAuB,CAAA;IAEvD,MAAM,CAAC,cAAc,CAAC,OAAO,CAAC,SAAS,EAAE,WAAW,EAAE;QACrD,GAAG;YACF,IAAI,WAAW,GAAuB,IAAI,CAAA;YAE1C,IAAI,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE;gBAC3B,WAAW,GAAG,YAAY,CAAC,GAAG,CAAC,IAAI,CAAE,CAAA;aACrC;iBAAM;gBACN,YAAY,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,WAAW,GAAG,IAAI,WAAW,EAAE,CAAC,CAAC,CAAA;aACzD;YAED,OAAO,WAAW,CAAA;QACnB,CAAC;KACD,CAAC,CAAA;IAEF,MAAM,aAAa,GAAG,OAAO,CAAC,SAAS,CAAC,YAAY,CAAA;IAEpD,OAAO,CAAC,SAAS,CAAC,YAAY,GAAG,UAAU,OAAO;QACjD,MAAM,IAAI,GAAG,aAAa,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;QAE9C,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,KAAK,EAAE,YAAY,CAAC,CAAA;QAEjD,OAAO,IAAI,CAAA;IACZ,CAAC,CAAA;IAED,UAAU,CAAC,gBAAgB,CAAC,MAAM,CAAC,KAAK,EAAE,YAAY,CAAC,CAAA;CACvD"} \ No newline at end of file diff --git a/dist/global.test.d.ts b/dist/global.test.d.ts deleted file mode 100644 index 4100fcd..0000000 --- a/dist/global.test.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -import './tests-shared.js'; -//# sourceMappingURL=global.test.d.ts.map \ No newline at end of file diff --git a/dist/global.test.d.ts.map b/dist/global.test.d.ts.map deleted file mode 100644 index 8ab652e..0000000 --- a/dist/global.test.d.ts.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"global.test.d.ts","sourceRoot":"","sources":["../src/global.test.ts"],"names":[],"mappings":"AAAA,OAAO,mBAAmB,CAAA"} \ No newline at end of file diff --git a/dist/global.test.js b/dist/global.test.js deleted file mode 100644 index 8317a60..0000000 --- a/dist/global.test.js +++ /dev/null @@ -1,2 +0,0 @@ -import './tests-shared.js'; -//# sourceMappingURL=global.test.js.map \ No newline at end of file diff --git a/dist/global.test.js.map b/dist/global.test.js.map deleted file mode 100644 index d8be21b..0000000 --- a/dist/global.test.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"global.test.js","sourceRoot":"","sources":["../src/global.test.ts"],"names":[],"mappings":"AAAA,OAAO,mBAAmB,CAAA"} \ No newline at end of file diff --git a/dist/index.test.d.ts b/dist/index.test.d.ts index aa31c7a..a8cefbf 100644 --- a/dist/index.test.d.ts +++ b/dist/index.test.d.ts @@ -1,3 +1,5 @@ import './index.js'; -import './tests-shared.js'; +declare global { + function expect(...args: any[]): any; +} //# sourceMappingURL=index.test.d.ts.map \ No newline at end of file diff --git a/dist/index.test.d.ts.map b/dist/index.test.d.ts.map index 2e058ff..128d2e9 100644 --- a/dist/index.test.d.ts.map +++ b/dist/index.test.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"index.test.d.ts","sourceRoot":"","sources":["../src/index.test.ts"],"names":[],"mappings":"AACA,OAAO,YAAY,CAAA;AACnB,OAAO,mBAAmB,CAAA"} \ No newline at end of file +{"version":3,"file":"index.test.d.ts","sourceRoot":"","sources":["../src/index.test.ts"],"names":[],"mappings":"AACA,OAAO,YAAY,CAAA;AAKnB,OAAO,CAAC,MAAM,CAAC;IACd,SAAS,MAAM,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,GAAG,CAAA;CACpC"} \ No newline at end of file diff --git a/dist/index.test.js b/dist/index.test.js index 9c72762..2c18c9d 100644 --- a/dist/index.test.js +++ b/dist/index.test.js @@ -1,7 +1,222 @@ import { createEffect } from 'solid-js'; import './index.js'; -import './tests-shared.js'; describe('element-behaviors', () => { + it('exposes the library globally', () => { + expect(elementBehaviors).toBeInstanceOf(Object); + expect(elementBehaviors.define).toBeInstanceOf(Function); + expect(elementBehaviors.get).toBeInstanceOf(Function); + expect(elementBehaviors.has).toBeInstanceOf(Function); + }); + it('defines an element behavior', () => { + class Foo { + constructor() { + this.foo = 'bar'; + } + } + elementBehaviors.define('foo', Foo); + expect(elementBehaviors.has('foo')).toBe(true); + expect(() => elementBehaviors.define('foo', Foo)).toThrow(); + const _Foo = elementBehaviors.get('foo'); + expect(_Foo).toBe(Foo); + }); + it('similar lifecycle methods as custom elements', async () => { + const div = document.createElement('div'); + div.setAttribute('foo', '0'); + let attrChangedCount = 0; + const attrChangedArgs = []; + let constructCount = 0; + let connectedCount = 0; + let disconnectedCount = 0; + class Awesomeness { + constructor(el) { + this.el = el; + constructCount++; + expect(this.el).toBe(div); + } + static { this.observedAttributes = ['foo']; } + connectedCallback(element) { + connectedCount++; + expect(element).toBe(this.el); + expect(element).toBe(div); + } + disconnectedCallback(element) { + disconnectedCount++; + expect(element).toBe(this.el); + expect(element).toBe(div); + } + attributeChangedCallback(attr, oldVal, newVal, element) { + attrChangedCount++; + attrChangedArgs.push(attr, oldVal, newVal); + expect(element).toBe(this.el); + expect(element).toBe(div); + } + } + elementBehaviors.define('awesomeness', Awesomeness); + document.body.append(div); + div.setAttribute('has', 'awesomeness'); + await new Promise(r => setTimeout(r)); + expect(constructCount).toBe(1); + expect(connectedCount).toBe(1); + await new Promise(r => setTimeout(r)); + div.setAttribute('foo', '1'); + div.setAttribute('foo', '2'); + div.setAttribute('foo', '3'); + div.removeAttribute('foo'); + await new Promise(r => setTimeout(r)); + expect(attrChangedCount).toBe(5, 'expected attributeChangedCallback to be called 4 times'); + expect(attrChangedArgs).toEqual([ + 'foo', null, '0', + 'foo', '0', '1', + 'foo', '1', '2', + 'foo', '2', '3', + 'foo', '3', null, + ], 'expected attributeChangedCallback to be called with certain args each time'); + div.remove(); + await new Promise(r => setTimeout(r)); + expect(disconnectedCount).toBe(1, 'expected disconnectedCallback to be called once'); + document.body.append(div); + await new Promise(r => setTimeout(r)); + expect(constructCount).toBe(2); + expect(connectedCount).toBe(2); + div.remove(); + await new Promise(r => setTimeout(r)); + expect(disconnectedCount).toBe(2, 'expected disconnectedCallback to be called again'); + document.body.append(div); + await new Promise(r => setTimeout(r)); + expect(constructCount).toBe(3); + expect(connectedCount).toBe(3); + div.removeAttribute('has'); + await new Promise(r => setTimeout(r)); + expect(disconnectedCount).toBe(3, 'expected disconnectedCallback to be called again'); + div.setAttribute('has', 'awesomeness'); + await new Promise(r => setTimeout(r)); + expect(constructCount).toBe(4); + expect(connectedCount).toBe(4); + }); + it('works in shadow roots', async () => { + const container = document.createElement('div'); + const root = container.attachShadow({ mode: 'open' }); + document.body.append(container); + const div = document.createElement('div'); + div.setAttribute('foo', '0'); + let attrChangedCount = 0; + const attrChangedArgs = []; + let connectedCount = 0; + let disconnectedCount = 0; + class Shine { + constructor(el) { + this.el = el; + } + static { this.observedAttributes = ['foo']; } + connectedCallback() { + connectedCount++; + } + disconnectedCallback() { + disconnectedCount++; + } + attributeChangedCallback(attr, oldVal, newVal) { + attrChangedCount++; + attrChangedArgs.push(attr, oldVal, newVal); + } + } + elementBehaviors.define('shine', Shine); + root.append(div); + div.setAttribute('has', 'shine'); + await new Promise(r => setTimeout(r)); + expect(connectedCount).toBe(1); + await new Promise(r => setTimeout(r)); + div.setAttribute('foo', '1'); + div.setAttribute('foo', '2'); + div.setAttribute('foo', '3'); + div.removeAttribute('foo'); + await new Promise(r => setTimeout(r)); + expect(attrChangedCount).toBe(5, 'expected attributeChangedCallback to be called 4 times'); + expect(attrChangedArgs).toEqual([ + 'foo', null, '0', + 'foo', '0', '1', + 'foo', '1', '2', + 'foo', '2', '3', + 'foo', '3', null, + ], 'expected attributeChangedCallback to be called with certain args each time'); + div.remove(); + await new Promise(r => setTimeout(r)); + expect(disconnectedCount).toBe(1, 'expected disconnectedCallback to be called once'); + }); + describe('has="" attribute', () => { + it('properly adds or removes behaviors when its value changes', async () => { + class One { + } + elementBehaviors.define('one', One); + class Two { + } + elementBehaviors.define('two', Two); + class Three { + } + elementBehaviors.define('three', Three); + document.body.innerHTML = ` +
+ `; + const div = document.body.firstElementChild; + await new Promise(r => setTimeout(r)); + expect(div.behaviors.size).toBe(3); + div.setAttribute('has', 'one three'); + await new Promise(r => setTimeout(r)); + expect(div.behaviors.size).toBe(2); + expect(div.behaviors.has('one')).toEqual(true); + expect(div.behaviors.has('two')).toEqual(false); + expect(div.behaviors.has('three')).toEqual(true); + document.body.innerHTML = ''; + }); + }); + describe('awaitElementDefined', () => { + it('allows to prevent behaviors from being instantiated until custom elements are defined', async () => { + let waitingBehaviorConnected = false; + elementBehaviors.define('wait-for-element-defined', class WaitsForElementDefined { + static { this.awaitElementDefined = true; } + connectedCallback() { + waitingBehaviorConnected = true; + } + }); + let nonWaitingBehaviorConnected = false; + elementBehaviors.define('does-not-wait', class DoesNotWait { + static { this.awaitElementDefined = false; } + connectedCallback() { + nonWaitingBehaviorConnected = true; + } + }); + document.body.innerHTML = ` + + `; + await new Promise(r => setTimeout(r)); + expect(waitingBehaviorConnected).toEqual(false); + expect(nonWaitingBehaviorConnected).toEqual(true); + customElements.define('some-element', class extends HTMLElement { + }); + await new Promise(r => setTimeout(r)); + expect(waitingBehaviorConnected).toEqual(true); + expect(nonWaitingBehaviorConnected).toEqual(true); + }); + it('does not instantiate a waiting behavior if the element is disconnected before definition', async () => { + let waitingBehaviorConnected = false; + elementBehaviors.define('wait-for-element-defined-2', class WaitsForElementDefined { + static { this.awaitElementDefined = true; } + connectedCallback() { + waitingBehaviorConnected = true; + } + }); + document.body.innerHTML = ` + + `; + const someEl = document.body.firstElementChild; + await new Promise(r => setTimeout(r)); + expect(waitingBehaviorConnected).toEqual(false); + someEl.remove(); + customElements.define('some-element-2', class extends HTMLElement { + }); + await new Promise(r => setTimeout(r)); + expect(waitingBehaviorConnected).toEqual(false); + }); + }); describe('.behaviors property', () => { it('allows accessing behavior instances on an element reactively', done => { class Four { @@ -17,7 +232,10 @@ describe('element-behaviors', () => {
`; const div = document.body.firstElementChild; + let isDone = false; createEffect(() => { + if (isDone) + return; const four = div.behaviors.get('four'); const five = div.behaviors.get('five'); const six = div.behaviors.get('six'); @@ -26,6 +244,8 @@ describe('element-behaviors', () => { expect(four).toBeInstanceOf(Four); expect(five).toBeInstanceOf(Five); expect(six).toBeInstanceOf(Six); + isDone = true; + console.log('Reacted to behaviors after they exist.'); done(); }); }); diff --git a/dist/index.test.js.map b/dist/index.test.js.map index dc1aab8..51e3d69 100644 --- a/dist/index.test.js.map +++ b/dist/index.test.js.map @@ -1 +1 @@ -{"version":3,"file":"index.test.js","sourceRoot":"","sources":["../src/index.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,UAAU,CAAA;AACrC,OAAO,YAAY,CAAA;AACnB,OAAO,mBAAmB,CAAA;AAO1B,QAAQ,CAAC,mBAAmB,EAAE,GAAG,EAAE;IAClC,QAAQ,CAAC,qBAAqB,EAAE,GAAG,EAAE;QACpC,EAAE,CAAC,8DAA8D,EAAE,IAAI,CAAC,EAAE;YACzE,MAAM,IAAI;aAAG;YACb,gBAAgB,CAAC,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAA;YAErC,MAAM,IAAI;aAAG;YACb,gBAAgB,CAAC,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAA;YAErC,MAAM,GAAG;aAAG;YACZ,gBAAgB,CAAC,MAAM,CAAC,KAAK,EAAE,GAAG,CAAC,CAAA;YAEnC,QAAQ,CAAC,IAAI,CAAC,SAAS,GAAY;;IAElC,CAAA;YAED,MAAM,GAAG,GAAG,QAAQ,CAAC,IAAI,CAAC,iBAAyC,CAAA;YAGnE,YAAY,CAA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,GAAG,CAAC;oBAAE,OAAM;gBAElC,MAAM,CAAC,IAAI,CAAC,CAAC,cAAc,CAAC,IAAI,CAAC,CAAA;gBACjC,MAAM,CAAC,IAAI,CAAC,CAAC,cAAc,CAAC,IAAI,CAAC,CAAA;gBACjC,MAAM,CAAC,GAAG,CAAC,CAAC,cAAc,CAAC,GAAG,CAAC,CAAA;gBAE/B,MAAM,GAAG,IAAI,CAAA;gBACb,OAAO,CAAC,GAAG,CAAC,wCAAwC,CAAC,CAAA;gBACrD,IAAI,EAAE,CAAA;YACP,CAAC,CAAC,CAAA;QACH,CAAC,CAAC,CAAA;IACH,CAAC,CAAC,CAAA;AACH,CAAC,CAAC,CAAA"} \ No newline at end of file diff --git a/dist/tests-shared.d.ts b/dist/tests-shared.d.ts deleted file mode 100644 index 1fdb7bd..0000000 --- a/dist/tests-shared.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -export {}; -//# sourceMappingURL=tests-shared.d.ts.map \ No newline at end of file diff --git a/dist/tests-shared.d.ts.map b/dist/tests-shared.d.ts.map deleted file mode 100644 index 8af4e37..0000000 --- a/dist/tests-shared.d.ts.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"tests-shared.d.ts","sourceRoot":"","sources":["../src/tests-shared.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/dist/tests-shared.js b/dist/tests-shared.js deleted file mode 100644 index 2ab2df7..0000000 --- a/dist/tests-shared.js +++ /dev/null @@ -1,225 +0,0 @@ -describe('element-behaviors', () => { - it('exposes the library globally', () => { - expect(elementBehaviors).toBeInstanceOf(Object); - expect(elementBehaviors.define).toBeInstanceOf(Function); - expect(elementBehaviors.get).toBeInstanceOf(Function); - expect(elementBehaviors.has).toBeInstanceOf(Function); - }); - it('defines an element behavior', () => { - class Foo { - constructor() { - this.foo = 'bar'; - } - } - elementBehaviors.define('foo', Foo); - expect(elementBehaviors.has('foo')).toBe(true); - expect(() => elementBehaviors.define('foo', Foo)).toThrow(); - const _Foo = elementBehaviors.get('foo'); - expect(_Foo).toBe(Foo); - }); - it('similar lifecycle methods as custom elements', async () => { - const div = document.createElement('div'); - div.setAttribute('foo', '0'); - let attrChangedCount = 0; - const attrChangedArgs = []; - let constructCount = 0; - let connectedCount = 0; - let disconnectedCount = 0; - class Awesomeness { - constructor(el) { - this.el = el; - constructCount++; - expect(this.el).toBe(div); - } - connectedCallback(element) { - connectedCount++; - expect(element).toBe(this.el); - expect(element).toBe(div); - } - disconnectedCallback(element) { - disconnectedCount++; - expect(element).toBe(this.el); - expect(element).toBe(div); - } - attributeChangedCallback(attr, oldVal, newVal, element) { - attrChangedCount++; - attrChangedArgs.push(attr, oldVal, newVal); - expect(element).toBe(this.el); - expect(element).toBe(div); - } - } - Awesomeness.observedAttributes = ['foo']; - elementBehaviors.define('awesomeness', Awesomeness); - document.body.append(div); - div.setAttribute('has', 'awesomeness'); - await new Promise(r => setTimeout(r)); - expect(constructCount).toBe(1); - expect(connectedCount).toBe(1); - await new Promise(r => setTimeout(r)); - div.setAttribute('foo', '1'); - div.setAttribute('foo', '2'); - div.setAttribute('foo', '3'); - div.removeAttribute('foo'); - await new Promise(r => setTimeout(r)); - expect(attrChangedCount).toBe(5, 'expected attributeChangedCallback to be called 4 times'); - expect(attrChangedArgs).toEqual([ - 'foo', null, '0', - 'foo', '0', '1', - 'foo', '1', '2', - 'foo', '2', '3', - 'foo', '3', null, - ], 'expected attributeChangedCallback to be called with certain args each time'); - div.remove(); - await new Promise(r => setTimeout(r)); - expect(disconnectedCount).toBe(1, 'expected disconnectedCallback to be called once'); - document.body.append(div); - await new Promise(r => setTimeout(r)); - expect(constructCount).toBe(2); - expect(connectedCount).toBe(2); - div.remove(); - await new Promise(r => setTimeout(r)); - expect(disconnectedCount).toBe(2, 'expected disconnectedCallback to be called again'); - document.body.append(div); - await new Promise(r => setTimeout(r)); - expect(constructCount).toBe(3); - expect(connectedCount).toBe(3); - div.removeAttribute('has'); - await new Promise(r => setTimeout(r)); - expect(disconnectedCount).toBe(3, 'expected disconnectedCallback to be called again'); - div.setAttribute('has', 'awesomeness'); - await new Promise(r => setTimeout(r)); - expect(constructCount).toBe(4); - expect(connectedCount).toBe(4); - }); - it('works in shadow roots', async () => { - const container = document.createElement('div'); - const root = container.attachShadow({ mode: 'open' }); - document.body.append(container); - const div = document.createElement('div'); - div.setAttribute('foo', '0'); - let attrChangedCount = 0; - const attrChangedArgs = []; - let connectedCount = 0; - let disconnectedCount = 0; - class Shine { - constructor(el) { - this.el = el; - } - connectedCallback() { - connectedCount++; - } - disconnectedCallback() { - disconnectedCount++; - } - attributeChangedCallback(attr, oldVal, newVal) { - attrChangedCount++; - attrChangedArgs.push(attr, oldVal, newVal); - } - } - Shine.observedAttributes = ['foo']; - elementBehaviors.define('shine', Shine); - root.append(div); - div.setAttribute('has', 'shine'); - await new Promise(r => setTimeout(r)); - expect(connectedCount).toBe(1); - await new Promise(r => setTimeout(r)); - div.setAttribute('foo', '1'); - div.setAttribute('foo', '2'); - div.setAttribute('foo', '3'); - div.removeAttribute('foo'); - await new Promise(r => setTimeout(r)); - expect(attrChangedCount).toBe(5, 'expected attributeChangedCallback to be called 4 times'); - expect(attrChangedArgs).toEqual([ - 'foo', null, '0', - 'foo', '0', '1', - 'foo', '1', '2', - 'foo', '2', '3', - 'foo', '3', null, - ], 'expected attributeChangedCallback to be called with certain args each time'); - div.remove(); - await new Promise(r => setTimeout(r)); - expect(disconnectedCount).toBe(1, 'expected disconnectedCallback to be called once'); - }); - describe('has="" attribute', () => { - it('properly adds or removes behaviors when its value changes', async () => { - class One { - } - elementBehaviors.define('one', One); - class Two { - } - elementBehaviors.define('two', Two); - class Three { - } - elementBehaviors.define('three', Three); - document.body.innerHTML = ` -
- `; - const div = document.body.firstElementChild; - await new Promise(r => setTimeout(r)); - expect(div.behaviors.size).toBe(3); - div.setAttribute('has', 'one three'); - await new Promise(r => setTimeout(r)); - expect(div.behaviors.size).toBe(2); - expect(div.behaviors.has('one')).toBeTrue(); - expect(div.behaviors.has('two')).toBeFalse(); - expect(div.behaviors.has('three')).toBeTrue(); - document.body.innerHTML = ''; - }); - }); - describe('awaitElementDefined', () => { - it('allows to prevent behaviors from being instantiated until custom elements are defined', async () => { - var _a, _b; - let waitingBehaviorConnected = false; - elementBehaviors.define('wait-for-element-defined', (_a = class WaitsForElementDefined { - connectedCallback() { - waitingBehaviorConnected = true; - } - }, - _a.awaitElementDefined = true, - _a)); - let nonWaitingBehaviorConnected = false; - elementBehaviors.define('does-not-wait', (_b = class DoesNotWait { - connectedCallback() { - nonWaitingBehaviorConnected = true; - } - }, - _b.awaitElementDefined = false, - _b)); - document.body.innerHTML = ` - - `; - await new Promise(r => setTimeout(r)); - expect(waitingBehaviorConnected).toBeFalse(); - expect(nonWaitingBehaviorConnected).toBeTrue(); - customElements.define('some-element', class extends HTMLElement { - }); - await new Promise(r => setTimeout(r)); - expect(waitingBehaviorConnected).toBeTrue(); - expect(nonWaitingBehaviorConnected).toBeTrue(); - }); - it('does not instantiate a waiting behavior if the element is disconnected before definition', async () => { - var _a; - let waitingBehaviorConnected = false; - elementBehaviors.define('wait-for-element-defined-2', (_a = class WaitsForElementDefined { - connectedCallback() { - waitingBehaviorConnected = true; - } - }, - _a.awaitElementDefined = true, - _a)); - document.body.innerHTML = ` - - `; - const someEl = document.body.firstElementChild; - await new Promise(r => setTimeout(r)); - expect(waitingBehaviorConnected).toBeFalse(); - someEl.remove(); - customElements.define('some-element-2', class extends HTMLElement { - }); - await new Promise(r => setTimeout(r)); - expect(waitingBehaviorConnected).toBeFalse(); - }); - }); -}); -export {}; -//# sourceMappingURL=tests-shared.js.map \ No newline at end of file diff --git a/dist/tests-shared.js.map b/dist/tests-shared.js.map deleted file mode 100644 index 641cdf2..0000000 --- a/dist/tests-shared.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"tests-shared.js","sourceRoot":"","sources":["../src/tests-shared.ts"],"names":[],"mappings":"AAEA,QAAQ,CAAC,mBAAmB,EAAE,GAAG,EAAE;IA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AG,IAAI,CAAA;oBAChC,CAAC;iBACD;gBALO,sBAAmB,GAAG,IAAI;oBAMlC,CAAA;YAED,QAAQ,CAAC,IAAI,CAAC,SAAS,GAAY;;IAElC,CAAA;YAED,MAAM,MAAM,GAAG,QAAQ,CAAC,IAAI,CAAC,iBAAkB,CAAA;YAE/C,MAAM,IAAI,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAA;YAErC,MAAM,CAAC,wBAAwB,CAAC,CAAC,SAAS,EAAE,CAAA;YAG5C,MAAM,CAAC,MAAM,EAAE,CAAA;YACf,cAAc,CAAC,MAAM,CAAC,gBAAgB,EAAE,KAAM,SAAQ,WAAW;aAAG,CAAC,CAAA;YAErE,MAAM,IAAI,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAA;YAGrC,MAAM,CAAC,wBAAwB,CAAC,CAAC,SAAS,EAAE,CAAA;QAC7C,CAAC,CAAC,CAAA;IACH,CAAC,CAAC,CAAA;AACH,CAAC,CAAC,CAAA"} \ No newline at end of file diff --git a/lume.config.cjs b/lume.config.cjs new file mode 100644 index 0000000..87301f5 --- /dev/null +++ b/lume.config.cjs @@ -0,0 +1,12 @@ +/** @type {import('@lume/cli/config/getUserConfig.js').UserConfig} */ +module.exports = { + importMap: { + imports: { + '@lume/custom-attributes/': '/node_modules/@lume/custom-attributes/', + 'solid-js': '/node_modules/solid-js/dist/solid.js', + 'solid-js/web': '/node_modules/solid-js/web/dist/web.js', + 'solid-js/html': '/node_modules/solid-js/html/dist/html.js', + 'solid-js/store': '/node_modules/solid-js/store/dist/store.js', + }, + }, +} diff --git a/package.json b/package.json index 36475ec..1a2486a 100644 --- a/package.json +++ b/package.json @@ -6,11 +6,6 @@ "main": "dist/index.js", "types": "dist/index.d.ts", "type": "module", - "exports COMMENT:": "This removes 'dist' from import statements, as well as replaces the 'main' field. See https://github.com/nodejs/node/issues/14970#issuecomment-571887546", - "exports": { - ".": "./dist/index.js", - "./": "./dist/" - }, "homepage": "https://github.com/trusktr/element-behaviors", "scripts": { "LUME SCRIPTS XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX": "", @@ -20,7 +15,7 @@ "typecheck": "lume typecheck", "typecheck:watch": "lume typecheckWatch", "test": "lume test", - "test:debug": "lume testDebug", + "test:watch": "lume test --watch", "prettier": "lume prettier", "prettier:check": "lume prettierCheck", "release:patch": "lume releasePatch", diff --git a/src/global.test.ts b/src/global.test.ts deleted file mode 100644 index d0772e3..0000000 --- a/src/global.test.ts +++ /dev/null @@ -1 +0,0 @@ -import './tests-shared.js' diff --git a/src/index.test.ts b/src/index.test.ts index 56b9aca..e7b4355 100644 --- a/src/index.test.ts +++ b/src/index.test.ts @@ -1,13 +1,346 @@ import {createEffect} from 'solid-js' import './index.js' // adds elementBehaviors to global -import './tests-shared.js' import type {ElementWithBehaviors} from './BehaviorRegistry.js' +// TODO move type def to @lume/cli, map @types/jest's `expect` type into the +// global env. +declare global { + function expect(...args: any[]): any +} + // This test is here, not tested with global tests because the createEffect // otherwise seems to be from a duplicate solid-js lib during testing, hence is // fails to be reactive. // TODO update @lume/cli so that we can prevent duplicate solid-js libs. describe('element-behaviors', () => { + it('exposes the library globally', () => { + expect(elementBehaviors).toBeInstanceOf(Object) + expect(elementBehaviors.define).toBeInstanceOf(Function) + expect(elementBehaviors.get).toBeInstanceOf(Function) + expect(elementBehaviors.has).toBeInstanceOf(Function) + }) + + it('defines an element behavior', () => { + class Foo { + foo = 'bar' + } + + elementBehaviors.define('foo', Foo) + expect(elementBehaviors.has('foo')).toBe(true) + + // disallows duplicates + expect(() => elementBehaviors.define('foo', Foo)).toThrow() + + const _Foo = elementBehaviors.get('foo') + expect(_Foo).toBe(Foo) + }) + + it('similar lifecycle methods as custom elements', async () => { + const div = document.createElement('div') + + div.setAttribute('foo', '0') + + let attrChangedCount = 0 + const attrChangedArgs: any[] = [] + let constructCount = 0 + let connectedCount = 0 + let disconnectedCount = 0 + + class Awesomeness { + constructor(public el: Element) { + constructCount++ + expect(this.el).toBe(div) + } + + static observedAttributes = ['foo'] + + connectedCallback(element: Element) { + connectedCount++ + expect(element).toBe(this.el) + expect(element).toBe(div) + } + + disconnectedCallback(element: Element) { + disconnectedCount++ + expect(element).toBe(this.el) + expect(element).toBe(div) + } + + attributeChangedCallback(attr: string, oldVal: string | null, newVal: string | null, element: Element) { + attrChangedCount++ + attrChangedArgs.push(attr, oldVal, newVal) + expect(element).toBe(this.el) + expect(element).toBe(div) + } + } + + elementBehaviors.define('awesomeness', Awesomeness) + + document.body.append(div) + + // give the div element awesomeness + div.setAttribute('has', 'awesomeness') + + // TODO try similar things with Custom Elements, and see if they need or + // don't need similar setTimeout deferrals, and make sure + // element-behaviors follows the same behavior. + + await new Promise(r => setTimeout(r)) + + expect(constructCount).toBe(1) + expect(connectedCount).toBe(1) + + await new Promise(r => setTimeout(r)) + + div.setAttribute('foo', '1') + div.setAttribute('foo', '2') + div.setAttribute('foo', '3') + div.removeAttribute('foo') + + await new Promise(r => setTimeout(r)) + + expect(attrChangedCount).toBe(5, 'expected attributeChangedCallback to be called 4 times') + // prettier-ignore + expect(attrChangedArgs).toEqual([ + 'foo', null, '0', + 'foo', '0', '1', + 'foo', '1', '2', + 'foo', '2', '3', + 'foo', '3', null, + ], 'expected attributeChangedCallback to be called with certain args each time') + + div.remove() + + await new Promise(r => setTimeout(r)) + + expect(disconnectedCount).toBe(1, 'expected disconnectedCallback to be called once') + + document.body.append(div) + + await new Promise(r => setTimeout(r)) + + expect(constructCount).toBe(2) + expect(connectedCount).toBe(2) + + div.remove() + + await new Promise(r => setTimeout(r)) + + expect(disconnectedCount).toBe(2, 'expected disconnectedCallback to be called again') + + document.body.append(div) + + await new Promise(r => setTimeout(r)) + + expect(constructCount).toBe(3) + expect(connectedCount).toBe(3) + + div.removeAttribute('has') + + await new Promise(r => setTimeout(r)) + + expect(disconnectedCount).toBe(3, 'expected disconnectedCallback to be called again') + + div.setAttribute('has', 'awesomeness') + + await new Promise(r => setTimeout(r)) + + expect(constructCount).toBe(4) + expect(connectedCount).toBe(4) + }) + + it('works in shadow roots', async () => { + const container = document.createElement('div') + + const root = container.attachShadow({mode: 'open'}) + + document.body.append(container) + + const div = document.createElement('div') + + div.setAttribute('foo', '0') + + let attrChangedCount = 0 + const attrChangedArgs: any[] = [] + let connectedCount = 0 + let disconnectedCount = 0 + + class Shine { + constructor(public el: Element) {} + + static observedAttributes = ['foo'] + + connectedCallback() { + connectedCount++ + } + + disconnectedCallback() { + disconnectedCount++ + } + + attributeChangedCallback(attr: string, oldVal: string | null, newVal: string | null) { + attrChangedCount++ + attrChangedArgs.push(attr, oldVal, newVal) + } + } + + elementBehaviors.define('shine', Shine) + + root.append(div) + + // give the div element shine + div.setAttribute('has', 'shine') + + // TODO try similar things with Custom Elements, and see if they need or + // don't need similar setTimeout deferrals, and make sure + // element-behaviors follows the same behavior. + + await new Promise(r => setTimeout(r)) + + expect(connectedCount).toBe(1) + + await new Promise(r => setTimeout(r)) + + div.setAttribute('foo', '1') + div.setAttribute('foo', '2') + div.setAttribute('foo', '3') + div.removeAttribute('foo') + + await new Promise(r => setTimeout(r)) + + expect(attrChangedCount).toBe(5, 'expected attributeChangedCallback to be called 4 times') + // prettier-ignore + expect(attrChangedArgs).toEqual([ + 'foo', null, '0', + 'foo', '0', '1', + 'foo', '1', '2', + 'foo', '2', '3', + 'foo', '3', null, + ], 'expected attributeChangedCallback to be called with certain args each time') + + div.remove() + + await new Promise(r => setTimeout(r)) + + expect(disconnectedCount).toBe(1, 'expected disconnectedCallback to be called once') + }) + + describe('has="" attribute', () => { + it('properly adds or removes behaviors when its value changes', async () => { + class One {} + elementBehaviors.define('one', One) + + class Two {} + elementBehaviors.define('two', Two) + + class Three {} + elementBehaviors.define('three', Three) + + document.body.innerHTML = /*html*/ ` +
+ ` + + const div = document.body.firstElementChild as ElementWithBehaviors + + // Defer so that MutationObserver has a chance to fire first. + await new Promise(r => setTimeout(r)) + + expect(div!.behaviors.size).toBe(3) + + div.setAttribute('has', 'one three') + + // Defer so that MutationObserver has a chance to fire first. + await new Promise(r => setTimeout(r)) + + expect(div!.behaviors.size).toBe(2) + expect(div!.behaviors.has('one')).toEqual(true) + expect(div!.behaviors.has('two')).toEqual(false) + expect(div!.behaviors.has('three')).toEqual(true) + + document.body.innerHTML = '' + }) + }) + + describe('awaitElementDefined', () => { + it('allows to prevent behaviors from being instantiated until custom elements are defined', async () => { + let waitingBehaviorConnected = false + + elementBehaviors.define( + 'wait-for-element-defined', + class WaitsForElementDefined { + static awaitElementDefined = true + + connectedCallback() { + waitingBehaviorConnected = true + } + }, + ) + + let nonWaitingBehaviorConnected = false + + elementBehaviors.define( + 'does-not-wait', + class DoesNotWait { + static awaitElementDefined = false // This is the default + + connectedCallback() { + nonWaitingBehaviorConnected = true + } + }, + ) + + document.body.innerHTML = /*html*/ ` + + ` + + await new Promise(r => setTimeout(r)) // wait for MutationObservers + + expect(waitingBehaviorConnected).toEqual(false) + expect(nonWaitingBehaviorConnected).toEqual(true) + + customElements.define('some-element', class extends HTMLElement {}) + + await new Promise(r => setTimeout(r)) // wait for MutationObservers + + expect(waitingBehaviorConnected).toEqual(true) + expect(nonWaitingBehaviorConnected).toEqual(true) + }) + + it('does not instantiate a waiting behavior if the element is disconnected before definition', async () => { + let waitingBehaviorConnected = false + + elementBehaviors.define( + 'wait-for-element-defined-2', + class WaitsForElementDefined { + static awaitElementDefined = true + + connectedCallback() { + waitingBehaviorConnected = true + } + }, + ) + + document.body.innerHTML = /*html*/ ` + + ` + + const someEl = document.body.firstElementChild! + + await new Promise(r => setTimeout(r)) // wait for MutationObservers + + expect(waitingBehaviorConnected).toEqual(false) + + // remove before defining + someEl.remove() + customElements.define('some-element-2', class extends HTMLElement {}) + + await new Promise(r => setTimeout(r)) // wait for MutationObservers + + // behavior will not erroneously be connected after awaiting the element definition + expect(waitingBehaviorConnected).toEqual(false) + }) + }) + describe('.behaviors property', () => { it('allows accessing behavior instances on an element reactively', done => { class Four {} @@ -25,8 +358,19 @@ describe('element-behaviors', () => { const div = document.body.firstElementChild as ElementWithBehaviors + let isDone = false + // .behaviors is reactive, useful in Solid effects createEffect(() => { + // TODO INVESTIGATE: The effect runs two more times than expected, + // and so we guard against that using the isDone variable, otherwise + // the test will fail saying that done() was called too many times. + // It might have to do with what .behaviors is doing. + // + // In practice, the extra runs are fine if state is declarative, but + // we want to be efficient. + if (isDone) return + const four = div.behaviors.get('four') const five = div.behaviors.get('five') const six = div.behaviors.get('six') @@ -37,6 +381,8 @@ describe('element-behaviors', () => { expect(five).toBeInstanceOf(Five) expect(six).toBeInstanceOf(Six) + isDone = true + console.log('Reacted to behaviors after they exist.') done() }) }) diff --git a/src/tests-shared.ts b/src/tests-shared.ts deleted file mode 100644 index b2aeda8..0000000 --- a/src/tests-shared.ts +++ /dev/null @@ -1,331 +0,0 @@ -import type {ElementWithBehaviors} from './BehaviorRegistry' - -describe('element-behaviors', () => { - it('exposes the library globally', () => { - expect(elementBehaviors).toBeInstanceOf(Object) - expect(elementBehaviors.define).toBeInstanceOf(Function) - expect(elementBehaviors.get).toBeInstanceOf(Function) - expect(elementBehaviors.has).toBeInstanceOf(Function) - }) - - it('defines an element behavior', () => { - class Foo { - foo = 'bar' - } - - elementBehaviors.define('foo', Foo) - expect(elementBehaviors.has('foo')).toBe(true) - - // disallows duplicates - expect(() => elementBehaviors.define('foo', Foo)).toThrow() - - const _Foo = elementBehaviors.get('foo') - expect(_Foo).toBe(Foo) - }) - - it('similar lifecycle methods as custom elements', async () => { - const div = document.createElement('div') - - div.setAttribute('foo', '0') - - let attrChangedCount = 0 - const attrChangedArgs: any[] = [] - let constructCount = 0 - let connectedCount = 0 - let disconnectedCount = 0 - - class Awesomeness { - constructor(public el: Element) { - constructCount++ - expect(this.el).toBe(div) - } - - static observedAttributes = ['foo'] - - connectedCallback(element: Element) { - connectedCount++ - expect(element).toBe(this.el) - expect(element).toBe(div) - } - - disconnectedCallback(element: Element) { - disconnectedCount++ - expect(element).toBe(this.el) - expect(element).toBe(div) - } - - attributeChangedCallback(attr: string, oldVal: string | null, newVal: string | null, element: Element) { - attrChangedCount++ - attrChangedArgs.push(attr, oldVal, newVal) - expect(element).toBe(this.el) - expect(element).toBe(div) - } - } - - elementBehaviors.define('awesomeness', Awesomeness) - - document.body.append(div) - - // give the div element awesomeness - div.setAttribute('has', 'awesomeness') - - // TODO try similar things with Custom Elements, and see if they need or - // don't need similar setTimeout deferrals, and make sure - // element-behaviors follows the same behavior. - - await new Promise(r => setTimeout(r)) - - expect(constructCount).toBe(1) - expect(connectedCount).toBe(1) - - await new Promise(r => setTimeout(r)) - - div.setAttribute('foo', '1') - div.setAttribute('foo', '2') - div.setAttribute('foo', '3') - div.removeAttribute('foo') - - await new Promise(r => setTimeout(r)) - - expect(attrChangedCount).toBe(5, 'expected attributeChangedCallback to be called 4 times') - // prettier-ignore - expect(attrChangedArgs).toEqual([ - 'foo', null, '0', - 'foo', '0', '1', - 'foo', '1', '2', - 'foo', '2', '3', - 'foo', '3', null, - ], 'expected attributeChangedCallback to be called with certain args each time') - - div.remove() - - await new Promise(r => setTimeout(r)) - - expect(disconnectedCount).toBe(1, 'expected disconnectedCallback to be called once') - - document.body.append(div) - - await new Promise(r => setTimeout(r)) - - expect(constructCount).toBe(2) - expect(connectedCount).toBe(2) - - div.remove() - - await new Promise(r => setTimeout(r)) - - expect(disconnectedCount).toBe(2, 'expected disconnectedCallback to be called again') - - document.body.append(div) - - await new Promise(r => setTimeout(r)) - - expect(constructCount).toBe(3) - expect(connectedCount).toBe(3) - - div.removeAttribute('has') - - await new Promise(r => setTimeout(r)) - - expect(disconnectedCount).toBe(3, 'expected disconnectedCallback to be called again') - - div.setAttribute('has', 'awesomeness') - - await new Promise(r => setTimeout(r)) - - expect(constructCount).toBe(4) - expect(connectedCount).toBe(4) - }) - - it('works in shadow roots', async () => { - const container = document.createElement('div') - - const root = container.attachShadow({mode: 'open'}) - - document.body.append(container) - - const div = document.createElement('div') - - div.setAttribute('foo', '0') - - let attrChangedCount = 0 - const attrChangedArgs: any[] = [] - let connectedCount = 0 - let disconnectedCount = 0 - - class Shine { - constructor(public el: Element) {} - - static observedAttributes = ['foo'] - - connectedCallback() { - connectedCount++ - } - - disconnectedCallback() { - disconnectedCount++ - } - - attributeChangedCallback(attr: string, oldVal: string | null, newVal: string | null) { - attrChangedCount++ - attrChangedArgs.push(attr, oldVal, newVal) - } - } - - elementBehaviors.define('shine', Shine) - - root.append(div) - - // give the div element shine - div.setAttribute('has', 'shine') - - // TODO try similar things with Custom Elements, and see if they need or - // don't need similar setTimeout deferrals, and make sure - // element-behaviors follows the same behavior. - - await new Promise(r => setTimeout(r)) - - expect(connectedCount).toBe(1) - - await new Promise(r => setTimeout(r)) - - div.setAttribute('foo', '1') - div.setAttribute('foo', '2') - div.setAttribute('foo', '3') - div.removeAttribute('foo') - - await new Promise(r => setTimeout(r)) - - expect(attrChangedCount).toBe(5, 'expected attributeChangedCallback to be called 4 times') - // prettier-ignore - expect(attrChangedArgs).toEqual([ - 'foo', null, '0', - 'foo', '0', '1', - 'foo', '1', '2', - 'foo', '2', '3', - 'foo', '3', null, - ], 'expected attributeChangedCallback to be called with certain args each time') - - div.remove() - - await new Promise(r => setTimeout(r)) - - expect(disconnectedCount).toBe(1, 'expected disconnectedCallback to be called once') - }) - - describe('has="" attribute', () => { - it('properly adds or removes behaviors when its value changes', async () => { - class One {} - elementBehaviors.define('one', One) - - class Two {} - elementBehaviors.define('two', Two) - - class Three {} - elementBehaviors.define('three', Three) - - document.body.innerHTML = /*html*/ ` -
- ` - - const div = document.body.firstElementChild as ElementWithBehaviors - - // Defer so that MutationObserver has a chance to fire first. - await new Promise(r => setTimeout(r)) - - expect(div!.behaviors.size).toBe(3) - - div.setAttribute('has', 'one three') - - // Defer so that MutationObserver has a chance to fire first. - await new Promise(r => setTimeout(r)) - - expect(div!.behaviors.size).toBe(2) - expect(div!.behaviors.has('one')).toBeTrue() - expect(div!.behaviors.has('two')).toBeFalse() - expect(div!.behaviors.has('three')).toBeTrue() - - document.body.innerHTML = '' - }) - }) - - describe('awaitElementDefined', () => { - it('allows to prevent behaviors from being instantiated until custom elements are defined', async () => { - let waitingBehaviorConnected = false - - elementBehaviors.define( - 'wait-for-element-defined', - class WaitsForElementDefined { - static awaitElementDefined = true - - connectedCallback() { - waitingBehaviorConnected = true - } - }, - ) - - let nonWaitingBehaviorConnected = false - - elementBehaviors.define( - 'does-not-wait', - class DoesNotWait { - static awaitElementDefined = false // This is the default - - connectedCallback() { - nonWaitingBehaviorConnected = true - } - }, - ) - - document.body.innerHTML = /*html*/ ` - - ` - - await new Promise(r => setTimeout(r)) // wait for MutationObservers - - expect(waitingBehaviorConnected).toBeFalse() - expect(nonWaitingBehaviorConnected).toBeTrue() - - customElements.define('some-element', class extends HTMLElement {}) - - await new Promise(r => setTimeout(r)) // wait for MutationObservers - - expect(waitingBehaviorConnected).toBeTrue() - expect(nonWaitingBehaviorConnected).toBeTrue() - }) - - it('does not instantiate a waiting behavior if the element is disconnected before definition', async () => { - let waitingBehaviorConnected = false - - elementBehaviors.define( - 'wait-for-element-defined-2', - class WaitsForElementDefined { - static awaitElementDefined = true - - connectedCallback() { - waitingBehaviorConnected = true - } - }, - ) - - document.body.innerHTML = /*html*/ ` - - ` - - const someEl = document.body.firstElementChild! - - await new Promise(r => setTimeout(r)) // wait for MutationObservers - - expect(waitingBehaviorConnected).toBeFalse() - - // remove before defining - someEl.remove() - customElements.define('some-element-2', class extends HTMLElement {}) - - await new Promise(r => setTimeout(r)) // wait for MutationObservers - - // behavior will not erroneously be connected after awaiting the element definition - expect(waitingBehaviorConnected).toBeFalse() - }) - }) -})