Skip to content

Commit d53e2c9

Browse files
committed
se termina de realizar los test
1 parent e34bd14 commit d53e2c9

File tree

5 files changed

+90
-25
lines changed

5 files changed

+90
-25
lines changed

files-md/pruebaEmpty.md

Whitespace-only changes.

files-md/pruebaLinksIncorrect.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Estos archivos `Markdown` normalmente contienen _links_ (vínculos/ligas) que
2+
muchas veces están rotos o ya no son válidos y eso perjudica mucho el valor de
3+
la información que se quiere compartir.
4+
5+
Dentro de una comunidad de código abierto, nos han propuesto crear una
6+
herramienta usando [Node.js](https://nodejs.orppg/), que lea y analice archivos
7+
en formato `Markdown`, para verificar los links que contengan y reportar
8+
algunas estadística

src/index.js

+9-7
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,23 @@ const mdLinks = (path, options = {}) => {
2121
}
2222

2323
// Verificación de existencia de la ruta
24-
const pathExists = verifyRoute(path);
25-
console.log("La ruta existe: " + pathExists);
24+
const pathExist = verifyRoute(path);
25+
console.log("La ruta existe: " + pathExist);
2626

27-
if (!pathExists) {
27+
if (!pathExist) {
2828
return new Promise((resolve, reject) => {
29-
reject("Rejected: El path ingresado es inválido");
29+
reject("Rejected: El path ingresado es inválido");
3030
});
3131
}
3232

3333
const pathType = veriFyIsFileOrDirectory(path);
3434
console.log("La ruta es de tipo: " + pathType);
3535

3636
return readFileOrDirectory(path, pathType).then((links) => {
37+
if(links.length === 0){
38+
return Promise.reject("No se encontraron links")
39+
}
40+
3741
if (options.validate) {
3842
const arrPromesas = links.map((link) => {
3943
// validar el link (status y ok)
@@ -80,8 +84,7 @@ function readFileOrDirectory(path, pathtype) {
8084
});
8185
} else if (pathtype === "file") {
8286
if (!path.endsWith(".md")) {
83-
console.error("El archivo no es md");
84-
return;
87+
return Promise.reject("El archivo no es md");
8588
}
8689

8790
return readFile(path)
@@ -93,7 +96,6 @@ function readFileOrDirectory(path, pathtype) {
9396
return { ...link, file: path.split("/").at(-1) };
9497
});
9598
})
96-
.catch((error) => console.log("Este archivo no se puede leer", error));
9799
}
98100
}
99101

src/main.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,7 @@ function veriFyIsFileOrDirectory(route) {
4545
return "file";
4646
} else if (stats.isDirectory()) {
4747
return "directory";
48-
} else {
49-
return "Desconocido";
50-
}
48+
}
5149
} catch (error) {
5250
console.log("Error: Archivo o directorio roto ", error);
5351
}

test/md-links.spec.js

