You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+79-2Lines changed: 79 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -42,12 +42,14 @@ npm i @algorandfoundation/algorand-typescript-testing
42
42
43
43
Let's write a simple contract and test it using the `algorand-typescript-testing` framework.
44
44
45
+
#### Configuring vitest
46
+
45
47
If you are using [vitest](https://vitest.dev/) with [@rollup/plugin-typescript](https://www.npmjs.com/package/@rollup/plugin-typescript) plugin, configure `puyaTsTransformer` as a `before` stage transformer of `typescript` plugin in `vitest.config.mts` file.
If you are using [jest](https://jestjs.io/) with [ts-jest](https://www.npmjs.com/package/ts-jest), [@jest/globals](https://www.npmjs.com/package/@jest/globals) and [ts-node](https://www.npmjs.com/package/ts-node) plugins, configure `puyaTsTransformer` as a `before` stage transformer of `typescript` plugin in `jest.config.ts` file.
`algorand-typescript-testing` package also exposes additional equality testers which enables the smart contract developers to write terser test by avoiding type casting in assertions. It can setup in `beforeAll` hook point in the setup file, `jest.setup.ts`.
There is also a patch file `ts-jest+29.2.5.patch` that needs to be applied to `ts-jest` package to for the `puyaTsTransformer` to work with the test files.
131
+
132
+
1. Place the file in `<rootDir>\patches` folder.
133
+
1. Install [patch-package](https://www.npmjs.com/package/patch-package) package as a dev dependency.
134
+
1. Add `"postinstall": "patch-package",` script in `package.json` file.
135
+
The patch will then be applied with every `npm install` call.
After the setup, the examples provided using `vitest` can be converted to work with `jest` by simply swapping the `import {...} from 'vitest'` with `import {...} from '@jest/globals'`.
Defined in: [src/test-transformer/jest-transformer.ts:49](https://github.com/algorandfoundation/algorand-typescript-testing/blob/main/src/test-transformer/jest-transformer.ts#L49)
12
+
13
+
Factory function that creates TypeScript program transformers for Jest.
14
+
Used by ts-jest to transform TypeScript files during test execution.
15
+
Initialized with default transformer configuration.
16
+
17
+
## Parameters
18
+
19
+
### compilerInstance
20
+
21
+
#### program
22
+
23
+
`Program`
24
+
25
+
## Returns
26
+
27
+
`TransformerFactory`\<`SourceFile`\>
28
+
29
+
## Example
30
+
31
+
```ts
32
+
// Use as before stage transformer with custom config in jest.config.ts
Defined in: [src/test-transformer/jest-transformer.ts:15](https://github.com/algorandfoundation/algorand-typescript-testing/blob/main/src/test-transformer/jest-transformer.ts#L15)
[@algorandfoundation/algorand-typescript-testing](../../../README.md) / [test-transformer/jest-transformer](../README.md) / version
6
+
7
+
# Variable: version
8
+
9
+
> `const`**version**: `"0.1.0"` = `'0.1.0'`
10
+
11
+
Defined in: [src/test-transformer/jest-transformer.ts:16](https://github.com/algorandfoundation/algorand-typescript-testing/blob/main/src/test-transformer/jest-transformer.ts#L16)
Defined in: [src/test-transformer/vitest-transformer.ts:54](https://github.com/algorandfoundation/algorand-typescript-testing/blob/main/src/test-transformer/vitest-transformer.ts#L54)
Defined in: [src/test-transformer/vitest-transformer.ts:55](https://github.com/algorandfoundation/algorand-typescript-testing/blob/main/src/test-transformer/vitest-transformer.ts#L55)
0 commit comments