<commit_before>/*jshint globalstrict:false, strict:false */

////////////////////////////////////////////////////////////////////////////////
/// @brief tests for Foxx console
///
/// @file
///
/// DISCLAIMER
///
/// Copyright 2015 triagens GmbH, Cologne, Germany
///
/// Licensed under the Apache License, Version 2.0 (the "License");
/// you may not use this file except in compliance with the License.
/// You may obtain a copy of the License at
///
///     http://www.apache.org/licenses/LICENSE-2.0
///
/// Unless required by applicable law or agreed to in writing, software
/// distributed under the License is distributed on an "AS IS" BASIS,
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
/// See the License for the specific language governing permissions and
/// limitations under the License.
///
/// Copyright holder is triAGENS GmbH, Cologne, Germany
///
/// @author <NAME>
/// @author Copyright 2015, triAGENS GmbH, Cologne, Germany
////////////////////////////////////////////////////////////////////////////////

var jsunity = require('jsunity');
const expect = require('chai').expect;
var util = require('util');
var Console = require('@arangodb/foxx/legacy/console').Console;
var db = require('@arangodb').db;
var qb = require('aqb');
var AssertionError = require('assert').AssertionError;

var mountPath = '##TEST##';

function ls() {
  'use strict';
  if (!db._foxxlog) {
    return [];
  }
  return db._query(
    qb.for('entry').in('_foxxlog')
    .filter(qb.eq('entry.mount', qb.str(mountPath)))
    .sort('entry.time', 'ASC')
    .return('entry')
  ).toArray();
}

function rmrf() {
  'use strict';
  if (!db._foxxlog) {
    return [];
  }
  return db._query(
    qb.for('entry').in('_foxxlog')
    .filter(qb.eq('entry.mount', qb.str(mountPath)))
    .remove('entry').in('_foxxlog')
  ).toArray();
}

////////////////////////////////////////////////////////////////////////////////
/// @brief test suite
////////////////////////////////////////////////////////////////////////////////

