首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ENFILE:文件表溢出与Karma

ENFILE:文件表溢出与Karma
EN

Stack Overflow用户
提问于 2016-03-08 17:00:57
回答 1查看 4.4K关注 0票数 4

在运行Karma测试时,我收到了一个文件表溢出问题,我不知道如何调试这个问题。

karma.conf.js:

代码语言:javascript
复制
module.exports = function (config) {
    config.set({
        frameworks: ['jspm', 'jasmine'],
        files: [

            'node_modules/karma-babel-preprocessor/node_modules/babel-core/browser-polyfill.js',
            'node_modules/jasmine-async-sugar/jasmine-async-sugar.js'
        ],

        jspm: {
            config: 'jspm.conf.js',
            loadFiles: ['src/app/app.js', 'src/app/**/*.spec.js'], //'src/app/**/!(*.e2e|*.po).js'
            serveFiles: ['src/app/**/*.+(js|html|css|json)'] // *.{a,b,c} to *.+(a|b|c) https://github.com/karma-runner/karma/issues/1532
        },

        proxies: {
            '/test/': '/base/test/',
            '/src/app/': '/base/src/app/',
            '/jspm_packages/': '/base/jspm_packages/'
        },

        //reporters: process.argv.slice(2).find((argv) => argv.includes('--nocoverage') || argv.includes('--no-coverage')) ? ['dots', 'junit'] : ['dots', 'junit', 'coverage'],

        // use dots reporter, as Travis terminal does not support escaping sequences;
        // when using Travis publish coverage to coveralls
        reporters: coveralls ? ['dots', 'junit', 'coverage', 'coveralls'] : nocoverage ? ['dots'] : ['dots', 'junit', 'coverage'],

        junitReporter: {
            outputDir: 'test-reports/unit-test-report/',
            suite: 'unit'
        },

        preprocessors: {
            // source files, that you wanna generate coverage for - do not include tests or libraries
            // (these files will be instrumented by Istanbul)
            'src/**/!(*.spec|*.mock|*-mock|*.e2e|*.po|*.test).js': ['babel', 'coverage']
        },

        // transpile with babel since the coverage reporter throws error on ES6 syntax
        babelPreprocessor: {
            options: {
                stage: 1,
                sourceMap: 'inline'
            }
        },

        coverageReporter: {
            instrumenters: { isparta : require('isparta') },
            instrumenter: {
                'src/**/*.js': 'isparta'
            },
            dir: 'test-reports/coverage/',
            subdir: normalizationBrowserName,
            reporters: [
                {type: 'html'}, // will generate html report
                {type: 'json'}, // will generate json report file and this report is loaded to make sure failed coverage cause gulp to exit non-zero
                {type: 'lcov'}, // will generate Icov report file and this report is published to coveralls
                {type: 'text-summary'} // it does not generate any file but it will print coverage to console
            ]
        },

        browsers: [process.env.TRAVIS ? 'Firefox' : 'Chrome'],

        browserNoActivityTimeout: 50000
    });

    function normalizationBrowserName(browser) {
        return browser.toLowerCase().split(/[ /-]/)[0];
    }
};

package.json:

代码语言:javascript
复制
"karma": "0.13.14",
"karma-jspm": "2.0.1",
"karma-jasmine": "0.3.6",
"karma-coverage": "douglasduteil/karma-coverage#next",
"karma-coveralls": "1.1.2",
"karma-ie-launcher": "0.2.0",
"karma-junit-reporter": "0.3.8",
"karma-chrome-launcher": "0.2.1",
"karma-safari-launcher": "0.1.1",
"karma-firefox-launcher": "0.1.6",
"karma-phantomjs-launcher": "0.2.1",
"karma-babel-preprocessor": "5.2.2"

测试-unit.js:

代码语言:javascript
复制
 gulp.task('karma', (cb) => {
    // remove 'coverage' directory before each test
    del.sync(path.test.testReports.coverage);
    // run the karma test
    const server = new Server({
        configFile: path.test.config.karma,
        browsers: BROWSERS.split(','),
        singleRun: !argv.watch,
        autoWatch: !!argv.watch
    }, function(code) {
        // make sure failed karma tests cause gulp to exit non-zero
        if(code === 1) {
            LOG(COLORS.red('Error: unit test failed '));
            return process.exit(1);
        }
        cb();
    });
    server.start();
});

错误:

