Ver y volver a ejecutar pruebas JS Jest
La documentación de Jest sugiere usar npm test
para ejecutar pruebas.
¿Hay alguna forma de ver su fuente y pruebas para volver a ejecutar las pruebas de Jest automáticamente cuando se han cambiado los archivos relevantes?
4 answers
Actualizar
Gracias a Erin Stanfill por señalar que Jest ya ha soportado volver a ejecutar automáticamente. La mejor configuración para package.json
sería
{
"scripts": {
"test": "jest"
}
}
Para activar el modo de reloj, simplemente use
$ npm run test -- --watch
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-04-13 06:12:59
Si tiene configurado npm test
, puede ejecutar npm test -- --watch
.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-10-22 15:41:27
- instale un par de paquetes de Grunt:
npm install grunt-contrib-watch grunt-exec --save-dev
- hacer un
Gruntfile.js
con lo siguiente:
module.exports = function(grunt) {
grunt.initConfig({
exec: {
jest: 'node node_modules/jest-cli/bin/jest'
},
watch: {
files: ['**/*.js'],
tasks: ['exec:jest']
}
});
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-exec');
}
- entonces simplemente ejecuta:
grunt watch
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-12-11 21:47:09
Este ejemplo muestra cómo usar gulp para ejecutar sus pruebas de Jest usando jest-cli
, así como una tarea tdd
gulp para ver archivos y volver a ejecutar pruebas de Jest cuando un archivo cambia:
var gulp = require('gulp');
var jest = require('jest-cli');
var jestConfig = {
rootDir: 'source'
};
gulp.task('test', function(done) {
jest.runCLI({ config : jestConfig }, ".", function() {
done();
});
});
gulp.task('tdd', function(done) {
gulp.watch([ jestConfig.rootDir + "/**/*.js" ], [ 'test' ]);
});
gulp.task('default', function() {
// place code for your default task here
});
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-05-31 21:21:17