diff --git a/Makefile b/Makefile index 6d8b3d514..9b392c133 100644 --- a/Makefile +++ b/Makefile @@ -118,6 +118,10 @@ test/features: bin/traceur.js bin/traceur-runtime.js $(FEATURE_TESTS) test/%-run: test/% bin/traceur.js node_modules/.bin/mocha $(MOCHA_OPTIONS) $< +test/mocha: bin/traceur.js + node_modules/.bin/mocha $(MOCHA_OPTIONS) \ + --compilers js:test/cjs-mocha-compiler.js --reporter dot test/feature/** + test/commonjs: test/commonjs-compiled node_modules/.bin/mocha $(MOCHA_OPTIONS) test/node-commonjs-test.js diff --git a/test/cjs-mocha-compiler.js b/test/cjs-mocha-compiler.js new file mode 100644 index 000000000..470c55fd0 --- /dev/null +++ b/test/cjs-mocha-compiler.js @@ -0,0 +1,43 @@ +'use strict'; + +var fs = require('fs'); +var traceurAPI = require('../src/node/api.js'); + +var org = require.extensions['.js']; +require.extensions['.js'] = function(module, path) { + if (!/\/node_modules\//.test(path)) { + var content = fs.readFileSync(path, 'utf8'); + if (shouldSkip(path, content)) { + return; + } + + var compiled = traceurAPI.compile(content, { + modules: 'commonjs', + importRuntime: true, + }, path, path); + + + if (needsWrapper(path)) { + var header = 'var assert = require("chai").assert, test = require("mocha").test;' + 'test("' + path + '", function(){'; + var footer = '});'; + compiled = header + compiled + footer; + } + + try { + return module._compile(compiled, path); + } catch (ex) { + console.log(compiled, path); + throw ex; + } + } + return org(module, path); +}; + +function needsWrapper(path) { + return /\/test\/feature\//.test(path) && !/\/resources\//.test(path); +} + +function shouldSkip(path, content) { + return /\/\/ (Error:|Options:|Skip.|Async.)/.test(content) || + /\.script\.js$/.test(path); +} diff --git a/test/feature/Modules/ImportDefault.js b/test/feature/Modules/ImportDefault.js index 2dfc7591c..fc3ad5f8d 100644 --- a/test/feature/Modules/ImportDefault.js +++ b/test/feature/Modules/ImportDefault.js @@ -1,3 +1,5 @@ +import {assert} from '../../asserts.js'; + import x from './resources/default.js'; assert.equal(x, 42); diff --git a/test/feature/Modules/resources/default-class.js b/test/feature/Modules/resources/default-class.js index 8c1e65c3b..ac5b10462 100644 --- a/test/feature/Modules/resources/default-class.js +++ b/test/feature/Modules/resources/default-class.js @@ -1,3 +1,5 @@ +import {assert} from '../../../asserts.js'; + export default class C { m() { return 'm'; diff --git a/test/feature/Modules/resources/default-function.js b/test/feature/Modules/resources/default-function.js index 352283809..267326281 100644 --- a/test/feature/Modules/resources/default-function.js +++ b/test/feature/Modules/resources/default-function.js @@ -1,3 +1,5 @@ +import {assert} from '../../../asserts.js'; + export default function f() { return 123; } diff --git a/test/feature/Syntax/NoNewLineHereEndOfFile.js b/test/feature/Syntax/NoNewLineHereEndOfFile.script.js similarity index 100% rename from test/feature/Syntax/NoNewLineHereEndOfFile.js rename to test/feature/Syntax/NoNewLineHereEndOfFile.script.js diff --git a/test/feature/TemplateLiterals/resources/m.js b/test/feature/TemplateLiterals/resources/m.js index 364751373..6ddd907d3 100644 --- a/test/feature/TemplateLiterals/resources/m.js +++ b/test/feature/TemplateLiterals/resources/m.js @@ -1,3 +1,5 @@ + +import {assert} from '../../../asserts.js'; import {f} from './f.js'; assert.equal('a', (f `a`)[0][0]); diff --git a/test/feature/TemplateLiterals/resources/n.js b/test/feature/TemplateLiterals/resources/n.js index 108fed14b..b9896e1f4 100644 --- a/test/feature/TemplateLiterals/resources/n.js +++ b/test/feature/TemplateLiterals/resources/n.js @@ -1,3 +1,4 @@ +import {assert} from '../../../asserts.js'; import {f} from './f.js'; assert.equal('b', (f `b`)[0][0]);