Skip to content

Commit

Permalink
Move tests alongside code under test (#354)
Browse files Browse the repository at this point in the history
All unit tests have been moved alongside the module under test. This
pattern is generally preferred by the team, and matches how tests are
organized in both the extension and mobile repos.
  • Loading branch information
Gudahtt authored and MajorLift committed Oct 11, 2023
1 parent 081699f commit 09211b6
Show file tree
Hide file tree
Showing 25 changed files with 64 additions and 61 deletions.
4 changes: 2 additions & 2 deletions tests/BaseController.test.ts → src/BaseController.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { stub } from 'sinon';
import BaseController, { BaseConfig, BaseState } from '../src/BaseController';
import ComposableController from '../src/ComposableController';
import BaseController, { BaseConfig, BaseState } from './BaseController';
import ComposableController from './ComposableController';

const STATE = { name: 'foo' };
const CONFIG = { disabled: true };
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { stub } from 'sinon';
import AddressBookController from '../src/user/AddressBookController';
import EnsController from '../src/third-party/EnsController';
import ComposableController from '../src/ComposableController';
import PreferencesController from '../src/user/PreferencesController';
import TokenRatesController from '../src/assets/TokenRatesController';
import { AssetsController } from '../src/assets/AssetsController';
import { NetworkController, NetworksChainId } from '../src/network/NetworkController';
import { AssetsContractController } from '../src/assets/AssetsContractController';
import CurrencyRateController from '../src/assets/CurrencyRateController';
import AddressBookController from './user/AddressBookController';
import EnsController from './third-party/EnsController';
import ComposableController from './ComposableController';
import PreferencesController from './user/PreferencesController';
import TokenRatesController from './assets/TokenRatesController';
import { AssetsController } from './assets/AssetsController';
import { NetworkController, NetworksChainId } from './network/NetworkController';
import { AssetsContractController } from './assets/AssetsContractController';
import CurrencyRateController from './assets/CurrencyRateController';

describe('ComposableController', () => {
it('should compose controller state', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { errorCodes } = require('eth-rpc-errors');
const ApprovalController = require('../src/approval/ApprovalController').default;
const ApprovalController = require('./ApprovalController').default;

const defaultConfig = {
showApprovalRequest: () => undefined,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { errorCodes } from 'eth-rpc-errors';
import ApprovalController from '../src/approval/ApprovalController';
import ApprovalController from './ApprovalController';

const sinon = require('sinon');

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { stub, spy } from 'sinon';
import AccountTrackerController from '../src/assets/AccountTrackerController';
import PreferencesController from '../src/user/PreferencesController';
import ComposableController from '../src/ComposableController';
import PreferencesController from '../user/PreferencesController';
import ComposableController from '../ComposableController';
import AccountTrackerController from './AccountTrackerController';

const HttpProvider = require('ethjs-provider-http');

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AssetsContractController } from '../src/assets/AssetsContractController';
import { AssetsContractController } from './AssetsContractController';

const HttpProvider = require('ethjs-provider-http');

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { createSandbox } from 'sinon';
import * as nock from 'nock';
import AssetsController from '../src/assets/AssetsController';
import ComposableController from '../src/ComposableController';
import PreferencesController from '../src/user/PreferencesController';
import { NetworkController, NetworksChainId } from '../src/network/NetworkController';
import { AssetsContractController } from '../src/assets/AssetsContractController';
import ComposableController from '../ComposableController';
import PreferencesController from '../user/PreferencesController';
import { NetworkController, NetworksChainId } from '../network/NetworkController';
import { AssetsContractController } from './AssetsContractController';
import AssetsController from './AssetsController';

const HttpProvider = require('ethjs-provider-http');

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { createSandbox, stub } from 'sinon';
import * as nock from 'nock';
import { AssetsDetectionController } from '../src/assets/AssetsDetectionController';
import { NetworkController, NetworksChainId } from '../src/network/NetworkController';
import { PreferencesController } from '../src/user/PreferencesController';
import { ComposableController } from '../src/ComposableController';
import { AssetsController } from '../src/assets/AssetsController';
import { AssetsContractController } from '../src/assets/AssetsContractController';
import { NetworkController, NetworksChainId } from '../network/NetworkController';
import { PreferencesController } from '../user/PreferencesController';
import { ComposableController } from '../ComposableController';
import { AssetsController } from './AssetsController';
import { AssetsContractController } from './AssetsContractController';
import { AssetsDetectionController } from './AssetsDetectionController';

const { BN } = require('ethereumjs-util');

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'isomorphic-fetch';
import { stub } from 'sinon';
import * as nock from 'nock';
import CurrencyRateController from '../src/assets/CurrencyRateController';
import CurrencyRateController from './CurrencyRateController';

describe('CurrencyRateController', () => {
beforeEach(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { createSandbox, stub } from 'sinon';
import ComposableController from '../src/ComposableController';
import TokenBalancesController from '../src/assets/TokenBalancesController';
import { AssetsController } from '../src/assets/AssetsController';
import { Token } from '../src/assets/TokenRatesController';
import { AssetsContractController } from '../src/assets/AssetsContractController';
import { NetworkController } from '../src/network/NetworkController';
import { PreferencesController } from '../src/user/PreferencesController';
import ComposableController from '../ComposableController';
import { NetworkController } from '../network/NetworkController';
import { PreferencesController } from '../user/PreferencesController';
import { AssetsController } from './AssetsController';
import { Token } from './TokenRatesController';
import { AssetsContractController } from './AssetsContractController';
import TokenBalancesController from './TokenBalancesController';

const { BN } = require('ethereumjs-util');
const HttpProvider = require('ethjs-provider-http');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { stub } from 'sinon';
import * as nock from 'nock';
import ComposableController from '../src/ComposableController';
import TokenRatesController, { Token } from '../src/assets/TokenRatesController';
import { AssetsController } from '../src/assets/AssetsController';
import { PreferencesController } from '../src/user/PreferencesController';
import { NetworkController } from '../src/network/NetworkController';
import { AssetsContractController } from '../src/assets/AssetsContractController';
import CurrencyRateController from '../src/assets/CurrencyRateController';
import ComposableController from '../ComposableController';
import { PreferencesController } from '../user/PreferencesController';
import { NetworkController } from '../network/NetworkController';
import TokenRatesController, { Token } from './TokenRatesController';
import { AssetsController } from './AssetsController';
import { AssetsContractController } from './AssetsContractController';
import CurrencyRateController from './CurrencyRateController';

const COINGECKO_HOST = 'https://api.coingecko.com';
const COINGECKO_PATH = '/api/v3/simple/token_price/ethereum';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import {
recoverTypedSignatureLegacy,
} from 'eth-sig-util';
import { stub } from 'sinon';
import KeyringController, { Keyring, KeyringConfig } from '../src/keyring/KeyringController';
import PreferencesController from '../src/user/PreferencesController';
import ComposableController from '../src/ComposableController';
import PreferencesController from '../user/PreferencesController';
import ComposableController from '../ComposableController';
import KeyringController, { Keyring, KeyringConfig } from './KeyringController';

const Transaction = require('ethereumjs-tx');
const mockEncryptor: any = require('./utils/mockEncryptor');
const mockEncryptor: any = require('../../tests/mocks/mockEncryptor');

const input =
'{"version":3,"id":"534e0199-53f6-41a9-a8fe-d504702ee5e8","address":"b97c80fab7a3793bbe746864db80d236f1345ea7",' +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import {
TypedMessage,
TypedMessageParams,
TypedMessageParamsMetamask,
} from '../src/message-manager/TypedMessageManager';
import AbstractMessageManager from '../src/message-manager/AbstractMessageManager';
} from './TypedMessageManager';
import AbstractMessageManager from './AbstractMessageManager';

class AbstractTestManager extends AbstractMessageManager<TypedMessage, TypedMessageParams, TypedMessageParamsMetamask> {
prepMessageForSigning(messageParams: TypedMessageParamsMetamask): Promise<TypedMessageParams> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import MessageManager from '../src/message-manager/MessageManager';
import MessageManager from './MessageManager';

describe('PersonalMessageManager', () => {
it('should set default state', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import PersonalMessageManager from '../src/message-manager/PersonalMessageManager';
import PersonalMessageManager from './PersonalMessageManager';

describe('PersonalMessageManager', () => {
it('should set default state', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import TypedMessageManager from '../src/message-manager/TypedMessageManager';
import TypedMessageManager from './TypedMessageManager';

const typedMessage = [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { stub } from 'sinon';
import NetworkController, { NetworksChainId, ProviderConfig } from '../src/network/NetworkController';
import NetworkController, { NetworksChainId, ProviderConfig } from './NetworkController';

const Web3ProviderEngine = require('web3-provider-engine');

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { toChecksumAddress } from 'ethereumjs-util';

import EnsController from '../src/third-party/EnsController';
import EnsController from './EnsController';

const address1 = '0x32Be343B94f860124dC4fEe278FDCBD38C102D88';
const address2 = '0xc38bf1ad06ef69f0c04e29dbeb4152b4175f0a8d';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { stub } from 'sinon';
import * as nock from 'nock';
import PhishingController from '../src/third-party/PhishingController';
import PhishingController from './PhishingController';

describe('PhishingController', () => {
afterEach(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { stub } from 'sinon';
import { NetworksChainId } from '../src/network/NetworkController';
import TransactionController from '../src/transaction/TransactionController';
import { NetworksChainId } from '../network/NetworkController';
import TransactionController from './TransactionController';

const globalAny: any = global;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import AddressBookController from '../src/user/AddressBookController';
import AddressBookController from './AddressBookController';

describe('AddressBookController', () => {
it('should set default state', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import PreferencesController from '../src/user/PreferencesController';
import PreferencesController from './PreferencesController';

describe('PreferencesController', () => {
it('should set default state', () => {
Expand Down
2 changes: 1 addition & 1 deletion tests/util.test.ts → src/util.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'isomorphic-fetch';
import * as nock from 'nock';

import * as util from '../src/util';
import * as util from './util';

const { BN } = require('ethereumjs-util');

Expand Down
File renamed without changes.
5 changes: 4 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
"target": "es6"
},
"include": [
"./src/**/*.ts"
"src/**/*.ts"
],
"exclude": [
"**/*.test.ts"
]
}

0 comments on commit 09211b6

Please sign in to comment.