create-codeverse 0.0.0-stage → 0.1.0
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.
- package/LICENSE +21 -0
- package/ReadMe.MD +484 -0
- package/bin/cli.js +346 -0
- package/lib/apply/front.js +122 -0
- package/lib/apply/test.js +73 -0
- package/lib/copyTemplate.js +73 -0
- package/lib/desktop.js +65 -0
- package/lib/installDependencies.js +96 -0
- package/lib/openInEditor.js +14 -0
- package/lib/packageJson.js +33 -0
- package/lib/paths.js +4 -0
- package/lib/prompts.js +147 -0
- package/lib/runCommand.js +44 -0
- package/lib/secret.js +80 -0
- package/lib/templates.js +97 -0
- package/lib/validateProjectName.js +24 -0
- package/lib/versions.js +110 -0
- package/package.json +49 -6
- package/templates/codeskills.enc +0 -0
- package/templates/extras/test-componentes/ReadMe.MD +44 -0
- package/templates/extras/test-componentes/cypress/component/Login.cy.jsx +120 -0
- package/templates/extras/test-componentes/cypress/fixtures/example.json +5 -0
- package/templates/extras/test-componentes/cypress/support/commands.js +25 -0
- package/templates/extras/test-componentes/cypress/support/component-index.html +14 -0
- package/templates/extras/test-componentes/cypress/support/component.js +24 -0
- package/templates/extras/test-componentes/cypress.config.js +10 -0
- package/templates/extras/test-componentes/src/app/page.jsx +5 -0
- package/templates/extras/test-componentes/src/components/Login.jsx +47 -0
- package/templates/extras/test-dependencias/tests/nome-do-script.test.js +79 -0
- package/templates/front/.env.example +0 -0
- package/templates/front/ReadMe.MD +51 -0
- package/templates/front/_gitignore +42 -0
- package/templates/front/biome.json +42 -0
- package/templates/front/jsconfig.json +8 -0
- package/templates/front/next.config.mjs +11 -0
- package/templates/front/package.template.json +41 -0
- package/templates/front/public/fonts/gitkeep +0 -0
- package/templates/front/public/icons/gitkeep +0 -0
- package/templates/front/public/images/gitkeep +0 -0
- package/templates/front/public/media/gitkeep +0 -0
- package/templates/front/public/sounds/gitkeep +0 -0
- package/templates/front/src/app/favicon.ico +0 -0
- package/templates/front/src/app/globals.css +9 -0
- package/templates/front/src/app/layout.js +14 -0
- package/templates/front/src/app/nome-da-rota/nome-da-rota.module.css +0 -0
- package/templates/front/src/app/nome-da-rota/page.jsx +5 -0
- package/templates/front/src/app/page.jsx +39 -0
- package/templates/front/src/app/page.module.css +98 -0
- package/templates/front/src/components/Nome-do-componente.jsx +5 -0
- package/templates/front/src/components/Nome-do-componente.module.css +0 -0
- package/templates/integracao/ReadMe.MD +41 -0
- package/templates/integracao/cypress/e2e/meu-teste.cy.js +75 -0
- package/templates/integracao/cypress/fixtures/example.json +5 -0
- package/templates/integracao/cypress/support/commands.js +25 -0
- package/templates/integracao/cypress/support/e2e.js +17 -0
- package/templates/integracao/cypress.config.js +7 -0
- package/templates/integracao/package.template.json +38 -0
- package/templates/test/.env.example +0 -0
- package/templates/test/ReadMe.MD +49 -0
- package/templates/test/_gitignore +25 -0
- package/templates/test/jest.reporters.config.mjs +14 -0
- package/templates/test/package.template.json +42 -0
- package/templates/test/src/nome-do-seu-script.js +4 -0
- package/templates/test/tests/nome-do-script.test.js +40 -0
- package/templates/versions.json +84 -0
- package/README.md +0 -3
package/package.json
CHANGED
|
@@ -1,6 +1,49 @@
|
|
|
1
|
-
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "create-codeverse",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Scaffolding CLI for Codeverse students to learn",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"create-codeverse": "bin/cli.js"
|
|
8
|
+
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"encrypt": "cls && node scripts/encrypt.js"
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
"bin",
|
|
14
|
+
"lib",
|
|
15
|
+
"templates",
|
|
16
|
+
"ReadMe.MD"
|
|
17
|
+
],
|
|
18
|
+
"engines": {
|
|
19
|
+
"node": ">=20"
|
|
20
|
+
},
|
|
21
|
+
"keywords": [
|
|
22
|
+
"create-codeverse",
|
|
23
|
+
"codeverse",
|
|
24
|
+
"cli",
|
|
25
|
+
"scaffold",
|
|
26
|
+
"generator",
|
|
27
|
+
"starter",
|
|
28
|
+
"template",
|
|
29
|
+
"education"
|
|
30
|
+
],
|
|
31
|
+
"author": {
|
|
32
|
+
"name": "Marcello",
|
|
33
|
+
"url": "https://github.com/mapcarboni/"
|
|
34
|
+
},
|
|
35
|
+
"contributors": [
|
|
36
|
+
{
|
|
37
|
+
"name": "Thiago",
|
|
38
|
+
"url": "https://github.com/thiago-rferreira/"
|
|
39
|
+
}
|
|
40
|
+
],
|
|
41
|
+
"homepage": "https://codeverse.dev.br",
|
|
42
|
+
"license": "MIT",
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"@clack/prompts": "1.9.0"
|
|
45
|
+
},
|
|
46
|
+
"bundleDependencies": [
|
|
47
|
+
"@clack/prompts"
|
|
48
|
+
]
|
|
49
|
+
}
|
|
Binary file
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# Projeto de Testes de Componentes — Cypress + Next.js
|
|
2
|
+
|
|
3
|
+
Projeto criado com o `create-codeverse`: Next.js (App Router) com o Cypress Component Testing, para
|
|
4
|
+
testar componentes React isolados.
|
|
5
|
+
|
|
6
|
+
## Como rodar os testes
|
|
7
|
+
|
|
8
|
+
| Passo | Comando |
|
|
9
|
+
|---|---|
|
|
10
|
+
| Abrir o terminal do VS Code | `` Ctrl + ` `` |
|
|
11
|
+
| Abrir o Cypress | `npm test` |
|
|
12
|
+
| No Cypress | Escolha **Component Testing**, depois um navegador, depois o teste `Login.cy.jsx` |
|
|
13
|
+
|
|
14
|
+
## Scripts
|
|
15
|
+
|
|
16
|
+
| Comando | O que faz |
|
|
17
|
+
|---|---|
|
|
18
|
+
| `npm test` | Abre o Cypress |
|
|
19
|
+
| `npm run dev` | Roda o projeto em [http://localhost:3000](http://localhost:3000) |
|
|
20
|
+
| `npm run lint` | Confere o código e a formatação com o Biome |
|
|
21
|
+
| `npm run format` | Formata todos os arquivos |
|
|
22
|
+
| `npm run clean` | Apaga do PC as versões antigas do programa Cypress (cerca de 200 MB cada), mantendo só a usada neste projeto |
|
|
23
|
+
|
|
24
|
+
## Estrutura
|
|
25
|
+
|
|
26
|
+
| Pasta / arquivo | Para que serve |
|
|
27
|
+
|---|---|
|
|
28
|
+
| `src/components/Login.jsx` | Componente testado |
|
|
29
|
+
| `src/app/page.jsx` | Página que mostra o `Login` |
|
|
30
|
+
| `cypress/component/Login.cy.jsx` | Teste do componente, com um exemplo de cada tipo de verificação |
|
|
31
|
+
| `cypress/fixtures/` | Dados de exemplo para os testes |
|
|
32
|
+
| `cypress/support/` | Arquivos de apoio do Cypress |
|
|
33
|
+
| `cypress.config.js` | Configuração do Cypress (Component Testing com Next.js) |
|
|
34
|
+
|
|
35
|
+
Pastas `cypress/screenshots/`, `cypress/videos/` e `cypress/downloads/` são geradas pelo Cypress e
|
|
36
|
+
ficam fora do Git (`.gitignore`).
|
|
37
|
+
|
|
38
|
+
## Para saber mais
|
|
39
|
+
|
|
40
|
+
| Assunto | Link |
|
|
41
|
+
|---|---|
|
|
42
|
+
| Cypress Component Testing | [docs.cypress.io](https://docs.cypress.io/app/core-concepts/testing-types#What-is-Component-Testing) |
|
|
43
|
+
| Next.js | [nextjs.org/docs](https://nextjs.org/docs) |
|
|
44
|
+
| Material da CodeVerse | [codeverse.dev.br](https://codeverse.dev.br) |
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { mount } from 'cypress/react';
|
|
2
|
+
import Login from '../../src/components/Login';
|
|
3
|
+
|
|
4
|
+
describe('Componente Login', () => {
|
|
5
|
+
it('estrutura inicial da tela', () => {
|
|
6
|
+
mount(<Login />);
|
|
7
|
+
|
|
8
|
+
// exist: o elemento existe no DOM
|
|
9
|
+
cy.get('form').should('exist');
|
|
10
|
+
|
|
11
|
+
// not.exist: a mensagem ainda não foi criada
|
|
12
|
+
cy.get('p').should('not.exist');
|
|
13
|
+
|
|
14
|
+
// be.visible: o formulário está visível na tela
|
|
15
|
+
cy.get('form').should('be.visible');
|
|
16
|
+
|
|
17
|
+
// have.text: texto exato do título
|
|
18
|
+
cy.get('h1').should('have.text', 'Login');
|
|
19
|
+
|
|
20
|
+
// have.html: HTML exato do título
|
|
21
|
+
cy.get('h1').should('have.html', 'Login');
|
|
22
|
+
|
|
23
|
+
// eq: compara o texto com igualdade (chai)
|
|
24
|
+
cy.get('h1').invoke('text').should('eq', 'Login');
|
|
25
|
+
|
|
26
|
+
// match: compara o texto com uma expressão regular
|
|
27
|
+
cy.get('h1').invoke('text').should('match', /login/i);
|
|
28
|
+
|
|
29
|
+
// contain.text: o texto contém um trecho
|
|
30
|
+
cy.get('h1').should('contain.text', 'Log');
|
|
31
|
+
|
|
32
|
+
// contain: o formulário contém o texto do botão
|
|
33
|
+
cy.get('form').should('contain', 'Entrar');
|
|
34
|
+
|
|
35
|
+
// have.length: existem 2 labels
|
|
36
|
+
cy.get('label').should('have.length', 2);
|
|
37
|
+
|
|
38
|
+
// deep.equal: lista de textos dos labels, comparada item a item
|
|
39
|
+
cy.get('label')
|
|
40
|
+
.then(($labels) => $labels.toArray().map((el) => el.textContent))
|
|
41
|
+
.should('deep.equal', ['Usuário', 'Senha']);
|
|
42
|
+
|
|
43
|
+
// be.enabled: o botão pode ser clicado
|
|
44
|
+
cy.get('button').should('be.enabled');
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('atributos dos campos', () => {
|
|
48
|
+
mount(<Login />);
|
|
49
|
+
|
|
50
|
+
// have.attr: atributo type do campo de usuário
|
|
51
|
+
cy.get('#usuario').should('have.attr', 'type', 'text');
|
|
52
|
+
|
|
53
|
+
// not.be.undefined: a propriedade type existe, lida via jQuery
|
|
54
|
+
cy.get('#senha').invoke('prop', 'type').should('not.be.undefined');
|
|
55
|
+
|
|
56
|
+
// be.undefined: o campo não tem placeholder
|
|
57
|
+
cy.get('#senha').invoke('attr', 'placeholder').should('be.undefined');
|
|
58
|
+
|
|
59
|
+
// be.oneOf: o tipo do campo é um dos valores permitidos
|
|
60
|
+
cy.get('#usuario').invoke('attr', 'type').should('be.oneOf', ['text', 'password']);
|
|
61
|
+
|
|
62
|
+
// be.empty: o campo começa vazio
|
|
63
|
+
cy.get('#usuario').invoke('val').should('be.empty');
|
|
64
|
+
|
|
65
|
+
// be.a: o valor do campo é uma string
|
|
66
|
+
cy.get('#usuario').invoke('val').should('be.a', 'string');
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it('foco nos campos', () => {
|
|
70
|
+
mount(<Login />);
|
|
71
|
+
|
|
72
|
+
// be.false: nenhum campo está com foco ao abrir a tela
|
|
73
|
+
cy.get('#usuario').then(($el) => $el.is(':focus')).should('be.false');
|
|
74
|
+
|
|
75
|
+
// have.focus: o campo recebe o foco ao ser clicado
|
|
76
|
+
cy.get('#usuario').focus().should('have.focus');
|
|
77
|
+
|
|
78
|
+
// be.true: confirma que o campo está com foco
|
|
79
|
+
cy.get('#usuario').then(($el) => $el.is(':focus')).should('be.true');
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it('digitação e limpeza', () => {
|
|
83
|
+
mount(<Login />);
|
|
84
|
+
|
|
85
|
+
// have.value: o valor digitado aparece no campo
|
|
86
|
+
cy.get('#usuario').type('admin').should('have.value', 'admin');
|
|
87
|
+
|
|
88
|
+
// not.have.value: depois de limpar, o valor não é mais o digitado
|
|
89
|
+
cy.get('#usuario').clear().should('not.have.value', 'admin');
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it('erro com usuário ou senha inválidos', () => {
|
|
93
|
+
mount(<Login />);
|
|
94
|
+
|
|
95
|
+
cy.get('#usuario').type('errado');
|
|
96
|
+
cy.get('#senha').type('000');
|
|
97
|
+
cy.contains('button', 'Entrar').click();
|
|
98
|
+
|
|
99
|
+
// include: o texto da mensagem contém a palavra-chave
|
|
100
|
+
cy.get('p').invoke('text').should('include', 'inválidos');
|
|
101
|
+
|
|
102
|
+
// not.include: a mensagem de sucesso não aparece
|
|
103
|
+
cy.get('p').invoke('text').should('not.include', 'sucesso');
|
|
104
|
+
|
|
105
|
+
// equal: texto exato da mensagem de erro
|
|
106
|
+
cy.get('p').invoke('text').should('equal', 'Usuário ou senha inválidos.');
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it('sucesso com admin e 123, enviado pela tecla Enter', () => {
|
|
110
|
+
mount(<Login />);
|
|
111
|
+
|
|
112
|
+
cy.get('#usuario').type('admin');
|
|
113
|
+
|
|
114
|
+
// {enter} envia o formulário sem clicar no botão
|
|
115
|
+
cy.get('#senha').type('123{enter}');
|
|
116
|
+
|
|
117
|
+
// not.be.empty: a mensagem de resultado foi preenchida
|
|
118
|
+
cy.get('p').invoke('text').should('not.be.empty');
|
|
119
|
+
});
|
|
120
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// ***********************************************
|
|
2
|
+
// This example commands.js shows you how to
|
|
3
|
+
// create various custom commands and overwrite
|
|
4
|
+
// existing commands.
|
|
5
|
+
//
|
|
6
|
+
// For more comprehensive examples of custom
|
|
7
|
+
// commands please read more here:
|
|
8
|
+
// https://on.cypress.io/custom-commands
|
|
9
|
+
// ***********************************************
|
|
10
|
+
//
|
|
11
|
+
//
|
|
12
|
+
// -- This is a parent command --
|
|
13
|
+
// Cypress.Commands.add('login', (email, password) => { ... })
|
|
14
|
+
//
|
|
15
|
+
//
|
|
16
|
+
// -- This is a child command --
|
|
17
|
+
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
|
|
18
|
+
//
|
|
19
|
+
//
|
|
20
|
+
// -- This is a dual command --
|
|
21
|
+
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
|
|
22
|
+
//
|
|
23
|
+
//
|
|
24
|
+
// -- This will overwrite an existing command --
|
|
25
|
+
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
6
|
+
<meta name="viewport" content="width=device-width,initial-scale=1.0">
|
|
7
|
+
<title>Components App</title>
|
|
8
|
+
<!-- Used by Next.js to inject CSS. -->
|
|
9
|
+
<div id="__next_css__DO_NOT_USE__"></div>
|
|
10
|
+
</head>
|
|
11
|
+
<body>
|
|
12
|
+
<div data-cy-root></div>
|
|
13
|
+
</body>
|
|
14
|
+
</html>
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// ***********************************************************
|
|
2
|
+
// This example support/component.js is processed and
|
|
3
|
+
// loaded automatically before your test files.
|
|
4
|
+
//
|
|
5
|
+
// This is a great place to put global configuration and
|
|
6
|
+
// behavior that modifies Cypress.
|
|
7
|
+
//
|
|
8
|
+
// You can change the location of this file or turn off
|
|
9
|
+
// automatically serving support files with the
|
|
10
|
+
// 'supportFile' configuration option.
|
|
11
|
+
//
|
|
12
|
+
// You can read more here:
|
|
13
|
+
// https://on.cypress.io/configuration
|
|
14
|
+
// ***********************************************************
|
|
15
|
+
|
|
16
|
+
// Import commands.js using ES2015 syntax:
|
|
17
|
+
import './commands'
|
|
18
|
+
|
|
19
|
+
import { mount } from 'cypress/react'
|
|
20
|
+
|
|
21
|
+
Cypress.Commands.add('mount', mount)
|
|
22
|
+
|
|
23
|
+
// Example use:
|
|
24
|
+
// cy.mount(<MyComponent />)
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useState } from 'react';
|
|
4
|
+
|
|
5
|
+
export default function Login() {
|
|
6
|
+
const [usuario, setUsuario] = useState('');
|
|
7
|
+
const [senha, setSenha] = useState('');
|
|
8
|
+
const [mensagem, setMensagem] = useState('');
|
|
9
|
+
|
|
10
|
+
function handleLogin(event) {
|
|
11
|
+
event.preventDefault();
|
|
12
|
+
|
|
13
|
+
if (usuario === 'admin' && senha === '123') {
|
|
14
|
+
setMensagem('Login realizado com sucesso!');
|
|
15
|
+
} else {
|
|
16
|
+
setMensagem('Usuário ou senha inválidos.');
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return (
|
|
21
|
+
<form onSubmit={handleLogin}>
|
|
22
|
+
<h1>Login</h1>
|
|
23
|
+
|
|
24
|
+
<label htmlFor="usuario">Usuário</label>
|
|
25
|
+
|
|
26
|
+
<input
|
|
27
|
+
id="usuario"
|
|
28
|
+
type="text"
|
|
29
|
+
value={usuario}
|
|
30
|
+
onChange={(event) => setUsuario(event.target.value)}
|
|
31
|
+
/>
|
|
32
|
+
|
|
33
|
+
<label htmlFor="senha">Senha</label>
|
|
34
|
+
|
|
35
|
+
<input
|
|
36
|
+
id="senha"
|
|
37
|
+
type="password"
|
|
38
|
+
value={senha}
|
|
39
|
+
onChange={(event) => setSenha(event.target.value)}
|
|
40
|
+
/>
|
|
41
|
+
|
|
42
|
+
<button type="submit">Entrar</button>
|
|
43
|
+
|
|
44
|
+
{mensagem && <p>{mensagem}</p>}
|
|
45
|
+
</form>
|
|
46
|
+
);
|
|
47
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { jest } from '@jest/globals';
|
|
2
|
+
import { nomeDaFuncao } from '../src/nome-do-seu-script.js';
|
|
3
|
+
|
|
4
|
+
// describe() agrupa testes relacionados em um bloco
|
|
5
|
+
describe('nomeDaFuncao', () => {
|
|
6
|
+
// it(): cada um é UM caso de teste
|
|
7
|
+
it('deve fazer o que a função promete', () => {
|
|
8
|
+
// expect(valorRecebido).matcher(valorEsperado)
|
|
9
|
+
expect(nomeDaFuncao(1)).toBe(1);
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
it('toBe() compara valores primitivos (número, string, boolean) por igualdade exata', () => {
|
|
13
|
+
expect(1 + 1).toBe(2);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it('toEqual() compara objetos e arrays por atributos', () => {
|
|
17
|
+
expect({ nome: 'Ana' }).toEqual({ nome: 'Ana' });
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it('toContain() verifica se um array ou string contém um item/trecho', () => {
|
|
21
|
+
expect([1, 2, 3]).toContain(2);
|
|
22
|
+
expect('JavaScript').toContain('Script');
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it('toBeTruthy() verifica se o valor é "verdadeiro" (truthy)', () => {
|
|
26
|
+
expect(1).toBeTruthy();
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('toBeFalsy() verifica se o valor é "falso" (falsy: 0, "", null, undefined, NaN, false)', () => {
|
|
30
|
+
expect(0).toBeFalsy();
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('toHaveLength() verifica o tamanho (length) de um array ou string', () => {
|
|
34
|
+
expect([1, 2, 3]).toHaveLength(3);
|
|
35
|
+
expect('abc').toHaveLength(3);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('toBeCloseTo() compara números decimais evitando erros de ponto flutuante', () => {
|
|
39
|
+
expect(0.1 + 0.2).toBeCloseTo(0.3);
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
// Mocks: jest.fn() cria uma função falsa que substitui uma dependência
|
|
44
|
+
// externa (uma API via Axios, por exemplo) e ainda registra como foi chamada.
|
|
45
|
+
describe('Mocks com jest.fn()', () => {
|
|
46
|
+
it('mockReturnValue() define o valor que o mock retorna', () => {
|
|
47
|
+
const buscar = jest.fn().mockReturnValue(7);
|
|
48
|
+
expect(buscar()).toBe(7);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('mockResolvedValue() faz o mock retornar uma Promise resolvida', async () => {
|
|
52
|
+
const buscar = jest.fn().mockResolvedValue('ok');
|
|
53
|
+
await expect(buscar()).resolves.toBe('ok');
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('mockRejectedValue() faz o mock retornar uma Promise rejeitada', async () => {
|
|
57
|
+
const buscar = jest.fn().mockRejectedValue(new Error('API fora do ar'));
|
|
58
|
+
await expect(buscar()).rejects.toThrow('API fora do ar');
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('toHaveBeenCalled() verifica se o mock foi chamado ao menos uma vez', () => {
|
|
62
|
+
const buscar = jest.fn();
|
|
63
|
+
buscar();
|
|
64
|
+
expect(buscar).toHaveBeenCalled();
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('toHaveBeenCalledTimes() verifica quantas vezes o mock foi chamado', () => {
|
|
68
|
+
const buscar = jest.fn();
|
|
69
|
+
buscar();
|
|
70
|
+
buscar();
|
|
71
|
+
expect(buscar).toHaveBeenCalledTimes(2);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it('toHaveBeenCalledWith() verifica com quais argumentos o mock foi chamado', () => {
|
|
75
|
+
const buscar = jest.fn();
|
|
76
|
+
buscar('USD', 10);
|
|
77
|
+
expect(buscar).toHaveBeenCalledWith('USD', 10);
|
|
78
|
+
});
|
|
79
|
+
});
|
|
File without changes
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# Projeto FrontEnd — Next.js
|
|
2
|
+
|
|
3
|
+
Projeto criado com o `create-codeverse`: Next.js (App Router) com React, React Compiler e Biome.
|
|
4
|
+
|
|
5
|
+
## Como rodar
|
|
6
|
+
|
|
7
|
+
| Passo | Comando |
|
|
8
|
+
|---|---|
|
|
9
|
+
| Abrir o terminal do VS Code | `` Ctrl + ` `` |
|
|
10
|
+
| Rodar o projeto | `npm run dev` |
|
|
11
|
+
| Ver no navegador | [http://localhost:3000](http://localhost:3000) |
|
|
12
|
+
| Parar o projeto | `Ctrl + C` no terminal |
|
|
13
|
+
|
|
14
|
+
## Scripts
|
|
15
|
+
|
|
16
|
+
| Comando | O que faz |
|
|
17
|
+
|---|---|
|
|
18
|
+
| `npm run dev` | Limpa o terminal e inicia o servidor de desenvolvimento |
|
|
19
|
+
| `npm run lint` | Confere o código e a formatação com o Biome |
|
|
20
|
+
| `npm run format` | Formata todos os arquivos |
|
|
21
|
+
|
|
22
|
+
## Estrutura
|
|
23
|
+
|
|
24
|
+
| Pasta / arquivo | Para que serve |
|
|
25
|
+
|---|---|
|
|
26
|
+
| `src/app/page.jsx` | Página inicial (`/`) |
|
|
27
|
+
| `src/app/layout.js` | Estrutura comum a todas as páginas (`<html>`, `<body>`) |
|
|
28
|
+
| `src/app/globals.css` | Estilos globais |
|
|
29
|
+
| `src/app/nome-da-rota/` | Exemplo de rota: renomeie a pasta e ela vira o endereço (ex.: `src/app/sobre/` → `/sobre`) |
|
|
30
|
+
| `src/components/` | Componentes reaproveitáveis (exemplo: `Nome-do-componente.jsx`) |
|
|
31
|
+
| `public/` | Arquivos estáticos: `fonts`, `icons`, `images`, `media`, `sounds` |
|
|
32
|
+
| `.env.example` | Modelo das variáveis de ambiente: copie para `.env` e preencha |
|
|
33
|
+
| `biome.json` | Regras de formatação e de lint |
|
|
34
|
+
| `jsconfig.json` | Atalhos de importação |
|
|
35
|
+
| `next.config.mjs` | Configuração do Next.js (React Compiler ligado) |
|
|
36
|
+
|
|
37
|
+
## Atalhos de importação
|
|
38
|
+
|
|
39
|
+
| Atalho | Aponta para | Exemplo |
|
|
40
|
+
|---|---|---|
|
|
41
|
+
| `@/` | `src/` | `import Botao from '@/components/Botao';` |
|
|
42
|
+
| `@components/` | `src/components/` | `import Botao from '@components/Botao';` |
|
|
43
|
+
|
|
44
|
+
## Para saber mais
|
|
45
|
+
|
|
46
|
+
| Assunto | Link |
|
|
47
|
+
|---|---|
|
|
48
|
+
| Next.js | [nextjs.org/docs](https://nextjs.org/docs) |
|
|
49
|
+
| React | [react.dev](https://react.dev) |
|
|
50
|
+
| Biome | [biomejs.dev](https://biomejs.dev) |
|
|
51
|
+
| Material da CodeVerse | [codeverse.dev.br](https://codeverse.dev.br) |
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
|
2
|
+
|
|
3
|
+
# dependencies
|
|
4
|
+
/node_modules
|
|
5
|
+
/.pnp
|
|
6
|
+
.pnp.*
|
|
7
|
+
.yarn/*
|
|
8
|
+
!.yarn/patches
|
|
9
|
+
!.yarn/plugins
|
|
10
|
+
!.yarn/releases
|
|
11
|
+
!.yarn/versions
|
|
12
|
+
|
|
13
|
+
# testing
|
|
14
|
+
/coverage
|
|
15
|
+
|
|
16
|
+
# next.js
|
|
17
|
+
/.next/
|
|
18
|
+
/out/
|
|
19
|
+
|
|
20
|
+
# production
|
|
21
|
+
/build
|
|
22
|
+
|
|
23
|
+
# misc
|
|
24
|
+
.DS_Store
|
|
25
|
+
*.pem
|
|
26
|
+
|
|
27
|
+
# debug
|
|
28
|
+
npm-debug.log*
|
|
29
|
+
yarn-debug.log*
|
|
30
|
+
yarn-error.log*
|
|
31
|
+
.pnpm-debug.log*
|
|
32
|
+
|
|
33
|
+
# env files (can opt-in for committing if needed)
|
|
34
|
+
.env*
|
|
35
|
+
!.env.example
|
|
36
|
+
|
|
37
|
+
# vercel
|
|
38
|
+
.vercel
|
|
39
|
+
|
|
40
|
+
# typescript
|
|
41
|
+
*.tsbuildinfo
|
|
42
|
+
next-env.d.ts
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "./node_modules/@biomejs/biome/configuration_schema.json",
|
|
3
|
+
"vcs": {
|
|
4
|
+
"enabled": true,
|
|
5
|
+
"clientKind": "git",
|
|
6
|
+
"useIgnoreFile": true
|
|
7
|
+
},
|
|
8
|
+
"files": {
|
|
9
|
+
"ignoreUnknown": true,
|
|
10
|
+
"includes": ["**", "!node_modules", "!.next", "!dist", "!build"]
|
|
11
|
+
},
|
|
12
|
+
"formatter": {
|
|
13
|
+
"enabled": true,
|
|
14
|
+
"indentStyle": "space",
|
|
15
|
+
"indentWidth": 4
|
|
16
|
+
},
|
|
17
|
+
"javascript": {
|
|
18
|
+
"formatter": {
|
|
19
|
+
"quoteStyle": "single"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"linter": {
|
|
23
|
+
"enabled": true,
|
|
24
|
+
"rules": {
|
|
25
|
+
"preset": "recommended",
|
|
26
|
+
"suspicious": {
|
|
27
|
+
"noUnknownAtRules": "off"
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"domains": {
|
|
31
|
+
"next": "recommended",
|
|
32
|
+
"react": "recommended"
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"assist": {
|
|
36
|
+
"actions": {
|
|
37
|
+
"source": {
|
|
38
|
+
"organizeImports": "on"
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "npx-next",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Projeto template padrão didático de front-end com NextJS (App Router) e React.",
|
|
5
|
+
"private": true,
|
|
6
|
+
"keywords": [
|
|
7
|
+
"javascript",
|
|
8
|
+
"nextjs",
|
|
9
|
+
"next",
|
|
10
|
+
"react",
|
|
11
|
+
"app-router",
|
|
12
|
+
"front-end",
|
|
13
|
+
"frontend",
|
|
14
|
+
"biome",
|
|
15
|
+
"codeverse"
|
|
16
|
+
],
|
|
17
|
+
"homepage": "https://codeverse.dev.br/",
|
|
18
|
+
"author": {
|
|
19
|
+
"name": "Marcello",
|
|
20
|
+
"url": "https://github.com/mapcarboni/"
|
|
21
|
+
},
|
|
22
|
+
"contributors": [
|
|
23
|
+
{
|
|
24
|
+
"name": "Marcello",
|
|
25
|
+
"url": "https://github.com/mapcarboni/"
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
"name": "Thiago",
|
|
29
|
+
"url": "https://github.com/thiago-rferreira/"
|
|
30
|
+
}
|
|
31
|
+
],
|
|
32
|
+
"license": "MIT",
|
|
33
|
+
"engines": {
|
|
34
|
+
"node": ">=20"
|
|
35
|
+
},
|
|
36
|
+
"scripts": {
|
|
37
|
+
"dev": "cls && next dev",
|
|
38
|
+
"lint": "biome check",
|
|
39
|
+
"format": "biome format --write"
|
|
40
|
+
}
|
|
41
|
+
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
Binary file
|