无法使用gulp.js读取未定义的属性'start'

yc0p9oo0  于 2022-12-08  发布在  Gulp
关注(0)|答案(1)|浏览(168)

因此,当我使用以下代码时,我的GULP中出现了1个错误:

node ./node_modules/gulp/bin/gulp.js test

下面是我运行时遇到的错误:js测试

PS C:\Users\myuser\repos\wwwroot\acqustn-aem-global-comps\ui.apps> node 
./node_modules/gulp/bin/gulp.js test
[09:41:14] Using gulpfile ~\repos\wwwroot\global-comps\ui.apps\gulpfile.js
[09:41:14] Starting 'test'...
[09:41:14] 'test' errored after 4.45 ms
[09:41:14] TypeError: Cannot read property 'start' of undefined
at C:\Users\myuser\repos\wwwroot\global-comps\ui.apps\gulpfile.js:12:11
at test (C:\Users\myuser\repos\wwwroot\global-comps\ui.apps\node_modules\undertaker\lib\set-task.js:13:15)     
at bound (domain.js:426:14)
at runBound (domain.js:439:12)
at asyncRunner (C:\Users\myuser\repos\wwwroot\global-comps\ui.apps\node_modules\async-done\index.js:55:18)     
at processTicksAndRejections (internal/process/task_queues.js:79:11)

这是我的karma.conf.js文件,它的格式如下。我在这里添加更多的文本,因为我不得不这样做,因为我不能张贴,除非我描述更多的信息

module.exports = function (config) {
  const process = require('process');
  process.env.CHROME_BIN = require('puppeteer').executablePath();
  config.set({

    // base path that will be used to resolve all patterns (eg. files, exclude)
    basePath: '',

    // frameworks to use
    // available frameworks: https://npmjs.org/browse/keyword/karma-adapter
    frameworks: ['jasmine-jquery', 'jasmine'],

    plugins: [
      require('jquery'),
      require('karma-junit-reporter'),
      require('karma-coverage'),
      require('karma-jasmine-jquery-2'),
      require('karma-jasmine'),
      require('karma-chrome-launcher'),
      require('karma-jasmine-html-reporter'),
      require('karma-phantomjs-launcher'),
      require('karma-coverage-istanbul-reporter'),
      require('@angular-devkit/build-angular/plugins/karma'),
      require('karma-sonarqube-unit-reporter')
    ],
    client: {
      clearContext: false // leave Jasmine Spec Runner output visible in browser
    },
    coverageIstanbulReporter: {
      dir: require('path').join(__dirname, './coverage/global-comps'),
      reports: ['lcovonly', 'text-summary'],
      fixWebpackSourcePaths: true
    },
    // list of files / patterns to load in the browser
    files: [
      './src/main/content/jcr_root/etc/designs/global-components/footer/**/*.js',
      './src/main/content/jcr_root/etc/designs/global-components/header/**/*.js',
      './src/main/content/jcr_root/etc/designs/global-components/action/**/*.js'
    ],

    // list of files / patterns to exclude
    exclude: [
    ],

    // preprocess matching files before serving them to the browser
    // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
    preprocessors: {
      './test/navigationClientLibs/js/header.spec.js': ['coverage']
    },

    // test results reporter to use
    // possible values: 'dots', 'progress'
    // available reporters: https://npmjs.org/browse/keyword/karma-reporter
    reporters: ['junit', 'progress', 'kjhtml', 'coverage-istanbul', 'sonarqubeUnit', 'coverage'],
    sonarQubeUnitReporter: {
      sonarQubeVersion: 'LATEST',
      outputFile: 'reports/ut_report.xml',
      overrideTestDescription: true,
      testPaths: ['./test/navigationClientLibs/'],
      testFilePattern: '.js',
      useBrowserName: false
    },

    // web server port
    port: 9876,

    // enable / disable colors in the output (reporters and logs)
    colors: true,

    // level of logging
    // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
    logLevel: config.LOG_INFO,

    // enable / disable watching file and executing tests whenever any file changes
    autoWatch: false,

    // start these browsers
    // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
    browsers: ['PhantomJS'],

    // Continuous Integration mode
    // if true, Karma captures browsers, runs the tests and exits
    singleRun: true,

    // Concurrency level
    // how many browser should be started simultaneous
    concurrency: Infinity,

    junitReporter: {
      outputFile: 'reports/junit/TESTS-xunit.xml'
    },

    coverageReporter: {
      type: 'lcov',
      dir: 'reports',
      subdir: 'coverage'
    }
  })
}

现在我的GULP文件,每当我在VS代码终端中的命令提示符下运行以下node./node_modules/gulp/bin/gulp. js测试时,它都会失败,并带有karma.start()

var gulp = require('gulp');
    var karma = require('karma').server;
    var replace = require('gulp-replace');

    var postprocessLCOV = function() {
        return gulp.src('reports/coverage/lcov.info')
            .pipe(replace('SF:.', 'SF:frontend-project'))
            .pipe(gulp.dest('reports/coverage'));
    };

    gulp.task('test', function () {
        karma.start({
            configFile: __dirname + '/src/test/js/karma.conf.ci.js'
        }, postprocessLCOV);
    });

注意:我的karma.conf.js和.ci.js是完全相同的,所以我不必在这里发布这两个文件。
最后是我的package.json,它显示了我正在使用的所有东西。每当我添加一个新的库时,我必须删除package.lock.json,在新的库安装后,重新运行npm安装。

