chore: webapi test now use chai (#3048)
This commit is contained in:
parent
47f20a189f
commit
1907255ca2
16 changed files with 510 additions and 785 deletions
|
@ -54,10 +54,12 @@
|
||||||
"@rollup/plugin-inject": "^4.0.4",
|
"@rollup/plugin-inject": "^4.0.4",
|
||||||
"@rollup/plugin-node-resolve": "^13.1.3",
|
"@rollup/plugin-node-resolve": "^13.1.3",
|
||||||
"@rollup/plugin-typescript": "^8.3.1",
|
"@rollup/plugin-typescript": "^8.3.1",
|
||||||
|
"@types/chai": "^4.3.0",
|
||||||
"@types/mocha": "^9.1.0",
|
"@types/mocha": "^9.1.0",
|
||||||
"@types/node": "^14.18.12",
|
"@types/node": "^14.18.12",
|
||||||
"@ungap/structured-clone": "^0.3.4",
|
"@ungap/structured-clone": "^0.3.4",
|
||||||
"abort-controller": "^3.0.0",
|
"abort-controller": "^3.0.0",
|
||||||
|
"chai": "^4.3.6",
|
||||||
"event-target-shim": "^6.0.2",
|
"event-target-shim": "^6.0.2",
|
||||||
"fetch-blob": "^3.1.5",
|
"fetch-blob": "^3.1.5",
|
||||||
"formdata-polyfill": "^4.0.10",
|
"formdata-polyfill": "^4.0.10",
|
||||||
|
|
|
@ -1,29 +0,0 @@
|
||||||
import { fileURLToPath } from 'url'
|
|
||||||
|
|
||||||
export { strict as assert } from 'assert'
|
|
||||||
|
|
||||||
export const pathFrom = (...args) =>
|
|
||||||
fileURLToPath(args.reduce((url, bit) => new URL(bit, url), new URL('file:')))
|
|
||||||
|
|
||||||
export const test = async (setup) => {
|
|
||||||
console.log(`Testing Node ${process.version}:`)
|
|
||||||
console.log('')
|
|
||||||
|
|
||||||
for (const test of setup()) {
|
|
||||||
try {
|
|
||||||
console.log(`- ${test.name}`)
|
|
||||||
|
|
||||||
await test.test()
|
|
||||||
} catch (error) {
|
|
||||||
console.error(error)
|
|
||||||
|
|
||||||
process.exit(1)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log('')
|
|
||||||
console.log('Pass!')
|
|
||||||
console.log('')
|
|
||||||
|
|
||||||
process.exit(0)
|
|
||||||
}
|
|
|
@ -1,48 +1,29 @@
|
||||||
import { assert, test } from '../run/test.setup.js'
|
import { expect } from 'chai'
|
||||||
import { polyfill } from '../mod.js'
|
import { polyfill } from '../mod.js'
|
||||||
|
|
||||||
test(() => {
|
describe('Base64', () => {
|
||||||
return [
|
const target = {}
|
||||||
{
|
|
||||||
name: 'Supports Base64 Methods',
|
|
||||||
test() {
|
|
||||||
const target = {}
|
|
||||||
|
|
||||||
polyfill(target)
|
before(() => polyfill(target))
|
||||||
|
|
||||||
assert.equal('atob' in target, true)
|
it('Supports Base64 Methods', () => {
|
||||||
assert.equal('btoa' in target, true)
|
expect(target).to.have.property('atob').that.is.a('function')
|
||||||
assert.equal(typeof target['atob'], 'function')
|
expect(target).to.have.property('btoa').that.is.a('function')
|
||||||
assert.equal(typeof target['btoa'], 'function')
|
})
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'Supports atob(data)',
|
|
||||||
test() {
|
|
||||||
const target = {}
|
|
||||||
|
|
||||||
polyfill(target)
|
it('Supports atob(data)', () => {
|
||||||
|
const a = 'SGVsbG8sIHdvcmxk'
|
||||||
|
const b = target.atob(a)
|
||||||
|
|
||||||
const a = 'SGVsbG8sIHdvcmxk'
|
expect(a).to.equal('SGVsbG8sIHdvcmxk')
|
||||||
const b = target.atob(a)
|
expect(b).to.equal('Hello, world')
|
||||||
|
})
|
||||||
|
|
||||||
assert.equal(a, 'SGVsbG8sIHdvcmxk')
|
it('Supports btoa(data)', () => {
|
||||||
assert.equal(b, 'Hello, world')
|
const b = 'Hello, world'
|
||||||
},
|
const a = target.btoa(b)
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'Supports btoa(data)',
|
|
||||||
test() {
|
|
||||||
const target = {}
|
|
||||||
|
|
||||||
polyfill(target)
|
expect(a).to.equal('SGVsbG8sIHdvcmxk')
|
||||||
|
expect(b).to.equal('Hello, world')
|
||||||
const b = 'Hello, world'
|
})
|
||||||
const a = target.btoa(b)
|
|
||||||
|
|
||||||
assert.equal(a, 'SGVsbG8sIHdvcmxk')
|
|
||||||
assert.equal(b, 'Hello, world')
|
|
||||||
},
|
|
||||||
},
|
|
||||||
]
|
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,214 +1,185 @@
|
||||||
import { assert, test } from '../run/test.setup.js'
|
import { expect } from 'chai'
|
||||||
import { polyfill } from '../mod.js'
|
import { polyfill } from '../mod.js'
|
||||||
|
|
||||||
test(() => {
|
describe('Basic', () => {
|
||||||
polyfill(globalThis)
|
before(() => polyfill(globalThis))
|
||||||
|
|
||||||
return [
|
it('Globals exist', () => {
|
||||||
{
|
const webAPIs = [
|
||||||
name: 'Globals exist',
|
'AbortController',
|
||||||
test() {
|
'AbortSignal',
|
||||||
const webAPIs = [
|
'Blob',
|
||||||
'AbortController',
|
'ByteLengthQueuingStrategy',
|
||||||
'AbortSignal',
|
'CSSStyleSheet',
|
||||||
'Blob',
|
'CountQueuingStrategy',
|
||||||
'ByteLengthQueuingStrategy',
|
'CustomElementRegistry',
|
||||||
'CSSStyleSheet',
|
'CustomEvent',
|
||||||
'CountQueuingStrategy',
|
'DOMException',
|
||||||
'CustomElementRegistry',
|
'Document',
|
||||||
'CustomEvent',
|
'DocumentFragment',
|
||||||
'DOMException',
|
'Element',
|
||||||
'Document',
|
'Event',
|
||||||
'DocumentFragment',
|
'EventTarget',
|
||||||
'Element',
|
'File',
|
||||||
'Event',
|
'FormData',
|
||||||
'EventTarget',
|
'HTMLDocument',
|
||||||
'File',
|
'HTMLElement',
|
||||||
'FormData',
|
'HTMLDivElement',
|
||||||
'HTMLDocument',
|
'HTMLHeadElement',
|
||||||
'HTMLElement',
|
'HTMLHtmlElement',
|
||||||
'HTMLDivElement',
|
'HTMLImageElement',
|
||||||
'HTMLHeadElement',
|
'HTMLStyleElement',
|
||||||
'HTMLHtmlElement',
|
'HTMLTemplateElement',
|
||||||
'HTMLImageElement',
|
'HTMLUnknownElement',
|
||||||
'HTMLStyleElement',
|
'Headers',
|
||||||
'HTMLTemplateElement',
|
'IntersectionObserver',
|
||||||
'HTMLUnknownElement',
|
'Image',
|
||||||
'Headers',
|
'MediaQueryList',
|
||||||
'IntersectionObserver',
|
'MutationObserver',
|
||||||
'Image',
|
'Node',
|
||||||
'MediaQueryList',
|
'ReadableByteStreamController',
|
||||||
'MutationObserver',
|
'ReadableStream',
|
||||||
'Node',
|
'ReadableStreamBYOBReader',
|
||||||
'ReadableByteStreamController',
|
'ReadableStreamBYOBRequest',
|
||||||
'ReadableStream',
|
'ReadableStreamDefaultController',
|
||||||
'ReadableStreamBYOBReader',
|
'ReadableStreamDefaultReader',
|
||||||
'ReadableStreamBYOBRequest',
|
'Request',
|
||||||
'ReadableStreamDefaultController',
|
'Response',
|
||||||
'ReadableStreamDefaultReader',
|
'ShadowRoot',
|
||||||
'Request',
|
'StyleSheet',
|
||||||
'Response',
|
'TransformStream',
|
||||||
'ShadowRoot',
|
'WritableStream',
|
||||||
'StyleSheet',
|
'WritableStreamDefaultController',
|
||||||
'TransformStream',
|
'WritableStreamDefaultWriter',
|
||||||
'WritableStream',
|
'Window',
|
||||||
'WritableStreamDefaultController',
|
'cancelAnimationFrame',
|
||||||
'WritableStreamDefaultWriter',
|
'cancelIdleCallback',
|
||||||
'Window',
|
'clearTimeout',
|
||||||
'cancelAnimationFrame',
|
'fetch',
|
||||||
'cancelIdleCallback',
|
'requestAnimationFrame',
|
||||||
'clearTimeout',
|
'requestIdleCallback',
|
||||||
'fetch',
|
'setTimeout',
|
||||||
'requestAnimationFrame',
|
]
|
||||||
'requestIdleCallback',
|
|
||||||
'setTimeout',
|
|
||||||
]
|
|
||||||
|
|
||||||
for (const name of webAPIs) {
|
for (const name of webAPIs) {
|
||||||
assert.equal(typeof globalThis[name], 'function')
|
expect(globalThis[name]).to.be.a('function')
|
||||||
}
|
}
|
||||||
},
|
})
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'Constructs an Event',
|
|
||||||
test() {
|
|
||||||
const e = new Event('test')
|
|
||||||
|
|
||||||
assert.equal(e.type, 'test')
|
it('Constructs an Event', () => {
|
||||||
},
|
const e = new Event('test')
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'Constructs an EventTarget',
|
|
||||||
test() {
|
|
||||||
const t = new EventTarget()
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'Dispatches an Event on an EventTarget',
|
|
||||||
test() {
|
|
||||||
const t = new EventTarget()
|
|
||||||
|
|
||||||
let pass = false
|
expect(e.type).to.equal('test')
|
||||||
|
})
|
||||||
|
|
||||||
t.addEventListener('test', (event) => {
|
it('Constructs an EventTarget', () => {
|
||||||
pass = true
|
const _t = new EventTarget()
|
||||||
})
|
})
|
||||||
|
|
||||||
const e = new Event('test')
|
it('Dispatches an Event on an EventTarget', () => {
|
||||||
|
const t = new EventTarget()
|
||||||
|
|
||||||
t.dispatchEvent(e)
|
let pass = false
|
||||||
|
|
||||||
assert.equal(pass, true)
|
t.addEventListener('test', (event) => {
|
||||||
},
|
pass = true
|
||||||
},
|
})
|
||||||
{
|
|
||||||
name: 'Classes extend as expected',
|
|
||||||
test() {
|
|
||||||
assert.equal(HTMLElement.prototype instanceof Element, true)
|
|
||||||
assert.equal(Element.prototype instanceof Node, true)
|
|
||||||
assert.equal(Node.prototype instanceof EventTarget, true)
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'DOM Methods have no effect',
|
|
||||||
test() {
|
|
||||||
const element = document.createElement('div')
|
|
||||||
|
|
||||||
assert.equal(element.innerHTML, '')
|
const e = new Event('test')
|
||||||
element.innerHTML = 'frozen'
|
|
||||||
assert.equal(element.innerHTML, '')
|
|
||||||
|
|
||||||
assert.equal(element.textContent, '')
|
t.dispatchEvent(e)
|
||||||
element.textContent = 'frozen'
|
|
||||||
assert.equal(element.textContent, '')
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'globalThis.window === globalThis',
|
|
||||||
test() {
|
|
||||||
assert.equal(globalThis.window, globalThis)
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'Relative Indexing Method (String#at)',
|
|
||||||
test() {
|
|
||||||
assert.equal(typeof String.prototype.at, 'function')
|
|
||||||
assert.equal(String.prototype.at.length, 1)
|
|
||||||
|
|
||||||
const example = 'The quick brown fox jumps over the lazy dog.'
|
expect(pass).to.equal(true)
|
||||||
|
})
|
||||||
|
|
||||||
assert.equal(example.at(2), 'e')
|
it('Classes extend as expected', () => {
|
||||||
assert.equal(example.at(-2), 'g')
|
expect(HTMLElement.prototype).to.be.an.instanceof(Element)
|
||||||
},
|
expect(Element.prototype).to.be.an.instanceof(Node)
|
||||||
},
|
expect(Node.prototype).to.be.an.instanceof(EventTarget)
|
||||||
{
|
})
|
||||||
name: 'Relative Indexing Method (Array#at)',
|
|
||||||
test() {
|
|
||||||
assert.equal(typeof Array.prototype.at, 'function')
|
|
||||||
assert.equal(Array.prototype.at.length, 1)
|
|
||||||
|
|
||||||
const example = [1, 3, 5, 7, 9]
|
it('DOM Methods have no effect', () => {
|
||||||
|
const element = document.createElement('div')
|
||||||
|
|
||||||
assert.equal(example.at(1), 3)
|
expect(element.innerHTML).to.be.empty
|
||||||
assert.equal(example.at(-1), 9)
|
element.innerHTML = 'frozen'
|
||||||
},
|
expect(element.innerHTML).to.be.empty
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'Relative Indexing Method (TypedArray#at)',
|
|
||||||
test() {
|
|
||||||
assert.equal(typeof Int8Array.prototype.at, 'function')
|
|
||||||
assert.equal(Int8Array.prototype.at.length, 1)
|
|
||||||
|
|
||||||
const example = new Int8Array([1, 3, 5, 7, 9])
|
expect(element.textContent).to.be.empty
|
||||||
|
element.textContent = 'frozen'
|
||||||
|
expect(element.textContent).to.be.empty
|
||||||
|
})
|
||||||
|
|
||||||
assert.equal(example.at(1), 3)
|
it('globalThis.window === globalThis', () => {
|
||||||
assert.equal(example.at(-1), 9)
|
expect(globalThis.window).to.equal(globalThis)
|
||||||
},
|
})
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'Object.hasOwn',
|
|
||||||
test() {
|
|
||||||
assert.equal(typeof Object.hasOwn, 'function')
|
|
||||||
assert.equal(Object.hasOwn.length, 2)
|
|
||||||
|
|
||||||
const example = {}
|
it('Relative Indexing Method (String#at)', () => {
|
||||||
|
expect(String.prototype.at).to.be.a('function')
|
||||||
|
expect(String.prototype.at.length).to.equal(1)
|
||||||
|
|
||||||
assert.equal(Object.hasOwn(example, 'prop'), false)
|
const example = 'The quick brown fox jumps over the lazy dog.'
|
||||||
|
|
||||||
example.prop = 'exists'
|
expect(example.at(2)).to.equal('e')
|
||||||
|
expect(example.at(-2)).to.equal('g')
|
||||||
|
})
|
||||||
|
|
||||||
assert.equal(Object.hasOwn(example, 'prop'), true)
|
it('Relative Indexing Method (Array#at)', () => {
|
||||||
},
|
expect(Array.prototype.at).to.be.a('function')
|
||||||
},
|
expect(Array.prototype.at.length).to.equal(1)
|
||||||
{
|
|
||||||
name: 'Promise.any',
|
|
||||||
test() {
|
|
||||||
assert.equal(typeof Promise.any, 'function')
|
|
||||||
assert.equal(Promise.any.length, 1)
|
|
||||||
|
|
||||||
Promise.any([
|
const example = [1, 3, 5, 7, 9]
|
||||||
Promise.resolve(42),
|
|
||||||
Promise.reject(-1),
|
|
||||||
Promise.reject(Infinity),
|
|
||||||
]).then((result) => {
|
|
||||||
assert.equal(result, 42)
|
|
||||||
})
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'String#replaceAll',
|
|
||||||
test() {
|
|
||||||
assert.equal(typeof String.prototype.replaceAll, 'function')
|
|
||||||
assert.equal(String.prototype.replaceAll.length, 2)
|
|
||||||
|
|
||||||
const t1 =
|
expect(example.at(1)).to.equal(3)
|
||||||
'Of all the sorcerers in Harry Potter, Halo is my favorite sorcerer.'
|
expect(example.at(-1)).to.equal(9)
|
||||||
const t2 = t1.replaceAll('sorcerer', 'philosopher')
|
})
|
||||||
const t3 =
|
|
||||||
'Of all the philosophers in Harry Potter, Halo is my favorite philosopher.'
|
|
||||||
|
|
||||||
assert.equal(t2, t3)
|
it('Relative Indexing Method (TypedArray#at)', () => {
|
||||||
},
|
expect(Int8Array.prototype.at).to.be.a('function')
|
||||||
},
|
expect(Int8Array.prototype.at.length).to.equal(1)
|
||||||
]
|
|
||||||
|
const example = new Int8Array([1, 3, 5, 7, 9])
|
||||||
|
|
||||||
|
expect(example.at(1)).to.equal(3)
|
||||||
|
expect(example.at(-1)).to.equal(9)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('Object.hasOwn', () => {
|
||||||
|
expect(Object.hasOwn).to.be.a('function')
|
||||||
|
expect(Object.hasOwn.length).to.equal(2)
|
||||||
|
|
||||||
|
const example = {}
|
||||||
|
|
||||||
|
expect(Object.hasOwn(example, 'prop')).to.equal(false)
|
||||||
|
|
||||||
|
example.prop = 'exists'
|
||||||
|
|
||||||
|
expect(Object.hasOwn(example, 'prop')).to.equal(true)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('Promise.any', () => {
|
||||||
|
expect(Promise.any).to.be.a('function')
|
||||||
|
expect(Promise.any.length).to.equal(1)
|
||||||
|
|
||||||
|
Promise.any([
|
||||||
|
Promise.resolve(42),
|
||||||
|
Promise.reject(-1),
|
||||||
|
Promise.reject(Infinity),
|
||||||
|
]).then((result) => {
|
||||||
|
expect(result).to.equal(42)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('String#replaceAll', () => {
|
||||||
|
expect(String.prototype.replaceAll).to.be.a('function')
|
||||||
|
expect(String.prototype.replaceAll.length).to.equal(2)
|
||||||
|
|
||||||
|
const t1 =
|
||||||
|
'Of all the sorcerers in Harry Potter, Halo is my favorite sorcerer.'
|
||||||
|
const t2 = t1.replaceAll('sorcerer', 'philosopher')
|
||||||
|
const t3 =
|
||||||
|
'Of all the philosophers in Harry Potter, Halo is my favorite philosopher.'
|
||||||
|
|
||||||
|
expect(t2).to.equal(t3)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,65 +1,42 @@
|
||||||
import { assert, test } from '../run/test.setup.js'
|
import { expect } from 'chai'
|
||||||
import { polyfill } from '../mod.js'
|
import { polyfill } from '../mod.js'
|
||||||
|
|
||||||
test(() => {
|
describe('CharacterData', () => {
|
||||||
return [
|
const target = {}
|
||||||
{
|
|
||||||
name: 'Includes CharacterData functionality',
|
|
||||||
test() {
|
|
||||||
const target = {}
|
|
||||||
|
|
||||||
polyfill(target)
|
before(() => polyfill(target))
|
||||||
|
|
||||||
assert.equal(Reflect.has(target, 'CharacterData'), true)
|
it('Includes CharacterData functionality', () => {
|
||||||
assert.equal(Reflect.has(target, 'Text'), true)
|
expect(target).to.have.property('CharacterData')
|
||||||
assert.equal(Reflect.has(target, 'Comment'), true)
|
expect(target).to.have.property('Text')
|
||||||
},
|
expect(target).to.have.property('Comment')
|
||||||
},
|
})
|
||||||
{
|
|
||||||
name: 'Throws new CharacterData',
|
|
||||||
test() {
|
|
||||||
const target = {}
|
|
||||||
|
|
||||||
polyfill(target)
|
it('Supports new Comment', () => {
|
||||||
},
|
expect(() => {
|
||||||
},
|
new target.Comment()
|
||||||
{
|
}).not.to.throw()
|
||||||
name: 'Supports new Comment',
|
|
||||||
test() {
|
|
||||||
const target = polyfill({})
|
|
||||||
|
|
||||||
assert.doesNotThrow(() => {
|
expect(new target.Comment().constructor.name).to.equal('Comment')
|
||||||
new target.Comment()
|
expect(Object.prototype.toString.call(new target.Comment())).to.equal(
|
||||||
})
|
'[object Comment]'
|
||||||
|
)
|
||||||
|
|
||||||
assert.equal(new target.Comment().constructor.name, 'Comment')
|
expect(new target.Comment('hello').data).to.equal('hello')
|
||||||
assert.equal(
|
expect(new target.Comment('hello').textContent).to.equal('hello')
|
||||||
Object.prototype.toString.call(new target.Comment()),
|
})
|
||||||
'[object Comment]'
|
|
||||||
)
|
|
||||||
|
|
||||||
assert.equal(new target.Comment('hello').data, 'hello')
|
it('Supports new Text', () => {
|
||||||
assert.equal(new target.Comment('hello').textContent, 'hello')
|
expect(() => {
|
||||||
},
|
new target.Text()
|
||||||
},
|
}).not.to.throw()
|
||||||
{
|
|
||||||
name: 'Supports new Text',
|
|
||||||
test() {
|
|
||||||
const target = polyfill({})
|
|
||||||
|
|
||||||
assert.doesNotThrow(() => {
|
expect(new target.Text().constructor.name).to.equal('Text')
|
||||||
new target.Text()
|
expect(Object.prototype.toString.call(new target.Text())).to.equals(
|
||||||
})
|
'[object Text]'
|
||||||
|
)
|
||||||
|
|
||||||
assert.equal(new target.Text().constructor.name, 'Text')
|
expect(new target.Text('hello').data).to.equal('hello')
|
||||||
assert.equal(
|
expect(new target.Text('hello').textContent).to.equal('hello')
|
||||||
Object.prototype.toString.call(new target.Text()),
|
})
|
||||||
'[object Text]'
|
|
||||||
)
|
|
||||||
|
|
||||||
assert.equal(new target.Text('hello').data, 'hello')
|
|
||||||
assert.equal(new target.Text('hello').textContent, 'hello')
|
|
||||||
},
|
|
||||||
},
|
|
||||||
]
|
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,96 +1,70 @@
|
||||||
import { assert, test } from '../run/test.setup.js'
|
import { expect } from 'chai'
|
||||||
import { polyfill } from '../mod.js'
|
import { polyfill } from '../mod.js'
|
||||||
|
|
||||||
test(() => {
|
describe('Custom Elements', () => {
|
||||||
return [
|
const target = {}
|
||||||
{
|
|
||||||
name: 'Includes Custom Element functionality',
|
|
||||||
test() {
|
|
||||||
const target = {}
|
|
||||||
|
|
||||||
polyfill(target)
|
beforeEach(() => polyfill(target))
|
||||||
|
|
||||||
assert.equal(Reflect.has(target, 'CustomElementRegistry'), true)
|
it('Includes Custom Element functionality', () => {
|
||||||
assert.equal(Reflect.has(target, 'customElements'), true)
|
expect(target).to.have.property('CustomElementRegistry')
|
||||||
assert.equal(Reflect.has(target, 'HTMLElement'), true)
|
expect(target).to.have.property('customElements')
|
||||||
},
|
expect(target).to.have.property('HTMLElement')
|
||||||
},
|
})
|
||||||
{
|
|
||||||
name: 'Supports Custom Element creation',
|
|
||||||
test() {
|
|
||||||
const target = {}
|
|
||||||
|
|
||||||
polyfill(target)
|
it('Supports Custom Element creation', () => {
|
||||||
|
const CustomElement = class HTMLCustomElement extends target.HTMLElement {}
|
||||||
|
|
||||||
const CustomElement = class HTMLCustomElement extends target.HTMLElement {}
|
target.customElements.define('custom-element', CustomElement)
|
||||||
|
|
||||||
target.customElements.define('custom-element', CustomElement)
|
expect(target.customElements.get('custom-element')).to.equal(CustomElement)
|
||||||
|
expect(target.customElements.getName(CustomElement)).to.equal(
|
||||||
|
'custom-element'
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
assert.equal(target.customElements.get('custom-element'), CustomElement)
|
it('Supports Custom Elements created from Document', () => {
|
||||||
assert.equal(
|
expect(target.document.body.localName).to.equal('body')
|
||||||
target.customElements.getName(CustomElement),
|
expect(target.document.body.tagName).to.equal('BODY')
|
||||||
'custom-element'
|
|
||||||
)
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'Supports Custom Elements created from Document',
|
|
||||||
test() {
|
|
||||||
const target = {}
|
|
||||||
|
|
||||||
polyfill(target)
|
expect(
|
||||||
|
target.document.createElement('custom-element').constructor.name
|
||||||
|
).to.equal('HTMLUnknownElement')
|
||||||
|
|
||||||
assert.equal(target.document.body.localName, 'body')
|
const CustomElement = class HTMLCustomElement extends target.HTMLElement {}
|
||||||
assert.equal(target.document.body.tagName, 'BODY')
|
|
||||||
|
|
||||||
assert.equal(
|
target.customElements.define('custom-element', CustomElement)
|
||||||
target.document.createElement('custom-element').constructor.name,
|
|
||||||
'HTMLUnknownElement'
|
|
||||||
)
|
|
||||||
|
|
||||||
const CustomElement = class HTMLCustomElement extends target.HTMLElement {}
|
expect(
|
||||||
|
target.document.createElement('custom-element').constructor.name
|
||||||
|
).to.equal('HTMLCustomElement')
|
||||||
|
})
|
||||||
|
|
||||||
target.customElements.define('custom-element', CustomElement)
|
it('Supports Custom Elements with properties', () => {
|
||||||
|
const testSymbol = Symbol.for('webapi.test')
|
||||||
|
|
||||||
assert.equal(
|
const CustomElement = class HTMLCustomElement extends target.HTMLElement {
|
||||||
target.document.createElement('custom-element').constructor.name,
|
otherMethod = () => testSymbol
|
||||||
'HTMLCustomElement'
|
|
||||||
)
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'Supports Custom Elements with properties',
|
|
||||||
test() {
|
|
||||||
const target = {}
|
|
||||||
|
|
||||||
polyfill(target)
|
method() {
|
||||||
|
return this.otherMethod()
|
||||||
|
}
|
||||||
|
|
||||||
const testSymbol = Symbol.for('webapi.test')
|
static method() {
|
||||||
|
return this.otherMethod()
|
||||||
|
}
|
||||||
|
|
||||||
const CustomElement = class HTMLCustomElement extends target.HTMLElement {
|
static otherMethod() {
|
||||||
otherMethod = () => testSymbol
|
return testSymbol
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
method() {
|
target.customElements.define('custom-element', CustomElement)
|
||||||
return this.otherMethod()
|
|
||||||
}
|
|
||||||
|
|
||||||
static method() {
|
expect(CustomElement.method()).to.equal(testSymbol)
|
||||||
return this.otherMethod()
|
|
||||||
}
|
|
||||||
|
|
||||||
static otherMethod() {
|
const customElement = new CustomElement()
|
||||||
return testSymbol
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
target.customElements.define('custom-element', CustomElement)
|
expect(customElement.method()).to.equal(testSymbol)
|
||||||
|
})
|
||||||
assert.equal(CustomElement.method(), testSymbol)
|
|
||||||
|
|
||||||
const customElement = new CustomElement()
|
|
||||||
|
|
||||||
assert.equal(customElement.method(), testSymbol)
|
|
||||||
},
|
|
||||||
},
|
|
||||||
]
|
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,142 +1,100 @@
|
||||||
import { assert, test } from '../run/test.setup.js'
|
import { expect } from 'chai'
|
||||||
import { polyfill } from '../mod.js'
|
import { polyfill } from '../mod.js'
|
||||||
|
|
||||||
test(() => {
|
describe('Fetch', () => {
|
||||||
return [
|
const target = {}
|
||||||
{
|
|
||||||
name: 'Fetch functionality',
|
|
||||||
test() {
|
|
||||||
const target = {}
|
|
||||||
|
|
||||||
polyfill(target)
|
before(() => polyfill(target))
|
||||||
|
|
||||||
assert.equal(Reflect.has(target, 'fetch'), true)
|
it('Fetch functionality', () => {
|
||||||
assert.equal(typeof target.fetch, 'function')
|
expect(target).to.have.property('fetch').that.is.a('function')
|
||||||
},
|
})
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'Fetch with https',
|
|
||||||
async test() {
|
|
||||||
const target = {}
|
|
||||||
|
|
||||||
polyfill(target)
|
it('Fetch with https', async () => {
|
||||||
|
const { fetch } = target
|
||||||
|
|
||||||
const { fetch } = target
|
const response = await fetch('https://api.openbrewerydb.org/breweries')
|
||||||
|
|
||||||
const response = await fetch('https://api.openbrewerydb.org/breweries')
|
expect(response.constructor).to.equal(target.Response)
|
||||||
|
|
||||||
assert.equal(response.constructor, target.Response)
|
const json = await response.json()
|
||||||
|
|
||||||
const json = await response.json()
|
expect(json).to.be.an('array')
|
||||||
|
})
|
||||||
|
|
||||||
assert.equal(Array.isArray(json), true)
|
it('Fetch with file', async () => {
|
||||||
},
|
const { fetch } = target
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'Fetch with file',
|
|
||||||
async test() {
|
|
||||||
const target = {}
|
|
||||||
|
|
||||||
polyfill(target)
|
const url = new URL('../package.json', import.meta.url)
|
||||||
|
|
||||||
const { fetch } = target
|
const response = await fetch(url)
|
||||||
|
|
||||||
const url = new URL('../package.json', import.meta.url)
|
expect(response.constructor).to.equal(target.Response)
|
||||||
|
|
||||||
const response = await fetch(url)
|
expect(response.status).to.equal(200)
|
||||||
|
expect(response.statusText).to.be.empty
|
||||||
|
expect(response.headers.has('date')).to.equal(true)
|
||||||
|
expect(response.headers.has('content-length')).to.equal(true)
|
||||||
|
expect(response.headers.has('last-modified')).to.equal(true)
|
||||||
|
|
||||||
assert.equal(response.constructor, target.Response)
|
const json = await response.json()
|
||||||
|
|
||||||
assert.equal(response.status, 200)
|
expect(json.name).to.equal('@astrojs/webapi')
|
||||||
assert.equal(response.statusText, '')
|
})
|
||||||
assert.equal(response.headers.has('date'), true)
|
|
||||||
assert.equal(response.headers.has('content-length'), true)
|
|
||||||
assert.equal(response.headers.has('last-modified'), true)
|
|
||||||
|
|
||||||
const json = await response.json()
|
it('Fetch with missing file', async () => {
|
||||||
|
const { fetch } = target
|
||||||
|
|
||||||
assert.equal(json.name, '@astrojs/webapi')
|
const url = new URL('../missing.json', import.meta.url)
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'Fetch with missing file',
|
|
||||||
async test() {
|
|
||||||
const target = {}
|
|
||||||
|
|
||||||
polyfill(target)
|
const response = await fetch(url)
|
||||||
|
|
||||||
const { fetch } = target
|
expect(response.constructor).to.equal(target.Response)
|
||||||
|
|
||||||
const url = new URL('../missing.json', import.meta.url)
|
expect(response.status).to.equal(404)
|
||||||
|
expect(response.statusText).to.be.empty
|
||||||
|
expect(response.headers.has('date')).to.equal(true)
|
||||||
|
expect(response.headers.has('content-length')).to.equal(false)
|
||||||
|
expect(response.headers.has('last-modified')).to.equal(false)
|
||||||
|
})
|
||||||
|
|
||||||
const response = await fetch(url)
|
it('Fetch with (file) Request', async () => {
|
||||||
|
const { Request, fetch } = target
|
||||||
|
|
||||||
assert.equal(response.constructor, target.Response)
|
const request = new Request(new URL('../package.json', import.meta.url))
|
||||||
|
|
||||||
assert.equal(response.status, 404)
|
const response = await fetch(request)
|
||||||
assert.equal(response.statusText, '')
|
|
||||||
assert.equal(response.headers.has('date'), true)
|
|
||||||
assert.equal(response.headers.has('content-length'), false)
|
|
||||||
assert.equal(response.headers.has('last-modified'), false)
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'Fetch with (file) Request',
|
|
||||||
async test() {
|
|
||||||
const target = {}
|
|
||||||
|
|
||||||
polyfill(target)
|
expect(response.constructor).to.equal(target.Response)
|
||||||
|
|
||||||
const { Request, fetch } = target
|
const json = await response.json()
|
||||||
|
|
||||||
const request = new Request(new URL('../package.json', import.meta.url))
|
expect(json.name).to.equal('@astrojs/webapi')
|
||||||
|
})
|
||||||
|
|
||||||
const response = await fetch(request)
|
it('Fetch with relative file', async () => {
|
||||||
|
const { fetch } = target
|
||||||
|
|
||||||
assert.equal(response.constructor, target.Response)
|
const response = await fetch('package.json')
|
||||||
|
|
||||||
const json = await response.json()
|
const json = await response.json()
|
||||||
|
|
||||||
assert.equal(json.name, '@astrojs/webapi')
|
expect(json.name).to.equal('@astrojs/webapi')
|
||||||
},
|
})
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'Fetch with relative file',
|
|
||||||
async test() {
|
|
||||||
const target = {}
|
|
||||||
|
|
||||||
polyfill(target)
|
it('Fetch with data', async () => {
|
||||||
|
const { fetch } = target
|
||||||
|
|
||||||
const { fetch } = target
|
const jsonURI = `data:application/json,${encodeURIComponent(
|
||||||
|
JSON.stringify({
|
||||||
|
name: '@astrojs/webapi',
|
||||||
|
})
|
||||||
|
)}`
|
||||||
|
|
||||||
const response = await fetch('package.json')
|
const response = await fetch(jsonURI)
|
||||||
|
|
||||||
const json = await response.json()
|
const json = await response.json()
|
||||||
|
|
||||||
assert.equal(json.name, '@astrojs/webapi')
|
expect(json.name).to.equal('@astrojs/webapi')
|
||||||
},
|
})
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'Fetch with data',
|
|
||||||
async test() {
|
|
||||||
const target = {}
|
|
||||||
|
|
||||||
polyfill(target)
|
|
||||||
|
|
||||||
const { fetch } = target
|
|
||||||
|
|
||||||
const jsonURI = `data:application/json,${encodeURIComponent(
|
|
||||||
JSON.stringify({
|
|
||||||
name: '@astrojs/webapi',
|
|
||||||
})
|
|
||||||
)}`
|
|
||||||
|
|
||||||
const response = await fetch(jsonURI)
|
|
||||||
|
|
||||||
const json = await response.json()
|
|
||||||
|
|
||||||
assert.equal(json.name, '@astrojs/webapi')
|
|
||||||
},
|
|
||||||
},
|
|
||||||
]
|
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,84 +1,54 @@
|
||||||
import { assert, test } from '../run/test.setup.js'
|
import { expect } from 'chai'
|
||||||
import { polyfill } from '../mod.js'
|
import { polyfill } from '../mod.js'
|
||||||
|
|
||||||
test(() => {
|
describe('ImageData', () => {
|
||||||
return [
|
const target = {}
|
||||||
{
|
|
||||||
name: 'Supports ImageData',
|
|
||||||
test() {
|
|
||||||
const target = {}
|
|
||||||
|
|
||||||
polyfill(target)
|
before(() => polyfill(target))
|
||||||
|
|
||||||
assert.equal('ImageData' in target, true)
|
it('Supports ImageData', () => {
|
||||||
assert.equal(typeof target['ImageData'], 'function')
|
expect(target).to.have.property('ImageData').that.is.a('function')
|
||||||
},
|
})
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'Supports new (data: Uint8ClampedArray, width: number, height: number): ImageData',
|
|
||||||
test() {
|
|
||||||
const target = {}
|
|
||||||
|
|
||||||
polyfill(target)
|
it('Supports new (data: Uint8ClampedArray, width: number, height: number): ImageData', () => {
|
||||||
|
const w = 640
|
||||||
|
const h = 480
|
||||||
|
const d = new Uint8ClampedArray(w * h * 4)
|
||||||
|
|
||||||
const w = 640
|
const id = new target.ImageData(d, w, h)
|
||||||
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)
|
||||||
|
})
|
||||||
|
|
||||||
assert.equal(id.data, d)
|
it('Supports new (data: Uint8ClampedArray, width: number): ImageData', () => {
|
||||||
assert.equal(id.width, w)
|
const w = 640
|
||||||
assert.equal(id.height, h)
|
const h = 480
|
||||||
},
|
const d = new Uint8ClampedArray(w * h * 4)
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'Supports new (data: Uint8ClampedArray, width: number): ImageData',
|
|
||||||
test() {
|
|
||||||
const target = {}
|
|
||||||
|
|
||||||
polyfill(target)
|
const id = new target.ImageData(d, w)
|
||||||
|
|
||||||
const w = 640
|
expect(id.data).to.equal(d)
|
||||||
const h = 480
|
expect(id.width).to.equal(w)
|
||||||
const d = new Uint8ClampedArray(w * h * 4)
|
expect(id.height).to.equal(h)
|
||||||
|
})
|
||||||
|
|
||||||
const id = new target.ImageData(d, w)
|
it('Supports new (width: number, height: number): ImageData', () => {
|
||||||
|
const w = 640
|
||||||
|
const h = 480
|
||||||
|
|
||||||
assert.equal(id.data, d)
|
const id = new target.ImageData(w, h)
|
||||||
assert.equal(id.width, w)
|
|
||||||
assert.equal(id.height, h)
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'Supports new (width: number, height: number): ImageData',
|
|
||||||
test() {
|
|
||||||
const target = {}
|
|
||||||
|
|
||||||
polyfill(target)
|
expect(id.data).to.have.lengthOf(w * h * 4)
|
||||||
|
expect(id.width).to.equal(w)
|
||||||
|
expect(id.height).to.equal(h)
|
||||||
|
})
|
||||||
|
|
||||||
const w = 640
|
it('Supports Object.keys(new ImageData(640, 480))', () => {
|
||||||
const h = 480
|
const keys = Object.keys(new target.ImageData(640, 480))
|
||||||
|
|
||||||
const id = new target.ImageData(w, h)
|
expect(keys).to.have.lengthOf(1)
|
||||||
|
expect(keys[0]).to.equal('data')
|
||||||
assert.equal(id.data.length, w * h * 4)
|
})
|
||||||
assert.equal(id.width, w)
|
|
||||||
assert.equal(id.height, h)
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'Supports Object.keys(new ImageData(640, 480))',
|
|
||||||
test() {
|
|
||||||
const target = {}
|
|
||||||
|
|
||||||
polyfill(target)
|
|
||||||
|
|
||||||
const keys = Object.keys(new target.ImageData(640, 480))
|
|
||||||
|
|
||||||
assert.equal(keys.length, 1)
|
|
||||||
assert.equal(keys[0], 'data')
|
|
||||||
},
|
|
||||||
},
|
|
||||||
]
|
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,34 +1,26 @@
|
||||||
import { assert, test } from '../run/test.setup.js'
|
import { expect } from 'chai'
|
||||||
import { polyfill } from '../mod.js'
|
import { polyfill } from '../mod.js'
|
||||||
|
|
||||||
test(() => {
|
it('Includes polyfill.internals functionality', () => {
|
||||||
return [
|
const target = {}
|
||||||
{
|
|
||||||
name: 'Includes polyfill.internals functionality',
|
|
||||||
test() {
|
|
||||||
const target = {}
|
|
||||||
|
|
||||||
polyfill(target, { exclude: 'window document' })
|
polyfill(target, { exclude: 'window document' })
|
||||||
|
|
||||||
const pseudo = { ...target }
|
const pseudo = { ...target }
|
||||||
|
|
||||||
assert.equal(Reflect.has(pseudo, 'document'), false)
|
expect(pseudo).to.not.have.property('document')
|
||||||
|
|
||||||
const CustomElement = class extends pseudo.HTMLElement {}
|
const CustomElement = class extends pseudo.HTMLElement {}
|
||||||
|
|
||||||
pseudo.customElements.define('custom-element', CustomElement)
|
pseudo.customElements.define('custom-element', CustomElement)
|
||||||
|
|
||||||
polyfill.internals(pseudo, 'Document')
|
polyfill.internals(pseudo, 'Document')
|
||||||
|
|
||||||
assert.equal(Reflect.has(pseudo, 'document'), true)
|
expect(pseudo).to.have.property('document')
|
||||||
|
|
||||||
assert.equal(
|
expect(
|
||||||
CustomElement.prototype.isPrototypeOf(
|
CustomElement.prototype.isPrototypeOf(
|
||||||
pseudo.document.createElement('custom-element')
|
pseudo.document.createElement('custom-element')
|
||||||
),
|
)
|
||||||
true
|
).to.equal(true)
|
||||||
)
|
|
||||||
},
|
|
||||||
},
|
|
||||||
]
|
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,31 +1,20 @@
|
||||||
import { assert, test } from '../run/test.setup.js'
|
import { expect } from 'chai'
|
||||||
import { polyfill } from '../mod.js'
|
import { polyfill } from '../mod.js'
|
||||||
|
|
||||||
test(() => {
|
describe('Media', () => {
|
||||||
return [
|
const target = {}
|
||||||
{
|
|
||||||
name: 'Includes MediaQueryList functionality',
|
|
||||||
test() {
|
|
||||||
const target = {}
|
|
||||||
|
|
||||||
polyfill(target)
|
before(() => polyfill(target))
|
||||||
|
|
||||||
assert.equal(Reflect.has(target, 'MediaQueryList'), true)
|
it('Includes MediaQueryList functionality', () => {
|
||||||
assert.equal(Reflect.has(target, 'matchMedia'), true)
|
expect(target).to.have.property('MediaQueryList')
|
||||||
},
|
expect(target).to.have.property('matchMedia')
|
||||||
},
|
})
|
||||||
{
|
|
||||||
name: 'Supports matchMedia creation',
|
|
||||||
test() {
|
|
||||||
const target = {}
|
|
||||||
|
|
||||||
polyfill(target)
|
it('Supports matchMedia creation', () => {
|
||||||
|
const mql = target.matchMedia('(min-width: 640px)')
|
||||||
|
|
||||||
const mql = target.matchMedia('(min-width: 640px)')
|
expect(mql.matches).to.equal(false)
|
||||||
|
expect(mql.media).to.equal('(min-width: 640px)')
|
||||||
assert.equal(mql.matches, false)
|
})
|
||||||
assert.equal(mql.media, '(min-width: 640px)')
|
|
||||||
},
|
|
||||||
},
|
|
||||||
]
|
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,57 +1,39 @@
|
||||||
import { assert, test } from '../run/test.setup.js'
|
import { expect } from 'chai'
|
||||||
import { polyfill } from '../mod.js'
|
import { polyfill } from '../mod.js'
|
||||||
|
|
||||||
test(() => {
|
describe('OffscreenCanvas', () => {
|
||||||
return [
|
const target = {}
|
||||||
{
|
|
||||||
name: 'Supports OffscreenCanvas',
|
|
||||||
test() {
|
|
||||||
const target = {}
|
|
||||||
|
|
||||||
polyfill(target)
|
before(() => polyfill(target))
|
||||||
|
|
||||||
assert.equal('OffscreenCanvas' in target, true)
|
it('Supports OffscreenCanvas', () => {
|
||||||
assert.equal(typeof target['OffscreenCanvas'], 'function')
|
expect(target).to.have.property('OffscreenCanvas').that.is.a('function')
|
||||||
},
|
})
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'Supports new (width: number, height: number): OffscreenCanvas',
|
|
||||||
test() {
|
|
||||||
const target = {}
|
|
||||||
|
|
||||||
polyfill(target)
|
it('Supports new (width: number, height: number): OffscreenCanvas', () => {
|
||||||
|
const w = 640
|
||||||
|
const h = 480
|
||||||
|
|
||||||
const w = 640
|
const canvas = new target.OffscreenCanvas(w, h)
|
||||||
const h = 480
|
|
||||||
|
|
||||||
const canvas = new target.OffscreenCanvas(w, h)
|
expect(canvas.width).to.equal(w)
|
||||||
|
expect(canvas.height).to.equal(h)
|
||||||
|
})
|
||||||
|
|
||||||
assert.equal(canvas.width, w)
|
it('Supports OffscreenCanvas#getContext', () => {
|
||||||
assert.equal(canvas.height, h)
|
const w = 640
|
||||||
},
|
const h = 480
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'Supports OffscreenCanvas#getContext',
|
|
||||||
test() {
|
|
||||||
const target = {}
|
|
||||||
|
|
||||||
polyfill(target)
|
const canvas = new target.OffscreenCanvas(w, h)
|
||||||
|
|
||||||
const w = 640
|
const context = canvas.getContext('2d')
|
||||||
const h = 480
|
|
||||||
|
|
||||||
const canvas = new target.OffscreenCanvas(w, h)
|
expect(context.canvas).to.equal(canvas)
|
||||||
|
|
||||||
const context = canvas.getContext('2d')
|
const imageData = context.createImageData(w, h)
|
||||||
|
|
||||||
assert.equal(context.canvas, canvas)
|
expect(imageData.width).to.equal(w)
|
||||||
|
expect(imageData.height).to.equal(h)
|
||||||
const imageData = context.createImageData(w, h)
|
expect(imageData.data).to.have.lengthOf(w * h * 4)
|
||||||
|
})
|
||||||
assert.equal(imageData.width, w)
|
|
||||||
assert.equal(imageData.height, h)
|
|
||||||
assert.equal(imageData.data.length, w * h * 4)
|
|
||||||
},
|
|
||||||
},
|
|
||||||
]
|
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,53 +1,44 @@
|
||||||
import { assert, test } from '../run/test.setup.js'
|
import { expect } from 'chai'
|
||||||
import { polyfill } from '../mod.js'
|
import { polyfill } from '../mod.js'
|
||||||
|
|
||||||
test(() => {
|
describe('Options', () => {
|
||||||
return [
|
it('Can exclude HTMLElement+', () => {
|
||||||
{
|
const target = {}
|
||||||
name: 'Can exclude HTMLElement+',
|
|
||||||
test() {
|
|
||||||
const target = {}
|
|
||||||
|
|
||||||
polyfill(target, {
|
polyfill(target, {
|
||||||
exclude: 'HTMLElement+',
|
exclude: 'HTMLElement+',
|
||||||
})
|
})
|
||||||
|
|
||||||
assert.equal(Reflect.has(target, 'Event'), true)
|
expect(target).to.have.property('Event')
|
||||||
assert.equal(Reflect.has(target, 'EventTarget'), true)
|
expect(target).to.have.property('EventTarget')
|
||||||
assert.equal(Reflect.has(target, 'Element'), true)
|
expect(target).to.have.property('Element')
|
||||||
assert.equal(Reflect.has(target, 'HTMLElement'), false)
|
expect(target).to.not.have.property('HTMLElement')
|
||||||
assert.equal(Reflect.has(target, 'HTMLDivElement'), false)
|
expect(target).to.not.have.property('HTMLDivElement')
|
||||||
},
|
})
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'Can exclude Event+',
|
|
||||||
test() {
|
|
||||||
const target = {}
|
|
||||||
|
|
||||||
polyfill(target, {
|
it('Can exclude Event+', () => {
|
||||||
exclude: 'Event+',
|
const target = {}
|
||||||
})
|
|
||||||
|
|
||||||
assert.equal(Reflect.has(target, 'Event'), false)
|
polyfill(target, {
|
||||||
assert.equal(Reflect.has(target, 'EventTarget'), false)
|
exclude: 'Event+',
|
||||||
assert.equal(Reflect.has(target, 'Element'), false)
|
})
|
||||||
assert.equal(Reflect.has(target, 'HTMLElement'), false)
|
|
||||||
assert.equal(Reflect.has(target, 'HTMLDivElement'), false)
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'Can exclude document',
|
|
||||||
test() {
|
|
||||||
const target = {}
|
|
||||||
|
|
||||||
polyfill(target, {
|
expect(target).to.not.have.property('Event')
|
||||||
exclude: 'document',
|
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')
|
||||||
|
})
|
||||||
|
|
||||||
assert.equal(Reflect.has(target, 'Document'), true)
|
it('Can exclude document', () => {
|
||||||
assert.equal(Reflect.has(target, 'HTMLDocument'), true)
|
const target = {}
|
||||||
assert.equal(Reflect.has(target, 'document'), false)
|
|
||||||
},
|
polyfill(target, {
|
||||||
},
|
exclude: 'document',
|
||||||
]
|
})
|
||||||
|
|
||||||
|
expect(target).to.have.property('Document')
|
||||||
|
expect(target).to.have.property('HTMLDocument')
|
||||||
|
expect(target).to.not.have.property('document')
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,45 +1,32 @@
|
||||||
import { assert, test } from '../run/test.setup.js'
|
import { expect } from 'chai'
|
||||||
import { polyfill } from '../mod.js'
|
import { polyfill } from '../mod.js'
|
||||||
|
|
||||||
test(() => {
|
describe('Storage', () => {
|
||||||
return [
|
const target = {}
|
||||||
{
|
|
||||||
name: 'Includes Storage functionality',
|
|
||||||
test() {
|
|
||||||
const target = {}
|
|
||||||
|
|
||||||
polyfill(target)
|
before(() => polyfill(target))
|
||||||
|
|
||||||
assert.equal(Reflect.has(target, 'Storage'), true)
|
it('Includes Storage functionality', () => {
|
||||||
assert.equal(Reflect.has(target, 'localStorage'), true)
|
expect(target).to.have.property('Storage').that.is.a('function')
|
||||||
assert.equal(typeof target.Storage, 'function')
|
expect(target).to.have.property('localStorage').that.is.an('object')
|
||||||
assert.equal(typeof target.localStorage, 'object')
|
})
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'Supports Storage methods',
|
|
||||||
test() {
|
|
||||||
const target = {}
|
|
||||||
|
|
||||||
polyfill(target)
|
it('Supports Storage methods', () => {
|
||||||
|
expect(target.localStorage.setItem('hello', 'world')).to.equal(undefined)
|
||||||
assert.equal(target.localStorage.setItem('hello', 'world'), undefined)
|
expect(target.localStorage.getItem('hello')).to.equal('world')
|
||||||
assert.equal(target.localStorage.getItem('hello'), 'world')
|
expect(target.localStorage.key(0)).to.equal('hello')
|
||||||
assert.equal(target.localStorage.key(0), 'hello')
|
expect(target.localStorage.key(1)).to.equal(null)
|
||||||
assert.equal(target.localStorage.key(1), null)
|
expect(target.localStorage.length).to.equal(1)
|
||||||
assert.equal(target.localStorage.length, 1)
|
expect(target.localStorage.setItem('world', 'hello')).to.equal(undefined)
|
||||||
assert.equal(target.localStorage.setItem('world', 'hello'), undefined)
|
expect(target.localStorage.key(1)).to.equal('world')
|
||||||
assert.equal(target.localStorage.key(1), 'world')
|
expect(target.localStorage.key(2)).to.equal(null)
|
||||||
assert.equal(target.localStorage.key(2), null)
|
expect(target.localStorage.length).to.equal(2)
|
||||||
assert.equal(target.localStorage.length, 2)
|
expect(target.localStorage.removeItem('hello')).to.equal(undefined)
|
||||||
assert.equal(target.localStorage.removeItem('hello'), undefined)
|
expect(target.localStorage.key(0)).to.equal('world')
|
||||||
assert.equal(target.localStorage.key(0), 'world')
|
expect(target.localStorage.key(1)).to.equal(null)
|
||||||
assert.equal(target.localStorage.key(1), null)
|
expect(target.localStorage.length).to.equal(1)
|
||||||
assert.equal(target.localStorage.length, 1)
|
expect(target.localStorage.clear()).to.equal(undefined)
|
||||||
assert.equal(target.localStorage.clear(), undefined)
|
expect(target.localStorage.key(0)).to.equal(null)
|
||||||
assert.equal(target.localStorage.key(0), null)
|
expect(target.localStorage.length).to.equal(0)
|
||||||
assert.equal(target.localStorage.length, 0)
|
})
|
||||||
},
|
|
||||||
},
|
|
||||||
]
|
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,40 +1,28 @@
|
||||||
import { assert, test } from '../run/test.setup.js'
|
import { expect } from 'chai'
|
||||||
import { polyfill } from '../mod.js'
|
import { polyfill } from '../mod.js'
|
||||||
|
|
||||||
test(() => {
|
describe('structuredClone', () => {
|
||||||
return [
|
const target = {}
|
||||||
{
|
|
||||||
name: 'Includes structuredClone',
|
|
||||||
test() {
|
|
||||||
const target = {}
|
|
||||||
|
|
||||||
polyfill(target)
|
before(() => polyfill(target))
|
||||||
|
|
||||||
assert.equal(Reflect.has(target, 'structuredClone'), true)
|
it('Includes structuredClone', () => {
|
||||||
assert.equal(typeof target.structuredClone, 'function')
|
expect(target).to.have.property('structuredClone').that.is.a('function')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('Supports structuredClone usage', () => {
|
||||||
|
const obj = {
|
||||||
|
foo: 'bar',
|
||||||
|
baz: {
|
||||||
|
qux: 'quux',
|
||||||
},
|
},
|
||||||
},
|
}
|
||||||
{
|
|
||||||
name: 'Supports structuredClone usage',
|
|
||||||
test() {
|
|
||||||
const target = {}
|
|
||||||
|
|
||||||
polyfill(target)
|
const clone = target.structuredClone(obj)
|
||||||
|
|
||||||
const obj = {
|
expect(obj).to.not.equal(clone)
|
||||||
foo: 'bar',
|
expect(obj.baz).to.not.equal(clone.baz)
|
||||||
baz: {
|
|
||||||
qux: 'quux',
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
const clone = target.structuredClone(obj)
|
expect(obj.baz.qux).to.equal(clone.baz.qux)
|
||||||
|
})
|
||||||
assert.notEqual(obj, clone)
|
|
||||||
assert.notEqual(obj.baz, clone.baz)
|
|
||||||
|
|
||||||
assert.equal(obj.baz.qux, clone.baz.qux)
|
|
||||||
},
|
|
||||||
},
|
|
||||||
]
|
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,31 +1,19 @@
|
||||||
import { assert, test } from '../run/test.setup.js'
|
import { expect } from 'chai'
|
||||||
import { polyfill } from '../mod.js'
|
import { polyfill } from '../mod.js'
|
||||||
|
|
||||||
test(() => {
|
describe('URLPattern', () => {
|
||||||
return [
|
const target = {}
|
||||||
{
|
|
||||||
name: 'Includes URLPattern',
|
|
||||||
test() {
|
|
||||||
const target = {}
|
|
||||||
|
|
||||||
polyfill(target)
|
before(() => polyfill(target))
|
||||||
|
|
||||||
assert.equal(Reflect.has(target, 'URLPattern'), true)
|
it('Includes URLPattern', () => {
|
||||||
assert.equal(typeof target.URLPattern, 'function')
|
expect(target).to.have.property('URLPattern').that.is.a('function')
|
||||||
},
|
})
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'Supports URLPattern usage',
|
|
||||||
test() {
|
|
||||||
const target = {}
|
|
||||||
|
|
||||||
polyfill(target)
|
it('Supports URLPattern usage', () => {
|
||||||
|
const pattern = new target.URLPattern({ pathname: '/hello/:name' })
|
||||||
|
const match = pattern.exec('https://example.com/hello/Deno')
|
||||||
|
|
||||||
const pattern = new target.URLPattern({ pathname: '/hello/:name' })
|
expect(match.pathname.groups).to.deep.equal({ name: 'Deno' })
|
||||||
const match = pattern.exec('https://example.com/hello/Deno')
|
})
|
||||||
|
|
||||||
assert.deepEqual(match.pathname.groups, { name: 'Deno' })
|
|
||||||
},
|
|
||||||
},
|
|
||||||
]
|
|
||||||
})
|
})
|
||||||
|
|
|
@ -1526,10 +1526,12 @@ importers:
|
||||||
'@rollup/plugin-inject': ^4.0.4
|
'@rollup/plugin-inject': ^4.0.4
|
||||||
'@rollup/plugin-node-resolve': ^13.1.3
|
'@rollup/plugin-node-resolve': ^13.1.3
|
||||||
'@rollup/plugin-typescript': ^8.3.1
|
'@rollup/plugin-typescript': ^8.3.1
|
||||||
|
'@types/chai': ^4.3.0
|
||||||
'@types/mocha': ^9.1.0
|
'@types/mocha': ^9.1.0
|
||||||
'@types/node': ^14.18.12
|
'@types/node': ^14.18.12
|
||||||
'@ungap/structured-clone': ^0.3.4
|
'@ungap/structured-clone': ^0.3.4
|
||||||
abort-controller: ^3.0.0
|
abort-controller: ^3.0.0
|
||||||
|
chai: ^4.3.6
|
||||||
event-target-shim: ^6.0.2
|
event-target-shim: ^6.0.2
|
||||||
fetch-blob: ^3.1.5
|
fetch-blob: ^3.1.5
|
||||||
formdata-polyfill: ^4.0.10
|
formdata-polyfill: ^4.0.10
|
||||||
|
@ -1546,10 +1548,12 @@ importers:
|
||||||
'@rollup/plugin-inject': 4.0.4_rollup@2.70.1
|
'@rollup/plugin-inject': 4.0.4_rollup@2.70.1
|
||||||
'@rollup/plugin-node-resolve': 13.1.3_rollup@2.70.1
|
'@rollup/plugin-node-resolve': 13.1.3_rollup@2.70.1
|
||||||
'@rollup/plugin-typescript': 8.3.1_8fb0118e9d69f3600cbb8f144f7d456c
|
'@rollup/plugin-typescript': 8.3.1_8fb0118e9d69f3600cbb8f144f7d456c
|
||||||
|
'@types/chai': 4.3.0
|
||||||
'@types/mocha': 9.1.0
|
'@types/mocha': 9.1.0
|
||||||
'@types/node': 14.18.12
|
'@types/node': 14.18.12
|
||||||
'@ungap/structured-clone': 0.3.4
|
'@ungap/structured-clone': 0.3.4
|
||||||
abort-controller: 3.0.0
|
abort-controller: 3.0.0
|
||||||
|
chai: 4.3.6
|
||||||
event-target-shim: 6.0.2
|
event-target-shim: 6.0.2
|
||||||
fetch-blob: 3.1.5
|
fetch-blob: 3.1.5
|
||||||
formdata-polyfill: 4.0.10
|
formdata-polyfill: 4.0.10
|
||||||
|
|
Loading…
Reference in a new issue