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
Original file line number Diff line number Diff line change
Expand Up @@ -2,61 +2,42 @@

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",
"LICENSE",
"README.md",
"__tests__/",
"__tests__/basic.test.ts",
"jest.config.js",
"package.json",
]
`;

exports[`cached template integration tests first clone with variable replacement should snapshot package.json files if they exist 1`] = `
{
"module/package.json": {
"author": "____fullName____ <____email____>",
"package.json": {
"author": "Test User test <tester-test@example.com>",
"bugs": {
"url": "https://github.com/____username____/____repoName____/issues",
"url": "https://github.com/Test User test/Test User test/issues",
},
"description": "____moduleDesc____",
"description": "Test Module test",
"devDependencies": {
"pgsql-test": "^2.13.2",
},
"homepage": "https://github.com/____username____/____repoName____",
"homepage": "https://github.com/Test User test/Test User test",
"keywords": [],
"license": "____license____",
"name": "____packageIdentifier____",
"license": "MIT",
"name": "integration-test",
"pnpm": {
"overrides": {
"graphql": "14.7.0",
},
},
"publishConfig": {
"access": "____access____",
"access": "public",
"directory": "dist",
},
"repository": {
"type": "git",
"url": "https://github.com/____username____/____repoName____",
"url": "https://github.com/Test User test/Test User test",
},
"scripts": {
"lint": "eslint . --fix",
Expand All @@ -65,108 +46,47 @@ exports[`cached template integration tests first clone with variable replacement
},
"version": "0.0.1",
},
"workspace/package.json": {
"author": "____fullName____ <____email____>",
"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",
"LICENSE",
"README.md",
"__tests__/",
"__tests__/basic.test.ts",
"jest.config.js",
"package.json",
]
`;

exports[`cached template integration tests second clone from cache should snapshot package.json files from cached template 1`] = `
{
"module/package.json": {
"author": "____fullName____ <____email____>",
"package.json": {
"author": "Test User cached <tester-cached@example.com>",
"bugs": {
"url": "https://github.com/____username____/____repoName____/issues",
"url": "https://github.com/Test User cached/Test User cached/issues",
},
"description": "____moduleDesc____",
"description": "Test Module cached",
"devDependencies": {
"pgsql-test": "^2.13.2",
},
"homepage": "https://github.com/____username____/____repoName____",
"homepage": "https://github.com/Test User cached/Test User cached",
"keywords": [],
"license": "____license____",
"name": "____packageIdentifier____",
"license": "MIT",
"name": "integration-cached",
"pnpm": {
"overrides": {
"graphql": "14.7.0",
},
},
"publishConfig": {
"access": "____access____",
"access": "public",
"directory": "dist",
},
"repository": {
"type": "git",
"url": "https://github.com/____username____/____repoName____",
"url": "https://github.com/Test User cached/Test User cached",
},
"scripts": {
"lint": "eslint . --fix",
Expand All @@ -175,47 +95,5 @@ exports[`cached template integration tests second clone from cache should snapsh
},
"version": "0.0.1",
},
"workspace/package.json": {
"author": "____fullName____ <____email____>",
"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/*",
],
},
}
`;
79 changes: 46 additions & 33 deletions packages/create-gen-app-test/src/__tests__/cached-template.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import * as path from 'path';

import { appstash, resolve } from 'appstash';

import { createFromCachedTemplate, TemplateCache } from '../index';
import { createFromTemplate, CacheManager, GitCloner } from '../index';
import { buildAnswers, TEST_REPO, TEST_TEMPLATE } from '../test-utils/integration-helpers';

const DEFAULT_TEMPLATE_URL = 'https://github.com/launchql/pgpm-boilerplates';
const DEFAULT_TEMPLATE_URL = TEST_REPO;

describe('cached template integration tests', () => {
let testOutputDir: string;
Expand Down Expand Up @@ -35,25 +36,36 @@ describe('cached template integration tests', () => {

describe('cache functionality', () => {
let sharedCachePath: string;
let templateCache: TemplateCache;
let cacheManager: CacheManager;

beforeAll(() => {
templateCache = new TemplateCache({
enabled: true,
cacheManager = new CacheManager({
toolName: testCacheTool,
});
});

it('should return null when cache does not exist for new URL', () => {
const nonExistentUrl = 'https://github.com/nonexistent/repo-test-123456';
const cachedRepo = templateCache.get(nonExistentUrl);
const cacheKey = cacheManager.createKey(nonExistentUrl);
const cachedRepo = cacheManager.get(cacheKey);
expect(cachedRepo).toBeNull();
});

it('should clone repository to cache', () => {
const cachePath = templateCache.set(DEFAULT_TEMPLATE_URL);
// Use GitCloner + CacheManager to clone and cache
const gitCloner = new GitCloner();
const normalizedUrl = gitCloner.normalizeUrl(DEFAULT_TEMPLATE_URL);
const cacheKey = cacheManager.createKey(normalizedUrl);

// Clone to cache directory
const cachePath = path.join(cacheManager.getReposDir(), cacheKey);
gitCloner.clone(normalizedUrl, cachePath, { depth: 1 });

// Register in cache manager
cacheManager.set(cacheKey, cachePath);
sharedCachePath = cachePath;

// Verify cache was created correctly
expect(fs.existsSync(cachePath)).toBe(true);
expect(fs.existsSync(path.join(cachePath, '.git'))).toBe(false);

Expand All @@ -62,7 +74,11 @@ describe('cached template integration tests', () => {
}, 60000);

it('should retrieve cached repository', () => {
const cachedRepo = templateCache.get(DEFAULT_TEMPLATE_URL);
const gitCloner = new GitCloner();
const normalizedUrl = gitCloner.normalizeUrl(DEFAULT_TEMPLATE_URL);
const cacheKey = cacheManager.createKey(normalizedUrl);
const cachedRepo = cacheManager.get(cacheKey);

expect(cachedRepo).not.toBeNull();
expect(cachedRepo).toBe(sharedCachePath);
expect(fs.existsSync(cachedRepo!)).toBe(true);
Expand All @@ -76,16 +92,13 @@ describe('cached template integration tests', () => {
beforeAll(async () => {
firstOutputDir = fs.mkdtempSync(path.join(os.tmpdir(), 'first-clone-'));

firstCloneResult = await createFromCachedTemplate({
firstCloneResult = await createFromTemplate({
templateUrl: DEFAULT_TEMPLATE_URL,
outputDir: firstOutputDir,
answers: {
PROJECT_NAME: 'test-project',
AUTHOR: 'Test Author',
DESCRIPTION: 'A test project',
MODULE_NAME: 'testmodule'
},
cacheTool: testCacheTool
answers: buildAnswers('test'),
toolName: testCacheTool,
noTty: true,
fromPath: TEST_TEMPLATE
});
}, 60000);

Expand Down Expand Up @@ -128,11 +141,15 @@ describe('cached template integration tests', () => {
});

it('should verify template cache was created', () => {
const templateCache = new TemplateCache({
enabled: true,
// Verify cache was created by createFromTemplate
const cacheManager = new CacheManager({
toolName: testCacheTool,
});
const cachedRepo = templateCache.get(DEFAULT_TEMPLATE_URL);
const gitCloner = new GitCloner();
const normalizedUrl = gitCloner.normalizeUrl(DEFAULT_TEMPLATE_URL);
const cacheKey = cacheManager.createKey(normalizedUrl);
const cachedRepo = cacheManager.get(cacheKey);

expect(cachedRepo).not.toBeNull();
expect(fs.existsSync(cachedRepo!)).toBe(true);
});
Expand All @@ -143,28 +160,24 @@ describe('cached template integration tests', () => {
let secondOutputDir: string;

beforeAll(async () => {
await createFromCachedTemplate({
await createFromTemplate({
templateUrl: DEFAULT_TEMPLATE_URL,
outputDir: fs.mkdtempSync(path.join(os.tmpdir(), 'warmup-')),
answers: {
PROJECT_NAME: 'warmup',
MODULE_NAME: 'warmup'
},
cacheTool: testCacheTool
answers: buildAnswers('warmup'),
toolName: testCacheTool,
noTty: true,
fromPath: TEST_TEMPLATE
});

secondOutputDir = fs.mkdtempSync(path.join(os.tmpdir(), 'second-clone-'));

secondCloneResult = await createFromCachedTemplate({
secondCloneResult = await createFromTemplate({
templateUrl: DEFAULT_TEMPLATE_URL,
outputDir: secondOutputDir,
answers: {
PROJECT_NAME: 'cached-project',
AUTHOR: 'Cached Author',
DESCRIPTION: 'A cached test project',
MODULE_NAME: 'cachedmodule'
},
cacheTool: testCacheTool
answers: buildAnswers('cached'),
toolName: testCacheTool,
noTty: true,
fromPath: TEST_TEMPLATE
});
}, 60000);

Expand Down
Loading