mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-10-22 03:12:42 +02:00
24eae1d3c6
* Use fake provider for NetworkController unit tests In the unit tests for NetworkController, it's important to prevent network requests from occurring. Currently we do that by using Nock. However, the `core` version of NetworkController uses a fake provider object. This is arguably a better approach for unit tests because it prevents us from having to think about the behavior that a specific middleware may have. For instance, the Infura middleware intercepts `eth_chainId` to return a static result, and the block cache middleware replaces the `latest` block tag with the latest block number, making an extra call to `eth_blockNumber` in doing so. We have to account for these kinds of behaviors when using Nock, but we do not need to do this when using a fake provider. This should make it easier to compare the difference between the unit tests in this repo vs. in the `core` repo, which should ultimately help us merge the two controllers together. * Rename fake-provider-engine to fake-provider * Rearrange imports * Move fake-provider and fake-block-tracker into a directory and exclude it from coverage * Make FakeBlockTracker inert, and fix JSDocs * Remove generics from FakeProvider * Call beforeCompleting (and beforeResolving) using async/await * Fix signature of sendAsync; align other signatures within FakeProvider * No need to check whether error is not a string * Don't exclude the provider-api-tests directory from coverage * Make sure to mock both net_version and eth_getBlockByNumber when testing network status * Fix FakeProvider so that none of the methods have optional callbacks
68 lines
2.6 KiB
JavaScript
68 lines
2.6 KiB
JavaScript
module.exports = {
|
|
collectCoverageFrom: [
|
|
'<rootDir>/app/scripts/constants/error-utils.js',
|
|
'<rootDir>/app/scripts/controllers/network/**/*.js',
|
|
'<rootDir>/app/scripts/controllers/network/**/*.ts',
|
|
'!<rootDir>/app/scripts/controllers/network/**/test/*.ts',
|
|
'<rootDir>/app/scripts/controllers/permissions/**/*.js',
|
|
'<rootDir>/app/scripts/controllers/sign.ts',
|
|
'<rootDir>/app/scripts/flask/**/*.js',
|
|
'<rootDir>/app/scripts/lib/**/*.js',
|
|
'<rootDir>/app/scripts/lib/createRPCMethodTrackingMiddleware.js',
|
|
'<rootDir>/app/scripts/migrations/*.js',
|
|
'<rootDir>/app/scripts/platforms/*.js',
|
|
'<rootDir>/shared/**/*.(js|ts|tsx)',
|
|
'<rootDir>/ui/**/*.(js|ts|tsx)',
|
|
'<rootDir>/development/fitness-functions/**/*.test.(js|ts|tsx)',
|
|
],
|
|
coverageDirectory: './coverage',
|
|
coveragePathIgnorePatterns: ['.stories.*', '.snap'],
|
|
coverageReporters: ['json'],
|
|
reporters: [
|
|
'default',
|
|
[
|
|
'jest-junit',
|
|
{
|
|
outputDirectory: 'test/test-results/',
|
|
outputName: 'junit.xml',
|
|
},
|
|
],
|
|
],
|
|
// TODO: enable resetMocks
|
|
// resetMocks: true,
|
|
restoreMocks: true,
|
|
setupFiles: [
|
|
'<rootDir>/test/setup.js',
|
|
'<rootDir>/test/env.js',
|
|
'<rootDir>/test/jest/env.js', // jest specific env vars that break mocha tests
|
|
],
|
|
setupFilesAfterEnv: ['<rootDir>/test/jest/setup.js'],
|
|
testMatch: [
|
|
'<rootDir>/app/scripts/constants/error-utils.test.js',
|
|
'<rootDir>/app/scripts/controllers/app-state.test.js',
|
|
'<rootDir>/app/scripts/controllers/network/**/*.test.js',
|
|
'<rootDir>/app/scripts/controllers/network/**/*.test.ts',
|
|
'<rootDir>/app/scripts/controllers/permissions/**/*.test.js',
|
|
'<rootDir>/app/scripts/controllers/sign.test.ts',
|
|
'<rootDir>/app/scripts/flask/**/*.test.js',
|
|
'<rootDir>/app/scripts/lib/**/*.test.js',
|
|
'<rootDir>/app/scripts/lib/**/*.test.ts',
|
|
'<rootDir>/app/scripts/lib/createRPCMethodTrackingMiddleware.test.js',
|
|
'<rootDir>/app/scripts/migrations/*.test.js',
|
|
'<rootDir>/app/scripts/platforms/*.test.js',
|
|
'<rootDir>/shared/**/*.test.(js|ts)',
|
|
'<rootDir>/ui/**/*.test.(js|ts|tsx)',
|
|
'<rootDir>/development/fitness-functions/**/*.test.(js|ts|tsx)',
|
|
],
|
|
testTimeout: 5500,
|
|
// We have to specify the environment we are running in, which is jsdom. The
|
|
// default is 'node'. This can be modified *per file* using a comment at the
|
|
// head of the file. So it may be worthwhile to switch to 'node' in any
|
|
// background tests.
|
|
testEnvironment: 'jsdom',
|
|
testEnvironmentOptions: {
|
|
customExportConditions: ['node', 'node-addons'],
|
|
},
|
|
workerIdleMemoryLimit: '500MB',
|
|
};
|