--test-name-pattern needing to come before filenames is hostile to npm scripts
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- JavaScript
- Estrellas
- 122k
- Forks
- 37.3k
- Merge medio
- 4 d 2 h
- PR fusionados (30 d)
- 283
Descripción
What is the problem this feature will solve?
It is common practice to set up npm scripts for testing. E.g.
{
"test": "node --test tests/*.js more-tests/*.js"
}
However, this cannot be combined with --test-name-pattern. Attempting to do so, e.g.
npm test -- --test-name-pattern="my pattern"
will not work, because this gets translated to
node --test tests/*.js more-tests/*.js --test-name-pattern="my pattern"
which, I believe, ends up passing --test-name-pattern="my pattern" as an argument to these test files, instead of passing it as an argument to the test runner. The correct invocation is
node --test-name-pattern="my pattern" --test tests/*.js more-tests/*.js
but this is impossible to do via npm scripts, it seems. (See alternatives considered.)
What is the feature you are proposing to solve the problem?
I don't know what a good solution to this would be. Some possible ideas:
-
Special-case command line processing such that when
--testis present,nodegrabs the--test-name-patternargument for itself instead of passing it to scripts? -
Introduce a new binary, e.g.
node_test, which processes command-line arguments in such a way? I believe this is how most test runners behave. -
Introduce a file-based customization of the test runner, including which tests to run, so that I don't have to pass the test filenames as arguments to the test runner in a way that causes this problem?
-
Improve npm scripts to support a better method of passing arguments in the middle of the script? (See below.)
What alternatives have you considered?
I investigated how to get npm scripts to substitute in arguments you pass to npm run into the script command, so that the translation becomes the correct one. This is a well-studied problem, and the following two Stack Overflow posts have the best answers, as far as I can tell:
None of them seem very satisfactory, unfortunately. In particular, if you want something that works cross-platform, you basically have to write a wrapper script.
As an alternative, I could continue using other test runners, which support npm scripts better.
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Comienza reproduciendo la invocación de npm test con --test-name-pattern y compárala con el comando funcional en el que la opción precede a --test y a los nombres de archivo. Investiga el procesamiento de la línea de comandos de Node para --test y --test-name-pattern; para darlo por terminado se requiere un enfoque definido que admita este caso de uso de npm-script, probablemente con pruebas que cubran el orden de los argumentos.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- javascript, node.js
- Área
- cli, testing-qa
- Tipo de issue
- Nueva funcionalidad
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Estado de actividad
- Estancado
- Claridad
- Necesita aclaración
- Aptitud para principiantes
- 25/100