Skip to content

Commit

Permalink
add test for .cjsx omitExt issue and fix #20
Browse files Browse the repository at this point in the history
  • Loading branch information
Zordius Chen committed Jan 12, 2016
1 parent 2db59a3 commit 3ad90ca
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
12 changes: 11 additions & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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);

Expand Down
6 changes: 5 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'}),
Expand Down Expand Up @@ -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) {
Expand Down
10 changes: 10 additions & 0 deletions test/test8.cjsx
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 3ad90ca

Please sign in to comment.