From d261154911ba59bc776fe35d3ff7bb3c08ab8053 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Torres?= <30977845+Torres-ssf@users.noreply.github.com> Date: Thu, 1 Feb 2024 13:17:22 -0300 Subject: [PATCH] chore: stop removing `fuel-ts/utils` node modules on unit test (#1692) --- .changeset/honest-parrots-wait.md | 2 ++ packages/abi-coder/src/coders/boolean.test.ts | 8 -------- packages/abi-typegen/test/utils/mockVersions.ts | 17 ----------------- .../cli/commands/dev/autoStartFuelCore.test.ts | 8 -------- .../commands/init/shouldUseBuiltinForc.test.ts | 8 -------- .../init/shouldUseBuiltinFuelCore.test.ts | 8 -------- packages/providers/package.json | 3 +-- packages/providers/test/provider.test.ts | 16 ---------------- packages/utils/package.json | 4 +--- .../utils/src/cli-utils/findBinPath.test.ts | 10 ++++++++-- packages/wallet/src/account.test.ts | 8 -------- packages/wallet/src/utils.test.ts | 8 -------- packages/wallet/src/wallet-unlocked.test.ts | 8 -------- pnpm-lock.yaml | 10 +++------- 14 files changed, 15 insertions(+), 103 deletions(-) create mode 100644 .changeset/honest-parrots-wait.md diff --git a/.changeset/honest-parrots-wait.md b/.changeset/honest-parrots-wait.md new file mode 100644 index 00000000000..a845151cc84 --- /dev/null +++ b/.changeset/honest-parrots-wait.md @@ -0,0 +1,2 @@ +--- +--- diff --git a/packages/abi-coder/src/coders/boolean.test.ts b/packages/abi-coder/src/coders/boolean.test.ts index 35c39ee2f4d..4598c2ea723 100644 --- a/packages/abi-coder/src/coders/boolean.test.ts +++ b/packages/abi-coder/src/coders/boolean.test.ts @@ -3,14 +3,6 @@ import { expectToThrowFuelError } from '@fuel-ts/errors/test-utils'; import { BooleanCoder } from './boolean'; -vi.mock('@fuel-ts/math', async () => { - const mod = await vi.importActual('@fuel-ts/math'); - return { - __esModule: true, - ...mod, - }; -}); - /** * @group node */ diff --git a/packages/abi-typegen/test/utils/mockVersions.ts b/packages/abi-typegen/test/utils/mockVersions.ts index bf0b666a746..f0ec62cac13 100644 --- a/packages/abi-typegen/test/utils/mockVersions.ts +++ b/packages/abi-typegen/test/utils/mockVersions.ts @@ -1,22 +1,5 @@ import * as versionsMod from '@fuel-ts/versions'; -// TODO: Check if there's a better alternative to this -/** - * This makes it possible to mock modules that are exported - * from package's index files, using exports syntax such as: - * - * export * from '...' - * - * https://stackoverflow.com/a/72885576 - */ -vi.mock('@fuel-ts/versions', async () => { - const mod = await vi.importActual('@fuel-ts/versions'); - return { - __esModule: true, - ...mod, - }; -}); - export function mockVersions( values: { FUELS: string; diff --git a/packages/fuels/src/cli/commands/dev/autoStartFuelCore.test.ts b/packages/fuels/src/cli/commands/dev/autoStartFuelCore.test.ts index 35cbbf508dc..2b270f493d8 100644 --- a/packages/fuels/src/cli/commands/dev/autoStartFuelCore.test.ts +++ b/packages/fuels/src/cli/commands/dev/autoStartFuelCore.test.ts @@ -8,14 +8,6 @@ import type { FuelsConfig } from '../../types'; import type { FuelCoreNode } from './autoStartFuelCore'; import { autoStartFuelCore } from './autoStartFuelCore'; -vi.mock('@fuel-ts/wallet/test-utils', async () => { - const mod = await vi.importActual('@fuel-ts/wallet/test-utils'); - return { - __esModule: true, - ...mod, - }; -}); - /** * @group node */ diff --git a/packages/fuels/src/cli/commands/init/shouldUseBuiltinForc.test.ts b/packages/fuels/src/cli/commands/init/shouldUseBuiltinForc.test.ts index 560c5597616..6324b16246a 100644 --- a/packages/fuels/src/cli/commands/init/shouldUseBuiltinForc.test.ts +++ b/packages/fuels/src/cli/commands/init/shouldUseBuiltinForc.test.ts @@ -4,14 +4,6 @@ import { mockLogger } from '../../../../test/utils/mockLogger'; import { shouldUseBuiltinFuelCore } from './shouldUseBuiltinFuelCore'; -vi.mock('@fuel-ts/versions/cli', async () => { - const mod = await vi.importActual('@fuel-ts/versions/cli'); - return { - __esModule: true, - ...mod, - }; -}); - vi.mock('prompts', async () => { const mod = await vi.importActual('prompts'); return { diff --git a/packages/fuels/src/cli/commands/init/shouldUseBuiltinFuelCore.test.ts b/packages/fuels/src/cli/commands/init/shouldUseBuiltinFuelCore.test.ts index 04d44fe6629..3f02b09f773 100644 --- a/packages/fuels/src/cli/commands/init/shouldUseBuiltinFuelCore.test.ts +++ b/packages/fuels/src/cli/commands/init/shouldUseBuiltinFuelCore.test.ts @@ -4,14 +4,6 @@ import { mockLogger } from '../../../../test/utils/mockLogger'; import { shouldUseBuiltinForc } from './shouldUseBuiltinForc'; -vi.mock('@fuel-ts/versions/cli', async () => { - const mod = await vi.importActual('@fuel-ts/versions/cli'); - return { - __esModule: true, - ...mod, - }; -}); - /** * @group node */ diff --git a/packages/providers/package.json b/packages/providers/package.json index d7a9b680755..01cee3c5182 100644 --- a/packages/providers/package.json +++ b/packages/providers/package.json @@ -36,8 +36,8 @@ "@fuel-ts/math": "workspace:*", "@fuel-ts/hasher": "workspace:*", "@fuel-ts/transactions": "workspace:*", - "ethers": "^6.7.1", "@fuel-ts/versions": "workspace:*", + "ethers": "^6.7.1", "graphql": "^16.6.0", "graphql-request": "5.0.0", "graphql-tag": "^2.12.6", @@ -45,7 +45,6 @@ "tai64": "^1.0.0" }, "devDependencies": { - "@fuel-ts/utils": "workspace:*", "@graphql-codegen/cli": "^2.13.7", "@graphql-codegen/typescript": "^2.8.0", "@graphql-codegen/typescript-operations": "^2.5.5", diff --git a/packages/providers/test/provider.test.ts b/packages/providers/test/provider.test.ts index 95cc5339398..2ba7d4d08a4 100644 --- a/packages/providers/test/provider.test.ts +++ b/packages/providers/test/provider.test.ts @@ -25,22 +25,6 @@ import * as gasMod from '../src/utils/gas'; import { messageProofResponse, messageStatusResponse } from './fixtures'; -vi.mock('@fuel-ts/versions', async () => { - const mod = await vi.importActual('@fuel-ts/versions'); - return { - __esModule: true, - ...mod, - }; -}); - -vi.mock('@fuel-ts/math', async () => { - const mod = await vi.importActual('@fuel-ts/math'); - return { - __esModule: true, - ...mod, - }; -}); - afterEach(() => { vi.restoreAllMocks(); }); diff --git a/packages/utils/package.json b/packages/utils/package.json index ff339800609..0ded8fa075a 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -48,10 +48,8 @@ "license": "Apache-2.0", "dependencies": { "@fuel-ts/interfaces": "workspace:*", + "@fuel-ts/errors": "workspace:*", "ramda": "^0.29.0", "rimraf": "^3.0.2" - }, - "devDependencies": { - "@fuel-ts/errors": "workspace:*" } } diff --git a/packages/utils/src/cli-utils/findBinPath.test.ts b/packages/utils/src/cli-utils/findBinPath.test.ts index cb1ddde4c9c..48c1247299a 100644 --- a/packages/utils/src/cli-utils/findBinPath.test.ts +++ b/packages/utils/src/cli-utils/findBinPath.test.ts @@ -14,7 +14,13 @@ describe('findBinPath', () => { const bin = join(mods, '.bin'); const cmdPath = join(bin, cmdName); - const resetDisk = () => rmSync(mods, { recursive: true }); + const resetDisk = (params?: { cmdOnly: boolean }) => { + if (params?.cmdOnly) { + rmSync(cmdPath); + } else { + rmSync(mods, { recursive: true }); + } + }; mkdirSync(bin, { recursive: true }); writeFileSync(cmdPath, ''); @@ -45,7 +51,7 @@ describe('findBinPath', () => { const { cmdName, cmdPath, resetDisk } = bootstrap(base); const binPath = findBinPath(cmdName, base); - resetDisk(); + resetDisk({ cmdOnly: true }); expect(binPath).toEqual(cmdPath); }); diff --git a/packages/wallet/src/account.test.ts b/packages/wallet/src/account.test.ts index e0259eabe54..187e6b316bb 100644 --- a/packages/wallet/src/account.test.ts +++ b/packages/wallet/src/account.test.ts @@ -16,14 +16,6 @@ import type { TxParamsType } from './account'; import { Account } from './account'; import { FUEL_NETWORK_URL } from './configs'; -vi.mock('@fuel-ts/providers', async () => { - const mod = await vi.importActual('@fuel-ts/providers'); - return { - __esModule: true, - ...mod, - }; -}); - let provider: Provider; afterEach(() => { diff --git a/packages/wallet/src/utils.test.ts b/packages/wallet/src/utils.test.ts index 6dc90931c7e..fdf91e7f34e 100644 --- a/packages/wallet/src/utils.test.ts +++ b/packages/wallet/src/utils.test.ts @@ -9,14 +9,6 @@ import { formatScriptDataForTransferringToContract, } from './utils'; -vi.mock('@fuels/vm-asm', async () => { - const mod = await vi.importActual('@fuels/vm-asm'); - return { - __esModule: true, - ...mod, - }; -}); - vi.mock('ethers', async () => { const mod = await vi.importActual('ethers'); return { diff --git a/packages/wallet/src/wallet-unlocked.test.ts b/packages/wallet/src/wallet-unlocked.test.ts index 04e3f7ae400..2891ebd45ff 100644 --- a/packages/wallet/src/wallet-unlocked.test.ts +++ b/packages/wallet/src/wallet-unlocked.test.ts @@ -14,14 +14,6 @@ import * as keystoreWMod from './keystore-wallet'; import walletSpec from './wallet-spec'; import { WalletLocked, WalletUnlocked } from './wallets'; -vi.mock('@fuel-ts/providers', async () => { - const mod = await vi.importActual('@fuel-ts/providers'); - return { - __esModule: true, - ...mod, - }; -}); - const { ScriptTransactionRequest } = providersMod; /** diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index e6b76f555b6..59a24a378c3 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1028,9 +1028,6 @@ importers: specifier: ^1.0.0 version: 1.0.0 devDependencies: - '@fuel-ts/utils': - specifier: workspace:* - version: link:../utils '@graphql-codegen/cli': specifier: ^2.13.7 version: 2.13.7(@babel/core@7.23.3)(@types/node@20.10.5)(graphql@16.6.0)(ts-node@10.9.1)(typescript@5.2.2) @@ -1137,6 +1134,9 @@ importers: packages/utils: dependencies: + '@fuel-ts/errors': + specifier: workspace:* + version: link:../errors '@fuel-ts/interfaces': specifier: workspace:* version: link:../interfaces @@ -1146,10 +1146,6 @@ importers: rimraf: specifier: ^3.0.2 version: 3.0.2 - devDependencies: - '@fuel-ts/errors': - specifier: workspace:* - version: link:../errors packages/versions: dependencies: