node.js - ¿Cómo puedo omitir pruebas al usar el ejecutor de pruebas nativo de Node con TypeScript/esrun?
Estoy usando el ejecutor de pruebas de node. tengo algunas pruebas en un archivo de demostración pequeño:
import { describe, test } from "node:test";
import assert from "node:assert";
describe("thing", () => {
test("it works", () => {
assert.ok(true);
});
});
describe("this should not be tested", () => {
test("it works", () => {
assert.ok(true);
});
});
Cuando ejecuto node --test-name-pattern="thing" runme.test.mjs puedo ver que solo se prueba thing y se omite esto no debería ser probado:
▶ thing
✔ it works (0.153ms)
▶ thing (1.306708ms)
▶ this should not be tested
﹣ it works (0.13525ms) # test name does not match pattern
▶ this should not be tested (0.23425ms)
ℹ tests 2
ℹ suites 2
ℹ pass 1
ℹ fail 0
ℹ cancelled 0
ℹ skipped 1
ℹ todo 0
ℹ duration_ms 0.079417
¡Genial! Puedo ver que this should not be tested se ha omitido!
Sin embargo, quiero usar TypeScript para mis pruebas. Usando esrun y siguiendo la documentación de esrun estoy ejecutando:
esrun runme.test.mjs --test-name-pattern="thing"
(sí, este es el mismo archivo JS de antes, esrun también puede ejecutar archivos JS)
Sin embargo, las pruebas no se omiten:
▶ thing
✔ it works (0.11725ms)
▶ thing (0.945292ms)
▶ this should not be tested
✔ it works (0.040375ms)
▶ this should not be tested (0.100708ms)
ℹ tests 2
ℹ suites 2
ℹ pass 2
ℹ fail 0
ℹ cancelled 0
ℹ skipped 0
ℹ todo 0
ℹ duration_ms 0.105375
¿Cómo puedo omitir pruebas al usar el ejecutor de pruebas nativo de Node con TypeScript/esrun?
Respuesta #1
Respondiendo a mi propia pregunta para ayudar a otros
La sintaxis correcta se menciona en la documentación de esrun, pero me la había perdido:
Puedes pasar opciones personalizadas al CLI de Node anteponiendo el nombre de la opción con "--node", así: esrun --node-max-old-space-size=4096 foo.ts
Entonces, para omitir pruebas con el ejecutor de pruebas nativo, usa --node-test-name-pattern:
esrun --node-test-name-pattern="thing" runme.test.mjs
▶ thing
✔ it works (0.144791ms)
▶ thing (1.027917ms)
▶ this should not be tested
﹣ it works (0.048459ms) # test name does not match pattern
▶ this should not be tested (0.124208ms)
ℹ tests 2
ℹ suites 2
ℹ pass 1
ℹ fail 0
ℹ cancelled 0
ℹ skipped 1
ℹ todo 0
ℹ duration_ms 0.124166
Esto también funciona con archivos TS (incluyendo tanto .ts como .mts).
