Laravel app karma webpack config не запускает тесты жасмина - PullRequest
0 голосов
/ 11 марта 2020

Я пытаюсь настроить Karma с Jasmine для тестирования реагирующих компонентов. Конфигурация кармы, которую я использовал:

/* eslint-disable no-undef */
var webpackConf = require('./node_modules/laravel-mix/setup/webpack.config.js');
delete webpackConf.entry

module.exports = function(config) {
    config.set({
        basePath: "./resources/js/",
        files: [
            { pattern: 'spec/**/*.js', watched: true, served: true, included: true }
        ],
        exclude: [],
        autoWatch: false,
        singleRun: false,
        failOnEmptyTestSuite: false,
        logLevel: config.LOG_WARN,
        frameworks: ["jasmine"],
        browsers: [
            'PhantomJS'/* 'Chrome','Firefox','Edge','ChromeCanary','Opera','IE','Safari'*/
        ],
        reporters: ["mocha", "kjhtml" /*,'dots','progress','spec'*/],
        listenAddress: "0.0.0.0",
        hostname: "localhost",
        port: 9876,
        retryLimit: 2,
        browserDisconnectTimeout: 5000,
        browserNoActivityTimeout: 10000,
        client: {
            //capture all console output and pipe it to the terminal, true is default
            captureConsole: true,
            //if true, Karma clears the context window upon the completion of running the tests, true is default
            clearContext: false,
            //run the tests on the same window as the client, without using iframe or a new window, false is default
            runInParent: false,
            //true: runs the tests inside an iFrame; false: runs the tests in a new window, true is default
            useIframe: true,
            jasmine: {
                //tells jasmine to run specs in semi random order, false is default
                random: false
            }
        },
        /* karma-webpack config
       pass your webpack configuration for karma
       add `babel-loader` to the webpack configuration to make 
       the ES6+ code in the test files readable to the browser  
       eg. import, export keywords */
        webpack: webpackConf,
        webpackMiddleware: {
            //turn off webpack bash output when run the tests
            noInfo: true,
            stats: "errors-only"
        },
        preprocessors: {
            //add webpack as preprocessor to support require() in test-suits .js files
            "spec/**/*.js": ["webpack"],
            "admin.js": ["webpack", "sourcemap"],
            "views/**/*.js": ["webpack", "sourcemap"],
            "components/**/*.js": ["webpack", "sourcemap"],
            "containers/**/*.js": ["webpack", "sourcemap"],
        },
        /*karma-mocha-reporter config*/
        mochaReporter: {
            output: "noFailures" //full, autowatch, minimal
        },
        colors: true,
        plugins: [
            'karma-webpack',
            'karma-jasmine',
            'karma-sourcemap-loader',
            'karma-phantomjs-launcher',
          ],
    });
};

, вот структура каталогов

anadi@MacAnadi js % pwd
/Users/anadi/Code/github/website/adminpanel/resources/js
anadi@MacAnadi js % ls -ltr

 views
 app.js
 containers
 __mocks__
 components
 bootstrap.js
 admin.js
 tests
 spec

И все тесты Жасмин находятся в каталоге spec. Затем я добавил сценарий int-test в package.json

"int-test": "karma start --coverage",

И добавил простой тест для одного из компонентов

import React from 'react'
import { mount, configure } from 'enzyme'
import jasmineEnzyme from 'jasmine-enzyme';
import Adapter from 'enzyme-adapter-react-16';

configure({ adapter: new Adapter() });

import Editor from "../../views/Blogs/Editor/UpdateEditor";

describe("Blog Update Editor", () => {
    beforeEach(() => {
        jasmineEnzyme();
    });

    it("renders without errors", () => {
      expect(mount(<Editor match={{ params: { slug: "a-title" }, isExact: true, path: "", url: "" }}/>)).toMatchSnapshot();
    });
});

Но когда я запускаю тесты, ни один из них выполнить, сообщений на консоли после этого

anadi@MacAnadi adminpanel % npm run int-test

> @ int-test /Users/anadi/Code/github/website/adminpanel
> karma start --coverage

11 03 2020 17:30:07.265:WARN [karma]: No captured browser, open http://localhost:9876/
11 03 2020 17:30:07.315:INFO [karma-server]: Karma v4.4.1 server started at http://0.0.0.0:9876/

NPM модулей, которые я установил для этой цели, нет:

"enzyme": "3.11.0",
"enzyme-adapter-react-16": "1.15.2",
"jasmine-enzyme": "7.1.2",
"webpack-cli": "3.3.11",
"webpack-karma-jasmine": "3.0.8"

вот ссылка на полный пакет. json

1 Ответ

0 голосов
/ 11 марта 2020

Файл конфигурации Karma должен быть karma.conf.js, а не karma.config.js; это исправило.

...