-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: added global type file & changed setup file directory
- Loading branch information
Showing
7 changed files
with
45 additions
and
36 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,5 @@ | ||
--- | ||
"fuels": minor | ||
--- | ||
|
||
chore: integrate vitest matchers globally |
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,15 @@ | ||
import type { BNInput } from 'fuels'; | ||
|
||
declare global { | ||
namespace Vitest { | ||
interface Assertion { | ||
toEqualBn(expected: BNInput): void; | ||
} | ||
interface ExpectStatic { | ||
toEqualBn(expected: BNInput): { | ||
asymmetricMatch(actual: BNInput): boolean; | ||
toString(): string; | ||
}; | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,49 +1,38 @@ | ||
import { bn } from 'fuels'; | ||
import type { BNInput } from 'fuels'; | ||
import type { BNInput, BN } from 'fuels'; | ||
|
||
type MatcherResult = { | ||
message: () => string; | ||
pass: boolean; | ||
}; | ||
|
||
type BNAsymmetricMatcher = { | ||
asymmetricMatch(actual: BNInput): boolean; | ||
toString(): string; | ||
}; | ||
interface Matchers<R = BN> { | ||
toEqualBn: (expected: BNInput) => R; | ||
} | ||
|
||
declare module 'vitest' { | ||
interface Expect { | ||
toEqualBn(expected: BNInput): void; | ||
} | ||
interface Assertion extends Matchers {} | ||
interface AsymmetricMatchersContaining extends Matchers {} | ||
interface ExpectStatic { | ||
toEqualBn(expected: BNInput): BNAsymmetricMatcher; | ||
} | ||
interface AsymmetricMatchersContaining { | ||
toEqualBn(expected: BNInput): BNAsymmetricMatcher; | ||
toEqualBn(expected: BNInput): BN; | ||
} | ||
} | ||
|
||
const createMatcher = (expected: BNInput): BNAsymmetricMatcher => ({ | ||
asymmetricMatch: (actual: BNInput) => bn(actual).eq(bn(expected)), | ||
toString: () => `BNMatcher(${expected})`, | ||
}); | ||
|
||
export const setupTestMatchers = () => { | ||
expect.extend({ | ||
toEqualBn(received: BNInput, expected: BNInput): MatcherResult { | ||
toEqualBn(received: BNInput, expected: BNInput) { | ||
const actualBn = bn(received); | ||
const expectedBn = bn(expected); | ||
const pass = actualBn.eq(expectedBn); | ||
|
||
if (pass) { | ||
return { | ||
pass, | ||
message: () => `Expected ${actualBn} not to equal ${expectedBn}`, | ||
actual: actualBn, | ||
}; | ||
} | ||
|
||
return { | ||
pass, | ||
message: () => | ||
pass | ||
? `Expected ${actualBn.toString()} not to equal ${expectedBn.toString()}` | ||
: `Expected ${actualBn.toString()} to equal ${expectedBn.toString()}`, | ||
message: () => `Expected ${actualBn} to equal ${expectedBn}`, | ||
actual: expectedBn, | ||
}; | ||
}, | ||
}); | ||
|
||
expect.toEqualBn = createMatcher; | ||
}; |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,7 +1,8 @@ | ||
{ | ||
"extends": "../../tsconfig.base.json", | ||
"compilerOptions": { | ||
"outDir": "./dist" | ||
"outDir": "./dist", | ||
"types": ["vitest/globals"] | ||
}, | ||
"include": ["src", "test"] | ||
"include": ["src", "global.d.ts"] | ||
} |
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,3 @@ | ||
import { setupTestMatchers } from './src/abi/vitest.matcher'; | ||
|
||
setupTestMatchers(); |
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