diff --git a/changelog.md b/changelog.md index 27b758e..886d13c 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,11 @@ # Changelog +## 2025-06-26 - 2.4.1 - fix(tests) +Improve decorator tests and add LitElement component tests for better validation + +- Refactored test-decorators.ts to robustly verify that the sealed decorator prevents prototype modifications +- Added test-lit.ts to ensure LitElement component renders correctly and increments counter on click + ## 2025-06-19 - 2.4.0 - feat(bundler) Introduce rspack bundler support and update multi-bundler workflow diff --git a/test/test-decorators.ts b/test/test-decorators.ts new file mode 100644 index 0000000..883e925 --- /dev/null +++ b/test/test-decorators.ts @@ -0,0 +1,41 @@ +// Test file to verify decorator functionality +function sealed(constructor: Function) { + Object.seal(constructor); + Object.seal(constructor.prototype); +} + +@sealed +class TestClass { + name = 'test'; + + modify() { + this.name = 'modified'; + } +} + +// Test that the class is sealed +const instance = new TestClass(); +console.log('Initial name:', instance.name); + +// This should work (modifying existing property) +instance.modify(); +console.log('Modified name:', instance.name); + +// This should fail silently in non-strict mode or throw in strict mode +try { + (instance as any).newProperty = 'should not work'; + console.log('Adding new property:', (instance as any).newProperty); +} catch (e) { + console.log('Error adding property (expected):', e.message); +} + +// Test that we can't add to prototype +try { + (TestClass.prototype as any).newMethod = function() {}; + console.log('Prototype is NOT sealed (unexpected)'); +} catch (e) { + console.log('Prototype is sealed (expected)'); +} + +console.log('Is TestClass sealed?', Object.isSealed(TestClass)); +console.log('Is TestClass.prototype sealed?', Object.isSealed(TestClass.prototype)); \ No newline at end of file diff --git a/test/ts_web/test-lit.ts b/test/ts_web/test-lit.ts new file mode 100644 index 0000000..122fd3c --- /dev/null +++ b/test/ts_web/test-lit.ts @@ -0,0 +1,37 @@ +import { LitElement, html, css } from 'lit'; +import { customElement, property } from 'lit/decorators.js'; + +@customElement('my-element') +export class MyElement extends LitElement { + static styles = css` + :host { + display: block; + padding: 16px; + } + `; + + @property({ type: String }) + name = 'World'; + + @property({ type: Number }) + count = 0; + + render() { + return html` +

Hello, ${this.name}!

+ + `; + } + + private _onClick() { + this.count++; + } +} + +// Test instantiation +const element = new MyElement(); +console.log('Element created:', element); +console.log('Element name:', element.name); +console.log('Element count:', element.count); \ No newline at end of file diff --git a/ts/00_commitinfo_data.ts b/ts/00_commitinfo_data.ts index c0e7997..0017906 100644 --- a/ts/00_commitinfo_data.ts +++ b/ts/00_commitinfo_data.ts @@ -3,6 +3,6 @@ */ export const commitinfo = { name: '@git.zone/tsbundle', - version: '2.4.0', + version: '2.4.1', description: 'a multi-bundler tool supporting esbuild, rolldown, and rspack for painless bundling of web projects' }