diff --git a/packages/global-jsdom/esm/index.mjs b/packages/global-jsdom/esm/index.mjs index 6bd8ab4..eb2450f 100644 --- a/packages/global-jsdom/esm/index.mjs +++ b/packages/global-jsdom/esm/index.mjs @@ -50,7 +50,10 @@ export default function globalJsdom(html = defaultHtml, options = {}) { // add access to our jsdom instance global.$jsdom = jsdom - const cleanup = () => KEYS.forEach((key) => delete global[key]) + const cleanup = () => { + KEYS.forEach((key) => delete global[key]) + KEYS.length = 0 + } document.destroy = cleanup diff --git a/packages/global-jsdom/test/jsdom.test.cjs b/packages/global-jsdom/test/jsdom.test.cjs index 0b30b42..ff99ac0 100644 --- a/packages/global-jsdom/test/jsdom.test.cjs +++ b/packages/global-jsdom/test/jsdom.test.cjs @@ -4,7 +4,7 @@ describe('jsdom-global', () => { beforeEach(() => global.document && global.document.destroy && global.document.destroy()) afterEach(() => global.document && global.document.destroy && global.document.destroy()) - const expectedKeys = ['document', 'alert', 'requestAnimationFrame'] + const expectedKeys = ['document', 'alert', 'requestAnimationFrame', 'NodeList'] describe('initialization and cleanup', () => { it('works', () => { @@ -16,6 +16,16 @@ describe('jsdom-global', () => { }) }) + describe('initialization and cleanup with `scripts: dangerously`', () => { + it('works', () => { + expectedKeys.forEach((k) => expect(global[k]).to.be.undefined) + const cleanup = jsdom(undefined, { runScripts: 'dangerously' }) + expectedKeys.forEach((k) => expect(global[k]).to.exist) + cleanup() + expectedKeys.forEach((k) => expect(global[k]).to.be.undefined) + }) + }) + describe('dom', () => { it('works', () => { jsdom() diff --git a/packages/global-jsdom/test/jsdom.test.js b/packages/global-jsdom/test/jsdom.test.js index 0b30b42..ff99ac0 100644 --- a/packages/global-jsdom/test/jsdom.test.js +++ b/packages/global-jsdom/test/jsdom.test.js @@ -4,7 +4,7 @@ describe('jsdom-global', () => { beforeEach(() => global.document && global.document.destroy && global.document.destroy()) afterEach(() => global.document && global.document.destroy && global.document.destroy()) - const expectedKeys = ['document', 'alert', 'requestAnimationFrame'] + const expectedKeys = ['document', 'alert', 'requestAnimationFrame', 'NodeList'] describe('initialization and cleanup', () => { it('works', () => { @@ -16,6 +16,16 @@ describe('jsdom-global', () => { }) }) + describe('initialization and cleanup with `scripts: dangerously`', () => { + it('works', () => { + expectedKeys.forEach((k) => expect(global[k]).to.be.undefined) + const cleanup = jsdom(undefined, { runScripts: 'dangerously' }) + expectedKeys.forEach((k) => expect(global[k]).to.exist) + cleanup() + expectedKeys.forEach((k) => expect(global[k]).to.be.undefined) + }) + }) + describe('dom', () => { it('works', () => { jsdom() diff --git a/packages/global-jsdom/test/jsdom.test.mjs b/packages/global-jsdom/test/jsdom.test.mjs index b5defb9..eab3e95 100644 --- a/packages/global-jsdom/test/jsdom.test.mjs +++ b/packages/global-jsdom/test/jsdom.test.mjs @@ -5,7 +5,7 @@ describe('jsdom-global', () => { beforeEach(() => global.document && global.document.destroy && global.document.destroy()) afterEach(() => global.document && global.document.destroy && global.document.destroy()) - const expectedKeys = ['document', 'alert', 'requestAnimationFrame'] + const expectedKeys = ['document', 'alert', 'requestAnimationFrame', 'NodeList'] describe('initialization and cleanup', () => { it('works', () => { @@ -17,6 +17,16 @@ describe('jsdom-global', () => { }) }) + describe('initialization and cleanup with `scripts: dangerously`', () => { + it('works', () => { + expectedKeys.forEach((k) => expect(global[k]).to.be.undefined) + const cleanup = jsdom(undefined, { runScripts: 'dangerously' }) + expectedKeys.forEach((k) => expect(global[k]).to.exist) + cleanup() + expectedKeys.forEach((k) => expect(global[k]).to.be.undefined) + }) + }) + describe('dom', () => { it('works', () => { jsdom()