+72-15
Original file line numberDiff line numberDiff line change
@@ -12,40 +12,46 @@ const {
1212
// });
1313
const pathRelativa = "./files-md/prueba2.md";
1414
const pathDirectory =
15-
"C:/Users/diana/Documents/Projects/Laboratoria/md-links/files-md";
16-
const path =
15+
"./files-md";
16+
const pathFile =
1717
"C:/Users/diana/Documents/Projects/Laboratoria/md-links/files-md/prueba2.md";
18+
const pathFileInvalid =
19+
"C:/Users/diana/Documents/Projects/Laboratoria/md-links/files-md/prueba2.mde";
20+
const pathFileEmpty =
21+
"C:/Users/diana/Documents/Projects/Laboratoria/md-links/files-md/pruebaEmpty.md";
22+
const pathFileTxt = "C:/Users/diana/Documents/Projects/Laboratoria/md-links/files-md/archivo.txt";
23+
const pathFileLinkIncorrect = "C:/Users/diana/Documents/Projects/Laboratoria/md-links/files-md/pruebaLinksIncorrect.md"
1824
const optionTrue = { validate: true };
1925
const optionFalse = { validate: false };
2026

21-
// FUNCION MD-LINKS QUE RETORNARA DE UNA RUTA FILE, UN OBJETO TEXT, HREF, FILE, STATUS Y OK
22-
describe("funcion que retornara un array de objetos incluido el estado de HTTP", () => {
23-
it("Debería retornar un array con objetos incluido el estado de HTTP", (done) => {
24-
const resultMdLinks = mdLinks(path, optionTrue);
27+
// FUNCION MD-LINKS QUE RETORNARA DE UNA RUTA FILE UN OBJETO TEXT, HREF Y FILE
28+
describe("funcion que retornara un array de objetos sin el estado de HTTP", () => {
29+
it("Debería retornar un array con objetos sin incluir el estado de HTTP", (done) => {
30+
const resultMdLinks = mdLinks(pathFile, optionFalse);
2531
expect(resultMdLinks)
2632
.resolves.toEqual([
2733
{
2834
text: "Node.js",
2935
href: "https://nodejs.org/",
3036
file: "prueba2.md",
31-
status: 200,
32-
ok: "ok",
3337
},
3438
])
3539
.then(done);
3640
});
3741
});
3842

39-
// FUNCION MD-LINKS QUE RETORNARA DE UNA RUTA FILE UN OBJETO TEXT, HREF Y FILE
40-
describe("funcion que retornara un array de objetos sin el estado de HTTP", () => {
41-
it("Debería retornar un array con objetos sin incluir el estado de HTTP", (done) => {
42-
const resultMdLinks = mdLinks(path, optionFalse);
43+
// FUNCION MD-LINKS QUE RETORNARA DE UNA RUTA FILE, UN OBJETO TEXT, HREF, FILE, STATUS Y OK
44+
describe("funcion que retornara un array de objetos incluido el estado de HTTP", () => {
45+
it("Debería retornar un array con objetos incluido el estado de HTTP", (done) => {
46+
const resultMdLinks = mdLinks(pathFile, optionTrue);
4347
expect(resultMdLinks)
4448
.resolves.toEqual([
4549
{
4650
text: "Node.js",
4751
href: "https://nodejs.org/",
4852
file: "prueba2.md",
53+
status: 200,
54+
ok: "ok",
4955
},
5056
])
5157
.then(done);
@@ -54,7 +60,7 @@ describe("funcion que retornara un array de objetos sin el estado de HTTP", () =
5460

5561
// FUNCION MD-LINKS QUE RETORNARA DE UNA RUTA DIRECTORY UN OBJETO TEXT, HREF , FILE , status , ok
5662
describe("funcion que retornara un array de objetos sin el estado de HTTP", () => {
57-
it("Debería retornar un array con objetos sin incluir el estado de HTTP", (done) => {
63+
it("Debería retornar un array con objetos sin incluir el estado de HTTP", () => {
5864
const resultMdLinks = mdLinks(pathDirectory, optionTrue);
5965
expect(resultMdLinks)
6066
.resolves.toEqual([
@@ -73,18 +79,69 @@ describe("funcion que retornara un array de objetos sin el estado de HTTP", () =
7379
ok: "ok",
7480
},
7581
])
82+
;
83+
});
84+
});
85+
86+
// FUNCION MD-LINKS QUE RETORNARA DE UNA RUTA DIRECTORY INVALIDA, UN MENSAJE DE ERROR
87+
describe("funcion que retornara un mensaje de error", () => {
88+
it("Debería retornar un string",(done) => {
89+
const resultMdLinks = mdLinks(pathFileInvalid, optionFalse);
90+
expect(resultMdLinks).rejects.toEqual("Rejected: El path ingresado es inválido").then(done);
91+
});
92+
});
93+
94+
// FUNCION MD-LINKS QUE RETORNARA DE UNA RUTA FILE QUE NO TIENE LINKS UN MENSAJE DE ERROR
95+
describe("funcion que retornara un mensaje de error por no encontrar links", () => {
96+
it("Debería retornar un string",(done) => {
97+
const resultMdLinks = mdLinks(pathFileEmpty, optionFalse);
98+
expect(resultMdLinks).rejects.toEqual("No se encontraron links").then(done);
99+
});
100+
});
101+
102+
// FUNCION MD-LINKS QUE RETORNARA DE UNA RUTA FILE TXT UN MENSAJE DE ERROR
103+
describe("funcion que retornara un mensaje de error por no ser un md", () => {
104+
it("Debería retornar un string",(done) => {
105+
const resultMdLinks = mdLinks(pathFileTxt, optionFalse);
106+
expect(resultMdLinks).rejects.toEqual("El archivo no es md").then(done);
107+
});
108+
});
109+
110+
// FUNCION MD-LINKS QUE RETORNARA DE UNA RUTA FILE, LINKS CON STATUS -1 Y OK FAIL
111+
describe("funcion que retornara un array de objetos incluido el estado de HTTP", () => {
112+
it("Debería retornar un array con objetos incluido el estado negativo de HTTP", (done) => {
113+
const resultMdLinks = mdLinks(pathFileLinkIncorrect, optionTrue);
114+
expect(resultMdLinks)
115+
.resolves.toEqual([
116+
{
117+
file: "pruebaLinksIncorrect.md",
118+
href: "https://nodejs.orppg/",
119+
ok: "fail",
120+
status: -1,
121+
text: "Node.js",
122+
},
123+
])
76124
.then(done);
77125
});
78126
});
79127

128+
80129
// FUNCION PARA VERIFICAR SI ES RUTA ABSOLUTA
81130
describe(" funcion para verificar si es una ruta absoluta", () => {
82131
it("Debería retornar un valor booleano", () => {
83-
const result = fnIsAbsolute(path);
132+
const result = fnIsAbsolute(pathFile);
84133
expect(result).toEqual(true);
85134
});
86135
});
87136

137+
// FUNCION PARA VERIFICAR SI ES RUTA ABSOLUTA
138+
describe(" funcion para verificar si es una ruta absoluta", () => {
139+
it("Debería retornar un valor booleano", () => {
140+
const result = fnIsAbsolute(pathRelativa);
141+
expect(result).toEqual(false);
142+
});
143+
});
144+
88145
// FUNCION PARA CONVERTIR UNA RUTA RELATIVA A ABOSLUTA
89146
describe(" funcion para convertir una ruta relativa a absoluta", () => {
90147
it("Debería retornar una ruta absoluta", () => {
@@ -98,7 +155,7 @@ describe(" funcion para convertir una ruta relativa a absoluta", () => {
98155
// VERIFICAR SI ES UN ARCHIVO
99156
describe(" funcion para verificar que la ruta sea de file", () => {
100157
it("Debería retornar un string", () => {
101-
const result = veriFyIsFileOrDirectory(path);
158+
const result = veriFyIsFileOrDirectory(pathFile);
102159
expect(result).toEqual("file");
103160
});
104161
});

0 commit comments

Comments
 (0)