Sha256: feb7f36fec7d16df0d625496ebc91d9ab519013786353f39d2d12ec8c275ad2c

Contents?: true

Size: 929 Bytes

Versions: 1

Compression:

Stored size: 929 Bytes

Contents

require 'test/unit'
require 'tempfile'
require 'sprockets-cjs'

class SprocketsCJSTest < Test::Unit::TestCase

  TEST_DIR = File.expand_path('..', __FILE__)
  LIB_DIR  = File.expand_path('../lib/assets/javascripts', TEST_DIR)

  attr_reader :output

  def setup
    env = Sprockets::Environment.new
    env.register_postprocessor 'application/javascript', Sprockets::CJS
    env.append_path TEST_DIR
    env.append_path LIB_DIR
    outfile = Tempfile.new('sprockets-output')
    env['source.js'].write_to outfile.path
    @output = File.read outfile.path
  end

  def test_adds_commonjs_require
    assert_match %r[var require = function\(name, root\) {], @output
  end

  def test_modularizes_modules
    assert_match %r[require.define\({"foo":function], @output
    assert_match %r["Foo!"], @output
  end

  def test_does_not_modularize_non_modules
    assert_no_match %r[require.define\({\"bar\":function], @output
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sprockets-cjs-0.2.1 test/sprockets_cjs_test.rb