<commit_before>import assert from 'assert';
import rollup from 'rollup';
import commonjs from 'rollup-plugin-commonjs';
import coffeePlugin from '..';
import coffee from 'coffee-script';
import fs from 'fs';

process.chdir(__dirname);

describe('rollup-plugin-coffeescript', function() {
  this.timeout(5000);

  it('runs code through coffeescript', () => {
    const entry = 'sample/basic/main.coffee';
    const source = fs.readFileSync(entry).toString();

    return rollup.rollup({
      entry: entry,
      plugins: [coffeePlugin()]
    }).then(function(bundle) {
      const generated = bundle.generate();
      const coffeeOutput = coffee.compile(source, { bare: true });
      assert.equal(generated.code.trim(), coffeeOutput.trim());
    });
  });

  it('only runs code with defined extensions through coffee script', () => {
    const entry = 'sample/invalid-coffee.js';
    const source = fs.readFileSync(entry).toString();

    return rollup.rollup({
      entry: entry,
      plugins: [coffeePlugin()]
    }).then(function(bundle) {
      const generated = bundle.generate();
      assert.ok(generated.code.indexOf('answer = 42') !== -1);
    });
  });

  it('works with requires when used with commonjs plugin', () => {
    const entry = 'sample/import-class/main.coffee';
    const source = fs.readFileSync(entry).toString();

    return rollup.rollup({
      entry: entry,
      plugins: [coffeePlugin(), commonjs({ extensions: ['.coffee']})]
    }).then(function(bundle) {
      const generated = bundle.generate();
      const code = generated.code;
      assert.ok(code.indexOf('class') === -1, code);
      assert.ok(code.indexOf('var A = __commonjs(') !== -1, code);
    });
  });

  it('allows overriding default options', () => {
    const entry = 'sample/litcoffee/example.coffee.md';
    const source = fs.readFileSync(entry).toString();

    return rollup.rollup({
      entry: entry,
      plugins: [coffeePlugin({ extensions: ['.md' ], literate: true })]
    }).then(function(bundle) {
      const generated = bundle.generate();
      const code = generated.code;
      assert.ok(generated.code.indexOf('answer = 42') !== -1);
    });
  });

  it('compiles .litcoffee', () => {
    const entry = 'sample/litcoffee/main.litcoffee';
    const source = fs.readFileSync(entry).toString();

    return rollup.rollup({
      entry: entry,
      plugins: [coffeePlugin({})]
    }).then(function(bundle) {
      const generated = bundle.generate();
      const code = generated.code;
      assert.ok(generated.code.indexOf('answer = 42') !== -1);
    });
  });
});<commit_msg>Don’t read source file when not needed in tests<commit_after>import assert from 'assert';
import rollup from 'rollup';
import commonjs from 'rollup-plugin-commonjs';
import coffeePlugin from '..';
import coffee from 'coffee-script';
import fs from 'fs';

process.chdir(__dirname);

describe('rollup-plugin-coffeescript', function() {
  this.timeout(5000);

  it('runs code through coffeescript', () => {
    const entry = 'sample/basic/main.coffee';
    const source = fs.readFileSync(entry).toString();

    return rollup.rollup({
      entry: entry,
      plugins: [coffeePlugin()]
    }).then(function(bundle) {
      const generated = bundle.generate();
      const coffeeOutput = coffee.compile(source, { bare: true });
      assert.equal(generated.code.trim(), coffeeOutput.trim());
    });
  });

  it('only runs code with defined extensions through coffee script', () => {
    const entry = 'sample/invalid-coffee.js';

    return rollup.rollup({
      entry: entry,
      plugins: [coffeePlugin()]
    }).then(function(bundle) {
      const generated = bundle.generate();
      assert.ok(generated.code.indexOf('answer = 42') !== -1);
    });
  });

  it('works with requires when used with commonjs plugin', () => {
    const entry = 'sample/import-class/main.coffee';

    return rollup.rollup({
      entry: entry,
      plugins: [coffeePlugin(), commonjs({ extensions: ['.coffee']})]
    }).then(function(bundle) {
      const generated = bundle.generate();
      const code = generated.code;
      assert.ok(code.indexOf('class') === -1, code);
      assert.ok(code.indexOf('var A = __commonjs(') !== -1, code);
    });
  });

  it('allows overriding default options', () => {
    const entry = 'sample/litcoffee/example.coffee.md';

    return rollup.rollup({
      entry: entry,
      plugins: [coffeePlugin({ extensions: ['.md' ], literate: true })]
    }).then(function(bundle) {
      const generated = bundle.generate();
      const code = generated.code;
      assert.ok(generated.code.indexOf('answer = 42') !== -1);
    });
  });

  it('compiles .litcoffee', () => {
    const entry = 'sample/litcoffee/main.litcoffee';

    return rollup.rollup({
      entry: entry,
      plugins: [coffeePlugin({})]
    }).then(function(bundle) {
      const generated = bundle.generate();
      const code = generated.code;
      assert.ok(generated.code.indexOf('answer = 42') !== -1);
    });
  });
});
{'fraction_non_alphanumeric': 0.16826347305389222, 'fraction_numerical': 0.005988023952095809, 'mean_word_length': 3.2719522591645354, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '1297933', 'n_tokens_mistral': 1561, 'n_tokens_neox': 1490, 'n_words': 344}