0

我目前正在将单元测试添加到我继承的自定义构建的 FE 框架中。我正在使用 gulp-jest 包添加 Jest,所有测试都运行并按预期提供必要的详细信息。

当将 gulp jest 任务与 gulp watch 一起使用时,问题就出现了,我似乎在任务本身和相关插件上遇到了错误。以下是我当前的设置

gulp.task('watch', ['browserSync'], function() {
 gulp.watch(config.modFiles + '/**/assets/*.*', ['assets', 'echo', browserSync.reload]);
 gulp.watch(config.modFiles + '/**/*.scss', ['sass', 'modularCSS', 'hf', 'listDir', 'moduleListing', 'echo', browserSync.reload]);
 gulp.watch(config.modFiles + '/**/*.js', ['javascript', 'javascriptv2', 'modularJS', 'templates', 'hf', 'listDir', 'moduleListing', 'jest', 'echo', browserSync.reload]);
 gulp.watch(config.modFiles + '/**/*.html', ['html', 'listDir', 'moduleListing', 'echo', browserSync.reload]);
 gulp.watch(config.modFiles + '/**/*.hbs', ['templates', 'echo', browserSync.reload]);
 gulp.watch(config.sourceFiles + '/assets/**/*.*', ['fontStack', 'assets', 'echo', browserSync.reload]);
});  

并在一个单独的文件中

var gulp = require('gulp');
var jest = require('gulp-jest').default;


var TEST_ROOT_DIR = '<rootDir>/modules/';
var JEST_OPTIONS = {
 "testPathIgnorePatterns" : [
   "<rootDir>/build/",
   "<rootDir>/node_modules/"
 ],
 "preprocessorIgnorePatterns": [
   "<rootDir>/build/", "<rootDir>/node_modules/"
 ],
};

// run all tests
gulp.task('jest', function () {
 process.env.NODE_ENV = 'test';
   return gulp.src('.').pipe(jest(JEST_OPTIONS));
});

这是手表收到任何更改后的错误

[10:56:46] 'jest' errored after 3.03 s
[10:56:46] Error in plugin "gulp-jest"
Message:
   Tests Failed

我的 package.json 依赖项列表

"devDependencies": {
   "@babel/cli": "^7.13.16",
   "@babel/core": "^7.14.0",
   "@babel/preset-env": "^7.14.0",
   "browser-sync": "^2.24.7",
   "critical": "^1.3.9",
   "gsap": "^2.1.3",
   "gulp": "^3.9.1",
   "gulp-autoprefixer": "^5.0.0",
   "gulp-bump": "^3.1.1",
   "gulp-clean": "^0.4.0",
   "gulp-clean-css": "^4.2.0",
   "gulp-concat": "^2.6.1",
   "gulp-connect": "^5.6.1",
   "gulp-count": "^1.0.0",
   "gulp-csso": "^3.0.1",
   "gulp-debug": "^3.2.0",
   "gulp-declare": "^0.3.0",
   "gulp-dest": "^0.2.3",
   "gulp-directory-map": "^0.1.3",
   "gulp-file-include": "^2.2.2",
   "gulp-footer": "^2.0.1",
   "gulp-handlebars": "^5.0.2",
   "gulp-if": "^2.0.2",
   "gulp-imagemin": "^6.0.0",
   "gulp-json-editor": "^2.4.1",
   "gulp-plumber": "^1.2.0",
   "gulp-rename": "^1.3.0",
   "gulp-run": "^1.7.1",
   "gulp-sass": "^3.2.1",
   "gulp-shell": "^0.6.5",
   "gulp-sourcemaps": "^2.6.4",
   "gulp-spreadsheet2json": "^1.0.6",
   "gulp-string-replace": "^1.1.0",
   "gulp-strip-css-comments": "^2.0.0",
   "gulp-strip-debug": "^3.0.0",
   "gulp-uglify": "^3.0.0",
   "gulp-wrap": "^0.13.0",
   "handlebars": "4.1.2",
   "i": "^0.3.6",
   "jest": "^26.6.3",
   "require-dir": "^1.2.0"
 },
 "dependencies": {
   "babel-jest": "^26.6.3",
   "babel-preset-env": "^1.7.0",
   "draggabilly": "^2.2.0",
   "emitter-steward": "^1.0.0",
   "express": "^4.16.3",
   "gulp-babel": "^8.0.0",
   "gulp-jest": "^4.0.4",
   "gulp-v3": "^3.12.1",
   "harmonize": "^2.0.0",
   "jquery.easing": "^1.4.1",
   "node-sass": "^4.13.1",
   "run-sequence": "^2.2.1",
   "showdown": "^1.9.1",
   "smooth-scroll": "^16.1.2",
   "smoothscroll-polyfill": "^0.4.4",
   "spdy": "^3.4.7",
   "yargs": "^13.2.2"
 },

任何想法为什么会发生这种情况?

4

0 回答 0