【问题标题】:Babel not preprocessing filesBabel 不预处理文件
【发布时间】:2020-04-15 18:51:26
【问题描述】:

我在配置我的 karma.conf.js 文件以通过 Webstorm 使用 babel 和 Karma 在 ES6 上进行单元测试时遇到问题。

我在这里要做的是在'/test/BaseElement.test.js' 上运行测试 启动测试时,我收到以下错误:

An error was thrown in afterAll
Uncaught SyntaxError: Unexpected token 'export'
SyntaxError: Unexpected token 'export'

这对我来说意味着预处理没有正确完成。

这是我的 package.json 中的依赖项:

"dependencies": {},
"devDependencies": {
"@babel/core": "^7.9.0",
"@babel/plugin-proposal-class-properties": "^7.8.3",
"@babel/preset-env": "^7.9.5",
"@webcomponents/webcomponentsjs": "^2.4.3",
"jasmine": "^3.5.0",
"jspm": "^2.0.0-beta.7",
"karma": "^5.0.1",
"karma-babel-preprocessor": "^8.0.1",
"karma-chrome-launcher": "^3.1.0",
"karma-jasmine": "^3.1.1",
"karma-spec-reporter": "0.0.32",
"mocha": "^7.1.1"

还有我的 Karma.config.js 文件:

module.exports = function(config) {
        config.set({
            basePath: "",
            frameworks: ["jasmine"],
            Preprocessors: {
                //'./Control/**/*.js': ['babel'],
               // './lib/**/*.js': ['babel'],
                //'./Module/**/*.js': ['babel'],
               '../lib/Element/BaseElement.js': ['babel'],
                '../test/BaseElement.test.js ': ['babel']
            },
            babelPreprocessor: {
                options: {
                    presets: ['@babel/preset-env']
                }
                },
            plugins: [
                '@babel/core',
                'karma-jasmine',
                'karma-chrome-launcher',
                'karma-babel-preprocessor'
            ],
            files: [
                {pattern: '../lib/Element/BaseElement.js', watched: true, included: true, served: true},
                { pattern: "*.test.js", type: "module", included: true }
            ],
            //reporters: ['jasmine'],
            port: 9876,
            colors: true,
            logLevel: config.LOG_INFO,
            autoWatch: true,
            browsers: ["Chrome"],
            singleRun: true,
            concurrency: Infinity
        });
    };

当我使用 --log-level 调试标志输出时,不会出现任何关于预处理的内容。

文件的位置如下:

在根目录中:package.json

在根目录/测试中:BaseElement.test.jskarma.conf.js

root/lib/Element BaseElement.js

任何帮助将不胜感激。 谢谢。

【问题讨论】:

    标签: javascript unit-testing karma-jasmine babeljs webstorm


    【解决方案1】:

    我发现了问题。它是预处理器而不是预处理器。

    【讨论】:

      猜你喜欢
      • 2017-10-04
      • 2015-08-25
      • 1970-01-01
      • 2015-10-05
      • 2021-05-29
      • 2013-11-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多