简体   繁体   English

ENFILE:Karma文件表溢出

[英]ENFILE: File Table Overflow with Karma

I am getting a file table overflow issue while running the Karma tests, and I have no clue how to debug this. 我在运行Karma测试时遇到文件表溢出问题,我不知道如何调试它。

karma.conf.js: karma.conf.js:

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: 的package.json:

"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"

test-unit.js: 测试unit.js:

 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();
});

Error: 错误:

[08:44:36] 'karma' errored after 2.48 s [08:44:36] Error: ENFILE: file table overflow, scandir '/Users/Abhi/Documents/projects/test/src/app' at Error (native) at Object.fs.readdirSync (fs.js:808:18) at GlobSync._readdir (/Users/Abhi/Documents/projects/test/node_modules/karma/node_modules/glob/sync.js:275:41) at GlobSync._processGlobStar (/Users/Abhi/Documents/projects/test/node_modules/karma/node_modules/glob/sync.js:330:22) at GlobSync._process (/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 /Users/Abhi/Documents/projects/test/node_modules/karma/lib/file-list.js:161:14 at Array.map (native) at [object Object].List._refresh (/Users/Abhi/Documents/projects/test/node_modules/karma/lib/file-list.js:153:37) at [object Object].List.refresh (/U [08:44:36]'业力'在2.48秒后出错[08:44:36]错误:ENFILE:文件表溢出,scandir'/ Users / Abhi / Documents / projects / test / src / app'出错(原生)在GlobSync的GlobSync._readdir(/Users/Abhi/Documents/projects/test/node_modules/karma/node_modules/glob/sync.js:275:41)的Object.fs.readdirSync(fs.js:808:18)处GlobSync._process上的._processGlobStar(/Users/Abhi/Documents/projects/test/node_modules/karma/node_modules/glob/sync.js:330:22)(/ Users / Abhi / Documents / projects / test / node_modules / karma / node_modules / glob / sync.js:128:10)新GlobSync(/Users/Abhi/Documents/projects/test/node_modules/karma/node_modules/glob/sync.js:46:10)新Glob(/ Users / Abhi / Documents / projects / test / node_modules / karma / node_modules / glob / glob.js:111:12)atUsers/Abhi/Documents/projects/test/node_modules/karma/lib/file-list.js:161: 14位于[object Object]的[object object] .List._refresh(/Users/Abhi/Documents/projects/test/node_modules/karma/lib/file-list.js:153:37)的Array.map(native) .List.refresh(/ U. sers/Abhi/Documents/projects/test/node_modules/karma/lib/file-list.js:252:27) at [object Object].Server._start (/Users/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. sers / Abhi / Documents / projects / test / node_modules / karma / lib / file-list.js:252:27)at [object Object] .Server._start(/ Users / Abhi / Documents / projects / test / node_modules / karma) /lib/server.js:177:12)在[object Object] .invoke(/Users/Abhi/Documents/projects/test/node_modules/karma/node_modules/di/lib/injector.js:75:15)at [ Gulp上的对象] .Server.start(/Users/Abhi/Documents/projects/test/node_modules/karma/lib/server.js:101:18)。 (/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 (/Users/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) (/Users/Abhi/Documents/projects/test/gulp/tasks/test-unit.js:53:12)在module.exports(/ Users / Abhi / Documents / projects / test / node_modules / gulp / node_modules / orchestrator /) lib / runTask.js:34:7)在Gulp.Orchestrator._runStep的Gulp.Orchestrator._runTask(/Users/Abhi/Documents/projects/test/node_modules/gulp/node_modules/orchestrator/index.js:273:3) (/Users/Abhi/Documents/projects/test/node_modules/gulp/node_modules/orchestrator/index.js:214:10)在Gulp.Orchestrator.start(/ Users / Abhi / Documents / projects / test / node_modules / gulp / node_modules / orchestrator / index.js:134:8)atUsers/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)

Karma Issue Tracker: https://github.com/karma-runner/karma/issues/1979 Karma问题跟踪器: https//github.com/karma-runner/karma/issues/1979

Abhi, ABHI,

I spent a good afternoon on this and found a workaround, to what i have admit is a best guess issue that i have zero idea WHY is happening. 我度过了一个愉快的下午并发现了一个解决方法,我承认这是一个最好的猜测问题,我不知道为什么会发生这种情况。

My issue was with the globs inside of serveFiles and loadFiles in the Karma config. 我的问题是在Karma配置中的serveFiles和loadFiles中的globs。 To fix i did my own globbing using glob.sync to generate the arrays as i needed and this WORKED! 要修复我使用glob.sync生成我自己的globbing,以生成我需要的数组,这就算了!

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
    });
};

The filesToServe and specsToLoad are treated slightly differently, i needed to remove the ./ from the files to load as it interferes with SystemJS's loading internally (this can be recognised by it trying to load a .ts.js file). filesToServe和specsToLoad的处理略有不同,我需要从要加载的文件中删除./,因为它会干扰SystemJS的内部加载(这可以通过它尝试加载.ts.js文件来识别)。 Also i've got my work in a sub folder, 'www' which you might not need eg remove the cwd. 此外,我的工作在子文件夹'www',你可能不需要,例如删除cwd。

Hopefully you can see what i've done here and it helps you find a workaround. 希望你能看到我在这里做了什么,它可以帮助你找到一个解决方法。 If anyone knows why something like glob is breaking i'd love to know. 如果有人知道为什么像glob这样的东西会破碎,我很想知道。

To prove it was glob i did a simple test, using 为了证明它是glob我做了一个简单的测试,使用

require(glob)("src/**/*",function(file){ console.log(file); });

This triggered the same error, clearly NOTHING to do with too many files or a file table issue. 这触发了同样的错误,显然没有太多文件或文件表问题。 If this pops up in other places, i'm going to have to clean install the OS again i think. 如果这在其他地方弹出,我想我必须再次清理安装操作系统。 However in my code base i use globs in other places, without any issue. 但是在我的代码库中,我在其他地方使用globs,没有任何问题。 I had wondered if it perhaps was the difference between using the 'sync' version of the process... 我想知道使用过程的'sync'版本是否有区别...

A day of wading through options to end up here... i had hoped to find a better answer. 一天趟过选项结束这里...我希望找到一个更好的答案。

K ķ

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM