Skip to content

refactor: change convention for test file extension to opt-in to puyaTsTransformer #87

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,14 @@ Let's write a simple contract and test it using the `algorand-typescript-testing

#### Simulating AVM

`algorand-typescript-testing` includes a TypeScript transformer (`puyaTsTransformer`) that ensures contracts (with `.algo.ts` extension) and tests (with `.spec.ts` or `.test.ts` extensions) behave consistently between Node.js and AVM environments.
`algorand-typescript-testing` includes a TypeScript transformer (`puyaTsTransformer`) that ensures contracts (with `.algo.ts` extension) and tests (with `.algo.spec.ts` or `.algo.test.ts` extensions) behave consistently between Node.js and AVM environments.

The transformer replicates AVM behavior, such as integer-only arithmetic where `3 / 2` produces `1`. For code requiring standard Node.js behaviour (e.g., `3 / 2` produces `1.5`), place it in separate `.ts` files and reference them from test files.

The transformer also redirects `@algorandfoundation/algorand-typescript` imports to `@algorandfoundation/algorand-typescript-testing/internal` to provide executable implementations of Algorand TypeScript constructs like `Global`, `Box`, `Uint64`, and `clone`.

If there are tests which do not need to be executed in the AVM context such as end to end tests, simply use `.test.ts` or `.spec.ts` file extensions without `.algo` part and the transformer would skip them.

#### Configuring vitest

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 the `typescript` plugin in `vitest.config.mts` file.
Expand Down Expand Up @@ -93,7 +97,7 @@ import { createDefaultEsmPreset, type JestConfigWithTsJest } from 'ts-jest'
const presetConfig = createDefaultEsmPreset({})
const jestConfig: JestConfigWithTsJest = {
...presetConfig,
testMatch: ['**/*.test.ts'],
testMatch: ['**/*.algo.test.ts'],
setupFilesAfterEnv: ['<rootDir>/jest.setup.ts'],
transform: {
'^.+\\.tsx?$': [
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"tsx": "4.19.3",
"typedoc": "^0.28.1",
"typedoc-plugin-markdown": "^4.6.0",
"typescript": "^5.8.2",
"typescript": "^5.8.3",
"upath": "^2.0.1",
"vitest": "3.2.4"
},
Expand Down
2 changes: 1 addition & 1 deletion src/test-transformer/program-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export interface TransformerConfig {
testingPackageName: string
}
export const defaultTransformerConfig: TransformerConfig = {
includeExt: ['.algo.ts', '.spec.ts', '.test.ts'],
includeExt: ['.algo.ts', '.algo.spec.ts', '.algo.test.ts'],
testingPackageName: '@algorandfoundation/algorand-typescript-testing',
}

Expand Down
2 changes: 1 addition & 1 deletion src/test-transformer/vitest-transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ programTransformer.factory = createProgramFactory(defaultTransformerConfig)
** @type {ts.TransformerFactory<ts.SourceFile> & ((config: Partial<TransformerConfig>) => ts.TransformerFactory<ts.SourceFile>)}
*
* @param {Partial<TransformerConfig>} [config] Configuration options
* @param {string[]} [config.includeExt=['.algo.ts', '.spec.ts']] File extensions to process
* @param {string[]} [config.includeExt=['.algo.ts', '.algo.spec.ts']] File extensions to process
* @param {string} [config.testingPackageName='@algorandfoundation/algorand-typescript-testing'] Package name for testing imports
*
* @example
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.