Skip to content
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
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ jobs:
- yanse
- inquirerer
- create-gen-app
- create-gen-app-test

steps:
- name: Checkout code
Expand Down
88 changes: 88 additions & 0 deletions packages/create-gen-app-test/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# create-gen-app-test

Integration tests for `create-gen-app` with cache leveraging using `appstash`.

## Overview

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.

## Features

- Clone GitHub repositories to a local cache
- Reuse cached templates for faster project generation
- Variable replacement in templates
- Integration tests with real GitHub cloning
- Snapshot testing for generated files

## Usage

```typescript
import { createFromCachedTemplate } from 'create-gen-app-test';

const result = await createFromCachedTemplate({
templateUrl: 'https://github.com/launchql/pgpm-boilerplates',
outputDir: './my-new-project',
answers: {
PROJECT_NAME: 'my-project',
AUTHOR: 'Your Name',
MODULE_NAME: 'mymodule'
},
cacheTool: 'mymodule'
});

console.log('Cache used:', result.cacheUsed);
```

## API

### `getCachedRepo(templateUrl, cacheTool?)`

Get cached repository from appstash cache directory.

- `templateUrl`: Repository URL
- `cacheTool`: Tool name for appstash (default: 'mymodule')
- Returns: Cached repository path or null if not found

### `cloneToCache(templateUrl, cacheTool?)`

Clone repository to cache.

- `templateUrl`: Repository URL
- `cacheTool`: Tool name for appstash (default: 'mymodule')
- Returns: Path to cached repository

### `createFromCachedTemplate(options)`

Create project from cached template.

- `options.templateUrl`: Repository URL
- `options.outputDir`: Output directory path
- `options.answers`: Variable replacements
- `options.cacheTool`: Tool name for appstash (default: 'mymodule')
- Returns: Promise with result containing outputDir, cacheUsed, and cachePath

## Testing

The package includes comprehensive integration tests that:

1. Clone real repositories from GitHub (default: https://github.com/launchql/pgpm-boilerplates)
2. Cache templates using appstash
3. Process templates with variable replacement
4. Snapshot generated files and package.json files
5. Test cache reuse on subsequent clones
6. Verify cache persistence

Run tests:

```bash
pnpm test
```

## Cache Location

Templates are cached using appstash at:
- `~/.{cacheTool}/cache/repos/{md5-hash-of-url}`

## License

MIT
19 changes: 19 additions & 0 deletions packages/create-gen-app-test/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
transform: {
'^.+\\.tsx?$': [
'ts-jest',
{
babelConfig: false,
tsconfig: 'tsconfig.json',
},
],
},
transformIgnorePatterns: [`/node_modules/*`],
testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$',
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
modulePathIgnorePatterns: ['dist/*'],
testTimeout: 60000,
};
39 changes: 39 additions & 0 deletions packages/create-gen-app-test/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"name": "create-gen-app-test",
"version": "0.1.0",
"author": "Dan Lynch <[email protected]>",
"description": "Integration tests for create-gen-app with cache leveraging",
"main": "index.js",
"module": "esm/index.js",
"types": "index.d.ts",
"homepage": "https://github.com/hyperweb-io/dev-utils",
"license": "MIT",
"private": true,
"publishConfig": {
"access": "restricted",
"directory": "dist"
},
"repository": {
"type": "git",
"url": "https://github.com/hyperweb-io/dev-utils"
},
"bugs": {
"url": "https://github.com/hyperweb-io/dev-utils/issues"
},
"scripts": {
"copy": "makage assets",
"clean": "makage clean",
"prepublishOnly": "npm run build",
"build": "npm run clean && makage build-ts && npm run copy",
"test": "jest",
"test:watch": "jest --watch"
},
"dependencies": {
"appstash": "workspace:*",
"create-gen-app": "workspace:*"
},
"devDependencies": {
"makage": "0.1.5"
},
"keywords": []
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,221 @@
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing

exports[`cached template integration tests first clone with variable replacement should snapshot created directory structure 1`] = `
[
"module/",
"module/README.md",
"module/__tests__/",
"module/__tests__/basic.test.ts",
"module/jest.config.js",
"module/package.json",
"workspace/",
"workspace/.eslintrc.json",
"workspace/.github/",
"workspace/.github/run-tests.yaml",
"workspace/.gitignore",
"workspace/.prettierrc.json",
"workspace/.vscode/",
"workspace/.vscode/settings.json",
"workspace/LICENSE",
"workspace/Makefile",
"workspace/README.md",
"workspace/bin/",
"workspace/bin/install.sh",
"workspace/docker-compose.yml",
"workspace/launchql.json",
"workspace/lerna.json",
"workspace/package.json",
"workspace/pnpm-workspace.yaml",
"workspace/tsconfig.json",
]
`;

