<commit_before>/*
 Copyright 2019 - 2019 by <NAME>

 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.
 */

/* eslint-env mocha */

'use strict'

const Contract = require('../lib/IV/Contract')
const cases = require('./_cases')

const contract = new Contract({ pre: [cases.intentionallyFailingFunction] })

describe('mocha this', function () {
  before(function () {
    this.subject = contract.implementation(function () {})
  })

  it('works when a precondition violation occurs when a function is called with a mocha fixture as this', function () {
    try {
      this.subject()
      true.should.be.false()
    } catch (err) {
      // logging the error produces the same problem, because console.log uses util.inspect too
      console.log('' + err)
      const stack = err.stack
      console.log(stack)
      stack.should.match(/𝕋⚖️ \[\[failed to represent the value]]/)
      stack.should.match(/\(Converting circular structure to JSON\)/)
      console.log()
    }<commit_msg>only test when the problem occurs - now npm test also works, but we don't have coverage of the new catch<commit_after>/*
 Copyright 2019 - 2019 by <NAME>

 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.
 */

/* eslint-env mocha */

'use strict'

const Contract = require('../lib/IV/Contract')
const cases = require('./_cases')

const contract = new Contract({ pre: [cases.intentionallyFailingFunction] })

describe('mocha this', function () {
  before(function () {
    this.subject = contract.implementation(function () {})
  })

  it('works when a precondition violation occurs when a function is called with a mocha fixture as this', function () {
    // noinspection JSUnresolvedVariable
    if (this.test.intellij_test_node) {
      try {
        this.subject()
        true.should.be.false()
      } catch (err) {
        // logging the error produces the same problem, because console.log uses util.inspect too
        console.log('' + err)
        const details = err.getDetails()
        console.log(details)
        details.should.match(/𝕋⚖️ \[\[failed to represent the value]]/)
        details.should.match(/\(Converting circular structure to JSON\)/)
        console.log()
      }
    } else {
      console.log(
        'skipping a test that verifies the workaround to a bug that only occurs in IntelliJ or with mocha-reporter'
      )
    }
{'fraction_non_alphanumeric': 0.09912094574113367, 'fraction_numerical': 0.007274931797514398, 'mean_word_length': 3.230769230769231, 'pattern_counts': {'":': 0, '<': 5, '<?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': '6402886', 'n_tokens_mistral': 906, 'n_tokens_neox': 871, 'n_words': 361}