From 312f24fddc0ea1183ca6c6404d4dbee9022ae031 Mon Sep 17 00:00:00 2001 From: Brad Decker Date: Thu, 12 Jan 2023 09:38:12 -0500 Subject: [PATCH] allow importing of typescript in E2E test suite (#17141) --- package.json | 8 ++-- test/e2e/.mocharc.js | 5 +++ test/e2e/benchmark.js | 1 - test/e2e/e2e-mocha-setup.js | 5 +++ test/e2e/fixture-builder.js | 73 +++++++++++++++++++------------------ test/e2e/run-e2e-test.js | 5 ++- 6 files changed, 55 insertions(+), 42 deletions(-) create mode 100644 test/e2e/.mocharc.js create mode 100644 test/e2e/e2e-mocha-setup.js diff --git a/package.json b/package.json index f7bd5a657..4c68bc6ea 100644 --- a/package.json +++ b/package.json @@ -14,10 +14,10 @@ "build": "yarn lavamoat:build", "build:dev": "node development/build/index.js", "start:test": "SEGMENT_HOST='https://api.segment.io' SEGMENT_WRITE_KEY='FAKE' SENTRY_DSN_DEV=https://fake@sentry.io/0000000 PORTFOLIO_URL=http://127.0.0.1:8080 yarn build:dev testDev", - "benchmark:chrome": "SELENIUM_BROWSER=chrome node test/e2e/benchmark.js", - "mv3:stats:chrome": "SELENIUM_BROWSER=chrome ENABLE_MV3=true node test/e2e/mv3-perf-stats/index.js", - "user-actions-benchmark:chrome": "SELENIUM_BROWSER=chrome node test/e2e/user-actions-benchmark.js", - "benchmark:firefox": "SELENIUM_BROWSER=firefox node test/e2e/benchmark.js", + "benchmark:chrome": "SELENIUM_BROWSER=chrome ts-node test/e2e/benchmark.js", + "mv3:stats:chrome": "SELENIUM_BROWSER=chrome ENABLE_MV3=true ts-node test/e2e/mv3-perf-stats/index.js", + "user-actions-benchmark:chrome": "SELENIUM_BROWSER=chrome ts-node test/e2e/user-actions-benchmark.js", + "benchmark:firefox": "SELENIUM_BROWSER=firefox ts-node test/e2e/benchmark.js", "build:test": "SEGMENT_HOST='https://api.segment.io' SEGMENT_WRITE_KEY='FAKE' SENTRY_DSN_DEV=https://fake@sentry.io/0000000 PORTFOLIO_URL=http://127.0.0.1:8080 yarn build test", "build:test:flask": "yarn build test --build-type flask", "build:test:mv3": "ENABLE_MV3=true SEGMENT_HOST='https://api.segment.io' SEGMENT_WRITE_KEY='FAKE' SENTRY_DSN_DEV=https://fake@sentry.io/0000000 PORTFOLIO_URL=http://127.0.0.1:8080 yarn build test", diff --git a/test/e2e/.mocharc.js b/test/e2e/.mocharc.js new file mode 100644 index 000000000..3513eaa0e --- /dev/null +++ b/test/e2e/.mocharc.js @@ -0,0 +1,5 @@ +// This file exists to add mocha configuration options specific to our +// E2E Test suite. +module.exports = { + require: ['test/e2e/e2e-mocha-setup.js'], +}; diff --git a/test/e2e/benchmark.js b/test/e2e/benchmark.js index 760f4f70b..df44a6dce 100755 --- a/test/e2e/benchmark.js +++ b/test/e2e/benchmark.js @@ -1,5 +1,4 @@ #!/usr/bin/env node - const path = require('path'); const { promises: fs } = require('fs'); const yargs = require('yargs/yargs'); diff --git a/test/e2e/e2e-mocha-setup.js b/test/e2e/e2e-mocha-setup.js new file mode 100644 index 000000000..26965006e --- /dev/null +++ b/test/e2e/e2e-mocha-setup.js @@ -0,0 +1,5 @@ +// This file simply registers babel and ts-node so that we may use the same +// ECMAScript features in E2E tests that we use elsewhere in our code. It also +// allows values to be read from TypeScript files. +require('@babel/register'); +require('ts-node/register'); diff --git a/test/e2e/fixture-builder.js b/test/e2e/fixture-builder.js index a6f2ddcea..cc1936642 100644 --- a/test/e2e/fixture-builder.js +++ b/test/e2e/fixture-builder.js @@ -1,4 +1,5 @@ const { merge } = require('lodash'); +const { CHAIN_IDS } = require('../../shared/constants/network'); function defaultFixture() { return { @@ -134,14 +135,14 @@ function defaultFixture() { showTestnetMessageInDropdown: true, trezorModel: null, usedNetworks: { - '0x1': true, - '0x5': true, - '0x539': true, + [CHAIN_IDS.MAINNET]: true, + [CHAIN_IDS.GOERLI]: true, + [CHAIN_IDS.LOCALHOST]: true, }, }, CachedBalancesController: { cachedBalances: { - '0x539': {}, + [CHAIN_IDS.LOCALHOST]: {}, }, }, CurrencyController: { @@ -159,9 +160,9 @@ function defaultFixture() { IncomingTransactionsController: { incomingTransactions: {}, incomingTxLastFetchedBlockByChainId: { - '0x1': null, - '0x5': null, - '0xaa36a7': null, + [CHAIN_IDS.MAINNET]: null, + [CHAIN_IDS.GOERLI]: null, + [CHAIN_IDS.SEPOLIA]: null, }, }, KeyringController: { @@ -178,7 +179,7 @@ function defaultFixture() { NetworkController: { network: '1337', provider: { - chainId: '0x539', + chainId: CHAIN_IDS.LOCALHOST, nickname: 'Localhost 8545', rpcPrefs: {}, rpcUrl: 'http://localhost:8545', @@ -205,7 +206,7 @@ function defaultFixture() { forgottenPassword: false, frequentRpcListDetail: [ { - chainId: '0x539', + chainId: CHAIN_IDS.LOCALHOST, nickname: 'Localhost 8545', rpcPrefs: {}, rpcUrl: 'http://localhost:8545', @@ -245,7 +246,7 @@ function defaultFixture() { fees: {}, liveness: true, smartTransactions: { - '0x1': [], + [CHAIN_IDS.MAINNET]: [], }, }, }, @@ -300,9 +301,9 @@ function onboardingFixture() { showTestnetMessageInDropdown: true, trezorModel: null, usedNetworks: { - '0x1': true, - '0x5': true, - '0x539': true, + [CHAIN_IDS.MAINNET]: true, + [CHAIN_IDS.GOERLI]: true, + [CHAIN_IDS.LOCALHOST]: true, }, }, NetworkController: { @@ -311,7 +312,7 @@ function onboardingFixture() { ticker: 'ETH', type: 'rpc', rpcUrl: 'http://localhost:8545', - chainId: '0x539', + chainId: CHAIN_IDS.LOCALHOST, nickname: 'Localhost 8545', }, }, @@ -325,7 +326,7 @@ function onboardingFixture() { forgottenPassword: false, frequentRpcListDetail: [ { - chainId: '0x539', + chainId: CHAIN_IDS.LOCALHOST, nickname: 'Localhost 8545', rpcPrefs: {}, rpcUrl: 'http://localhost:8545', @@ -358,7 +359,7 @@ function onboardingFixture() { fees: {}, liveness: true, smartTransactions: { - '0x1': [], + [CHAIN_IDS.MAINNET]: [], }, }, }, @@ -450,7 +451,7 @@ class FixtureBuilder { incomingTransactions: { '0xf1af8286e4fa47578c2aec5f08c108290643df978ebc766d72d88476eee90bab': { blockNumber: '1', - chainId: '0x539', + chainId: CHAIN_IDS.LOCALHOST, hash: '0xf1af8286e4fa47578c2aec5f08c108290643df978ebc766d72d88476eee90bab', id: 5748272735958807, metamaskNetworkId: '1337', @@ -656,14 +657,14 @@ class FixtureBuilder { return this.withTransactionController({ transactions: { 7911313280012623: { - chainId: '0x539', + chainId: CHAIN_IDS.LOCALHOST, dappSuggestedGasFees: { gas: '0x5208', gasPrice: '0x4a817c800', }, history: [ { - chainId: '0x539', + chainId: CHAIN_IDS.LOCALHOST, dappSuggestedGasFees: { gas: '0x5208', gasPrice: '0x4a817c800', @@ -709,14 +710,14 @@ class FixtureBuilder { type: 'simpleSend', }, 7911313280012624: { - chainId: '0x539', + chainId: CHAIN_IDS.LOCALHOST, dappSuggestedGasFees: { gas: '0x5208', gasPrice: '0x4a817c800', }, history: [ { - chainId: '0x539', + chainId: CHAIN_IDS.LOCALHOST, dappSuggestedGasFees: { gas: '0x5208', gasPrice: '0x4a817c800', @@ -762,14 +763,14 @@ class FixtureBuilder { type: 'simpleSend', }, 7911313280012625: { - chainId: '0x539', + chainId: CHAIN_IDS.LOCALHOST, dappSuggestedGasFees: { gas: '0x5208', gasPrice: '0x4a817c800', }, history: [ { - chainId: '0x539', + chainId: CHAIN_IDS.LOCALHOST, dappSuggestedGasFees: { gas: '0x5208', gasPrice: '0x4a817c800', @@ -815,14 +816,14 @@ class FixtureBuilder { type: 'simpleSend', }, 7911313280012626: { - chainId: '0x539', + chainId: CHAIN_IDS.LOCALHOST, dappSuggestedGasFees: { gas: '0x5208', gasPrice: '0x4a817c800', }, history: [ { - chainId: '0x539', + chainId: CHAIN_IDS.LOCALHOST, dappSuggestedGasFees: { gas: '0x5208', gasPrice: '0x4a817c800', @@ -875,10 +876,10 @@ class FixtureBuilder { return this.withTransactionController({ transactions: { 4046084157914634: { - chainId: '0x539', + chainId: CHAIN_IDS.LOCALHOST, history: [ { - chainId: '0x539', + chainId: CHAIN_IDS.LOCALHOST, id: 4046084157914634, loadingDefaults: true, metamaskNetworkId: '1337', @@ -909,7 +910,7 @@ class FixtureBuilder { metamaskNetworkId: '1337', origin: 'metamask', primaryTransaction: { - chainId: '0x539', + chainId: CHAIN_IDS.LOCALHOST, id: 4046084157914634, loadingDefaults: true, metamaskNetworkId: '1337', @@ -944,10 +945,10 @@ class FixtureBuilder { return this.withTransactionController({ transactions: { 4046084157914634: { - chainId: '0x539', + chainId: CHAIN_IDS.LOCALHOST, history: [ { - chainId: '0x539', + chainId: CHAIN_IDS.LOCALHOST, id: 4046084157914634, loadingDefaults: true, metamaskNetworkId: '1337', @@ -980,7 +981,7 @@ class FixtureBuilder { metamaskNetworkId: '1337', origin: 'metamask', primaryTransaction: { - chainId: '0x539', + chainId: CHAIN_IDS.LOCALHOST, id: 4046084157914634, loadingDefaults: true, metamaskNetworkId: '1337', @@ -1019,10 +1020,10 @@ class FixtureBuilder { return this.withTransactionController({ transactions: { 4046084157914634: { - chainId: '0x539', + chainId: CHAIN_IDS.LOCALHOST, history: [ { - chainId: '0x539', + chainId: CHAIN_IDS.LOCALHOST, id: 4046084157914634, loadingDefaults: true, metamaskNetworkId: '1337', @@ -1091,7 +1092,7 @@ class FixtureBuilder { metamaskNetworkId: '1337', origin: 'metamask', primaryTransaction: { - chainId: '0x539', + chainId: CHAIN_IDS.LOCALHOST, id: 4046084157914634, loadingDefaults: true, metamaskNetworkId: '1337', @@ -1130,10 +1131,10 @@ class FixtureBuilder { return this.withTransactionController({ transactions: { 5748272735958801: { - chainId: '0x539', + chainId: CHAIN_IDS.LOCALHOST, history: [ { - chainId: 0x539, + chainId: CHAIN_IDS.LOCALHOST, id: 5748272735958801, loadingDefaults: true, metamaskNetworkId: '1337', diff --git a/test/e2e/run-e2e-test.js b/test/e2e/run-e2e-test.js index 6ede0be71..dd8d537ae 100644 --- a/test/e2e/run-e2e-test.js +++ b/test/e2e/run-e2e-test.js @@ -1,4 +1,5 @@ const { promises: fs } = require('fs'); +const path = require('path'); const yargs = require('yargs/yargs'); const { hideBin } = require('yargs/helpers'); const { runInShell } = require('../../development/lib/run-command'); @@ -88,10 +89,12 @@ async function main() { exit = '--no-exit'; } + const configFile = path.join(__dirname, '.mocharc.js'); + await retry({ retries }, async () => { await runInShell('yarn', [ 'mocha', - '--no-config', + `--config=${configFile}`, '--timeout', testTimeoutInMilliseconds, e2eTestPath,