Update tests and doc for filters

This commit is contained in:
Alessandro Molina 2016-09-25 10:37:32 +02:00
parent 611dccc697
commit 07feda5a3c
2 changed files with 24 additions and 20 deletions

View File

@ -121,12 +121,13 @@ compile ES6 code in your assets pipeline. You register this filter as
register_filter(BabelJS)
Which makes the filter available with the ``babeljs`` name.
Only supported filter option is currently `BABEL_MODULES_LOADER = 'systemjs'` to
specify that compiled code should use SystemJS instead of CommonJS for modules.
Only supported filter option is currently `BABEL_MODULES_LOADER` with value
``systemjs`` or ``umd`` to specify that compiled code should use SystemJS
or UMD instead of CommonJS for modules.
**NOTE:** When using the BabelJS compiler for code that needs to run
in the browser, make sure to add
https://cdnjs.cloudflare.com/ajax/libs/babel-polyfill/6.6.1/polyfill.min.js
https://cdnjs.cloudflare.com/ajax/libs/babel-polyfill/6.13.0/polyfill.min.js
dependency.
JSX to React Transpiling

View File

@ -10,9 +10,15 @@ except:
from StringIO import StringIO
class TestAssetsFilters(object):
class TestAssetsFilters(TempEnvironmentHelper):
@classmethod
def setup_class(cls):
from webassets.filter import register_filter
register_filter(BabelJS)
register_filter(TypeScript)
def test_babeljs_filter(self):
es6source = StringIO('''
ES6CODE = '''
class Point {
constructor(x, y) {
this.x = x;
@ -22,20 +28,17 @@ class Point {
return '(' + this.x + ', ' + this.y + ')';
}
}
''')
out = StringIO()
BabelJS().input(es6source, out)
out.seek(0)
ans = out.read()
'''
self.create_files({'in': ES6CODE})
self.mkbundle('in', filters='babeljs', output='out').build()
ans = self.get('out')
assert '''var Point = function () {
function Point(x, y) {
''' in ans, ans
def test_typescript_filter(self):
typeScript_source = StringIO('''
typeScript_source = '''
class Greeter {
constructor(public greeting: string) { }
greet() {
@ -43,13 +46,12 @@ class Greeter {
}
};
var greeter = new Greeter("Hello, world!");
''')
out = StringIO()
TypeScript().input(typeScript_source, out)
out.seek(0)
ans = out.read()
'''
self.create_files({'in': typeScript_source})
self.mkbundle('in', filters='typescript', output='out').build()
ans = self.get('out')
expected = """System.register([], function(exports_1) {
var Greeter, greeter;
return {
@ -110,6 +112,7 @@ class TestLessFilter(TempEnvironmentHelper):
}
"""
class TestJSXFilter(TempEnvironmentHelper):
JSX_CODE = '''
import Component from 'react';