From 85b15f06259ea6b4bdc46f7bad81c913bcfc696f Mon Sep 17 00:00:00 2001 From: 7000pctAUTO Date: Sat, 31 Jan 2026 20:27:46 +0000 Subject: [PATCH] Initial upload with CI/CD workflow --- tests/cli.test.ts | 94 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 tests/cli.test.ts diff --git a/tests/cli.test.ts b/tests/cli.test.ts new file mode 100644 index 0000000..3533e54 --- /dev/null +++ b/tests/cli.test.ts @@ -0,0 +1,94 @@ +import * as path from 'path'; +import * as fs from 'fs'; +import { execSync } from 'child_process'; + +describe('CLI', () => { + const fixturesDir = path.join(__dirname, 'fixtures'); + const cliPath = path.join(__dirname, '..', 'dist', 'index.js'); + + describe('--help flag', () => { + test('shows help', () => { + const output = execSync( + `node ${cliPath} --help`, + { encoding: 'utf-8' } + ); + + expect(output).toContain('Usage'); + expect(output).toContain('validate'); + expect(output).toContain('generate'); + expect(output).toContain('migrate'); + }); + }); + + describe('--version flag', () => { + test('shows version', () => { + const output = execSync( + `node ${cliPath} --version`, + { encoding: 'utf-8' } + ); + + expect(output).toMatch(/^\d+\.\d+\.\d+/); + }); + }); + + describe('validate command', () => { + test('validates valid .env file', () => { + const envPath = path.join(fixturesDir, '.env'); + const schemaPath = path.join(fixturesDir, 'schema.json'); + + const output = execSync( + `node ${cliPath} validate -e ${envPath} -s ${schemaPath}`, + { encoding: 'utf-8' } + ); + + expect(output).toContain('Validation passed'); + }); + }); + + describe('generate command', () => { + test('generates TypeScript interface', () => { + const envPath = path.join(fixturesDir, '.env'); + + const output = execSync( + `node ${cliPath} generate -e ${envPath}`, + { encoding: 'utf-8' } + ); + + expect(output).toContain('export interface EnvVariables'); + expect(output).toContain('PORT: number;'); + }); + + test('writes output to file', () => { + const envPath = path.join(fixturesDir, '.env'); + const outputFile = path.join(__dirname, 'output.ts'); + + execSync( + `node ${cliPath} generate -e ${envPath} -o ${outputFile}`, + { encoding: 'utf-8' } + ); + + const generated = fs.readFileSync(outputFile, 'utf-8'); + expect(generated).toContain('export interface EnvVariables'); + + fs.unlinkSync(outputFile); + }); + }); + + describe('migrate command', () => { + test('generates schema.json', () => { + const envPath = path.join(fixturesDir, '.env'); + const outputFile = path.join(__dirname, 'schema_output.json'); + + execSync( + `node ${cliPath} migrate -e ${envPath} -o ${outputFile}`, + { encoding: 'utf-8' } + ); + + const schema = JSON.parse(fs.readFileSync(outputFile, 'utf-8')); + expect(schema.variables).toBeDefined(); + expect(schema.variables.PORT).toBeDefined(); + + fs.unlinkSync(outputFile); + }); + }); +});