@devquest/cli 1.0.9 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -10,7 +10,7 @@ const path_1 = __importDefault(require("path"));
10
10
  const fs_1 = __importDefault(require("fs"));
11
11
  /**
12
12
  * Suite de testes para o desafio Build Your Own Formatter
13
- * Estágio 1: Scanner / Lexer
13
+ * Estágio 1: fmt_read (Leitura e Saída Crua)
14
14
  */
15
15
  async function runStage(stage, cwd) {
16
16
  console.log(chalk_1.default.blue(`\n[Test Suite] Avaliando Estágio ${stage} para build-your-own-formatter...`));
@@ -21,48 +21,47 @@ async function runStage(stage, cwd) {
21
21
  return true;
22
22
  }
23
23
  async function testStage1(cwd) {
24
- console.log(chalk_1.default.gray(`[Lexer Test] Validando saída do scanner para tokens básicos...`));
25
- // Cria um arquivo de teste temporário para o formatador ler
26
- const testFilePath = path_1.default.join(cwd, 'test_input.ts');
27
- const testContent = `const x = 10;`;
28
- fs_1.default.writeFileSync(testFilePath, testContent);
29
- try {
30
- // Executa o código do usuário: node dist/index.js test_input.ts
31
- // Assumindo que o usuário usa a estrutura padrão: ts-node ou dist/index.js
32
- const entryPoint = fs_1.default.existsSync(path_1.default.join(cwd, 'dist/index.js'))
33
- ? 'dist/index.js'
34
- : 'src/index.ts';
35
- const cmd = entryPoint.endsWith('.ts') ? 'npx ts-node' : 'node';
36
- const result = (0, child_process_1.spawnSync)(`${cmd} ${entryPoint} ${testFilePath}`, {
37
- shell: true,
38
- cwd,
39
- encoding: 'utf-8'
40
- });
41
- if (result.status !== 0) {
42
- console.log(chalk_1.default.red(`❌ Erro ao executar o código: ${result.stderr}`));
43
- return false;
44
- }
45
- const output = result.stdout;
46
- console.log(chalk_1.default.gray(`Saída do usuário:\n${output}`));
47
- // Validação mock para o estágio 1: o usuário deve imprimir algo relacionado a tokens
48
- // Na plataforma real, esperaríamos JSON estruturado, aqui buscamos palavras-chave
49
- const lowerOutput = output.toLowerCase();
50
- const hasTokens = lowerOutput.includes('token') || lowerOutput.includes('const') || lowerOutput.includes('x');
51
- if (hasTokens) {
52
- console.log(chalk_1.default.green(`✅ Scanner identificou os tokens básicos com sucesso.`));
53
- return true;
54
- }
55
- else {
56
- console.log(chalk_1.default.red(`❌ Scanner não produziu a saída esperada (tokens ou logs de depuração).`));
57
- return false;
58
- }
24
+ console.log(chalk_1.default.gray(`[Validador fmt_read] Validando se o arquivo é lido e impresso sem alterações...`));
25
+ const entryPoint = fs_1.default.existsSync(path_1.default.join(cwd, 'dist/index.js'))
26
+ ? 'dist/index.js'
27
+ : 'src/index.ts';
28
+ const cmd = entryPoint.endsWith('.ts') ? 'npx ts-node' : 'node';
29
+ // 1. Teste de Leitura Correta
30
+ const testFilePath = path_1.default.join(cwd, 'test_sample.ts');
31
+ const sampleContent = 'const a = 1;\nconsole.log(a);';
32
+ fs_1.default.writeFileSync(testFilePath, sampleContent);
33
+ const runValid = (0, child_process_1.spawnSync)(`${cmd} ${entryPoint} ${testFilePath}`, { shell: true, cwd, encoding: 'utf-8' });
34
+ if (runValid.status !== 0) {
35
+ console.log(chalk_1.default.red(`❌ Erro: O programa deve retornar exit code 0 para arquivos válidos. Recebido: ${runValid.status}`));
36
+ return false;
37
+ }
38
+ if (runValid.stdout.trim() !== sampleContent.trim()) {
39
+ console.log(chalk_1.default.red(`❌ Erro: O conteúdo impresso no stdout não coincide exatamente com o arquivo de entrada.`));
40
+ console.log(chalk_1.default.yellow(`Esperado:\n${sampleContent}`));
41
+ console.log(chalk_1.default.yellow(`Recebido:\n${runValid.stdout}`));
42
+ return false;
59
43
  }
60
- catch (e) {
61
- console.log(chalk_1.default.red(`❌ Falha técnica no teste: ${e.message}`));
44
+ console.log(chalk_1.default.green(`✅ Conteúdo lido e impresso corretamente.`));
45
+ // 2. Teste de Ausência de Argumentos
46
+ console.log(chalk_1.default.gray(`[Validador usage] Verificando tratamento de falta de argumentos...`));
47
+ const runNoArgs = (0, child_process_1.spawnSync)(`${cmd} ${entryPoint}`, { shell: true, cwd, encoding: 'utf-8' });
48
+ if (runNoArgs.status === 0) {
49
+ console.log(chalk_1.default.red(`❌ Erro: O programa deve retornar exit code 1 quando nenhum argumento é passado.`));
62
50
  return false;
63
51
  }
64
- finally {
65
- if (fs_1.default.existsSync(testFilePath))
66
- fs_1.default.unlinkSync(testFilePath);
52
+ if (!runNoArgs.stderr.toLowerCase().includes('usage') && !runNoArgs.stdout.toLowerCase().includes('usage')) {
53
+ console.log(chalk_1.default.yellow(`⚠️ Aviso: Recomenda-se imprimir uma mensagem de "Usage" ao falhar por falta de argumentos.`));
67
54
  }
55
+ console.log(chalk_1.default.green(`✅ Tratamento de falta de argumentos validado.`));
56
+ // 3. Teste de Arquivo Inexistente
57
+ console.log(chalk_1.default.gray(`[Validador file_error] Verificando tratamento de arquivo inexistente...`));
58
+ const runInexistent = (0, child_process_1.spawnSync)(`${cmd} ${entryPoint} inexistent.ts`, { shell: true, cwd, encoding: 'utf-8' });
59
+ if (runInexistent.status === 0) {
60
+ console.log(chalk_1.default.red(`❌ Erro: O programa deve retornar exit code 1 para arquivos inexistentes.`));
61
+ return false;
62
+ }
63
+ console.log(chalk_1.default.green(`✅ Tratamento de arquivo inexistente validado.`));
64
+ if (fs_1.default.existsSync(testFilePath))
65
+ fs_1.default.unlinkSync(testFilePath);
66
+ return true;
68
67
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devquest/cli",
3
- "version": "1.0.9",
3
+ "version": "1.1.1",
4
4
  "description": "DevQuest CLI - Construa seu próprio Redis, Docker, Git e mais",
5
5
  "main": "dist/index.js",
6
6
  "bin": {