Skip to content

Commit 14a2704

Browse files
Merge pull request #8 from nazarli-shabnam/dependency
Dependency
2 parents a6da007 + edb4368 commit 14a2704

4 files changed

Lines changed: 107 additions & 3 deletions

File tree

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,7 @@ Example: `envkit -q setup`
136136
| `envkit share export` | Export sanitized config (optional `-o` path) |
137137
| `envkit share import <file>` | Import shared config (optional `-o` path) |
138138

139-
For more detail: `envkit --help` or `envkit <command> --help`. A short **“what to run when”** guide is in [DOCUMENTATION.md](./DOCUMENTATION.md).
140-
139+
For more detail: `envkit --help` or `envkit <command> --help`.
141140
---
142141

143142
## Development and testing
@@ -149,7 +148,7 @@ npm install
149148
npm test
150149
```
151150

152-
Use `npm test -- --coverage` for a coverage report. See [DEVELOPMENT.md](./DEVELOPMENT.md) for the full contributor guide.
151+
Use `npm test -- --coverage` for a coverage report.
153152

154153
---
155154

tests/cli/integration.test.ts

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,52 @@ describe('CLI integration', () => {
9090
expect(out).toContain('generate');
9191
});
9292

93+
it('generate writes docker-compose.yml when config has docker enabled', () => {
94+
const os = require('os');
95+
const tempDir = path.join(os.tmpdir(), `devkit-e2e-generate-${Date.now()}`);
96+
fs.ensureDirSync(tempDir);
97+
const config = [
98+
'name: e2e-generate',
99+
'version: "1.0.0"',
100+
'databases:',
101+
' - type: postgresql',
102+
' port: 5432',
103+
' - type: redis',
104+
' port: 6379',
105+
'docker:',
106+
' enabled: true',
107+
' output_file: docker-compose.yml',
108+
].join('\n');
109+
fs.writeFileSync(path.join(tempDir, '.dev-env.yml'), config);
110+
try {
111+
runCli(['generate'], tempDir);
112+
const composePath = path.join(tempDir, 'docker-compose.yml');
113+
expect(fs.pathExistsSync(composePath)).toBe(true);
114+
const content = fs.readFileSync(composePath, 'utf-8');
115+
expect(content).toMatch(/version:|services:/);
116+
expect(content).toMatch(/postgres|redis/);
117+
} finally {
118+
fs.removeSync(tempDir);
119+
}
120+
});
121+
122+
it('generate -o writes to custom path', () => {
123+
const os = require('os');
124+
const tempDir = path.join(os.tmpdir(), `devkit-e2e-generate-o-${Date.now()}`);
125+
fs.ensureDirSync(tempDir);
126+
fs.writeFileSync(
127+
path.join(tempDir, '.dev-env.yml'),
128+
'name: e2e\ndatabases:\n - type: redis\n port: 6379\ndocker:\n enabled: true'
129+
);
130+
try {
131+
runCli(['generate', '-o', 'my-compose.yml'], tempDir);
132+
expect(fs.pathExistsSync(path.join(tempDir, 'my-compose.yml'))).toBe(true);
133+
expect(fs.pathExistsSync(path.join(tempDir, 'docker-compose.yml'))).toBe(false);
134+
} finally {
135+
fs.removeSync(tempDir);
136+
}
137+
});
138+
93139
it('setup --help shows skip and dry-run options', () => {
94140
const out = runCli(['setup', '--help']);
95141
expect(out).toMatch(/skip-deps|skip-db|dry-run/);
@@ -181,4 +227,49 @@ describe('CLI integration', () => {
181227
fs.removeSync(tempDir);
182228
}
183229
});
230+
231+
it('share export -o writes to custom path', () => {
232+
const os = require('os');
233+
const tempDir = path.join(os.tmpdir(), `devkit-e2e-share-export-o-${Date.now()}`);
234+
fs.ensureDirSync(tempDir);
235+
fs.writeFileSync(path.join(tempDir, '.dev-env.yml'), 'name: e2e\nversion: "1.0.0"\ndatabases: []');
236+
try {
237+
runCli(['share', 'export', '-o', 'custom-shared.yml'], tempDir);
238+
expect(fs.pathExistsSync(path.join(tempDir, 'custom-shared.yml'))).toBe(true);
239+
const content = fs.readFileSync(path.join(tempDir, 'custom-shared.yml'), 'utf-8');
240+
expect(content).toMatch(/name:\s*e2e/);
241+
} finally {
242+
fs.removeSync(tempDir);
243+
}
244+
});
245+
246+
it('share import -o writes to custom path', () => {
247+
const os = require('os');
248+
const tempDir = path.join(os.tmpdir(), `devkit-e2e-share-import-o-${Date.now()}`);
249+
fs.ensureDirSync(tempDir);
250+
const shared = 'name: imported-via-o\nversion: "1.0.0"\ndatabases: []';
251+
fs.writeFileSync(path.join(tempDir, 'in.yml'), shared);
252+
try {
253+
runCli(['share', 'import', 'in.yml', '-o', 'custom-config.yml'], tempDir);
254+
expect(fs.pathExistsSync(path.join(tempDir, 'custom-config.yml'))).toBe(true);
255+
const content = fs.readFileSync(path.join(tempDir, 'custom-config.yml'), 'utf-8');
256+
expect(content).toMatch(/imported-via-o/);
257+
} finally {
258+
fs.removeSync(tempDir);
259+
}
260+
});
261+
262+
it('snapshot list shows created snapshot name', () => {
263+
const os = require('os');
264+
const tempDir = path.join(os.tmpdir(), `devkit-e2e-list-${Date.now()}`);
265+
fs.ensureDirSync(tempDir);
266+
fs.writeFileSync(path.join(tempDir, '.dev-env.yml'), 'name: e2e\nversion: "1.0.0"');
267+
runCli(['snapshot', 'create', 'list-test-snap'], tempDir);
268+
try {
269+
const out = runCli(['snapshot', 'list'], tempDir);
270+
expect(out).toContain('list-test-snap');
271+
} finally {
272+
fs.removeSync(tempDir);
273+
}
274+
});
184275
});

tests/commands/init.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ describe('init command', () => {
4646
const name = await getDefaultProjectName(tempDir);
4747
expect(name).toBe(path.basename(tempDir));
4848
});
49+
50+
it('returns directory basename when package.json is invalid JSON', async () => {
51+
await fs.writeFile(path.join(tempDir, 'package.json'), 'not valid json {');
52+
const name = await getDefaultProjectName(tempDir);
53+
expect(name).toBe(path.basename(tempDir));
54+
});
4955
});
5056

5157
describe('isInteractive', () => {

tests/core/config/loader.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,14 @@ describe('config loader', () => {
109109
});
110110

111111
describe('loadConfigOrPromptInit', () => {
112+
it('returns config without prompting when .dev-env.yml exists', async () => {
113+
await fs.writeFile(path.join(tempDir, '.dev-env.yml'), validConfigYaml);
114+
const cfg = await loadConfigOrPromptInit(tempDir);
115+
expect(cfg.name).toBe('test-project');
116+
expect(prompts).not.toHaveBeenCalled();
117+
expect(runInit).not.toHaveBeenCalled();
118+
});
119+
112120
it('throws with a helpful message when missing and not a TTY', async () => {
113121
const stdout = process.stdout as NodeJS.WriteStream & { isTTY?: boolean };
114122
const original = stdout.isTTY;

0 commit comments

Comments
 (0)