<commit_before>'use strict'

const test = require('tape')
const fs = require('fs')
const path = require('path')
const rimraf = require('rimraf')
const vm = require('vm')
const bundleify = require('./')

test('compressed', function (t) {
  t.plan(4)

  rimraf.sync('compressed')
  fs.mkdirSync('compressed')

  bundleify({
    entry: 'fixture.js',
    compress: true,
    destination: 'compressed',
    config: {
      foo: 'env-value'
    }
  }, function (err) {
    if (err) return t.end(err)

    const code = fs.readFileSync(path.resolve(__dirname, 'compressed/bundle.js'))
    const map = fs.readFileSync(path.resolve(__dirname, 'compressed/bundle.js.map'))

    t.doesNotThrow(function () {
      JSON.parse(map)
    }, 'writes json source map')

    const context = {}
    const result = vm.runInNewContext(code, context)
    const bundleRequire = context.require

    const app = bundleRequire('app')

    t.deepEqual(app, {
      env: 'env-value',
      undefinedEnv: undefined,
      value: 123
    }, 'exports entry as "app"')

    t.ok(String(code).includes('env:"env-value"'), 'compresses module code')
    t.ok(String(code).includes('undefinedEnv:void 0'), 'strips undefined env vars')

    rimraf.sync('compressed')
  })
})

test('uncompressed', function (t) {
  t.plan(4)

  rimraf.sync('uncompressed')
  fs.mkdirSync('uncompressed')

  bundleify({
    entry: 'fixture.js',
    compress: false,
    destination: 'uncompressed',
    config: {
      foo: 'env-value'
    }
  }, function (err) {
    if (err) return t.end(err)

    const code = fs.readFileSync(path.resolve(__dirname, 'uncompressed/bundle.js'))

    const context = {}
    const result = vm.runInNewContext(code, context)
    const bundleRequire = context.require<commit_msg>Remove undefined refs from tests<commit_after>'use strict'

const test = require('tape')
const fs = require('fs')
const path = require('path')
const rimraf = require('rimraf')
const vm = require('vm')
const bundleify = require('./')

test('compressed', function (t) {
  t.plan(4)

  rimraf.sync('compressed')
  fs.mkdirSync('compressed')

  bundleify({
    entry: 'fixture.js',
    compress: true,
    destination: 'compressed',
    config: {
      foo: 'env-value'
    }
  }, function (err) {
    if (err) return t.end(err)

    const code = fs.readFileSync(path.resolve(__dirname, 'compressed/bundle.js'))
    const map = fs.readFileSync(path.resolve(__dirname, 'compressed/bundle.js.map'))

    t.doesNotThrow(function () {
      JSON.parse(map)
    }, 'writes json source map')

    const context = {}
    vm.runInNewContext(code, context)
    const bundleRequire = context.require

    const app = bundleRequire('app')

    t.deepEqual(app, {
      env: 'env-value',
      undefinedEnv: undefined,
      value: 123
    }, 'exports entry as "app"')

    t.ok(String(code).includes('env:"env-value"'), 'compresses module code')
    t.ok(String(code).includes('undefinedEnv:void 0'), 'strips undefined env vars')

    rimraf.sync('compressed')
  })
})

test('uncompressed', function (t) {
  t.plan(4)

  rimraf.sync('uncompressed')
  fs.mkdirSync('uncompressed')

  bundleify({
    entry: 'fixture.js',
    compress: false,
    destination: 'uncompressed',
    config: {
      foo: 'env-value'
    }
  }, function (err) {
    if (err) return t.end(err)

    const code = fs.readFileSync(path.resolve(__dirname, 'uncompressed/bundle.js'))

    const context = {}
    vm.runInNewContext(code, context)
    const bundleRequire = context.require
{'fraction_non_alphanumeric': 0.154418072633686, 'fraction_numerical': 0.0034315127251930227, 'mean_word_length': 3.490372272143774, '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': '2686461', 'n_tokens_mistral': 1172, 'n_tokens_neox': 1133, 'n_words': 249}