{
  "name": "global-comps",
  "version": "1.0.0",
  "description": "This is for the Navigator",
  "main": "qunit.js",
  "scripts": {
    "lint": "eslint '**/*.js'",
    "test": "qunit",
    "compodoc": "npx compodoc -p tsconfig.doc.json",
    "ng": "ng",
    "clean": "rm -rf node*",
    "ng-cli": "npm install --no-optional @angular/cli",
    "start": "ng serve --proxy-config proxy.config.json",
    "build": "ng build",
    "prod": "node --max_old_space_size=8192 node_modules/@angular/cli/bin/ng build --prod --output-hashing none && npm run test && npm run clean",
    "e2e": "ng e2e",
    "sonar": "sonar-scanner"
  },
  "repository": {
    "type": "git",
    "url": "somerepo.git"
  },
  "author": "Some Author",
  "license": "MIT",
  "dependencies": {
    "@angular/common": "~9.0.2",
    "@angular/compiler": "~9.0.2",
    "@angular/core": "~9.0.2",
    "@angular/platform-browser": "~9.0.2",
    "@angular/platform-browser-dynamic": "~9.0.2",
    "@angular/router": "~9.0.2",
    "@types/mocha": "^9.0.0",
    "JSONPath": "^0.11.2",
    "browserify": "^17.0.0",
    "common-js": "^0.3.8",
    "eslint-plugin-qunit": "^6.1.1",
    "jquery": "^3.4.1",
    "jquery-browserify": "^1.8.1",
    "jsdom": "^16.5.3",
    "junit": "^1.4.9",
    "karma-junit-reporter": "^2.0.1",
    "ng-mocks": "^11.10.1",
    "node": "^15.12.0",
    "npm-check-updates": "^11.5.13",
    "phantomjs": "^2.1.7",
    "qunit-reporter-junit": "^1.1.1",
    "qunit-reporter-lcov": "^1.0.2",
    "require": "^2.4.20",
    "rxjs": "~6.5.4",
    "tslib": "^1.10.0"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^12.1.3",
    "@angular-devkit/build-webpack": "^0.1201.3",
    "@angular/compiler-cli": "~9.0.2",
    "@types/jasmine": "~3.5.0",
    "@types/jasminewd2": "~2.0.3",
    "@types/jsdom": "^16.2.13",
    "@types/node": "^12.11.1",
    "codelyzer": "^5.1.2",
    "grunt": "^1.3.0",
    "grunt-contrib-connect": "^3.0.0",
    "grunt-contrib-copy": "^1.0.0",
    "grunt-contrib-qunit": "^4.0.0",
    "grunt-git-authors": "^3.2.0",
    "grunt-search": "^0.1.8",
    "gulp": "^4.0.2",
    "gulp-replace": "^1.1.3",
    "jasmine-core": "~3.5.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "^6.3.2",
    "karma-chrome-launcher": "^3.1.0",
    "karma-coverage": "^2.0.3",
    "karma-coverage-istanbul-reporter": "^3.0.3",
    "karma-jasmine": "^4.0.1",
    "karma-jasmine-html-reporter": "^1.7.0",
    "karma-jasmine-jquery-2": "^0.1.1",
    "karma-mocha-reporter": "^2.2.5",
    "karma-phantomjs-launcher": "^1.0.4",
    "karma-qunit": "^4.1.2",
    "karma-sonarqube-unit-reporter": "0.0.23",
    "karma-webpack": "^5.0.0",
    "protractor": "~5.4.3",
    "puppeteer": "^1.20.0",
    "sonar-scanner": "^3.1.0",
    "sonarqube-scanner": "~2.7.0",
    "ts-node": "~8.3.0",
    "typescript": "~3.7.5"
  },
  "global": "window"
}

所以,这就是我在哪里。

更新!

所以,我放弃了海湾,让卡玛工作。
但是在SONARQUBE中,我得到的是0%的覆盖率,因为Karma没有创建lcov.info文件,即使它正在创建覆盖率目录和后续文件。

**备注:**我可以在QUNIT的浏览器中运行我的测试,并查看它们是否成功。

但是我需要KARMAlcov.info用我在.js文件中创建的测试来创建www.example.com文件。
这里有一个我的SONARQUBE覆盖的屏幕截图,告诉你我得到了什么。

我真的需要帮助。
同样,这里有两个简单的测试文件,我正在使用QUNIT运行它们,但当我在Karma中运行它们时,它们却不工作。
谢谢大家一直以来的支持。

describe('A Suite for a simple test', () => {

        var a;

        it('and so it is a spec', () => {
            a = true;
            expect(a).toBe(true);
        });

        it('2 plus 2 should be 4', () => {
            const result = add(2, 2);

            expect(result).toBe(4);

        });

    });

    describe('Test case 1', () => {
        var zipcodevalue = '';

        const test1 = sendToTest1;

        console.log('Test 1 is: ', test1);

        beforeEach(function () {
            zipToTestCase.call(this, {
                assert: assert,
                zipcodevalue: '98237',
                expected: "Success"
            });
        });

        function zipToTestCase() {

            if (isNaN(zipcodevalue === false)) {
                expect(zipcodevalue, '98237', 'string value and hard code value are NOT equal', function (callback) {
                    callback(zipcodevalue);
                });
            } else {
                expect(zipcodevalue, '98237', 'string value and hard code value are equal', function (callback) {
                    callback(zipcodevalue);
                });
            }

        }

        it('test for Valid ZipCode', () => {
            expect(zipcodevalue).toBeTruthy();
        })

        it('test for INValid ZipCode', () => {
            expect(zipcodevalue).toBeFalsy();
        })

    });

相关问题