exports[`cached template integration tests first clone with variable replacement should snapshot package.json files if they exist 1`] = `
{
"module/package.json": {
"author": "__USERFULLNAME__ <__USEREMAIL__>",
"bugs": {
"url": "https://github.com/__USERNAME__/__REPONAME__/issues",
},
"description": "__MODULEDESC__",
"devDependencies": {
"pgsql-test": "^2.13.2",
},
"homepage": "https://github.com/__USERNAME__/__REPONAME__",
"keywords": [],
"license": "SEE LICENSE IN LICENSE",
"name": "__PACKAGE_IDENTIFIER__",
"pnpm": {
"overrides": {
"graphql": "14.7.0",
},
},
"publishConfig": {
"access": "__ACCESS__",
"directory": "dist",
},
"repository": {
"type": "git",
"url": "https://github.com/__USERNAME__/__REPONAME__",
},
"scripts": {
"lint": "eslint . --fix",
"test": "jest",
"test:watch": "jest --watch",
},
"version": "0.0.1",
},
"workspace/package.json": {
"author": "__USERFULLNAME__ <__USEREMAIL__>",
"devDependencies": {
"@types/jest": "^29.5.14",
"@types/node": "^22.10.2",
"@typescript-eslint/eslint-plugin": "^8.15.0",
"@typescript-eslint/parser": "^8.15.0",
"eslint": "^9.13.0",
"eslint-config-prettier": "^10.1.1",
"eslint-plugin-simple-import-sort": "^12.1.1",
"eslint-plugin-unused-imports": "^4.3.0",
"jest": "^29.7.0",
"lerna": "^8.2.4",
"pgsql-test": "^2.13.2",
"prettier": "^3.3.3",
"ts-jest": "^29.2.5",
"ts-node": "^10.9.2",
"typescript": "^5.6.3",
},
"license": "SEE LICENSE IN LICENSE",
"name": "__MODULENAME__",
"pnpm": {
"overrides": {
"graphql": "14.7.0",
},
},
"private": true,
"publishConfig": {
"access": "restricted",
},
"repository": {
"type": "git",
"url": "https://github.com/__USERNAME__/__MODULENAME__",
},
"scripts": {
"lint": "pnpm -r run lint",
},
"version": "0.0.1",
"workspaces": [
"packages/*",
],
},
}
`;

exports[`cached template integration tests second clone from cache should snapshot created directory structure from cache 1`] = `
[
"module/",
"module/README.md",
"module/__tests__/",
"module/__tests__/basic.test.ts",
"module/jest.config.js",
"module/package.json",
"workspace/",
"workspace/.eslintrc.json",
"workspace/.github/",
"workspace/.github/run-tests.yaml",
"workspace/.gitignore",
"workspace/.prettierrc.json",
"workspace/.vscode/",
"workspace/.vscode/settings.json",
"workspace/LICENSE",
"workspace/Makefile",
"workspace/README.md",
"workspace/bin/",
"workspace/bin/install.sh",
"workspace/docker-compose.yml",
"workspace/launchql.json",
"workspace/lerna.json",
"workspace/package.json",
"workspace/pnpm-workspace.yaml",
"workspace/tsconfig.json",
]
`;

exports[`cached template integration tests second clone from cache should snapshot package.json files from cached template 1`] = `
{
"module/package.json": {
"author": "__USERFULLNAME__ <__USEREMAIL__>",
"bugs": {
"url": "https://github.com/__USERNAME__/__REPONAME__/issues",
},
"description": "__MODULEDESC__",
"devDependencies": {
"pgsql-test": "^2.13.2",
},
"homepage": "https://github.com/__USERNAME__/__REPONAME__",
"keywords": [],
"license": "SEE LICENSE IN LICENSE",
"name": "__PACKAGE_IDENTIFIER__",
"pnpm": {
"overrides": {
"graphql": "14.7.0",
},
},
"publishConfig": {
"access": "__ACCESS__",
"directory": "dist",
},
"repository": {
"type": "git",
"url": "https://github.com/__USERNAME__/__REPONAME__",
},
"scripts": {
"lint": "eslint . --fix",
"test": "jest",
"test:watch": "jest --watch",
},
"version": "0.0.1",
},
"workspace/package.json": {
"author": "__USERFULLNAME__ <__USEREMAIL__>",
"devDependencies": {
"@types/jest": "^29.5.14",
"@types/node": "^22.10.2",
"@typescript-eslint/eslint-plugin": "^8.15.0",
"@typescript-eslint/parser": "^8.15.0",
"eslint": "^9.13.0",
"eslint-config-prettier": "^10.1.1",
"eslint-plugin-simple-import-sort": "^12.1.1",
"eslint-plugin-unused-imports": "^4.3.0",
"jest": "^29.7.0",
"lerna": "^8.2.4",
"pgsql-test": "^2.13.2",
"prettier": "^3.3.3",
"ts-jest": "^29.2.5",
"ts-node": "^10.9.2",
"typescript": "^5.6.3",
},
"license": "SEE LICENSE IN LICENSE",
"name": "__MODULENAME__",
"pnpm": {
"overrides": {
"graphql": "14.7.0",
},
},
"private": true,
"publishConfig": {
"access": "restricted",
},
"repository": {
"type": "git",
"url": "https://github.com/__USERNAME__/__MODULENAME__",
},
"scripts": {
"lint": "pnpm -r run lint",
},
"version": "0.0.1",
"workspaces": [
"packages/*",
],
},
}
`;
Loading