forked from MetaMask/snaps
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement tests using
webdriverio
(MetaMask#1231)
* Implement tests using webdriverio * Add test for iframe sandboxing * Run wdio in CI * Patch mocha types * Fix jest coverage * Update snap shasums * Test accessing iframe contentWindow.document * Properly test iframe sandboxing * Remove unnecessary timeout * Run yarn lint:fix * Move iframe URL to constant * Improve test HTML * Fix test * Replace Ava with Webdriverio (MetaMask#1234) * Set up webdriverio for snaps-execution-environments * Convert BaseSnapExecutor test * Run tests in CI * Convert endowment hardening tests * Remove ava and related files * Update all snaps-execution-environments tests to use Webdriverio * Fix Jest config * Fix network tests * Add IframeExecutionService tests * Update wdio config * Fix open handles * Fix more open handles * Fix one more open handle * Add hack for atob, btoa, console * Revert change to lockdown call * Increase timeouts and change port * Run test:browser in separate step * Set maxInstances to 1 * Run tests in Firefox as well * Update snaps-execution-environments tests to pass in Firefox * Update snaps-controllers to run in Firefox too * Use data-testid for getting snap iframe * Update error message * Add missing tests * Use spy for testing error event handler * Remove more unused dependencies * Add comment to math endowment test * Remove iframe-test bundle * Move SILENT_LOGGER to execution environments package * Revert logger * Ignore test-utils for coverage * Add comment to test * Fix test * Add realtimeReporting option * Collect coverage * Merge Jest coverage with Wdio coverage * Update coverage reporters * Fix webpack build * Remove CI step * Update snapshot * Fix controllers * Update more snapshots * Add new line * Update coverage * Update coverage * Try Codecov coverage merging * Use Codecov for merging snaps-execution-environments too * Add missing command * Improve coverage merging * Add comment to Mocha patch * Use shared sleep funtion
- Loading branch information
Showing
71 changed files
with
6,314 additions
and
2,764 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
`@types/mocha` and `@types/jest` both declare global `describe`, `it` and some other functions, which causes a conflict | ||
in TypeScript. This patch removes the global declarations from `@types/mocha`, which are not needed in most cases. They | ||
can still be imported from `mocha` if needed. | ||
|
||
diff --git a/index.d.ts b/index.d.ts | ||
index 8e5122397bd0b9418decc4db6c508e6a018abd33..702191271bebb2c8505c123420d2b704f5351425 100755 | ||
/** | ||
* Execute before running tests. | ||
@@ -2620,7 +2620,7 @@ declare var before: Mocha.HookFunction; | ||
* | ||
* @see https://mochajs.org/api/global.html#before | ||
*/ | ||
-declare var suiteSetup: Mocha.HookFunction; | ||
+// declare var suiteSetup: Mocha.HookFunction; | ||
|
||
/** | ||
* Execute after running tests. | ||
@@ -2629,7 +2629,7 @@ declare var suiteSetup: Mocha.HookFunction; | ||
* | ||
* @see https://mochajs.org/api/global.html#after | ||
*/ | ||
-declare var after: Mocha.HookFunction; | ||
+// declare var after: Mocha.HookFunction; | ||
|
||
/** | ||
* Execute after running tests. | ||
@@ -2638,7 +2638,7 @@ declare var after: Mocha.HookFunction; | ||
* | ||
* @see https://mochajs.org/api/global.html#after | ||
*/ | ||
-declare var suiteTeardown: Mocha.HookFunction; | ||
+// declare var suiteTeardown: Mocha.HookFunction; | ||
|
||
/** | ||
* Execute before each test case. | ||
@@ -2647,7 +2647,7 @@ declare var suiteTeardown: Mocha.HookFunction; | ||
* | ||
* @see https://mochajs.org/api/global.html#beforeEach | ||
*/ | ||
-declare var beforeEach: Mocha.HookFunction; | ||
+// declare var beforeEach: Mocha.HookFunction; | ||
|
||
/** | ||
* Execute before each test case. | ||
@@ -2656,7 +2656,7 @@ declare var beforeEach: Mocha.HookFunction; | ||
* | ||
* @see https://mochajs.org/api/global.html#beforeEach | ||
*/ | ||
-declare var setup: Mocha.HookFunction; | ||
+// declare var setup: Mocha.HookFunction; | ||
|
||
/** | ||
* Execute after each test case. | ||
@@ -2665,7 +2665,7 @@ declare var setup: Mocha.HookFunction; | ||
* | ||
* @see https://mochajs.org/api/global.html#afterEach | ||
*/ | ||
-declare var afterEach: Mocha.HookFunction; | ||
+// declare var afterEach: Mocha.HookFunction; | ||
|
||
/** | ||
* Execute after each test case. | ||
@@ -2674,77 +2674,77 @@ declare var afterEach: Mocha.HookFunction; | ||
* | ||
* @see https://mochajs.org/api/global.html#afterEach | ||
*/ | ||
-declare var teardown: Mocha.HookFunction; | ||
+// declare var teardown: Mocha.HookFunction; | ||
|
||
/** | ||
* Describe a "suite" containing nested suites and tests. | ||
* | ||
* - _Only available when invoked via the mocha CLI._ | ||
*/ | ||
-declare var describe: Mocha.SuiteFunction; | ||
+// declare var describe: Mocha.SuiteFunction; | ||
|
||
/** | ||
* Describe a "suite" containing nested suites and tests. | ||
* | ||
* - _Only available when invoked via the mocha CLI._ | ||
*/ | ||
-declare var context: Mocha.SuiteFunction; | ||
+// declare var context: Mocha.SuiteFunction; | ||
|
||
/** | ||
* Describe a "suite" containing nested suites and tests. | ||
* | ||
* - _Only available when invoked via the mocha CLI._ | ||
*/ | ||
-declare var suite: Mocha.SuiteFunction; | ||
+// declare var suite: Mocha.SuiteFunction; | ||
|
||
/** | ||
* Pending suite. | ||
* | ||
* - _Only available when invoked via the mocha CLI._ | ||
*/ | ||
-declare var xdescribe: Mocha.PendingSuiteFunction; | ||
+// declare var xdescribe: Mocha.PendingSuiteFunction; | ||
|
||
/** | ||
* Pending suite. | ||
* | ||
* - _Only available when invoked via the mocha CLI._ | ||
*/ | ||
-declare var xcontext: Mocha.PendingSuiteFunction; | ||
+// declare var xcontext: Mocha.PendingSuiteFunction; | ||
|
||
/** | ||
* Describes a test case. | ||
* | ||
* - _Only available when invoked via the mocha CLI._ | ||
*/ | ||
-declare var it: Mocha.TestFunction; | ||
+// declare var it: Mocha.TestFunction; | ||
|
||
/** | ||
* Describes a test case. | ||
* | ||
* - _Only available when invoked via the mocha CLI._ | ||
*/ | ||
-declare var specify: Mocha.TestFunction; | ||
+// declare var specify: Mocha.TestFunction; | ||
|
||
/** | ||
* Describes a test case. | ||
* | ||
* - _Only available when invoked via the mocha CLI._ | ||
*/ | ||
-declare var test: Mocha.TestFunction; | ||
+// declare var test: Mocha.TestFunction; | ||
|
||
/** | ||
* Describes a pending test case. | ||
* | ||
* - _Only available when invoked via the mocha CLI._ | ||
*/ | ||
-declare var xit: Mocha.PendingTestFunction; | ||
+// declare var xit: Mocha.PendingTestFunction; | ||
|
||
/** | ||
* Describes a pending test case. | ||
* | ||
* - _Only available when invoked via the mocha CLI._ | ||
*/ | ||
-declare var xspecify: Mocha.PendingTestFunction; | ||
+// declare var xspecify: Mocha.PendingTestFunction; | ||
|
||
// #endregion Test interface augmentations | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
diff --git a/src/index.js b/src/index.js | ||
index 42015c1815447aab80df4524d1af91ac33e5751d..003aa9a2f0ce3ac4a65053b0b29ca0fe9b5c7ff3 100644 | ||
--- a/src/index.js | ||
+++ b/src/index.js | ||
@@ -82,7 +82,8 @@ const isFn = unknown => typeof unknown === 'function' | ||
const isMocking = jest.fn(staticMatches(true)) | ||
|
||
const abortError = () => | ||
- new DOMException('The operation was aborted. ', 'AbortError') | ||
+ // `DOMException` is not available in Node.js. | ||
+ new Error('The operation was aborted. ') | ||
|
||
const abort = () => { | ||
throw abortError() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,7 @@ | |
"build:post-tsc": "yarn workspaces foreach --parallel --topological --verbose run build:post-tsc", | ||
"clean": "yarn workspaces foreach --parallel --verbose run clean", | ||
"test": "yarn workspaces foreach --parallel --verbose run test", | ||
"test:browser": "yarn workspaces foreach --verbose run test:browser", | ||
"test:ci": "yarn workspace @metamask/snaps-execution-environments run build:test && yarn workspaces foreach --parallel --verbose run test:ci" | ||
}, | ||
"simple-git-hooks": { | ||
|
@@ -39,6 +40,10 @@ | |
"prettier --write" | ||
] | ||
}, | ||
"resolutions": { | ||
"@types/mocha@^10.0.1": "patch:@types/mocha@npm:10.0.1#.yarn/patches/@types-mocha-npm-10.0.1-7c94e9e170.patch", | ||
"jest-fetch-mock@^3.0.3": "patch:jest-fetch-mock@npm:3.0.3#.yarn/patches/jest-fetch-mock-npm-3.0.3-ac072ca8af.patch" | ||
}, | ||
"devDependencies": { | ||
"@lavamoat/allow-scripts": "^2.0.3", | ||
"@metamask/auto-changelog": "^3.1.0", | ||
|
@@ -50,13 +55,15 @@ | |
"@types/node": "^14.14.25", | ||
"@typescript-eslint/eslint-plugin": "^5.42.1", | ||
"@typescript-eslint/parser": "^5.42.1", | ||
"chromedriver": "^110.0.0", | ||
"eslint": "^8.27.0", | ||
"eslint-config-prettier": "^8.5.0", | ||
"eslint-plugin-import": "^2.26.0", | ||
"eslint-plugin-jest": "^27.1.5", | ||
"eslint-plugin-jsdoc": "^39.6.2", | ||
"eslint-plugin-node": "^11.1.0", | ||
"eslint-plugin-prettier": "^4.2.1", | ||
"geckodriver": "^3.2.0", | ||
"jest": "^29.0.2", | ||
"lint-staged": "^12.4.1", | ||
"prettier": "^2.7.1", | ||
|
@@ -73,7 +80,10 @@ | |
"allowScripts": { | ||
"@lavamoat/preinstall-always-fail": false, | ||
"simple-git-hooks": false, | ||
"$root$": false | ||
"$root$": false, | ||
"chromedriver": true, | ||
"jest>jest-cli>jest-config>ts-node>@swc/core": false, | ||
"geckodriver": true | ||
} | ||
}, | ||
"packageManager": "[email protected]" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"branches": 87.43, | ||
"functions": 94.21, | ||
"lines": 95.25, | ||
"statements": 95.17 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.