Skip to content

Commit e1fa468

Browse files
authored
test: Improve test stability with TestResource class (#32)
### **User description** - Created a reusable TestResource class for consistent resource management - Provides isolated filesystem and database resources for all tests - Added proper cleanup via the disposable pattern - Implemented resilient assertion patterns to reduce flaky tests - Enabled parallelized test execution with increased concurrency --- Notes: * This PR was written _entirely_ by Claude, only using my voice to command it. * The first few commits were via RooCode, the last via https://docs.anthropic.com/en/docs/agents-and-tools/claude-code/overview ___ ### **PR Type** Tests, Enhancement ___ ### **Description** - Introduced `TestResource` class for consistent test resource management. - Provides isolated filesystem and database resources. - Implements proper cleanup using the disposable pattern. - Reduces flaky tests with resilient assertion patterns. - Refactored tests to use `TestResource` for improved stability and isolation. - Enabled parallelized test execution with increased concurrency. - Updated test configurations and added new utility methods for testing. ___ ### **Changes walkthrough** 📝 <table><thead><tr><th></th><th align="left">Relevant files</th></tr></thead><tbody><tr><td><strong>Tests</strong></td><td><details><summary>5 files</summary><table> <tr> <td><strong>apply.test.tsx</strong><dd><code>Updated test directory structure for isolation</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dd></td> <td><a href="https://github.com/t1mmen/srtd/pull/32/files#diff-b86a1df589c794b641e68687d765ed5aa2dcc3d195afb6a056844b3dca864ce0">+1/-1</a>&nbsp; &nbsp; &nbsp; </td> </tr> <tr> <td><strong>build.test.tsx</strong><dd><code>Updated test directory structure for isolation</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dd></td> <td><a href="https://github.com/t1mmen/srtd/pull/32/files#diff-f82cace99bc6ced0d2a9bee725156909094b816f9028e9c764a32e5fab243101">+1/-1</a>&nbsp; &nbsp; &nbsp; </td> </tr> <tr> <td><strong>vitest.setup.ts</strong><dd><code>Adjusted test setup for resource isolation</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dd></td> <td><a href="https://github.com/t1mmen/srtd/pull/32/files#diff-a7231f65284d6b5befab281d02b36ac5f4ca6a6dc3a48c5b1e92fac80f2e485d">+3/-1</a>&nbsp; &nbsp; &nbsp; </td> </tr> <tr> <td><strong>templateManager.test.ts</strong><dd><code>Refactored tests to use `TestResource`</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dd></td> <td><a href="https://github.com/t1mmen/srtd/pull/32/files#diff-b0a41028136ed13c9f9e762da8548c680144f9a2872ffc91bcc85c547802dcd1">+368/-306</a></td> </tr> <tr> <td><strong>registerTemplate.test.ts</strong><dd><code>Refactored tests to use `TestResource`</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dd></td> <td><a href="https://github.com/t1mmen/srtd/pull/32/files#diff-fd68ada194b1717bd54d8a6e2dda664456514498bb907fbb226738d8806db009">+62/-86</a>&nbsp; </td> </tr> </table></details></td></tr><tr><td><strong>Enhancement</strong></td><td><details><summary>2 files</summary><table> <tr> <td><strong>TestResource.ts</strong><dd><code>Added `TestResource` class for test resource management</code>&nbsp; &nbsp; </dd></td> <td><a href="https://github.com/t1mmen/srtd/pull/32/files#diff-c474a92f081031dbfed0785a68937e11a37e65acdff55156fa62cb021d2eb3f3">+326/-0</a>&nbsp; </td> </tr> <tr> <td><strong>index.ts</strong><dd><code>Exported `TestResource` utility</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dd></td> <td><a href="https://github.com/t1mmen/srtd/pull/32/files#diff-41f83663a32268136dbb7de6f1ba49905ca17137d350c399936dcf4cc6ef3f0d">+1/-0</a>&nbsp; &nbsp; &nbsp; </td> </tr> </table></details></td></tr><tr><td><strong>Configuration changes</strong></td><td><details><summary>1 files</summary><table> <tr> <td><strong>vitest.config.ts</strong><dd><code>Enabled parallelized test execution</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dd></td> <td><a href="https://github.com/t1mmen/srtd/pull/32/files#diff-2ee894bf23aa44ff4ce12a3da8af19ab20180474ebf2176dbe5f2eea3f96dc92">+2/-0</a>&nbsp; &nbsp; &nbsp; </td> </tr> </table></details></td></tr><tr><td><strong>Documentation</strong></td><td><details><summary>1 files</summary><table> <tr> <td><strong>big-ads-clean.md</strong><dd><code>Added changeset for test stability improvements</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dd></td> <td><a href="https://github.com/t1mmen/srtd/pull/32/files#diff-4ee0590e047a4e79fc4ca960b8cd2bf690acee595d913c445ebd56f1c6039106">+11/-0</a>&nbsp; &nbsp; </td> </tr> </table></details></td></tr><tr><td><strong>Formatting</strong></td><td><details><summary>1 files</summary><table> <tr> <td><strong>srtd.config.json</strong><dd><code>Minor formatting adjustment</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dd></td> <td><a href="https://github.com/t1mmen/srtd/pull/32/files#diff-513f5e2650567f1141543846690cd1ace5383d325b3bb9b5d2e030a1cfae8edd">+1/-1</a>&nbsp; &nbsp; &nbsp; </td> </tr> </table></details></td></tr></tr></tbody></table> ___ > <details> <summary> Need help?</summary><li>Type <code>/help how to ...</code> in the comments thread for any questions about Qodo Merge usage.</li><li>Check out the <a href="https://qodo-merge-docs.qodo.ai/usage-guide/">documentation</a> for more information.</li></details>
1 parent 20e463f commit e1fa468

38 files changed

+2114
-578
lines changed

.changeset/big-ads-clean.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
"@t1mmen/srtd": patch
3+
---
4+
5+
Improve test stability and coverage
6+
7+
- Created a reusable TestResource class for consistent resource management
8+
- Provides isolated filesystem and database resources for all tests
9+
- Added proper cleanup via the disposable pattern with automated resource tracking
10+
- Implemented resilient assertion patterns to reduce flaky tests
11+
- Enabled parallelized test execution with increased concurrency
12+
- Fixed TypeScript errors in tests
13+
- Added E2E test framework for simple CLI operation validation

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ npm-debug.log*
88
*.tsbuildinfo
99
.npm
1010
.env
11+
coverage
1112

1213
# srtd's local logs should not be committed, as they're per-environment specific
1314
.srtd.buildlog.local.json

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ supabase migration up # Apply using Supabase CLI
9999
```
100100

101101
> [!TIP]
102-
> To reduce noise in PR's, consider adding `migration-templates/*srtd*.sql linguist-generated=true` to your [`.gitattributes` file.](https://docs.github.com/en/repositories/working-with-files/managing-files/customizing-how-changed-files-appear-on-github) (unless you manually edit the generated files)
102+
> To reduce noise in PR's, consider adding `supabase/migrations/*srtd*.sql linguist-generated=true` to your [`.gitattributes` file.](https://docs.github.com/en/repositories/working-with-files/managing-files/customizing-how-changed-files-appear-on-github) (unless you manually edit the generated files)
103103
104104

105105
## The Power of Templates 💪

biome.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
{
22
"$schema": "https://biomejs.dev/schemas/1.9.4/schema.json",
33
"vcs": { "enabled": false, "clientKind": "git", "useIgnoreFile": false },
4-
"files": { "ignoreUnknown": false, "ignore": [] },
4+
"files": { "ignoreUnknown": false, "ignore": ["dist/**", "build/**", "coverage/**"] },
55
"formatter": {
66
"enabled": true,
77
"useEditorconfig": true,
8-
"formatWithErrors": false,
8+
"formatWithErrors": true,
99
"indentStyle": "space",
1010
"indentWidth": 2,
1111
"lineEnding": "lf",
1212
"lineWidth": 100,
1313
"attributePosition": "auto",
1414
"bracketSpacing": true,
15-
"ignore": ["dist/**", "package-lock.json", "package.json"]
15+
"ignore": ["dist/**", "package-lock.json", "package.json", "build/**", "coverage/**"]
1616
},
1717
"organizeImports": { "enabled": true },
1818
"linter": {
19-
"ignore": ["dist/**", "package-lock.json", "package.json"],
19+
"ignore": ["dist/**", "build/**", "package-lock.json", "package.json"],
2020
"enabled": true,
2121
"rules": {
2222
"recommended": true,

lefthook.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,12 @@ pre-commit:
2020
. ~/.nvm/nvm.sh
2121
if [ -f ".nvmrc" ]; then
2222
nvm use
23-
./node_modules/.bin/biome lint {staged_files}
23+
# First try to fix errors automatically
24+
./node_modules/.bin/biome check --write {staged_files}
25+
# If there are still unsafe fixes available, apply them if requested
26+
if [ "$APPLY_UNSAFE_FIXES" = "true" ]; then
27+
./node_modules/.bin/biome check --write --unsafe {staged_files}
28+
fi
29+
# Add fixed files back to staging
30+
git add {staged_files}
2431
fi

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,17 @@
1717
"release": "npm run build && changeset publish",
1818
"build": "rm -rf dist && tsc",
1919
"typecheck": "tsc --noEmit",
20-
"lint": "biome lint . --write",
20+
"lint": "biome check . --write",
21+
"lint:unsafe": "biome check . --write --unsafe",
2122
"format": "biome format . --write",
2223
"dev": "tsc --watch",
2324
"test": "vitest",
2425
"test:coverage": "vitest run --coverage --reporter=junit --outputFile=test-report.junit.xml",
26+
"test:e2e": "vitest run src/__tests__/e2e/",
2527
"start": "tsx src/cli.tsx",
2628
"start:link": "npm run build && npm link && chmod u+x ./dist/cli.js && srtd",
29+
"precommit:safe": "lefthook run pre-commit",
30+
"precommit:all": "APPLY_UNSAFE_FIXES=true lefthook run pre-commit",
2731
"repomix": "mkdir build; npx repomix",
2832
"supabase:start": "npx supabase start",
2933
"supabase:stop": "npx supabase stop",
@@ -97,4 +101,4 @@
97101
"typescript": "^5.7.2",
98102
"vitest": "^2.1.8"
99103
}
100-
}
104+
}

src/__tests__/apply.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ describe('Apply Command', () => {
2424
const testContext = {
2525
timestamp: Date.now(),
2626
testFunctionName: `${TEST_FN_PREFIX}${Date.now()}`,
27-
testDir: path.join(tmpdir(), `test-apply-command-${Date.now()}`),
27+
testDir: path.join(tmpdir(), 'srtd-test', `test-apply-command-${Date.now()}`),
2828
};
2929

3030
vi.mock('ink', async importOriginal => {

src/__tests__/build.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ describe('Build Command', () => {
2323
const testContext = {
2424
timestamp: Date.now(),
2525
testFunctionName: `${TEST_FN_PREFIX}${Date.now()}`,
26-
testDir: path.join(tmpdir(), `test-build-command-${Date.now()}`),
26+
testDir: path.join(tmpdir(), 'srtd-test', `test-build-command-${Date.now()}`),
2727
};
2828

2929
vi.mock('ink', async importOriginal => {

src/__tests__/e2e/cli.test.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* Simple verification test for CLI command structure
3+
*
4+
* This test doesn't run the actual CLI but validates that all expected
5+
* commands are correctly defined and registered in the application.
6+
*/
7+
8+
import fs from 'node:fs/promises';
9+
import path from 'node:path';
10+
import { describe, expect, it } from 'vitest';
11+
12+
describe('CLI Commands Test', () => {
13+
// Check for the existence of command files
14+
it('should have all required command files', async () => {
15+
const commandsDir = path.resolve(process.cwd(), 'src/commands');
16+
const files = await fs.readdir(commandsDir);
17+
18+
// Verify core command files exist
19+
expect(files).toContain('apply.tsx');
20+
expect(files).toContain('build.tsx');
21+
expect(files).toContain('clear.tsx');
22+
expect(files).toContain('init.tsx');
23+
expect(files).toContain('watch.tsx');
24+
});
25+
26+
// Verify CLI entry point exists
27+
it('should have a main CLI entry point', async () => {
28+
const cliPath = path.resolve(process.cwd(), 'src/cli.tsx');
29+
const exists = await fs
30+
.stat(cliPath)
31+
.then(() => true)
32+
.catch(() => false);
33+
34+
expect(exists).toBe(true);
35+
});
36+
});

0 commit comments

Comments
 (0)