Как захватить console.log вне тестов в тесте карма + жасмин? - PullRequest
0 голосов
/ 01 октября 2018

У меня есть hello.js содержит console.log:

const $ = window.$;

console.log('------------ loading hello.js -----------------');

function hello(html) {
    return $(html).text()
}

Файл теста:

describe('hello', function () {
  it('should use jquery to get text of some html code', function () {
    console.log('--------- console.log inside test ---------------');
    expect(hello('<div>JQuery</div>')).toBe('JQuery')
  })
});

Я использую карму + жасмин для запуска теста, karma.conf.js:

module.exports = function (config) {
  config.set({

    logLevel: config.LOG_LOG,

    frameworks: ['jasmine'],

    files: [
      './node_modules/jquery/dist/jquery.js',
      'src/**.js'
    ],

    reporters: ['progress'],

    browsers: ['ChromeHeadless'],

    plugins: [
      'karma-chrome-launcher',
      'karma-jasmine'
    ],

    client: {
      captureConsole: true
    },

    browserConsoleLogOptions: {
      level: 'log'
    },
  });
};

Я ожидаю, что при запуске теста я могу увидеть журнал откуда-то.Я сделал все, что могу настроить, но не вижу его.

Вывод:

01 10 2018 23:06:59.291:WARN [karma]: No captured browser, open http://localhost:9877/ 01 10 2018 23:06:59.299:INFO [karma]: Karma v3.0.0 server started at http://0.0.0.0:9877/ 01 10 2018 23:06:59.300:INFO [launcher]: Launching browser ChromeHeadless with unlimited concurrency 01 10 2018 23:06:59.309:INFO [launcher]: Starting browser ChromeHeadless 01 10 2018 23:06:59.715:INFO [HeadlessChrome 0.0.0 (Mac OS X 10.13.3)]: Connected on socket O9-CJOOGs9L_DnMiAAAA with id 44722210 LOG: '--------- console.log inside test ---------------' HeadlessChrome 0.0.0 (Mac OS X 10.13.3): Executed 1 of 1 SUCCESS (0.003 secs / 0.004 secs) TOTAL: 1 SUCCESS

Вы можете видеть только console.log внутри тестов показано.

Есть ли способ захватить console.log в hello.js (внешние тесты)?

Полный небольшой демонстрационный проект по этому вопросу: https://github.com/freewind-demos/javascript-karma-jasmine-capture-console-log-when-loading-demo

...