<commit_before>import test from 'ava';
import path from 'path';
import clone from 'lodash.clone';

const
  processEnv = clone( process.env ),
  processCwd = process.cwd,
  workingDir = process.cwd(),
  mockedWorkingDirForOptFiles = path.resolve( workingDir, './fixtures/opt-files' ),
  mockedWorkingDirForPackageJson = path.resolve( workingDir, './fixtures/package' );

test.beforeEach( () => {
  process.cwd = () => workingDir;
} );

test.afterEach( () => {
  process.cwd = processCwd;
  process.env = processEnv;
} );

test( 'check explicit opt-ins & opt-outs (.opt-in and .opt-out existing)', ( t ) => {
  process.cwd = () => mockedWorkingDirForOptFiles;

  const
    { getExplicitOpts } = require( '../lib/index' ),
    expectedOpts = {
      'opted-in-foo-rule': true,
      'opted-in-bar-rule': true,
      'opted-out-foo-rule': false,
      'opted-out-bar-rule': false
    },
    retrievedOpts = getExplicitOpts();

  t.same( retrievedOpts, expectedOpts, 'retrieved opts should equal expected opts' );
} );

test( 'check explicit opt-ins & opt-outs (via package.json)', ( t ) => {
  process.cwd = () => mockedWorkingDirForPackageJson;

  const
    { getExplicitOpts } = require( '../lib/index' ),
    expectedOpts = {
      'package-json-opted-in-foo-rule': true,
      'package-json-opted-in-bar-rule': true,
      'package-json-opted-out-foo-rule': false,
      'package-json-opted-out-bar-rule': false
    },
    retrievedOpts = getExplicitOpts();

  t.same( retrievedOpts, expectedOpts, 'retrieved opts should equal expected opts' );
} );

test( 'check explicit opt-ins & opt-outs (via env vars)', ( t ) => {
  process.env = clone( processEnv );
  process.env.OPT_IN = 'ENV-VAR-OPTED-IN-FOO-RULE:ENV-VAR-OPTED-IN-BAR-RULE'; // eslint-disable-line id-match
  process.env.OPT_OUT = 'ENV-VAR-OPTED-OUT-FOO-RULE:ENV-VAR-OPTED-OUT-BAR-RULE'; // eslint-disable-line id-match

  const
    { getExplicitOpts } = require( '../lib/index' ),
    expectedOpts = {
      'ENV-VAR-OPTED-IN-FOO-RULE': true,
      'ENV-VAR-OPTED-IN-BAR-RULE': true,
      'ENV-VAR-OPTED-OUT-FOO-RULE': false,
      'ENV-VAR-OPTED-OUT-BAR-RULE': false
    },
    retrievedOpts = getExplicitOpts();

  t.same( retrievedOpts, expectedOpts, 'retrieved opts should equal expected opts' );
} );

test( 'test for particular opt-ins (.opt-in existing)', ( t ) => {
  process.cwd = () => mockedWorkingDirForOptFiles;

  const
    { testOptIn } = require( '../lib/index' );

  t.true(
    testOptIn( [ 'opted-in-foo-rule', 'opted-in-bar-rule' ] ),<commit_msg>fix(tests): Replace deprecated ava method (#43)<commit_after>import test from 'ava';
import path from 'path';
import clone from 'lodash.clone';

const
  processEnv = clone( process.env ),
  processCwd = process.cwd,
  workingDir = process.cwd(),
  mockedWorkingDirForOptFiles = path.resolve( workingDir, './fixtures/opt-files' ),
  mockedWorkingDirForPackageJson = path.resolve( workingDir, './fixtures/package' );

test.beforeEach( () => {
  process.cwd = () => workingDir;
} );

test.afterEach( () => {
  process.cwd = processCwd;
  process.env = processEnv;
} );

test( 'check explicit opt-ins & opt-outs (.opt-in and .opt-out existing)', ( t ) => {
  process.cwd = () => mockedWorkingDirForOptFiles;

  const
    { getExplicitOpts } = require( '../lib/index' ),
    expectedOpts = {
      'opted-in-foo-rule': true,
      'opted-in-bar-rule': true,
      'opted-out-foo-rule': false,
      'opted-out-bar-rule': false
    },
    retrievedOpts = getExplicitOpts();

  t.deepEqual( retrievedOpts, expectedOpts, 'retrieved opts should equal expected opts' );
} );

test( 'check explicit opt-ins & opt-outs (via package.json)', ( t ) => {
  process.cwd = () => mockedWorkingDirForPackageJson;

  const
    { getExplicitOpts } = require( '../lib/index' ),
    expectedOpts = {
      'package-json-opted-in-foo-rule': true,
      'package-json-opted-in-bar-rule': true,
      'package-json-opted-out-foo-rule': false,
      'package-json-opted-out-bar-rule': false
    },
    retrievedOpts = getExplicitOpts();

  t.deepEqual( retrievedOpts, expectedOpts, 'retrieved opts should equal expected opts' );
} );

test( 'check explicit opt-ins & opt-outs (via env vars)', ( t ) => {
  process.env = clone( processEnv );
  process.env.OPT_IN = 'ENV-VAR-OPTED-IN-FOO-RULE:ENV-VAR-OPTED-IN-BAR-RULE'; // eslint-disable-line id-match
  process.env.OPT_OUT = 'ENV-VAR-OPTED-OUT-FOO-RULE:ENV-VAR-OPTED-OUT-BAR-RULE'; // eslint-disable-line id-match

  const
    { getExplicitOpts } = require( '../lib/index' ),
    expectedOpts = {
      'ENV-VAR-OPTED-IN-FOO-RULE': true,
      'ENV-VAR-OPTED-IN-BAR-RULE': true,
      'ENV-VAR-OPTED-OUT-FOO-RULE': false,
      'ENV-VAR-OPTED-OUT-BAR-RULE': false
    },
    retrievedOpts = getExplicitOpts();

  t.deepEqual( retrievedOpts, expectedOpts, 'retrieved opts should equal expected opts' );
} );

test( 'test for particular opt-ins (.opt-in existing)', ( t ) => {
  process.cwd = () => mockedWorkingDirForOptFiles;

  const
    { testOptIn } = require( '../lib/index' );

  t.true(
    testOptIn( [ 'opted-in-foo-rule', 'opted-in-bar-rule' ] ),
{'fraction_non_alphanumeric': 0.17081292850146915, 'fraction_numerical': 0.0003917727717923604, 'mean_word_length': 3.240863787375415, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '1294308', 'n_tokens_mistral': 1849, 'n_tokens_neox': 1827, 'n_words': 341}