fix(build): support transpile to commonjs

This commit is contained in:
Tobias Bosch
2015-02-11 11:40:29 -08:00
parent fc1b791a7a
commit 013e1faf27
44 changed files with 189 additions and 112 deletions

View File

@ -1,4 +1,8 @@
var compiler = require('../index');
var temp = require('temp');
var fs = require('fs');
temp.track();
var DEFAULT_OPTIONS = {
sourceMaps: false,
@ -157,6 +161,34 @@ describe('transpile to es6', function() {
});
describe('transpile to cjs', function() {
var options;
beforeEach(function() {
options = merge(DEFAULT_OPTIONS, {modules: 'commonjs'});
});
function compileAndWrite(input) {
var transpiledCode = compiler.compile(options, "test.js", input).js;
var tempFile = temp.openSync('ng2transpiler');
fs.writeSync(tempFile.fd, transpiledCode);
return tempFile.path;
}
it('should transpile export *', function() {
var file1 = compileAndWrite('export var a = 1');
var file2 = compileAndWrite('export * from "' + file1 + '"');
expect(require(file2).a).toBe(1);
});
it('should transpile export {name}', function() {
var file1 = compileAndWrite('export var a = 1');
var file2 = compileAndWrite('export {a} from "' + file1 + '"');
expect(require(file2).a).toBe(1);
});
});
function merge(a, b) {
var result = {};