mirror of
https://github.com/rails/execjs
synced 2023-03-27 23:21:20 -04:00
Add smoke tests for parsing babel and uglify
This commit is contained in:
parent
e20941f927
commit
603a1b824c
3 changed files with 46200 additions and 0 deletions
43557
test/fixtures/babel.js
vendored
Normal file
43557
test/fixtures/babel.js
vendored
Normal file
File diff suppressed because one or more lines are too long
2613
test/fixtures/uglify.js
vendored
Normal file
2613
test/fixtures/uglify.js
vendored
Normal file
File diff suppressed because one or more lines are too long
|
@ -288,9 +288,39 @@ class TestExecJS < Test
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_babel
|
||||||
|
assert source = File.read(File.expand_path("../fixtures/babel.js", __FILE__))
|
||||||
|
source = <<-JS
|
||||||
|
var self = this;
|
||||||
|
#{source}
|
||||||
|
babel.eval = function(code) {
|
||||||
|
return eval(babel.transform(code)["code"]);
|
||||||
|
}
|
||||||
|
JS
|
||||||
|
context = ExecJS.compile(source)
|
||||||
|
assert_equal 64, context.call("babel.eval", "((x) => x * x)(8)")
|
||||||
|
end
|
||||||
|
|
||||||
def test_coffeescript
|
def test_coffeescript
|
||||||
assert source = File.read(File.expand_path("../fixtures/coffee-script.js", __FILE__))
|
assert source = File.read(File.expand_path("../fixtures/coffee-script.js", __FILE__))
|
||||||
context = ExecJS.compile(source)
|
context = ExecJS.compile(source)
|
||||||
assert_equal 64, context.call("CoffeeScript.eval", "((x) -> x * x)(8)")
|
assert_equal 64, context.call("CoffeeScript.eval", "((x) -> x * x)(8)")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_uglify
|
||||||
|
assert source = File.read(File.expand_path("../fixtures/uglify.js", __FILE__))
|
||||||
|
source = <<-JS
|
||||||
|
#{source}
|
||||||
|
|
||||||
|
function uglify(source) {
|
||||||
|
var ast = UglifyJS.parse(source);
|
||||||
|
var stream = UglifyJS.OutputStream();
|
||||||
|
ast.print(stream);
|
||||||
|
return stream.toString();
|
||||||
|
}
|
||||||
|
JS
|
||||||
|
context = ExecJS.compile(source)
|
||||||
|
assert_equal "function foo(bar){return bar}",
|
||||||
|
context.call("uglify", "function foo(bar) {\n return bar;\n}")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue