0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-23 21:53:55 -05:00
astro/packages/webapi/test/offscreencanvas.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

58 lines
1.1 KiB
JavaScript
Raw Normal View History

import { assert, test } from '../run/test.setup.js'
import { polyfill } from '../mod.js'
test(() => {
return [
{
name: 'Supports OffscreenCanvas',
test() {
const target = {}
2022-03-07 16:37:50 -05:00
polyfill(target)
2022-03-07 16:37:50 -05:00
assert.equal('OffscreenCanvas' in target, true)
assert.equal(typeof target['OffscreenCanvas'], 'function')
},
},
{
name: 'Supports new (width: number, height: number): OffscreenCanvas',
test() {
const target = {}
2022-03-07 16:37:50 -05:00
polyfill(target)
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 = {}
2022-03-07 16:37:50 -05:00
polyfill(target)
const w = 640
const h = 480
const canvas = new target.OffscreenCanvas(w, h)
const context = canvas.getContext('2d')
assert.equal(context.canvas, 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)
},
},
]
})