Skip to content

Commit 8e0efa6

Browse files
authored
Merge pull request #9 from hyperweb-io/test-cga
test CGA
2 parents 55edec2 + c65df88 commit 8e0efa6

File tree

10 files changed

+3301
-5005
lines changed

10 files changed

+3301
-5005
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ jobs:
6060
- yanse
6161
- inquirerer
6262
- create-gen-app
63+
- create-gen-app-test
6364

6465
steps:
6566
- name: Checkout code
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# create-gen-app-test
2+
3+
Integration tests for `create-gen-app` with cache leveraging using `appstash`.
4+
5+
## Overview
6+
7+
This package provides functionality to clone and cache template repositories for efficient reuse. It combines the power of `create-gen-app` for template processing and `appstash` for cache management.
8+
9+
## Features
10+
11+
- Clone GitHub repositories to a local cache
12+
- Reuse cached templates for faster project generation
13+
- Variable replacement in templates
14+
- Integration tests with real GitHub cloning
15+
- Snapshot testing for generated files
16+
17+
## Usage
18+
19+
```typescript
20+
import { createFromCachedTemplate } from 'create-gen-app-test';
21+
22+
const result = await createFromCachedTemplate({
23+
templateUrl: 'https://github.com/launchql/pgpm-boilerplates',
24+
outputDir: './my-new-project',
25+
answers: {
26+
PROJECT_NAME: 'my-project',
27+
AUTHOR: 'Your Name',
28+
MODULE_NAME: 'mymodule'
29+
},
30+
cacheTool: 'mymodule'
31+
});
32+
33+
console.log('Cache used:', result.cacheUsed);
34+
```
35+
36+
## API
37+
38+
### `getCachedRepo(templateUrl, cacheTool?)`
39+
40+
Get cached repository from appstash cache directory.
41+
42+
- `templateUrl`: Repository URL
43+
- `cacheTool`: Tool name for appstash (default: 'mymodule')
44+
- Returns: Cached repository path or null if not found
45+
46+
### `cloneToCache(templateUrl, cacheTool?)`
47+
48+
Clone repository to cache.
49+
50+
- `templateUrl`: Repository URL
51+
- `cacheTool`: Tool name for appstash (default: 'mymodule')
52+
- Returns: Path to cached repository
53+
54+
### `createFromCachedTemplate(options)`
55+
56+
Create project from cached template.
57+
58+
- `options.templateUrl`: Repository URL
59+
- `options.outputDir`: Output directory path
60+
- `options.answers`: Variable replacements
61+
- `options.cacheTool`: Tool name for appstash (default: 'mymodule')
62+
- Returns: Promise with result containing outputDir, cacheUsed, and cachePath
63+
64+
## Testing
65+
66+
The package includes comprehensive integration tests that:
67+
68+
1. Clone real repositories from GitHub (default: https://github.com/launchql/pgpm-boilerplates)
69+
2. Cache templates using appstash
70+
3. Process templates with variable replacement
71+
4. Snapshot generated files and package.json files
72+
5. Test cache reuse on subsequent clones
73+
6. Verify cache persistence
74+
75+
Run tests:
76+
77+
```bash
78+
pnpm test
79+
```
80+
81+
## Cache Location
82+
83+
Templates are cached using appstash at:
84+
- `~/.{cacheTool}/cache/repos/{md5-hash-of-url}`
85+
86+
## License
87+
88+
MIT
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/** @type {import('ts-jest').JestConfigWithTsJest} */
2+
module.exports = {
3+
preset: 'ts-jest',
4+
testEnvironment: 'node',
5+
transform: {
6+
'^.+\\.tsx?$': [
7+
'ts-jest',
8+
{
9+
babelConfig: false,
10+
tsconfig: 'tsconfig.json',
11+
},
12+
],
13+
},
14+
transformIgnorePatterns: [`/node_modules/*`],
15+
testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$',
16+
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
17+
modulePathIgnorePatterns: ['dist/*'],
18+
testTimeout: 60000,
19+
};
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"name": "create-gen-app-test",
3+
"version": "0.1.0",
4+
"author": "Dan Lynch <[email protected]>",
5+
"description": "Integration tests for create-gen-app with cache leveraging",
6+
"main": "index.js",
7+
"module": "esm/index.js",
8+
"types": "index.d.ts",
9+
"homepage": "https://github.com/hyperweb-io/dev-utils",
10+
"license": "MIT",
11+
"private": true,
12+
"publishConfig": {
13+
"access": "restricted",
14+
"directory": "dist"
15+
},
16+
"repository": {
17+
"type": "git",
18+
"url": "https://github.com/hyperweb-io/dev-utils"
19+
},
20+
"bugs": {
21+
"url": "https://github.com/hyperweb-io/dev-utils/issues"
22+
},
23+
"scripts": {
24+
"copy": "makage assets",
25+
"clean": "makage clean",
26+
"prepublishOnly": "npm run build",
27+
"build": "npm run clean && makage build-ts && npm run copy",
28+
"test": "jest",
29+
"test:watch": "jest --watch"
30+
},
31+
"dependencies": {
32+
"appstash": "workspace:*",
33+
"create-gen-app": "workspace:*"
34+
},
35+
"devDependencies": {
36+
"makage": "0.1.5"
37+
},
38+
"keywords": []
39+
}
Lines changed: 221 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,221 @@
1+
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
2+
3+
exports[`cached template integration tests first clone with variable replacement should snapshot created directory structure 1`] = `
4+
[
5+
"module/",
6+
"module/README.md",
7+
"module/__tests__/",
8+
"module/__tests__/basic.test.ts",
9+
"module/jest.config.js",
10+
"module/package.json",
11+
"workspace/",
12+
"workspace/.eslintrc.json",
13+
"workspace/.github/",
14+
"workspace/.github/run-tests.yaml",
15+
"workspace/.gitignore",
16+
"workspace/.prettierrc.json",
17+
"workspace/.vscode/",
18+
"workspace/.vscode/settings.json",
19+
"workspace/LICENSE",
20+
"workspace/Makefile",
21+
"workspace/README.md",
22+
"workspace/bin/",
23+
"workspace/bin/install.sh",
24+
"workspace/docker-compose.yml",
25+
"workspace/launchql.json",
26+
"workspace/lerna.json",
27+
"workspace/package.json",
28+
"workspace/pnpm-workspace.yaml",
29+
"workspace/tsconfig.json",
30+
]
31+
`;
32+
33+
exports[`cached template integration tests first clone with variable replacement should snapshot package.json files if they exist 1`] = `
34+
{
35+
"module/package.json": {
36+
"author": "__USERFULLNAME__ <__USEREMAIL__>",
37+
"bugs": {
38+
"url": "https://github.com/__USERNAME__/__REPONAME__/issues",
39+
},
40+
"description": "__MODULEDESC__",
41+
"devDependencies": {
42+
"pgsql-test": "^2.13.2",
43+
},
44+
"homepage": "https://github.com/__USERNAME__/__REPONAME__",
45+
"keywords": [],
46+
"license": "SEE LICENSE IN LICENSE",
47+
"name": "__PACKAGE_IDENTIFIER__",
48+
"pnpm": {
49+
"overrides": {
50+
"graphql": "14.7.0",
51+
},
52+
},
53+
"publishConfig": {
54+
"access": "__ACCESS__",
55+
"directory": "dist",
56+
},
57+
"repository": {
58+
"type": "git",
59+
"url": "https://github.com/__USERNAME__/__REPONAME__",
60+
},
61+
"scripts": {
62+
"lint": "eslint . --fix",
63+
"test": "jest",
64+
"test:watch": "jest --watch",
65+
},
66+
"version": "0.0.1",
67+
},
68+
"workspace/package.json": {
69+
"author": "__USERFULLNAME__ <__USEREMAIL__>",
70+
"devDependencies": {
71+
"@types/jest": "^29.5.14",
72+
"@types/node": "^22.10.2",
73+
"@typescript-eslint/eslint-plugin": "^8.15.0",
74+
"@typescript-eslint/parser": "^8.15.0",
75+
"eslint": "^9.13.0",
76+
"eslint-config-prettier": "^10.1.1",
77+
"eslint-plugin-simple-import-sort": "^12.1.1",
78+
"eslint-plugin-unused-imports": "^4.3.0",
79+
"jest": "^29.7.0",
80+
"lerna": "^8.2.4",
81+
"pgsql-test": "^2.13.2",
82+
"prettier": "^3.3.3",
83+
"ts-jest": "^29.2.5",
84+
"ts-node": "^10.9.2",
85+
"typescript": "^5.6.3",
86+
},
87+
"license": "SEE LICENSE IN LICENSE",
88+
"name": "__MODULENAME__",
89+
"pnpm": {
90+
"overrides": {
91+
"graphql": "14.7.0",
92+
},
93+
},
94+
"private": true,
95+
"publishConfig": {
96+
"access": "restricted",
97+
},
98+
"repository": {
99+
"type": "git",
100+
"url": "https://github.com/__USERNAME__/__MODULENAME__",
101+
},
102+
"scripts": {
103+
"lint": "pnpm -r run lint",
104+
},
105+
"version": "0.0.1",
106+
"workspaces": [
107+
"packages/*",
108+
],
109+
},
110+
}
111+
`;
112+
113+
exports[`cached template integration tests second clone from cache should snapshot created directory structure from cache 1`] = `
114+
[
115+
"module/",
116+
"module/README.md",
117+
"module/__tests__/",
118+
"module/__tests__/basic.test.ts",
119+
"module/jest.config.js",
120+
"module/package.json",
121+
"workspace/",
122+
"workspace/.eslintrc.json",
123+
"workspace/.github/",
124+
"workspace/.github/run-tests.yaml",
125+
"workspace/.gitignore",
126+
"workspace/.prettierrc.json",
127+
"workspace/.vscode/",
128+
"workspace/.vscode/settings.json",
129+
"workspace/LICENSE",
130+
"workspace/Makefile",
131+
"workspace/README.md",
132+
"workspace/bin/",
133+
"workspace/bin/install.sh",
134+
"workspace/docker-compose.yml",
135+
"workspace/launchql.json",
136+
"workspace/lerna.json",
137+
"workspace/package.json",
138+
"workspace/pnpm-workspace.yaml",
139+
"workspace/tsconfig.json",
140+
]
141+
`;
142+
143+
exports[`cached template integration tests second clone from cache should snapshot package.json files from cached template 1`] = `
144+
{
145+
"module/package.json": {
146+
"author": "__USERFULLNAME__ <__USEREMAIL__>",
147+
"bugs": {
148+
"url": "https://github.com/__USERNAME__/__REPONAME__/issues",
149+
},
150+
"description": "__MODULEDESC__",
151+
"devDependencies": {
152+
"pgsql-test": "^2.13.2",
153+
},
154+
"homepage": "https://github.com/__USERNAME__/__REPONAME__",
155+
"keywords": [],
156+
"license": "SEE LICENSE IN LICENSE",
157+
"name": "__PACKAGE_IDENTIFIER__",
158+
"pnpm": {
159+
"overrides": {
160+
"graphql": "14.7.0",
161+
},
162+
},
163+
"publishConfig": {
164+
"access": "__ACCESS__",
165+
"directory": "dist",
166+
},
167+
"repository": {
168+
"type": "git",
169+
"url": "https://github.com/__USERNAME__/__REPONAME__",
170+
},
171+
"scripts": {
172+
"lint": "eslint . --fix",
173+
"test": "jest",
174+
"test:watch": "jest --watch",
175+
},
176+
"version": "0.0.1",
177+
},
178+
"workspace/package.json": {
179+
"author": "__USERFULLNAME__ <__USEREMAIL__>",
180+
"devDependencies": {
181+
"@types/jest": "^29.5.14",
182+
"@types/node": "^22.10.2",
183+
"@typescript-eslint/eslint-plugin": "^8.15.0",
184+
"@typescript-eslint/parser": "^8.15.0",
185+
"eslint": "^9.13.0",
186+
"eslint-config-prettier": "^10.1.1",
187+
"eslint-plugin-simple-import-sort": "^12.1.1",
188+
"eslint-plugin-unused-imports": "^4.3.0",
189+
"jest": "^29.7.0",
190+
"lerna": "^8.2.4",
191+
"pgsql-test": "^2.13.2",
192+
"prettier": "^3.3.3",
193+
"ts-jest": "^29.2.5",
194+
"ts-node": "^10.9.2",
195+
"typescript": "^5.6.3",
196+
},
197+
"license": "SEE LICENSE IN LICENSE",
198+
"name": "__MODULENAME__",
199+
"pnpm": {
200+
"overrides": {
201+
"graphql": "14.7.0",
202+
},
203+
},
204+
"private": true,
205+
"publishConfig": {
206+
"access": "restricted",
207+
},
208+
"repository": {
209+
"type": "git",
210+
"url": "https://github.com/__USERNAME__/__MODULENAME__",
211+
},
212+
"scripts": {
213+
"lint": "pnpm -r run lint",
214+
},
215+
"version": "0.0.1",
216+
"workspaces": [
217+
"packages/*",
218+
],
219+
},
220+
}
221+
`;

0 commit comments

Comments
 (0)