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-node-resolve": "^13.1.3",
|
||||
"@rollup/plugin-typescript": "^8.3.1",
|
||||
"@types/chai": "^4.3.0",
|
||||
"@types/mocha": "^9.1.0",
|
||||
"@types/node": "^14.18.12",
|
||||
"@ungap/structured-clone": "^0.3.4",
|
||||
"abort-controller": "^3.0.0",
|
||||
"chai": "^4.3.6",
|
||||
"event-target-shim": "^6.0.2",
|
||||
"fetch-blob": "^3.1.5",
|
||||
"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'
|
||||
|
||||
test(() => {
|
||||
return [
|
||||
{
|
||||
name: 'Supports Base64 Methods',
|
||||
test() {
|
||||
describe('Base64', () => {
|
||||
const target = {}
|
||||
|
||||
polyfill(target)
|
||||
before(() => polyfill(target))
|
||||
|
||||
assert.equal('atob' in target, true)
|
||||
assert.equal('btoa' in target, true)
|
||||
assert.equal(typeof target['atob'], 'function')
|
||||
assert.equal(typeof target['btoa'], 'function')
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'Supports atob(data)',
|
||||
test() {
|
||||
const target = {}
|
||||
|
||||
polyfill(target)
|
||||
it('Supports Base64 Methods', () => {
|
||||
expect(target).to.have.property('atob').that.is.a('function')
|
||||
expect(target).to.have.property('btoa').that.is.a('function')
|
||||
})
|
||||
|
||||
it('Supports atob(data)', () => {
|
||||
const a = 'SGVsbG8sIHdvcmxk'
|
||||
const b = target.atob(a)
|
||||
|
||||
assert.equal(a, 'SGVsbG8sIHdvcmxk')
|
||||
assert.equal(b, 'Hello, world')
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'Supports btoa(data)',
|
||||
test() {
|
||||
const target = {}
|
||||
|
||||
polyfill(target)
|
||||
expect(a).to.equal('SGVsbG8sIHdvcmxk')
|
||||
expect(b).to.equal('Hello, world')
|
||||
})
|
||||
|
||||
it('Supports btoa(data)', () => {
|
||||
const b = 'Hello, world'
|
||||
const a = target.btoa(b)
|
||||
|
||||
assert.equal(a, 'SGVsbG8sIHdvcmxk')
|
||||
assert.equal(b, 'Hello, world')
|
||||
},
|
||||
},
|
||||
]
|
||||
expect(a).to.equal('SGVsbG8sIHdvcmxk')
|
||||
expect(b).to.equal('Hello, world')
|
||||
})
|
||||
})
|
||||
|
|
|
@ -1,13 +1,10 @@
|
|||
import { assert, test } from '../run/test.setup.js'
|
||||
import { expect } from 'chai'
|
||||
import { polyfill } from '../mod.js'
|
||||
|
||||
test(() => {
|
||||
polyfill(globalThis)
|
||||
describe('Basic', () => {
|
||||
before(() => polyfill(globalThis))
|
||||
|
||||
return [
|
||||
{
|
||||
name: 'Globals exist',
|
||||
test() {
|
||||
it('Globals exist', () => {
|
||||
const webAPIs = [
|
||||
'AbortController',
|
||||
'AbortSignal',
|
||||
|
@ -65,27 +62,21 @@ test(() => {
|
|||
]
|
||||
|
||||
for (const name of webAPIs) {
|
||||
assert.equal(typeof globalThis[name], 'function')
|
||||
expect(globalThis[name]).to.be.a('function')
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'Constructs an Event',
|
||||
test() {
|
||||
})
|
||||
|
||||
it('Constructs an Event', () => {
|
||||
const e = new Event('test')
|
||||
|
||||
assert.equal(e.type, 'test')
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'Constructs an EventTarget',
|
||||
test() {
|
||||
const t = new EventTarget()
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'Dispatches an Event on an EventTarget',
|
||||
test() {
|
||||
expect(e.type).to.equal('test')
|
||||
})
|
||||
|
||||
it('Constructs an EventTarget', () => {
|
||||
const _t = new EventTarget()
|
||||
})
|
||||
|
||||
it('Dispatches an Event on an EventTarget', () => {
|
||||
const t = new EventTarget()
|
||||
|
||||
let pass = false
|
||||
|
@ -98,108 +89,90 @@ test(() => {
|
|||
|
||||
t.dispatchEvent(e)
|
||||
|
||||
assert.equal(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() {
|
||||
expect(pass).to.equal(true)
|
||||
})
|
||||
|
||||
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')
|
||||
|
||||
assert.equal(element.innerHTML, '')
|
||||
expect(element.innerHTML).to.be.empty
|
||||
element.innerHTML = 'frozen'
|
||||
assert.equal(element.innerHTML, '')
|
||||
expect(element.innerHTML).to.be.empty
|
||||
|
||||
assert.equal(element.textContent, '')
|
||||
expect(element.textContent).to.be.empty
|
||||
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)
|
||||
expect(element.textContent).to.be.empty
|
||||
})
|
||||
|
||||
it('globalThis.window === globalThis', () => {
|
||||
expect(globalThis.window).to.equal(globalThis)
|
||||
})
|
||||
|
||||
it('Relative Indexing Method (String#at)', () => {
|
||||
expect(String.prototype.at).to.be.a('function')
|
||||
expect(String.prototype.at.length).to.equal(1)
|
||||
|
||||
const example = 'The quick brown fox jumps over the lazy dog.'
|
||||
|
||||
assert.equal(example.at(2), 'e')
|
||||
assert.equal(example.at(-2), 'g')
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'Relative Indexing Method (Array#at)',
|
||||
test() {
|
||||
assert.equal(typeof Array.prototype.at, 'function')
|
||||
assert.equal(Array.prototype.at.length, 1)
|
||||
expect(example.at(2)).to.equal('e')
|
||||
expect(example.at(-2)).to.equal('g')
|
||||
})
|
||||
|
||||
it('Relative Indexing Method (Array#at)', () => {
|
||||
expect(Array.prototype.at).to.be.a('function')
|
||||
expect(Array.prototype.at.length).to.equal(1)
|
||||
|
||||
const example = [1, 3, 5, 7, 9]
|
||||
|
||||
assert.equal(example.at(1), 3)
|
||||
assert.equal(example.at(-1), 9)
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'Relative Indexing Method (TypedArray#at)',
|
||||
test() {
|
||||
assert.equal(typeof Int8Array.prototype.at, 'function')
|
||||
assert.equal(Int8Array.prototype.at.length, 1)
|
||||
expect(example.at(1)).to.equal(3)
|
||||
expect(example.at(-1)).to.equal(9)
|
||||
})
|
||||
|
||||
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])
|
||||
|
||||
assert.equal(example.at(1), 3)
|
||||
assert.equal(example.at(-1), 9)
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'Object.hasOwn',
|
||||
test() {
|
||||
assert.equal(typeof Object.hasOwn, 'function')
|
||||
assert.equal(Object.hasOwn.length, 2)
|
||||
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 = {}
|
||||
|
||||
assert.equal(Object.hasOwn(example, 'prop'), false)
|
||||
expect(Object.hasOwn(example, 'prop')).to.equal(false)
|
||||
|
||||
example.prop = 'exists'
|
||||
|
||||
assert.equal(Object.hasOwn(example, 'prop'), true)
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'Promise.any',
|
||||
test() {
|
||||
assert.equal(typeof Promise.any, 'function')
|
||||
assert.equal(Promise.any.length, 1)
|
||||
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) => {
|
||||
assert.equal(result, 42)
|
||||
expect(result).to.equal(42)
|
||||
})
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'String#replaceAll',
|
||||
test() {
|
||||
assert.equal(typeof String.prototype.replaceAll, 'function')
|
||||
assert.equal(String.prototype.replaceAll.length, 2)
|
||||
})
|
||||
|
||||
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.'
|
||||
|
@ -207,8 +180,6 @@ test(() => {
|
|||
const t3 =
|
||||
'Of all the philosophers in Harry Potter, Halo is my favorite philosopher.'
|
||||
|
||||
assert.equal(t2, t3)
|
||||
},
|
||||
},
|
||||
]
|
||||
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'
|
||||
|
||||
test(() => {
|
||||
return [
|
||||
{
|
||||
name: 'Includes CharacterData functionality',
|
||||
test() {
|
||||
describe('CharacterData', () => {
|
||||
const target = {}
|
||||
|
||||
polyfill(target)
|
||||
before(() => polyfill(target))
|
||||
|
||||
assert.equal(Reflect.has(target, 'CharacterData'), true)
|
||||
assert.equal(Reflect.has(target, 'Text'), true)
|
||||
assert.equal(Reflect.has(target, 'Comment'), true)
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'Throws new CharacterData',
|
||||
test() {
|
||||
const target = {}
|
||||
|
||||
polyfill(target)
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'Supports new Comment',
|
||||
test() {
|
||||
const target = polyfill({})
|
||||
|
||||
assert.doesNotThrow(() => {
|
||||
new target.Comment()
|
||||
it('Includes CharacterData functionality', () => {
|
||||
expect(target).to.have.property('CharacterData')
|
||||
expect(target).to.have.property('Text')
|
||||
expect(target).to.have.property('Comment')
|
||||
})
|
||||
|
||||
assert.equal(new target.Comment().constructor.name, 'Comment')
|
||||
assert.equal(
|
||||
Object.prototype.toString.call(new target.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]'
|
||||
)
|
||||
|
||||
assert.equal(new target.Comment('hello').data, 'hello')
|
||||
assert.equal(new target.Comment('hello').textContent, 'hello')
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'Supports new Text',
|
||||
test() {
|
||||
const target = polyfill({})
|
||||
|
||||
assert.doesNotThrow(() => {
|
||||
new target.Text()
|
||||
expect(new target.Comment('hello').data).to.equal('hello')
|
||||
expect(new target.Comment('hello').textContent).to.equal('hello')
|
||||
})
|
||||
|
||||
assert.equal(new target.Text().constructor.name, 'Text')
|
||||
assert.equal(
|
||||
Object.prototype.toString.call(new target.Text()),
|
||||
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]'
|
||||
)
|
||||
|
||||
assert.equal(new target.Text('hello').data, 'hello')
|
||||
assert.equal(new target.Text('hello').textContent, 'hello')
|
||||
},
|
||||
},
|
||||
]
|
||||
expect(new target.Text('hello').data).to.equal('hello')
|
||||
expect(new target.Text('hello').textContent).to.equal('hello')
|
||||
})
|
||||
})
|
||||
|
|
|
@ -1,70 +1,46 @@
|
|||
import { assert, test } from '../run/test.setup.js'
|
||||
import { expect } from 'chai'
|
||||
import { polyfill } from '../mod.js'
|
||||
|
||||
test(() => {
|
||||
return [
|
||||
{
|
||||
name: 'Includes Custom Element functionality',
|
||||
test() {
|
||||
describe('Custom Elements', () => {
|
||||
const target = {}
|
||||
|
||||
polyfill(target)
|
||||
beforeEach(() => polyfill(target))
|
||||
|
||||
assert.equal(Reflect.has(target, 'CustomElementRegistry'), true)
|
||||
assert.equal(Reflect.has(target, 'customElements'), true)
|
||||
assert.equal(Reflect.has(target, 'HTMLElement'), true)
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'Supports Custom Element creation',
|
||||
test() {
|
||||
const target = {}
|
||||
|
||||
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)
|
||||
|
||||
assert.equal(target.customElements.get('custom-element'), CustomElement)
|
||||
assert.equal(
|
||||
target.customElements.getName(CustomElement),
|
||||
expect(target.customElements.get('custom-element')).to.equal(CustomElement)
|
||||
expect(target.customElements.getName(CustomElement)).to.equal(
|
||||
'custom-element'
|
||||
)
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'Supports Custom Elements created from Document',
|
||||
test() {
|
||||
const target = {}
|
||||
})
|
||||
|
||||
polyfill(target)
|
||||
it('Supports Custom Elements created from Document', () => {
|
||||
expect(target.document.body.localName).to.equal('body')
|
||||
expect(target.document.body.tagName).to.equal('BODY')
|
||||
|
||||
assert.equal(target.document.body.localName, 'body')
|
||||
assert.equal(target.document.body.tagName, 'BODY')
|
||||
|
||||
assert.equal(
|
||||
target.document.createElement('custom-element').constructor.name,
|
||||
'HTMLUnknownElement'
|
||||
)
|
||||
expect(
|
||||
target.document.createElement('custom-element').constructor.name
|
||||
).to.equal('HTMLUnknownElement')
|
||||
|
||||
const CustomElement = class HTMLCustomElement extends target.HTMLElement {}
|
||||
|
||||
target.customElements.define('custom-element', CustomElement)
|
||||
|
||||
assert.equal(
|
||||
target.document.createElement('custom-element').constructor.name,
|
||||
'HTMLCustomElement'
|
||||
)
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'Supports Custom Elements with properties',
|
||||
test() {
|
||||
const target = {}
|
||||
|
||||
polyfill(target)
|
||||
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 {
|
||||
|
@ -85,12 +61,10 @@ test(() => {
|
|||
|
||||
target.customElements.define('custom-element', CustomElement)
|
||||
|
||||
assert.equal(CustomElement.method(), testSymbol)
|
||||
expect(CustomElement.method()).to.equal(testSymbol)
|
||||
|
||||
const customElement = new CustomElement()
|
||||
|
||||
assert.equal(customElement.method(), testSymbol)
|
||||
},
|
||||
},
|
||||
]
|
||||
expect(customElement.method()).to.equal(testSymbol)
|
||||
})
|
||||
})
|
||||
|
|
|
@ -1,128 +1,88 @@
|
|||
import { assert, test } from '../run/test.setup.js'
|
||||
import { expect } from 'chai'
|
||||
import { polyfill } from '../mod.js'
|
||||
|
||||
test(() => {
|
||||
return [
|
||||
{
|
||||
name: 'Fetch functionality',
|
||||
test() {
|
||||
describe('Fetch', () => {
|
||||
const target = {}
|
||||
|
||||
polyfill(target)
|
||||
before(() => polyfill(target))
|
||||
|
||||
assert.equal(Reflect.has(target, 'fetch'), true)
|
||||
assert.equal(typeof target.fetch, 'function')
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'Fetch with https',
|
||||
async test() {
|
||||
const target = {}
|
||||
|
||||
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://api.openbrewerydb.org/breweries')
|
||||
|
||||
assert.equal(response.constructor, target.Response)
|
||||
expect(response.constructor).to.equal(target.Response)
|
||||
|
||||
const json = await response.json()
|
||||
|
||||
assert.equal(Array.isArray(json), true)
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'Fetch with file',
|
||||
async test() {
|
||||
const target = {}
|
||||
|
||||
polyfill(target)
|
||||
expect(json).to.be.an('array')
|
||||
})
|
||||
|
||||
it('Fetch with file', async () => {
|
||||
const { fetch } = target
|
||||
|
||||
const url = new URL('../package.json', import.meta.url)
|
||||
|
||||
const response = await fetch(url)
|
||||
|
||||
assert.equal(response.constructor, target.Response)
|
||||
expect(response.constructor).to.equal(target.Response)
|
||||
|
||||
assert.equal(response.status, 200)
|
||||
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)
|
||||
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)
|
||||
|
||||
const json = await response.json()
|
||||
|
||||
assert.equal(json.name, '@astrojs/webapi')
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'Fetch with missing file',
|
||||
async test() {
|
||||
const target = {}
|
||||
|
||||
polyfill(target)
|
||||
expect(json.name).to.equal('@astrojs/webapi')
|
||||
})
|
||||
|
||||
it('Fetch with missing file', async () => {
|
||||
const { fetch } = target
|
||||
|
||||
const url = new URL('../missing.json', import.meta.url)
|
||||
|
||||
const response = await fetch(url)
|
||||
|
||||
assert.equal(response.constructor, target.Response)
|
||||
expect(response.constructor).to.equal(target.Response)
|
||||
|
||||
assert.equal(response.status, 404)
|
||||
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.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)
|
||||
})
|
||||
|
||||
it('Fetch with (file) Request', async () => {
|
||||
const { Request, fetch } = target
|
||||
|
||||
const request = new Request(new URL('../package.json', import.meta.url))
|
||||
|
||||
const response = await fetch(request)
|
||||
|
||||
assert.equal(response.constructor, target.Response)
|
||||
expect(response.constructor).to.equal(target.Response)
|
||||
|
||||
const json = await response.json()
|
||||
|
||||
assert.equal(json.name, '@astrojs/webapi')
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'Fetch with relative file',
|
||||
async test() {
|
||||
const target = {}
|
||||
|
||||
polyfill(target)
|
||||
expect(json.name).to.equal('@astrojs/webapi')
|
||||
})
|
||||
|
||||
it('Fetch with relative file', async () => {
|
||||
const { fetch } = target
|
||||
|
||||
const response = await fetch('package.json')
|
||||
|
||||
const json = await response.json()
|
||||
|
||||
assert.equal(json.name, '@astrojs/webapi')
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'Fetch with data',
|
||||
async test() {
|
||||
const target = {}
|
||||
|
||||
polyfill(target)
|
||||
expect(json.name).to.equal('@astrojs/webapi')
|
||||
})
|
||||
|
||||
it('Fetch with data', async () => {
|
||||
const { fetch } = target
|
||||
|
||||
const jsonURI = `data:application/json,${encodeURIComponent(
|
||||
|
@ -135,8 +95,6 @@ test(() => {
|
|||
|
||||
const json = await response.json()
|
||||
|
||||
assert.equal(json.name, '@astrojs/webapi')
|
||||
},
|
||||
},
|
||||
]
|
||||
expect(json.name).to.equal('@astrojs/webapi')
|
||||
})
|
||||
})
|
||||
|
|
|
@ -1,84 +1,54 @@
|
|||
import { assert, test } from '../run/test.setup.js'
|
||||
import { expect } from 'chai'
|
||||
import { polyfill } from '../mod.js'
|
||||
|
||||
test(() => {
|
||||
return [
|
||||
{
|
||||
name: 'Supports ImageData',
|
||||
test() {
|
||||
describe('ImageData', () => {
|
||||
const target = {}
|
||||
|
||||
polyfill(target)
|
||||
before(() => polyfill(target))
|
||||
|
||||
assert.equal('ImageData' in target, true)
|
||||
assert.equal(typeof target['ImageData'], 'function')
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'Supports new (data: Uint8ClampedArray, width: number, height: number): ImageData',
|
||||
test() {
|
||||
const target = {}
|
||||
|
||||
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)
|
||||
|
||||
assert.equal(id.data, d)
|
||||
assert.equal(id.width, w)
|
||||
assert.equal(id.height, h)
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'Supports new (data: Uint8ClampedArray, width: number): ImageData',
|
||||
test() {
|
||||
const target = {}
|
||||
|
||||
polyfill(target)
|
||||
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)
|
||||
|
||||
assert.equal(id.data, d)
|
||||
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.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)
|
||||
|
||||
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)
|
||||
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))
|
||||
|
||||
assert.equal(keys.length, 1)
|
||||
assert.equal(keys[0], 'data')
|
||||
},
|
||||
},
|
||||
]
|
||||
expect(keys).to.have.lengthOf(1)
|
||||
expect(keys[0]).to.equal('data')
|
||||
})
|
||||
})
|
||||
|
|
|
@ -1,18 +1,14 @@
|
|||
import { assert, test } from '../run/test.setup.js'
|
||||
import { expect } from 'chai'
|
||||
import { polyfill } from '../mod.js'
|
||||
|
||||
test(() => {
|
||||
return [
|
||||
{
|
||||
name: 'Includes polyfill.internals functionality',
|
||||
test() {
|
||||
it('Includes polyfill.internals functionality', () => {
|
||||
const target = {}
|
||||
|
||||
polyfill(target, { exclude: 'window document' })
|
||||
|
||||
const pseudo = { ...target }
|
||||
|
||||
assert.equal(Reflect.has(pseudo, 'document'), false)
|
||||
expect(pseudo).to.not.have.property('document')
|
||||
|
||||
const CustomElement = class extends pseudo.HTMLElement {}
|
||||
|
||||
|
@ -20,15 +16,11 @@ test(() => {
|
|||
|
||||
polyfill.internals(pseudo, 'Document')
|
||||
|
||||
assert.equal(Reflect.has(pseudo, 'document'), true)
|
||||
expect(pseudo).to.have.property('document')
|
||||
|
||||
assert.equal(
|
||||
expect(
|
||||
CustomElement.prototype.isPrototypeOf(
|
||||
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'
|
||||
|
||||
test(() => {
|
||||
return [
|
||||
{
|
||||
name: 'Includes MediaQueryList functionality',
|
||||
test() {
|
||||
describe('Media', () => {
|
||||
const target = {}
|
||||
|
||||
polyfill(target)
|
||||
before(() => polyfill(target))
|
||||
|
||||
assert.equal(Reflect.has(target, 'MediaQueryList'), true)
|
||||
assert.equal(Reflect.has(target, 'matchMedia'), true)
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'Supports matchMedia creation',
|
||||
test() {
|
||||
const target = {}
|
||||
|
||||
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)')
|
||||
|
||||
assert.equal(mql.matches, false)
|
||||
assert.equal(mql.media, '(min-width: 640px)')
|
||||
},
|
||||
},
|
||||
]
|
||||
expect(mql.matches).to.equal(false)
|
||||
expect(mql.media).to.equal('(min-width: 640px)')
|
||||
})
|
||||
})
|
||||
|
|
|
@ -1,42 +1,26 @@
|
|||
import { assert, test } from '../run/test.setup.js'
|
||||
import { expect } from 'chai'
|
||||
import { polyfill } from '../mod.js'
|
||||
|
||||
test(() => {
|
||||
return [
|
||||
{
|
||||
name: 'Supports OffscreenCanvas',
|
||||
test() {
|
||||
describe('OffscreenCanvas', () => {
|
||||
const target = {}
|
||||
|
||||
polyfill(target)
|
||||
before(() => polyfill(target))
|
||||
|
||||
assert.equal('OffscreenCanvas' in target, true)
|
||||
assert.equal(typeof target['OffscreenCanvas'], 'function')
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'Supports new (width: number, height: number): OffscreenCanvas',
|
||||
test() {
|
||||
const target = {}
|
||||
|
||||
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)
|
||||
|
||||
assert.equal(canvas.width, w)
|
||||
assert.equal(canvas.height, h)
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'Supports OffscreenCanvas#getContext',
|
||||
test() {
|
||||
const target = {}
|
||||
|
||||
polyfill(target)
|
||||
expect(canvas.width).to.equal(w)
|
||||
expect(canvas.height).to.equal(h)
|
||||
})
|
||||
|
||||
it('Supports OffscreenCanvas#getContext', () => {
|
||||
const w = 640
|
||||
const h = 480
|
||||
|
||||
|
@ -44,14 +28,12 @@ test(() => {
|
|||
|
||||
const context = canvas.getContext('2d')
|
||||
|
||||
assert.equal(context.canvas, canvas)
|
||||
expect(context.canvas).to.equal(canvas)
|
||||
|
||||
const imageData = context.createImageData(w, h)
|
||||
|
||||
assert.equal(imageData.width, w)
|
||||
assert.equal(imageData.height, h)
|
||||
assert.equal(imageData.data.length, w * h * 4)
|
||||
},
|
||||
},
|
||||
]
|
||||
expect(imageData.width).to.equal(w)
|
||||
expect(imageData.height).to.equal(h)
|
||||
expect(imageData.data).to.have.lengthOf(w * h * 4)
|
||||
})
|
||||
})
|
||||
|
|
|
@ -1,53 +1,44 @@
|
|||
import { assert, test } from '../run/test.setup.js'
|
||||
import { expect } from 'chai'
|
||||
import { polyfill } from '../mod.js'
|
||||
|
||||
test(() => {
|
||||
return [
|
||||
{
|
||||
name: 'Can exclude HTMLElement+',
|
||||
test() {
|
||||
describe('Options', () => {
|
||||
it('Can exclude HTMLElement+', () => {
|
||||
const target = {}
|
||||
|
||||
polyfill(target, {
|
||||
exclude: 'HTMLElement+',
|
||||
})
|
||||
|
||||
assert.equal(Reflect.has(target, 'Event'), true)
|
||||
assert.equal(Reflect.has(target, 'EventTarget'), true)
|
||||
assert.equal(Reflect.has(target, 'Element'), true)
|
||||
assert.equal(Reflect.has(target, 'HTMLElement'), false)
|
||||
assert.equal(Reflect.has(target, 'HTMLDivElement'), false)
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'Can exclude Event+',
|
||||
test() {
|
||||
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+',
|
||||
})
|
||||
|
||||
assert.equal(Reflect.has(target, 'Event'), false)
|
||||
assert.equal(Reflect.has(target, 'EventTarget'), false)
|
||||
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() {
|
||||
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',
|
||||
})
|
||||
|
||||
assert.equal(Reflect.has(target, 'Document'), true)
|
||||
assert.equal(Reflect.has(target, 'HTMLDocument'), true)
|
||||
assert.equal(Reflect.has(target, 'document'), false)
|
||||
},
|
||||
},
|
||||
]
|
||||
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'
|
||||
|
||||
test(() => {
|
||||
return [
|
||||
{
|
||||
name: 'Includes Storage functionality',
|
||||
test() {
|
||||
describe('Storage', () => {
|
||||
const target = {}
|
||||
|
||||
polyfill(target)
|
||||
before(() => polyfill(target))
|
||||
|
||||
assert.equal(Reflect.has(target, 'Storage'), true)
|
||||
assert.equal(Reflect.has(target, 'localStorage'), true)
|
||||
assert.equal(typeof target.Storage, 'function')
|
||||
assert.equal(typeof target.localStorage, 'object')
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'Supports Storage methods',
|
||||
test() {
|
||||
const target = {}
|
||||
|
||||
polyfill(target)
|
||||
|
||||
assert.equal(target.localStorage.setItem('hello', 'world'), undefined)
|
||||
assert.equal(target.localStorage.getItem('hello'), 'world')
|
||||
assert.equal(target.localStorage.key(0), 'hello')
|
||||
assert.equal(target.localStorage.key(1), null)
|
||||
assert.equal(target.localStorage.length, 1)
|
||||
assert.equal(target.localStorage.setItem('world', 'hello'), undefined)
|
||||
assert.equal(target.localStorage.key(1), 'world')
|
||||
assert.equal(target.localStorage.key(2), null)
|
||||
assert.equal(target.localStorage.length, 2)
|
||||
assert.equal(target.localStorage.removeItem('hello'), undefined)
|
||||
assert.equal(target.localStorage.key(0), 'world')
|
||||
assert.equal(target.localStorage.key(1), null)
|
||||
assert.equal(target.localStorage.length, 1)
|
||||
assert.equal(target.localStorage.clear(), undefined)
|
||||
assert.equal(target.localStorage.key(0), null)
|
||||
assert.equal(target.localStorage.length, 0)
|
||||
},
|
||||
},
|
||||
]
|
||||
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)
|
||||
})
|
||||
})
|
||||
|
|
|
@ -1,26 +1,16 @@
|
|||
import { assert, test } from '../run/test.setup.js'
|
||||
import { expect } from 'chai'
|
||||
import { polyfill } from '../mod.js'
|
||||
|
||||
test(() => {
|
||||
return [
|
||||
{
|
||||
name: 'Includes structuredClone',
|
||||
test() {
|
||||
describe('structuredClone', () => {
|
||||
const target = {}
|
||||
|
||||
polyfill(target)
|
||||
before(() => polyfill(target))
|
||||
|
||||
assert.equal(Reflect.has(target, 'structuredClone'), true)
|
||||
assert.equal(typeof target.structuredClone, 'function')
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'Supports structuredClone usage',
|
||||
test() {
|
||||
const target = {}
|
||||
|
||||
polyfill(target)
|
||||
it('Includes structuredClone', () => {
|
||||
expect(target).to.have.property('structuredClone').that.is.a('function')
|
||||
})
|
||||
|
||||
it('Supports structuredClone usage', () => {
|
||||
const obj = {
|
||||
foo: 'bar',
|
||||
baz: {
|
||||
|
@ -30,11 +20,9 @@ test(() => {
|
|||
|
||||
const clone = target.structuredClone(obj)
|
||||
|
||||
assert.notEqual(obj, clone)
|
||||
assert.notEqual(obj.baz, clone.baz)
|
||||
expect(obj).to.not.equal(clone)
|
||||
expect(obj.baz).to.not.equal(clone.baz)
|
||||
|
||||
assert.equal(obj.baz.qux, clone.baz.qux)
|
||||
},
|
||||
},
|
||||
]
|
||||
expect(obj.baz.qux).to.equal(clone.baz.qux)
|
||||
})
|
||||
})
|
||||
|
|
|
@ -1,31 +1,19 @@
|
|||
import { assert, test } from '../run/test.setup.js'
|
||||
import { expect } from 'chai'
|
||||
import { polyfill } from '../mod.js'
|
||||
|
||||
test(() => {
|
||||
return [
|
||||
{
|
||||
name: 'Includes URLPattern',
|
||||
test() {
|
||||
describe('URLPattern', () => {
|
||||
const target = {}
|
||||
|
||||
polyfill(target)
|
||||
before(() => polyfill(target))
|
||||
|
||||
assert.equal(Reflect.has(target, 'URLPattern'), true)
|
||||
assert.equal(typeof target.URLPattern, 'function')
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'Supports URLPattern usage',
|
||||
test() {
|
||||
const target = {}
|
||||
|
||||
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')
|
||||
|
||||
assert.deepEqual(match.pathname.groups, { name: 'Deno' })
|
||||
},
|
||||
},
|
||||
]
|
||||
expect(match.pathname.groups).to.deep.equal({ name: 'Deno' })
|
||||
})
|
||||
})
|
||||
|
|
|
@ -1526,10 +1526,12 @@ importers:
|
|||
'@rollup/plugin-inject': ^4.0.4
|
||||
'@rollup/plugin-node-resolve': ^13.1.3
|
||||
'@rollup/plugin-typescript': ^8.3.1
|
||||
'@types/chai': ^4.3.0
|
||||
'@types/mocha': ^9.1.0
|
||||
'@types/node': ^14.18.12
|
||||
'@ungap/structured-clone': ^0.3.4
|
||||
abort-controller: ^3.0.0
|
||||
chai: ^4.3.6
|
||||
event-target-shim: ^6.0.2
|
||||
fetch-blob: ^3.1.5
|
||||
formdata-polyfill: ^4.0.10
|
||||
|
@ -1546,10 +1548,12 @@ importers:
|
|||
'@rollup/plugin-inject': 4.0.4_rollup@2.70.1
|
||||
'@rollup/plugin-node-resolve': 13.1.3_rollup@2.70.1
|
||||
'@rollup/plugin-typescript': 8.3.1_8fb0118e9d69f3600cbb8f144f7d456c
|
||||
'@types/chai': 4.3.0
|
||||
'@types/mocha': 9.1.0
|
||||
'@types/node': 14.18.12
|
||||
'@ungap/structured-clone': 0.3.4
|
||||
abort-controller: 3.0.0
|
||||
chai: 4.3.6
|
||||
event-target-shim: 6.0.2
|
||||
fetch-blob: 3.1.5
|
||||
formdata-polyfill: 4.0.10
|
||||
|
|
Loading…
Reference in a new issue