08:44:36‘业力’在2.48 s 08:44:36错误后出错:登记:文件表溢出,扫描/用户/Abhi/Documents/projects/test/src/app‘在Object.fs.readdirSync (fs.js:808:18)的错误(原生),在GlobSync._readdir,GlobSync._processGlobStar,fs.js:808:18,at GlobSync。(/Users/Abhi/Documents/projects/test/node_modules/karma/node_modules/glob/sync.js:128:10) at new GlobSync (/Users/Abhi/Documents/projects/test/node_modules/karma/node_modules/glob/sync.js:46:10) at new Glob (/Users/Abhi/Documents/projects/test/node_modules/karma/node_modules/glob/glob.js:111:12) at /User/Abhi/Documents/projects/test/node_modules/karma/lib/file-list.js:161:14 at Array.map (原生) at object Object.List._refresh,(/Users/Abhi/Documents/projects/test/node_modules/karma/lib/file-list.js:153:37) at object Object.List.refresh (/Users/Abhi/Documents/projects/test/node_modules/karma/lib/file-list.js:252:27) at object Object.Server._start (/User/Abhi/Documents/projects/test/node_modules/karma/lib/server.js:177:12) at object Object.invoke (/Users/Abhi/Documents/projects/test/node_modules/karma/node_modules/di/lib/injector.js:75:15) at object Object.Server.start (/Users/Abhi/Documents/projects/test/node_modules/karma/lib/server.js:101:18) at Gulp(/Users/Abhi/Documents/projects/test/gulp/tasks/test-unit.js:53:12) at module.exports (/Users/Abhi/Documents/projects/test/node_modules/gulp/node_modules/orchestrator/lib/runTask.js:34:7) at Gulp.Orchestrator._runTask (/Users/Abhi/Documents/projects/test/node_modules/gulp/node_modules/orchestrator/index.js:273:3) at Gulp.Orchestrator._runStep (/User/Abhi/Documents/projects/test/node_modules/gulp/node_modules/orchestrator/index.js:214:10) at Gulp.Orchestrator.start (/Users/Abhi/Documents/projects/test/node_modules/gulp/node_modules/orchestrator/index.js:134:8) at /Users/Abhi/Documents/projects/test/node_modules/gulp/bin/gulp.js:129:20 at nextTickCallbackWith0Args (node.js:419:9) at process._tickCallback (node.js:348:13)

卡玛问题追踪器:https://github.com/karma-runner/karma/issues/1979

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-03-09 16:57:25

阿比

我花了一个很好的下午,并找到了一个解决办法,我已经承认这是一个最好的猜测问题,我完全不知道为什么会发生。

我的问题是serveFiles和loadFiles内部的globs在Karma配置中。为了解决这个问题,我使用glob.sync来生成我所需要的数组,这是我自己做的工作!

代码语言:javascript
复制
module.exports = function(config) {

    var options = {cwd:"www"};
    var glob = require("glob");
    var filesToServe = glob.sync("./src/**/*.@(js|ts|css|scss|html)", options);
    var specsToLoad = glob.sync("./src/**/*.@(spec.ts)", options).map(function(file){
        return file.substr(2);
    });

    config.set({
        basePath: 'www',

        frameworks: ['jspm', 'jasmine'],

        jspm: {
            config: './test/config.js',
            loadFiles: ['test/boot.ts'].concat(specsToLoad),
            serveFiles: filesToServe,
        },

        files: [
        'http://cdn.auth0.com/js/lock-8.2.min.js'
        ],

        proxies: {
            '/src/': '/base/src/',
            '/.test/': '/base/.test/'
        },

        port: 9876,

        logLevel: config.LOG_DISABLE,

        colors: true,

        autoWatch: true,

        browsers: ['Chrome'],

        plugins: [
            'karma-jspm',
            'karma-jasmine',
            'karma-chrome-launcher',
            'karma-spec-reporter'
        ],

        reporters: ['spec'],

        singleRun: true
    });
};

对filesToServe和specsToLoad的处理略有不同,我需要从要加载的文件中删除./,因为它会在内部干扰SystemJS的加载(这可以通过试图加载.ts.js文件来识别)。此外,我的工作在一个子文件夹,'www‘,你可能不需要,例如删除cwd。

希望你能看到我在这里所做的一切,这有助于你找到解决办法。如果有人知道像glob这样的东西为什么会破裂,我很想知道。

为了证明这是glob,我做了一个简单的测试,用

代码语言:javascript
复制
require(glob)("src/**/*",function(file){ console.log(file); });

这引发了同样的错误,显然与过多的文件或文件表问题无关。如果这个弹出在其他地方,我想我将不得不再次清洁安装操作系统。但是,在我的代码库中,我在其他地方使用globs,没有任何问题。我想知道这是否是使用进程的“同步”版本之间的区别.

经过一天的跋涉终于来到这里..。我本希望能找到一个更好的答案。

K

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35873437

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档