<commit_before>import test from 'ava';

import { createConfig, Config, SourceSpec, Runtime, LogLevel } from '../src/config';
import { HostMock } from './helper';

test('createConfig should return the config defaults', t => {
  const host = new HostMock({
    '/paeckchen.json': '{}'
  }, '/');

  return createConfig({}, host)
    .then(config => {
      t.deepEqual(config, {
        input: {
          entryPoint: undefined,
          source: SourceSpec.ES2015,
        },
        output: {
          folder: host.cwd(),
          file: undefined,
          runtime: Runtime.browser,
          sourceMap: false
        },
        aliases: {},
        externals: {},
        watchMode: false,
        logLevel: LogLevel.default
      } as Config);
    });
});

test('createConfig should prefer entry point of options', t => {
  const host = new HostMock({
    '/paeckchen.json': '{"input": {"entry": "config"}}'
  }, '/');

  return createConfig({entryPoint: 'options'}, host)
    .then(config => {
      t.is(config.input.entryPoint, 'options');
    });
});

test('createConfig should fallback to entry point of config', t => {
  const host = new HostMock({
    '/paeckchen.json': '{"input": {"entry": "config"}}'
  }, '/');

  return createConfig({}, host)
    .then(config => {
      t.is(config.input.entryPoint, 'config');
    });
});

test('createConfig should prefer sourceMap of options', t => {
  const host = new HostMock({
    '/paeckchen.json': '{"output": {"sourceMap": false}}'
  }, '/');

  return createConfig({sourceMap: true}, host)
    .then(config => {
      t.is(config.output.sourceMap, true);
    });
});

test('createConfig should fallback to sourceMap of config', t => {
  const host = new HostMock({
    '/paeckchen.json': '{"output": {"sourceMap": true}}'
  }, '/');

  return createConfig({}, host)
    .then(config => {
      t.is(config.output.sourceMap, true);
    });
});

test('createConfig should prefer sourceMap of options (inline)', t => {
  const host = new HostMock({
    '/paeckchen.json': '{"output": {"sourceMap": true}}'
  }, '/');

  return createConfig({sourceMap: 'inline'}, host)
    .then(config => {
      t.is(config.output.sourceMap as string, 'inline');
    });
});

test('createConfig should prefer source level of options', t => {
  const host = new HostMock({
    '/paeckchen.json': '{"source": "es2015"}'
  }, '/');

  return createConfig({source: 'es5'}, host)
    .then(config => {
      t.is(config.input.source, SourceSpec.ES5);
    });
});

test('createConfig should throw on invalid source value', t => {<commit_msg>test(paeckchen-core): add missing test for source-map config (#171)<commit_after>import test from 'ava';

import { createConfig, Config, SourceSpec, Runtime, LogLevel } from '../src/config';
import { HostMock } from './helper';

test('createConfig should return the config defaults', t => {
  const host = new HostMock({
    '/paeckchen.json': '{}'
  }, '/');

  return createConfig({}, host)
    .then(config => {
      t.deepEqual(config, {
        input: {
          entryPoint: undefined,
          source: SourceSpec.ES2015,
        },
        output: {
          folder: host.cwd(),
          file: undefined,
          runtime: Runtime.browser,
          sourceMap: false
        },
        aliases: {},
        externals: {},
        watchMode: false,
        logLevel: LogLevel.default
      } as Config);
    });
});

test('createConfig should prefer entry point of options', t => {
  const host = new HostMock({
    '/paeckchen.json': '{"input": {"entry": "config"}}'
  }, '/');

  return createConfig({entryPoint: 'options'}, host)
    .then(config => {
      t.is(config.input.entryPoint, 'options');
    });
});

test('createConfig should fallback to entry point of config', t => {
  const host = new HostMock({
    '/paeckchen.json': '{"input": {"entry": "config"}}'
  }, '/');

  return createConfig({}, host)
    .then(config => {
      t.is(config.input.entryPoint, 'config');
    });
});

test('createConfig should prefer sourceMap of options', t => {
  const host = new HostMock({
    '/paeckchen.json': '{"output": {"sourceMap": false}}'
  }, '/');

  return createConfig({sourceMap: true}, host)
    .then(config => {
      t.is(config.output.sourceMap, true);
    });
});

test('createConfig should fallback to sourceMap of config', t => {
  const host = new HostMock({
    '/paeckchen.json': '{"output": {"sourceMap": true}}'
  }, '/');

  return createConfig({}, host)
    .then(config => {
      t.is(config.output.sourceMap, true);
    });
});

test('createConfig should prefer sourceMap of options (inline)', t => {
  const host = new HostMock({
    '/paeckchen.json': '{"output": {"sourceMap": true}}'
  }, '/');

  return createConfig({sourceMap: 'inline'}, host)
    .then(config => {
      t.is(config.output.sourceMap as string, 'inline');
    });
});

test('createConfig should allow sourceMap "true"', t => {
  const host = new HostMock({
    '/paeckchen.json': '{"output": {"sourceMap": "true"}}'
  }, '/');

  return createConfig({}, host)
    .then(config => {
      t.is(config.output.sourceMap, true);
    });
});

test('createConfig should allow sourceMap "false"', t => {
  const host = new HostMock({
    '/paeckchen.json': '{"output": {"sourceMap": "false"}}'
  }, '/');

  return createConfig({}, host)
    .then(config => {
      t.is(config.output.sourceMap, false);
    });
});

test('createConfig should fail on invalid sourceMap values', t => {
  const host = new HostMock({
    '/paeckchen.json': '{"output": {"sourceMap": "foo"}}'
  }, '/');

  return createConfig({}, host)
    .then(config => {
      t.fail('Expected exception');
    })
    .catch(e => {
      t.regex(e.message, /Invalid sourceMap/);
    });
});

test('createConfig should prefer source level of options', t => {
  const host = new HostMock({
    '/paeckchen.json': '{"source": "es2015"}'
  }, '/');

  return createConfig({source: 'es5'}, host)
    .then(config => {
      t.is(config.input.source, SourceSpec.ES5);
    });
});

test('createConfig should throw on invalid source value', t => {
{'fraction_non_alphanumeric': 0.19078083989501313, 'fraction_numerical': 0.003772965879265092, 'mean_word_length': 3.0111842105263156, 'pattern_counts': {'":': 28, '<': 3, '<?xml version=': 0, '>': 40, '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': '2639870', 'n_tokens_mistral': 1934, 'n_tokens_neox': 1887, 'n_words': 473}