diff options
Diffstat (limited to 'packages/webapi/test')
-rw-r--r-- | packages/webapi/test/basic.js | 87 | ||||
-rw-r--r-- | packages/webapi/test/characterdata.js | 42 | ||||
-rw-r--r-- | packages/webapi/test/elements.js | 70 | ||||
-rw-r--r-- | packages/webapi/test/fetch.js | 40 | ||||
-rw-r--r-- | packages/webapi/test/imagedata.js | 54 | ||||
-rw-r--r-- | packages/webapi/test/internals.js | 26 | ||||
-rw-r--r-- | packages/webapi/test/media.js | 20 | ||||
-rw-r--r-- | packages/webapi/test/offscreencanvas.js | 39 | ||||
-rw-r--r-- | packages/webapi/test/options.js | 44 | ||||
-rw-r--r-- | packages/webapi/test/storage.js | 32 | ||||
-rw-r--r-- | packages/webapi/test/structuredclone.js | 28 | ||||
-rw-r--r-- | packages/webapi/test/urlpattern.js | 19 |
12 files changed, 0 insertions, 501 deletions
diff --git a/packages/webapi/test/basic.js b/packages/webapi/test/basic.js deleted file mode 100644 index 9eb5864d5..000000000 --- a/packages/webapi/test/basic.js +++ /dev/null @@ -1,87 +0,0 @@ -import { expect } from 'chai' -import { polyfill } from '../mod.js' - -describe('Basic', () => { - before(() => polyfill(globalThis)) - - it('Globals exist', () => { - const webAPIs = [ - 'ByteLengthQueuingStrategy', - 'CSSStyleSheet', - 'CountQueuingStrategy', - 'CustomElementRegistry', - 'CustomEvent', - 'DOMException', - 'Document', - 'DocumentFragment', - 'Element', - 'Event', - 'EventTarget', - 'File', - 'FormData', - 'HTMLDocument', - 'HTMLElement', - 'HTMLDivElement', - 'HTMLHeadElement', - 'HTMLHtmlElement', - 'HTMLImageElement', - 'HTMLStyleElement', - 'HTMLTemplateElement', - 'HTMLUnknownElement', - 'Headers', - 'IntersectionObserver', - 'Image', - 'MediaQueryList', - 'MutationObserver', - 'Node', - 'ReadableByteStreamController', - 'ReadableStream', - 'ReadableStreamBYOBReader', - 'ReadableStreamBYOBRequest', - 'ReadableStreamDefaultController', - 'ReadableStreamDefaultReader', - 'Request', - 'Response', - 'ShadowRoot', - 'StyleSheet', - 'TransformStream', - 'WritableStream', - 'WritableStreamDefaultController', - 'WritableStreamDefaultWriter', - 'Window', - 'cancelAnimationFrame', - 'cancelIdleCallback', - 'clearTimeout', - 'fetch', - 'requestAnimationFrame', - 'requestIdleCallback', - 'setTimeout', - ] - - for (const name of webAPIs) { - expect(globalThis[name]).to.be.a('function') - } - }) - - it('Classes extend as expected', () => { - expect(HTMLElement.prototype).to.be.an.instanceof(Element) - expect(Element.prototype).to.be.an.instanceof(Node) - expect(Node.prototype).to.be.an.instanceof(EventTarget) - }) - - it('DOM Methods have no effect', () => { - const element = document.createElement('div') - - expect(element.innerHTML).to.be.empty - element.innerHTML = 'frozen' - expect(element.innerHTML).to.be.empty - - expect(element.textContent).to.be.empty - element.textContent = 'frozen' - expect(element.textContent).to.be.empty - }) - - it('globalThis.window === globalThis', () => { - expect(globalThis.window).to.equal(globalThis) - }) -}) diff --git a/packages/webapi/test/characterdata.js b/packages/webapi/test/characterdata.js deleted file mode 100644 index b9973db9f..000000000 --- a/packages/webapi/test/characterdata.js +++ /dev/null @@ -1,42 +0,0 @@ -import { expect } from 'chai' -import { polyfill } from '../mod.js' - -describe('CharacterData', () => { - const target = {} - - before(() => polyfill(target)) - - it('Includes CharacterData functionality', () => { - expect(target).to.have.property('CharacterData') - expect(target).to.have.property('Text') - expect(target).to.have.property('Comment') - }) - - it('Supports new Comment', () => { - expect(() => { - new target.Comment() - }).not.to.throw() - - expect(new target.Comment().constructor.name).to.equal('Comment') - expect(Object.prototype.toString.call(new target.Comment())).to.equal( - '[object Comment]' - ) - - expect(new target.Comment('hello').data).to.equal('hello') - expect(new target.Comment('hello').textContent).to.equal('hello') - }) - - it('Supports new Text', () => { - expect(() => { - new target.Text() - }).not.to.throw() - - expect(new target.Text().constructor.name).to.equal('Text') - expect(Object.prototype.toString.call(new target.Text())).to.equals( - '[object Text]' - ) - - expect(new target.Text('hello').data).to.equal('hello') - expect(new target.Text('hello').textContent).to.equal('hello') - }) -}) diff --git a/packages/webapi/test/elements.js b/packages/webapi/test/elements.js deleted file mode 100644 index f758559a5..000000000 --- a/packages/webapi/test/elements.js +++ /dev/null @@ -1,70 +0,0 @@ -import { expect } from 'chai' -import { polyfill } from '../mod.js' - -describe('Custom Elements', () => { - const target = {} - - beforeEach(() => polyfill(target)) - - it('Includes Custom Element functionality', () => { - expect(target).to.have.property('CustomElementRegistry') - expect(target).to.have.property('customElements') - expect(target).to.have.property('HTMLElement') - }) - - it('Supports Custom Element creation', () => { - const CustomElement = class HTMLCustomElement extends target.HTMLElement {} - - target.customElements.define('custom-element', CustomElement) - - expect(target.customElements.get('custom-element')).to.equal(CustomElement) - expect(target.customElements.getName(CustomElement)).to.equal( - 'custom-element' - ) - }) - - it('Supports Custom Elements created from Document', () => { - expect(target.document.body.localName).to.equal('body') - expect(target.document.body.tagName).to.equal('BODY') - - expect( - target.document.createElement('custom-element').constructor.name - ).to.equal('HTMLUnknownElement') - - const CustomElement = class HTMLCustomElement extends target.HTMLElement {} - - target.customElements.define('custom-element', CustomElement) - - expect( - target.document.createElement('custom-element').constructor.name - ).to.equal('HTMLCustomElement') - }) - - it('Supports Custom Elements with properties', () => { - const testSymbol = Symbol.for('webapi.test') - - const CustomElement = class HTMLCustomElement extends target.HTMLElement { - otherMethod = () => testSymbol - - method() { - return this.otherMethod() - } - - static method() { - return this.otherMethod() - } - - static otherMethod() { - return testSymbol - } - } - - target.customElements.define('custom-element', CustomElement) - - expect(CustomElement.method()).to.equal(testSymbol) - - const customElement = new CustomElement() - - expect(customElement.method()).to.equal(testSymbol) - }) -}) diff --git a/packages/webapi/test/fetch.js b/packages/webapi/test/fetch.js deleted file mode 100644 index ce0a2e700..000000000 --- a/packages/webapi/test/fetch.js +++ /dev/null @@ -1,40 +0,0 @@ -import { expect } from 'chai' -import { polyfill } from '../mod.js' - -describe('Fetch', () => { - const target = {} - - before(() => polyfill(target)) - - it('Fetch functionality', () => { - expect(target).to.have.property('fetch').that.is.a('function') - }) - - it('Fetch with https', async () => { - const { fetch } = target - - const response = await fetch('https://astro.build') - - expect(response.constructor).to.equal(target.Response) - - const html = await response.text() - - expect(html).to.include('<html') - }) - - it('Fetch with data', async () => { - const { fetch } = target - - const jsonURI = `data:application/json,${encodeURIComponent( - JSON.stringify({ - name: '@astrojs/webapi', - }) - )}` - - const response = await fetch(jsonURI) - - const json = await response.json() - - expect(json.name).to.equal('@astrojs/webapi') - }) -}) diff --git a/packages/webapi/test/imagedata.js b/packages/webapi/test/imagedata.js deleted file mode 100644 index b386a18d6..000000000 --- a/packages/webapi/test/imagedata.js +++ /dev/null @@ -1,54 +0,0 @@ -import { expect } from 'chai' -import { polyfill } from '../mod.js' - -describe('ImageData', () => { - const target = {} - - before(() => polyfill(target)) - - it('Supports ImageData', () => { - expect(target).to.have.property('ImageData').that.is.a('function') - }) - - it('Supports new (data: Uint8ClampedArray, width: number, height: number): ImageData', () => { - const w = 640 - const h = 480 - const d = new Uint8ClampedArray(w * h * 4) - - const id = new target.ImageData(d, w, h) - - expect(id.data).to.equal(d) - expect(id.width).to.equal(w) - expect(id.height).to.equal(h) - }) - - it('Supports new (data: Uint8ClampedArray, width: number): ImageData', () => { - const w = 640 - const h = 480 - const d = new Uint8ClampedArray(w * h * 4) - - const id = new target.ImageData(d, w) - - expect(id.data).to.equal(d) - expect(id.width).to.equal(w) - expect(id.height).to.equal(h) - }) - - it('Supports new (width: number, height: number): ImageData', () => { - const w = 640 - const h = 480 - - const id = new target.ImageData(w, h) - - expect(id.data).to.have.lengthOf(w * h * 4) - expect(id.width).to.equal(w) - expect(id.height).to.equal(h) - }) - - it('Supports Object.keys(new ImageData(640, 480))', () => { - const keys = Object.keys(new target.ImageData(640, 480)) - - expect(keys).to.have.lengthOf(1) - expect(keys[0]).to.equal('data') - }) -}) diff --git a/packages/webapi/test/internals.js b/packages/webapi/test/internals.js deleted file mode 100644 index 054b7e488..000000000 --- a/packages/webapi/test/internals.js +++ /dev/null @@ -1,26 +0,0 @@ -import { expect } from 'chai' -import { polyfill } from '../mod.js' - -it('Includes polyfill.internals functionality', () => { - const target = {} - - polyfill(target, { exclude: 'window document' }) - - const pseudo = { ...target } - - expect(pseudo).to.not.have.property('document') - - const CustomElement = class extends pseudo.HTMLElement {} - - pseudo.customElements.define('custom-element', CustomElement) - - polyfill.internals(pseudo, 'Document') - - expect(pseudo).to.have.property('document') - - expect( - CustomElement.prototype.isPrototypeOf( - pseudo.document.createElement('custom-element') - ) - ).to.equal(true) -}) diff --git a/packages/webapi/test/media.js b/packages/webapi/test/media.js deleted file mode 100644 index e6e7b82d4..000000000 --- a/packages/webapi/test/media.js +++ /dev/null @@ -1,20 +0,0 @@ -import { expect } from 'chai' -import { polyfill } from '../mod.js' - -describe('Media', () => { - const target = {} - - before(() => polyfill(target)) - - it('Includes MediaQueryList functionality', () => { - expect(target).to.have.property('MediaQueryList') - expect(target).to.have.property('matchMedia') - }) - - it('Supports matchMedia creation', () => { - const mql = target.matchMedia('(min-width: 640px)') - - expect(mql.matches).to.equal(false) - expect(mql.media).to.equal('(min-width: 640px)') - }) -}) diff --git a/packages/webapi/test/offscreencanvas.js b/packages/webapi/test/offscreencanvas.js deleted file mode 100644 index 6223e78e8..000000000 --- a/packages/webapi/test/offscreencanvas.js +++ /dev/null @@ -1,39 +0,0 @@ -import { expect } from 'chai' -import { polyfill } from '../mod.js' - -describe('OffscreenCanvas', () => { - const target = {} - - before(() => polyfill(target)) - - it('Supports OffscreenCanvas', () => { - expect(target).to.have.property('OffscreenCanvas').that.is.a('function') - }) - - it('Supports new (width: number, height: number): OffscreenCanvas', () => { - const w = 640 - const h = 480 - - const canvas = new target.OffscreenCanvas(w, h) - - expect(canvas.width).to.equal(w) - expect(canvas.height).to.equal(h) - }) - - it('Supports OffscreenCanvas#getContext', () => { - const w = 640 - const h = 480 - - const canvas = new target.OffscreenCanvas(w, h) - - const context = canvas.getContext('2d') - - expect(context.canvas).to.equal(canvas) - - const imageData = context.createImageData(w, h) - - expect(imageData.width).to.equal(w) - expect(imageData.height).to.equal(h) - expect(imageData.data).to.have.lengthOf(w * h * 4) - }) -}) diff --git a/packages/webapi/test/options.js b/packages/webapi/test/options.js deleted file mode 100644 index 0db1cbfe3..000000000 --- a/packages/webapi/test/options.js +++ /dev/null @@ -1,44 +0,0 @@ -import { expect } from 'chai' -import { polyfill } from '../mod.js' - -describe('Options', () => { - it('Can exclude HTMLElement+', () => { - const target = {} - - polyfill(target, { - exclude: 'HTMLElement+', - }) - - expect(target).to.have.property('Event') - expect(target).to.have.property('EventTarget') - expect(target).to.have.property('Element') - expect(target).to.not.have.property('HTMLElement') - expect(target).to.not.have.property('HTMLDivElement') - }) - - it('Can exclude Event+', () => { - const target = {} - - polyfill(target, { - exclude: 'Event+', - }) - - expect(target).to.not.have.property('Event') - expect(target).to.not.have.property('EventTarget') - expect(target).to.not.have.property('Element') - expect(target).to.not.have.property('HTMLElement') - expect(target).to.not.have.property('HTMLDivElement') - }) - - it('Can exclude document', () => { - const target = {} - - polyfill(target, { - exclude: 'document', - }) - - expect(target).to.have.property('Document') - expect(target).to.have.property('HTMLDocument') - expect(target).to.not.have.property('document') - }) -}) diff --git a/packages/webapi/test/storage.js b/packages/webapi/test/storage.js deleted file mode 100644 index 9a185644a..000000000 --- a/packages/webapi/test/storage.js +++ /dev/null @@ -1,32 +0,0 @@ -import { expect } from 'chai' -import { polyfill } from '../mod.js' - -describe('Storage', () => { - const target = {} - - before(() => polyfill(target)) - - it('Includes Storage functionality', () => { - expect(target).to.have.property('Storage').that.is.a('function') - expect(target).to.have.property('localStorage').that.is.an('object') - }) - - it('Supports Storage methods', () => { - expect(target.localStorage.setItem('hello', 'world')).to.equal(undefined) - expect(target.localStorage.getItem('hello')).to.equal('world') - expect(target.localStorage.key(0)).to.equal('hello') - expect(target.localStorage.key(1)).to.equal(null) - expect(target.localStorage.length).to.equal(1) - expect(target.localStorage.setItem('world', 'hello')).to.equal(undefined) - expect(target.localStorage.key(1)).to.equal('world') - expect(target.localStorage.key(2)).to.equal(null) - expect(target.localStorage.length).to.equal(2) - expect(target.localStorage.removeItem('hello')).to.equal(undefined) - expect(target.localStorage.key(0)).to.equal('world') - expect(target.localStorage.key(1)).to.equal(null) - expect(target.localStorage.length).to.equal(1) - expect(target.localStorage.clear()).to.equal(undefined) - expect(target.localStorage.key(0)).to.equal(null) - expect(target.localStorage.length).to.equal(0) - }) -}) diff --git a/packages/webapi/test/structuredclone.js b/packages/webapi/test/structuredclone.js deleted file mode 100644 index 0503cf904..000000000 --- a/packages/webapi/test/structuredclone.js +++ /dev/null @@ -1,28 +0,0 @@ -import { expect } from 'chai' -import { polyfill } from '../mod.js' - -describe('structuredClone', () => { - const target = {} - - before(() => polyfill(target)) - - it('Includes structuredClone', () => { - expect(target).to.have.property('structuredClone').that.is.a('function') - }) - - it('Supports structuredClone usage', () => { - const obj = { - foo: 'bar', - baz: { - qux: 'quux', - }, - } - - const clone = target.structuredClone(obj) - - expect(obj).to.not.equal(clone) - expect(obj.baz).to.not.equal(clone.baz) - - expect(obj.baz.qux).to.equal(clone.baz.qux) - }) -}) diff --git a/packages/webapi/test/urlpattern.js b/packages/webapi/test/urlpattern.js deleted file mode 100644 index b9ef6b31f..000000000 --- a/packages/webapi/test/urlpattern.js +++ /dev/null @@ -1,19 +0,0 @@ -import { expect } from 'chai' -import { polyfill } from '../mod.js' - -describe('URLPattern', () => { - const target = {} - - before(() => polyfill(target)) - - it('Includes URLPattern', () => { - expect(target).to.have.property('URLPattern').that.is.a('function') - }) - - it('Supports URLPattern usage', () => { - const pattern = new target.URLPattern({ pathname: '/hello/:name' }) - const match = pattern.exec('https://example.com/hello/Deno') - - expect(match.pathname.groups).to.deep.equal({ name: 'Deno' }) - }) -}) |