diff --git a/package.json b/package.json index 37a15e2..1235985 100644 --- a/package.json +++ b/package.json @@ -16,10 +16,11 @@ "examples": "serve .", "predeploy": "npm run test", "prepublishOnly": "npm run predeploy", - "test": "node test" + "test": "node test/index.js" }, "devDependencies": { "browser-env": "^3.3.0", + "resize-observer-polyfill": "^1.5.1", "serve": "^14.0.0", "tape": "^5.2.2" }, diff --git a/snabbdom-containerquery.js b/snabbdom-containerquery.js index 5ee30c4..dab071f 100644 --- a/snabbdom-containerquery.js +++ b/snabbdom-containerquery.js @@ -3,7 +3,7 @@ // today it's more performant to have 1 resizeObserver observe multiple elements rather than 1 per element. // see https://groups.google.com/a/chromium.org/g/blink-dev/c/z6ienONUb5A/m/F5-VcUZtBAAJ -const observer = new ResizeObserver(function (entries) { +const observer = new window.ResizeObserver(function (entries) { for (const entry of entries) { const breakpoints = JSON.parse(entry.target.dataset.breakpoints); diff --git a/test/index.js b/test/index.js new file mode 100644 index 0000000..15d96da --- /dev/null +++ b/test/index.js @@ -0,0 +1,15 @@ +import browserEnv from 'browser-env' +import ResizeObserver from 'resize-observer-polyfill' + + +browserEnv() + +// browser-env doesn't provide browser APIs beyond pure DOM/window stuff +window.ResizeObserver = ResizeObserver +window.requestAnimationFrame = function () { } + +async function main () { + await import('./test.js'); +} + +main(); diff --git a/test.js b/test/test.js similarity index 96% rename from test.js rename to test/test.js index 47b54c6..1232205 100644 --- a/test.js +++ b/test/test.js @@ -1,12 +1,8 @@ -import browserEnv from 'browser-env' -import snabby from './index.js' +import snabby from '../index.js' import { h } from 'snabbdom' // helper function for creating vnodes import test from 'tape' -browserEnv() - - test('creation', function (t) { t.plan(2)