diff --git a/karma.config.js b/karma.config.js index aede4434..d4ea9344 100644 --- a/karma.config.js +++ b/karma.config.js @@ -5,17 +5,28 @@ const globby = require('globby'); const istanbul = require('rollup-plugin-istanbul'); const { nodeResolve } = require('@rollup/plugin-node-resolve'); +const replaceRollupPlugin = require('@rollup/plugin-replace'); const path = require('node:path'); +const yargs = require('yargs/yargs'); +const { hideBin } = require('yargs/helpers'); process.env.CHROME_BIN = require('puppeteer').executablePath(); let testFilesPattern = './test/**/*.spec.js'; const basePath = path.resolve(__dirname, './'); -const matchArg = process.argv.indexOf('--match'); +const argv = yargs(hideBin(process.argv)) + .options({ + coverage: { type: 'boolean' }, + match: { type: 'string' }, + 'use-shadow-realm': { type: 'boolean' }, + }) + .hide('help') + .hide('version').argv; +const { coverage, match, useShadowRealm } = argv; -if (matchArg > -1) { - testFilesPattern = process.argv[matchArg + 1] || ''; +if (match) { + testFilesPattern = match; } if (globby.sync(testFilesPattern).length) { @@ -27,8 +38,6 @@ if (globby.sync(testFilesPattern).length) { process.exit(0); } -const coverage = process.argv.includes('--coverage'); - const customLaunchers = { ChromeHeadlessNoSandbox: { base: 'ChromeHeadless', @@ -74,6 +83,13 @@ module.exports = function (config) { nodeResolve({ preferBuiltins: true, }), + replaceRollupPlugin({ + include: ['./test/__bootstrap__/create-virtual-environment.js'], + preventAssignment: true, + values: { + 'process.env.USE_SHADOW_REALM': JSON.stringify(useShadowRealm), + }, + }), ], }, }; diff --git a/package.json b/package.json index 03f66ec5..4c5320b2 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "@commitlint/config-conventional": "17.1.0", "@rollup/plugin-babel": "5.3.1", "@rollup/plugin-node-resolve": "13.0.5", - "@rollup/plugin-replace": "4.0.0", + "@rollup/plugin-replace": "^5.0.2", "@rollup/plugin-typescript": "8.4.0", "@types/eslint": "8.4.6", "@types/jest": "29.0.0", @@ -111,5 +111,7 @@ "node": "16.13.1", "yarn": "1.22.11" }, - "dependencies": {} + "dependencies": { + "yargs": "^17.6.2" + } } diff --git a/test/.eslintrc b/test/.eslintrc index 2bd03277..b0666293 100644 --- a/test/.eslintrc +++ b/test/.eslintrc @@ -1,6 +1,7 @@ { "globals": { - "jasmine": "readonly" + "createVirtualEnvironment": true, + "jasmine": "readonly" }, "ignorePatterns": [".eslintrc.js"], "overrides": [ diff --git a/test/__bootstrap__/create-virtual-environment.js b/test/__bootstrap__/create-virtual-environment.js new file mode 100644 index 00000000..d34024f2 --- /dev/null +++ b/test/__bootstrap__/create-virtual-environment.js @@ -0,0 +1,13 @@ +import { SUPPORTS_SHADOW_REALM } from '@locker/near-membrane-shared'; +import createVirtualEnvironment from '@locker/near-membrane-dom'; + +const useShadowRealm = process.env.USE_SHADOW_REALM; + +globalThis.createVirtualEnvironment = function (globalObject, options = {}) { + if (SUPPORTS_SHADOW_REALM && !('useShadowRealm' in options) && useShadowRealm) { + options.useShadowRealm = useShadowRealm; + } + console.log(options); + + return createVirtualEnvironment(globalObject, options); +}; diff --git a/test/distortions/getter.spec.js b/test/distortions/getter.spec.js index 2ebc0658..b7600380 100644 --- a/test/distortions/getter.spec.js +++ b/test/distortions/getter.spec.js @@ -1,5 +1,3 @@ -import createVirtualEnvironment from '@locker/near-membrane-dom'; - // getting reference to the function to be distorted const { get: hostGetter } = Object.getOwnPropertyDescriptor(ShadowRoot.prototype, 'host'); const { get: localStorageGetter } = Object.getOwnPropertyDescriptor(window, 'localStorage'); @@ -36,7 +34,7 @@ describe('Getter Function Distortion', () => { expect(hostGetter.call(elm)).toBe(null); `); }); - it('should work for global property accessors (issue #64)', () => { + fit('should work for global property accessors (issue #64)', () => { expect.assertions(1); env.evaluate(` diff --git a/yarn.lock b/yarn.lock index e25949d2..7a440ed4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1954,6 +1954,11 @@ resolved "https://registry.yarnpkg.com/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.4.11.tgz#771a1d8d744eeb71b6adb35808e1a6c7b9b8c8ec" integrity sha512-Fg32GrJo61m+VqYSdRSjRXMjQ06j8YIYfcTqndLYVAaHmroZHLJZCydsWBOTDqXS2v+mjxohBWEMfg97GXmYQg== +"@jridgewell/sourcemap-codec@^1.4.13": + version "1.4.14" + resolved "https://registry.yarnpkg.com/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.4.14.tgz#add4c98d341472a289190b424efbdb096991bb24" + integrity sha512-XPSJHWmi394fuUuzDnGz1wiKqWfo1yXecHQMRf2l6hztTO+nPru658AyDngaBe7isIxEkRsPR3FZh+s7iVa4Uw== + "@jridgewell/trace-mapping@0.3.9": version "0.3.9" resolved "https://registry.yarnpkg.com/@jridgewell/trace-mapping/-/trace-mapping-0.3.9.tgz#6534fd5933a53ba7cbf3a17615e273a0d1273ff9" @@ -2964,13 +2969,13 @@ is-module "^1.0.0" resolve "^1.19.0" -"@rollup/plugin-replace@4.0.0": - version "4.0.0" - resolved "https://registry.yarnpkg.com/@rollup/plugin-replace/-/plugin-replace-4.0.0.tgz#e34c457d6a285f0213359740b43f39d969b38a67" - integrity sha512-+rumQFiaNac9y64OHtkHGmdjm7us9bo1PlbgQfdihQtuNxzjpaB064HbRnewUOggLQxVCCyINfStkgmBeQpv1g== +"@rollup/plugin-replace@^5.0.2": + version "5.0.2" + resolved "https://registry.yarnpkg.com/@rollup/plugin-replace/-/plugin-replace-5.0.2.tgz#45f53501b16311feded2485e98419acb8448c61d" + integrity sha512-M9YXNekv/C/iHHK+cvORzfRYfPbq0RDD8r0G+bMiTXjNGKulPnCT9O3Ss46WfhI6ZOCgApOP7xAdmCQJ+U2LAA== dependencies: - "@rollup/pluginutils" "^3.1.0" - magic-string "^0.25.7" + "@rollup/pluginutils" "^5.0.1" + magic-string "^0.27.0" "@rollup/plugin-typescript@8.4.0": version "8.4.0" @@ -2997,6 +3002,15 @@ estree-walker "^2.0.1" picomatch "^2.2.2" +"@rollup/pluginutils@^5.0.1": + version "5.0.2" + resolved "https://registry.yarnpkg.com/@rollup/pluginutils/-/pluginutils-5.0.2.tgz#012b8f53c71e4f6f9cb317e311df1404f56e7a33" + integrity sha512-pTd9rIsP92h+B6wWwFbW8RkZv4hiR/xKsqre4SIuAOaOEQRxi0lqLke9k2/7WegC85GgUs9pjmOjCUi3In4vwA== + dependencies: + "@types/estree" "^1.0.0" + estree-walker "^2.0.2" + picomatch "^2.3.1" + "@sinclair/typebox@^0.24.1": version "0.24.28" resolved "https://registry.yarnpkg.com/@sinclair/typebox/-/typebox-0.24.28.tgz#15aa0b416f82c268b1573ab653e4413c965fe794" @@ -3124,6 +3138,11 @@ resolved "https://registry.yarnpkg.com/@types/estree/-/estree-0.0.39.tgz#e177e699ee1b8c22d23174caaa7422644389509f" integrity sha512-EYNwp3bU+98cpU4lAWYYL7Zz+2gryWH1qbdDTidVd6hkiR6weksdbMadyXKXNPEkQFhXM+hVO9ZygomHXp+AIw== +"@types/estree@^1.0.0": + version "1.0.0" + resolved "https://registry.yarnpkg.com/@types/estree/-/estree-1.0.0.tgz#5fb2e536c1ae9bf35366eed879e827fa59ca41c2" + integrity sha512-WulqXMDUTYAXCjZnk6JtIHPigp55cVtDgDrO2gHRwhyJto21+1zbVCtOYB2L1F9w4qCQ0rOGWBnBe0FNTiEJIQ== + "@types/graceful-fs@^4.1.3": version "4.1.5" resolved "https://registry.yarnpkg.com/@types/graceful-fs/-/graceful-fs-4.1.5.tgz#21ffba0d98da4350db64891f92a9e5db3cdb4e15" @@ -4226,6 +4245,15 @@ cliui@^7.0.2: strip-ansi "^6.0.0" wrap-ansi "^7.0.0" +cliui@^8.0.1: + version "8.0.1" + resolved "https://registry.yarnpkg.com/cliui/-/cliui-8.0.1.tgz#0c04b075db02cbfe60dc8e6cf2f5486b1a3608aa" + integrity sha512-BSeNnyus75C4//NQ9gQt1/csTXyo/8Sb+afLAkzAptFuMsod9HFokGNudZpi/oQV73hnVK+sR+5PVRMd+Dr7YQ== + dependencies: + string-width "^4.2.0" + strip-ansi "^6.0.1" + wrap-ansi "^7.0.0" + clone-deep@^4.0.1: version "4.0.1" resolved "https://registry.yarnpkg.com/clone-deep/-/clone-deep-4.0.1.tgz#c19fd9bdbbf85942b4fd979c84dcf7d5f07c2387" @@ -5263,7 +5291,7 @@ estree-walker@^1.0.1: resolved "https://registry.yarnpkg.com/estree-walker/-/estree-walker-1.0.1.tgz#31bc5d612c96b704106b477e6dd5d8aa138cb700" integrity sha512-1fMXF3YP4pZZVozF8j/ZLfvnR8NSIljt56UhbZ5PeeDmmGHpgpdwQt7ITlGvYaQukCvuBRMLEiKiYC+oeIg4cg== -estree-walker@^2.0.1: +estree-walker@^2.0.1, estree-walker@^2.0.2: version "2.0.2" resolved "https://registry.yarnpkg.com/estree-walker/-/estree-walker-2.0.2.tgz#52f010178c2a4c117a7757cfe942adb7d2da4cac" integrity sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w== @@ -7679,12 +7707,12 @@ lru-cache@^7.4.4, lru-cache@^7.5.1, lru-cache@^7.7.1: resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-7.14.0.tgz#21be64954a4680e303a09e9468f880b98a0b3c7f" integrity sha512-EIRtP1GrSJny0dqb50QXRUNBxHJhcpxHC++M5tD7RYbvLLn5KVWKsbyswSSqDuU15UFi3bgTQIY8nhDMeF6aDQ== -magic-string@^0.25.7: - version "0.25.9" - resolved "https://registry.yarnpkg.com/magic-string/-/magic-string-0.25.9.tgz#de7f9faf91ef8a1c91d02c2e5314c8277dbcdd1c" - integrity sha512-RmF0AsMzgt25qzqqLc1+MbHmhdx0ojF2Fvs4XnOqz2ZOBXzzkEwc/dJQZCYHAn7v1jbVOjAZfK8msRn4BxO4VQ== +magic-string@^0.27.0: + version "0.27.0" + resolved "https://registry.yarnpkg.com/magic-string/-/magic-string-0.27.0.tgz#e4a3413b4bab6d98d2becffd48b4a257effdbbf3" + integrity sha512-8UnnX2PeRAPZuN12svgR9j7M1uWMovg/CEnIwIG0LFkXSJJe4PdfUGiTGl8V9bsBHFUtfVINcSyYxd7q+kx9fA== dependencies: - sourcemap-codec "^1.4.8" + "@jridgewell/sourcemap-codec" "^1.4.13" make-dir@^2.1.0: version "2.1.0" @@ -9775,11 +9803,6 @@ source-map@~0.2.0: dependencies: amdefine ">=0.0.4" -sourcemap-codec@^1.4.8: - version "1.4.8" - resolved "https://registry.yarnpkg.com/sourcemap-codec/-/sourcemap-codec-1.4.8.tgz#ea804bd94857402e6992d05a38ef1ae35a9ab4c4" - integrity sha512-9NykojV5Uih4lgo5So5dtw+f0JgJX30KCNI8gwhz2J9A15wD0Ml6tjHKwf6fTSa6fAdVBdZeNOs9eJ71qCk8vA== - spawn-wrap@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/spawn-wrap/-/spawn-wrap-2.0.0.tgz#103685b8b8f9b79771318827aa78650a610d457e" @@ -10926,7 +10949,7 @@ yargs-parser@^20.2.9: resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-20.2.9.tgz#2eb7dc3b0289718fc295f362753845c41a0c94ee" integrity sha512-y11nGElTIV+CT3Zv9t7VKl+Q3hTQoT9a1Qzezhhl6Rp21gJ/IVTW7Z3y9EWXhuUBC2Shnf+DX0antecpAwSP8w== -yargs-parser@^21.0.0: +yargs-parser@^21.0.0, yargs-parser@^21.1.1: version "21.1.1" resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-21.1.1.tgz#9096bceebf990d21bb31fa9516e0ede294a77d35" integrity sha512-tVpsJW7DdjecAiFpbIB1e3qxIQsE6NoPc5/eTdrbbIC4h0LVsWhnoa3g+m2HclBIujHzsxZ4VJVA+GUuc2/LBw== @@ -10987,6 +11010,19 @@ yargs@^17.3.1, yargs@^17.4.0: y18n "^5.0.5" yargs-parser "^21.0.0" +yargs@^17.6.2: + version "17.6.2" + resolved "https://registry.yarnpkg.com/yargs/-/yargs-17.6.2.tgz#2e23f2944e976339a1ee00f18c77fedee8332541" + integrity sha512-1/9UrdHjDZc0eOU0HxOHoS78C69UD3JRMvzlJ7S79S2nTaWRA/whGCTV8o9e/N/1Va9YIV7Q4sOxD8VV4pCWOw== + dependencies: + cliui "^8.0.1" + escalade "^3.1.1" + get-caller-file "^2.0.5" + require-directory "^2.1.1" + string-width "^4.2.3" + y18n "^5.0.5" + yargs-parser "^21.1.1" + yargs@^4.8.1: version "4.8.1" resolved "https://registry.yarnpkg.com/yargs/-/yargs-4.8.1.tgz#c0c42924ca4aaa6b0e6da1739dfb216439f9ddc0"