function ConsoleTestSuite () {
  'use strict';
  var console;

  return {

////////////////////////////////////////////////////////////////////////////////
/// @brief set up
////////////////////////////////////////////////////////////////////////////////

    setUp: function () {
      console = new Console(mountPath);
      rmrf();
    },

////////////////////////////////////////////////////////////////////////////////
/// @brief tear down
////////////////////////////////////////////////////////////////////////////////

    tearDown: function () {
      rmrf();
    },

////////////////////////////////////////////////////////////////////////////////
/// @brief tests
////////////////////////////////////////////////////////////////////////////////

    testConsoleLogLogsMessage: function () {
      rmrf();
      console.log('hi');
      var logs = ls();
      expect(logs.length).to.be.equal(1);
      expect(logs[0]).to.have.property('level', 'INFO');
      expect(logs[0]).to.have.property('levelNum', console._logLevels.INFO);
      expect(logs[0]).to.have.property('message', 'hi');
    },

    testConsoleLogUsesFormat: function () {
      rmrf();
      console.log('%s prevails', 'the goddess');
      console.log('%s plus', 1, 2);
      var logs = ls();
      expect(logs[0]).to.have.property('message', 'the goddess prevails');
      expect(logs[1]).to.have.property('message', '1 plus 2');
    },

    testConsoleLogLogsTime: function () {
      rmrf();
      var min = Date.now();
      console.log('hi');
      var max = Date.now();
      var logs = ls();
      expect(logs[0]).to.have.property('time');
      expect(logs[0].time).to.be.a('number');
      expect(logs[0].time).not.to.be.lessThan(min);
      expect(logs[0].time).not.to.be.greaterThan(max);
    },
    testConsoleTimeLogsDuration: function () {
      rmrf();
      var start = Date.now();
      console.time('hi');
      var min = Date.now();
      while (Date.now() - start < 3) {var a = true; a=false;} // make sure a measurable amount of time passes
      console.timeEnd('hi');
      var max = Date.now();
      expect(max).to.be.greaterThan(min); // sanity checking
      var logs = ls();
      var match = logs[0].message.match(/^([^:]+):\s+(\d+)ms$/);
      expect(match).to.be.ok;
      expect(match[1]).to.equal('hi');
      var elapsed = Number(match[2]);
      expect(elapsed).not.to.be.lessThan(min - start);
      expect(elapsed).not.to.be.greaterThan(max - start);
    },
    testConsoleTimeThrowsForInvalidLabel: function () {
      expect(function () {
        console.timeEnd('this is a label that does not exist');
      }).to.throw(Error);
    },

    testConsoleDirUsesInspect: function () {
      var args = [
        'lol',
        {_PRINT: function (ctx) {ctx.output += 'hello';}}
      ];
      rmrf();
      args.forEach(function (arg) {
        console.dir(arg);
      });
      var logs = ls();
      args.forEach(function (arg, i) {<commit_msg>attempt to fix Windows test<commit_after>/*jshint globalstrict:false, strict:false */

////////////////////////////////////////////////////////////////////////////////
/// @brief tests for Foxx console
///
/// @file
///
/// DISCLAIMER
///
/// Copyright 2015 triagens GmbH, Cologne, Germany
///
/// Licensed under the Apache License, Version 2.0 (the "License");
/// you may not use this file except in compliance with the License.
/// You may obtain a copy of the License at
///
///     http://www.apache.org/licenses/LICENSE-2.0
///
/// Unless required by applicable law or agreed to in writing, software
/// distributed under the License is distributed on an "AS IS" BASIS,
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
/// See the License for the specific language governing permissions and
/// limitations under the License.
///
/// Copyright holder is triAGENS GmbH, Cologne, Germany
///
/// @author <NAME>
/// @author Copyright 2015, triAGENS GmbH, Cologne, Germany
////////////////////////////////////////////////////////////////////////////////

var jsunity = require('jsunity');
const expect = require('chai').expect;
var util = require('util');
var Console = require('@arangodb/foxx/legacy/console').Console;
var db = require('@arangodb').db;
var qb = require('aqb');
var AssertionError = require('assert').AssertionError;

var mountPath = '##TEST##';

function ls() {
  'use strict';
  if (!db._foxxlog) {
    return [];
  }
  return db._query(
    qb.for('entry').in('_foxxlog')
    .filter(qb.eq('entry.mount', qb.str(mountPath)))
    .sort('entry.time', 'ASC')
    .return('entry')
  ).toArray();
}

function rmrf() {
  'use strict';
  if (!db._foxxlog) {
    return [];
  }
  return db._query(
    qb.for('entry').in('_foxxlog')
    .filter(qb.eq('entry.mount', qb.str(mountPath)))
    .remove('entry').in('_foxxlog')
  ).toArray();
}

////////////////////////////////////////////////////////////////////////////////
/// @brief test suite
////////////////////////////////////////////////////////////////////////////////

function ConsoleTestSuite () {
  'use strict';
  var console;

  return {

////////////////////////////////////////////////////////////////////////////////
/// @brief set up
////////////////////////////////////////////////////////////////////////////////

    setUp: function () {
      console = new Console(mountPath);
      rmrf();
    },

////////////////////////////////////////////////////////////////////////////////
/// @brief tear down
////////////////////////////////////////////////////////////////////////////////

    tearDown: function () {
      rmrf();
    },

////////////////////////////////////////////////////////////////////////////////
/// @brief tests
////////////////////////////////////////////////////////////////////////////////

    testConsoleLogLogsMessage: function () {
      rmrf();
      console.log('hi');
      var logs = ls();
      expect(logs.length).to.be.equal(1);
      expect(logs[0]).to.have.property('level', 'INFO');
      expect(logs[0]).to.have.property('levelNum', console._logLevels.INFO);
      expect(logs[0]).to.have.property('message', 'hi');
    },

    testConsoleLogUsesFormat: function () {
      rmrf();
      console.log('%s prevails', 'the goddess');
      console.log('%s plus', 1, 2);
      var logs = ls();
      expect(logs[0]).to.have.property('message', 'the goddess prevails');
      expect(logs[1]).to.have.property('message', '1 plus 2');
    },

    testConsoleLogLogsTime: function () {
      rmrf();
      var min = Date.now();
      console.log('hi');
      var max = Date.now();
      var logs = ls();
      expect(logs[0]).to.have.property('time');
      expect(logs[0].time).to.be.a('number');
      expect(logs[0].time).not.to.be.lessThan(min);
      expect(logs[0].time).not.to.be.greaterThan(max);
    },
    testConsoleTimeLogsDuration: function () {
      rmrf();
      var start = Date.now();
      console.time('hi');
      var min = Date.now();
      while (Date.now() - start < 3) {var a = true; a=false;} // make sure a measurable amount of time passes
      var max = Date.now();
      console.timeEnd('hi');
      var end = Date.now();
      expect(max).to.be.greaterThan(min); // sanity checking
      var logs = ls();
      var match = logs[0].message.match(/^([^:]+):\s+(\d+)ms$/);
      expect(match).to.be.ok;
      expect(match[1]).to.equal('hi');
      var elapsed = Number(match[2]);
      expect(elapsed).not.to.be.lessThan(max - min);
      expect(elapsed).not.to.be.greaterThan(end - start);
    },
    testConsoleTimeThrowsForInvalidLabel: function () {
      expect(function () {
        console.timeEnd('this is a label that does not exist');
      }).to.throw(Error);
    },

    testConsoleDirUsesInspect: function () {
      var args = [
        'lol',
        {_PRINT: function (ctx) {ctx.output += 'hello';}}
      ];
      rmrf();
      args.forEach(function (arg) {
        console.dir(arg);
      });
      var logs = ls();
      args.forEach(function (arg, i) {
{'fraction_non_alphanumeric': 0.3110557768924303, 'fraction_numerical': 0.00597609561752988, 'mean_word_length': 1.6066978193146417, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4817456', 'n_tokens_mistral': 2823, 'n_tokens_neox': 2725, 'n_words': 655}