diff --git a/gulpfile.js b/gulpfile.js index c31a857..9b51cf7 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,5 +1,5 @@ // Mocha test example -require('gulp').task('mocha_tests', require('./index').createTask({ +require('gulp').task('mocha_tests', ['mocha_emitext_tests'], require('./index').createTask({ src: ['test/test1.js', 'test/test2.jsx', 'test/test3.coffee', 'test/test7.cjsx'], istanbul: { preserveComments: true, @@ -58,6 +58,16 @@ var GJCoptions = { } }; +gulp.task('mocha_emitext_tests', GJC.createTask(Object.assign({}, GJCoptions, { + src: ['test/test8.cjsx'], + transpile: { + cjsx: { + include: /\.cjsx$/, + omitExt: ['.cjsx'] + } + }, +}))); + gulp.task('jasmine_tests', function () { GJC.initModuleLoaderHack(GJCoptions); diff --git a/index.js b/index.js index 5f69559..a120992 100644 --- a/index.js +++ b/index.js @@ -102,7 +102,6 @@ var initModuleLoaderHack = function (options) { exclude: /^$/, omitExt: false }, options.transpile ? options.transpile.cjsx : undefined); - var moduleLoader = function (module, filename) { var srcCache = sourceStore.map[filename], src = srcCache || fs.readFileSync(filename, {encoding: 'utf8'}), @@ -176,6 +175,11 @@ var initModuleLoaderHack = function (options) { Module._extensions[V] = moduleLoader; }); } + if (cjsxFiles.omitExt) { + cjsxFiles.omitExt.forEach(function (V) { + Module._extensions[V] = moduleLoader; + }); + } }; var stackDumper = function (stack) { diff --git a/test/test8.cjsx b/test/test8.cjsx new file mode 100644 index 0000000..d196483 --- /dev/null +++ b/test/test8.cjsx @@ -0,0 +1,10 @@ +mocha = require 'mocha' +assert = require 'assert' +Component = require './Component' +testlib = require './testlib' +ReactDOM = require 'react-dom' + +mocha.describe 'Component.cjsx (tested by test7.cjsx)', -> + mocha.it 'should render Hello World', -> + node = testlib.renderComponent(Component) + assert.equal('Hello World', ReactDOM.findDOMNode(node).innerHTML)