<commit_before>'use strict';

var Path = require('path');
var expect = require('unexpected').clone();
var tolk = require('../lib/baby-tolk');

function getPath(path) {
  return Path.join(process.cwd(), 'fixtures/source', path);
}

describe('readCompiled', function () {
  it('should read a file directly if there is no adapter', function () {
    return expect(tolk.read(getPath('unchanged.txt')), 'to be fulfilled with', {
      result: 'I am the same\n'
    });
  });

  it('should throw when reading a file that does not exist', function () {
    return expect(tolk.read(getPath('does-not-exist.txt')), 'when rejected', 'to satisfy', {
      code: 'ENOENT',
      path: /fixtures\/source\/does-not-exist\.txt$/,
      message: /^ENOENT.*?, open '.+?fixtures\/source\/does-not-exist\.txt'$/
    });
  });

  it('should compile a file if there is an adapter', function () {
    return expect(tolk.read(getPath('babel/simplest.jsx')), 'to be fulfilled with', {
      result: expect.it('to begin with', '\'use strict\';\n\nvar foo = \'bar\';'),
      extension: expect.it('to be', '.js'),
    });
  });

  it('should output source map if there is an adapter that supports source maps', function () {
    return expect(tolk.read(getPath('less/external.less')), 'to be fulfilled with', {
      sourcemap: {
        sources: expect.it('to have length', 2),
        mappings: expect.it('to begin with', 'AAAA;EACE,')
      }
    });
  });

  it('should support CSS minification (with compilation)', function () {
    return expect(tolk.read(getPath('less/external.less'), {minify: true}), 'to be fulfilled with', {
      result: expect.it('to begin with', '.bar{wow:\'foo\'}'),
      sourcemap: {
        sources: expect.it('to have length', 2),
        mappings: expect.it('to begin with', 'AAAA,KACE,')
      }
    });
  });

  it('should support CSS minification (without compilation)', function () {
    return expect(tolk.read(getPath('csso/basic.css'), {minify: true}), 'to be fulfilled with', {<commit_msg>Add a coffeescript test because it seems to be acting weird downstream in baconize<commit_after>'use strict';

var Path = require('path');
var expect = require('unexpected').clone();
var tolk = require('../lib/baby-tolk');

function getPath(path) {
  return Path.join(process.cwd(), 'fixtures/source', path);
}

describe('readCompiled', function () {
  it('should read a file directly if there is no adapter', function () {
    return expect(tolk.read(getPath('unchanged.txt')), 'to be fulfilled with', {
      result: 'I am the same\n'
    });
  });

  it('should throw when reading a file that does not exist', function () {
    return expect(tolk.read(getPath('does-not-exist.txt')), 'when rejected', 'to satisfy', {
      code: 'ENOENT',
      path: /fixtures\/source\/does-not-exist\.txt$/,
      message: /^ENOENT.*?, open '.+?fixtures\/source\/does-not-exist\.txt'$/
    });
  });

  it('should compile a file if there is an adapter', function () {
    return expect(tolk.read(getPath('babel/simplest.jsx')), 'to be fulfilled with', {
      result: expect.it('to begin with', '\'use strict\';\n\nvar foo = \'bar\';'),
      extension: expect.it('to be', '.js'),
    });
  });

  it('should output source map if there is an adapter that supports source maps', function () {
    return expect(tolk.read(getPath('less/external.less')), 'to be fulfilled with', {
      sourcemap: {
        sources: expect.it('to have length', 2),
        mappings: expect.it('to begin with', 'AAAA;EACE,')
      }
    });
  });

  it('should output source map if there is an adapter that supports source maps', function () {
    return expect(tolk.read(getPath('coffee/basic.coffee')), 'to be fulfilled with', {
      sourcemap: {
        sources: expect.it('to have length', 1),
        mappings: expect.it('to begin with', 'AAAA;EAAA,'),
        file: expect.it('to be', 'basic.js')
      }
    });
  });

  it('should support CSS minification (with compilation)', function () {
    return expect(tolk.read(getPath('less/external.less'), {minify: true}), 'to be fulfilled with', {
      result: expect.it('to begin with', '.bar{wow:\'foo\'}'),
      sourcemap: {
        sources: expect.it('to have length', 2),
        mappings: expect.it('to begin with', 'AAAA,KACE,')
      }
    });
  });

  it('should support CSS minification (without compilation)', function () {
    return expect(tolk.read(getPath('csso/basic.css'), {minify: true}), 'to be fulfilled with', {
{'fraction_non_alphanumeric': 0.17988351254480286, 'fraction_numerical': 0.0011200716845878136, 'mean_word_length': 3.403353057199211, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1772366', 'n_tokens_mistral': 1424, 'n_tokens_neox': 1376, 'n_words': 390}