Skip to content

Commit 307c47f

Browse files
committed
chore: moving unit tests
1 parent c6f5a20 commit 307c47f

24 files changed

+69
-54
lines changed

package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@
4040
"workspaces": [
4141
"./cli/*",
4242
"./packages/*",
43-
"./templates/*",
44-
"./tests/*"
43+
"./templates/*"
4544
],
4645
"dependencies": {
4746
"@tanstack/config": "^0.16.2"

pnpm-lock.yaml

+4-13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pnpm-workspace.yaml

-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,3 @@ packages:
22
- 'packages/*'
33
- 'cli/*'
44
- 'templates/*'
5-
- 'tests/*'

templates/react-cra/package.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"scripts": {
99
"build": "tsc",
1010
"dev": "tsc --watch",
11-
"test": "eslint ./src"
11+
"test": "eslint ./src && vitest run",
12+
"test:watch": "vitest"
1213
},
1314
"repository": {
1415
"type": "git",
@@ -33,6 +34,7 @@
3334
},
3435
"devDependencies": {
3536
"@types/node": "^22.13.4",
36-
"typescript": "^5.6.3"
37+
"typescript": "^5.6.3",
38+
"vitest": "^3.1.1"
3739
}
3840
}

tests/integration-tests/react-cra.test.ts renamed to templates/react-cra/tests/react-cra.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88

99
import type { AddOn, Options } from '@tanstack/cta-engine'
1010

11-
import { register as registerReactCra } from '@tanstack/cta-templates-react-cra'
11+
import { register as registerReactCra } from '../src/index.js'
1212

1313
import { cleanupOutput, createTestEnvironment } from './test-utilities.js'
1414

templates/solid/package.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"scripts": {
99
"build": "tsc",
1010
"dev": "tsc --watch",
11-
"test": "eslint ./src"
11+
"test": "eslint ./src && vitest run",
12+
"test:watch": "vitest"
1213
},
1314
"repository": {
1415
"type": "git",
@@ -32,6 +33,7 @@
3233
},
3334
"devDependencies": {
3435
"@types/node": "^22.13.4",
35-
"typescript": "^5.6.3"
36+
"typescript": "^5.6.3",
37+
"vitest": "^3.1.1"
3638
}
3739
}

tests/integration-tests/solid.test.ts renamed to templates/solid/tests/solid.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import type { AddOn, Options } from '@tanstack/cta-engine'
1010

1111
import { cleanupOutput, createTestEnvironment } from './test-utilities.js'
1212

13-
import { register as registerSolid } from '@tanstack/cta-templates-solid'
13+
import { register as registerSolid } from '../src/index.js'
1414

1515
beforeAll(async () => {
1616
registerSolid()
+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { dirname, join, basename, extname } from 'node:path'
2+
3+
import { createMemoryEnvironment } from '@tanstack/cta-engine'
4+
5+
const IGNORE_EXTENSIONS = ['.png', '.ico', '.svg']
6+
7+
export function createTestEnvironment(projectName: string) {
8+
const { environment, output } = createMemoryEnvironment()
9+
10+
const trimProjectRelativePath = (path: string) =>
11+
join(
12+
dirname(path).replace(new RegExp(`^.*/${projectName}`), ''),
13+
basename(path),
14+
)
15+
16+
return {
17+
environment,
18+
output,
19+
trimProjectRelativePath,
20+
}
21+
}
22+
23+
export function cleanupOutput(
24+
output: {
25+
files: Record<string, string>
26+
commands: Array<{
27+
command: string
28+
args: Array<string>
29+
}>
30+
},
31+
trimProjectRelativePath: (path: string) => string,
32+
) {
33+
const filteredFiles = Object.keys(output.files)
34+
.filter((key) => !IGNORE_EXTENSIONS.includes(extname(key)))
35+
.reduce(
36+
(acc, key) => {
37+
acc[trimProjectRelativePath(key)] = output.files[key]
38+
return acc
39+
},
40+
{} as Record<string, string>,
41+
)
42+
43+
const sortedFiles = Object.keys(filteredFiles)
44+
.sort()
45+
.reduce(
46+
(acc, key) => {
47+
acc[key] = filteredFiles[key]
48+
return acc
49+
},
50+
{} as Record<string, string>,
51+
)
52+
53+
output.files = sortedFiles
54+
}

tests/integration-tests/package.json

-15
This file was deleted.

tests/integration-tests/tsconfig.json

-17
This file was deleted.

0 commit comments

Comments
 (0)