Skip to content

Commit

Permalink
feat: test cube-babel
Browse files Browse the repository at this point in the history
  • Loading branch information
fishbar committed Oct 1, 2017
1 parent 33638a7 commit 0b606a2
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 9 deletions.
3 changes: 2 additions & 1 deletion example/empty_processor.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
'use strict';

class EmptyProcessor {
constructor(cube) {
constructor(cube, config) {
this.cube = cube;
this.config = config;
}
process(data, callback) {
callback(null, data);
Expand Down
9 changes: 9 additions & 0 deletions example/es6.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
'use strict';

class A {
constructor(name) {
this.name = name;
}
}

export default A;
10 changes: 9 additions & 1 deletion example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,15 @@
".coffee": "cube-coffee",
".ejs": "cube-ejs",
".jade": "cube-jade",
".styl": "cube-stylus"
".styl": "cube-stylus",
".js": [
[
"cube-babel",
{
"presets": [["es2015"]]
}
]
]
},
"ignoreRules": {
"skip":[],
Expand Down
4 changes: 2 additions & 2 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ exports.fixProcessorPath = function (processors, root, noRelative) {
if (noRelative) {
return;
}
return a[i] = path.join(root, v[0]);
return v[0] = path.join(root, v[0]);
}

let modPath;
Expand Down Expand Up @@ -378,7 +378,7 @@ exports.fixProcessorPath = function (processors, root, noRelative) {
console.error('[CUBE_ERROR] processor not find, please install the module `' + v[0] + '`');
process.exit(1);
}
a[i] = modPath;
v[0] = modPath;
});
return processors;
};
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"author": "fish <[email protected]> (https://github.com/fishbar)",
"name": "node-cube",
"description": "a new way to write js in browser",
"version": "3.0.0-beta.11",
"version": "3.0.0-beta.12",
"homepage": "https://github.com/fishbar/cube",
"repository": {
"type": "git",
Expand Down Expand Up @@ -39,6 +39,7 @@
"cube-coffee": "*",
"cube-ejs": "*",
"cube-es2015": "*",
"cube-babel": "*",
"cube-jade": "*",
"cube-less": "*",
"cube-react": "*",
Expand All @@ -48,7 +49,8 @@
"jsdom": "6.2.0",
"minami": "^1.1.1",
"mocha": "3.2.0",
"supertest": "3.0.0"
"supertest": "3.0.0",
"babel-preset-es2015": "*"
},
"optionalDependencies": {}
}
4 changes: 2 additions & 2 deletions service.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,13 +243,13 @@ function createMiddleware(cube, serveStatic, checkSkip) {
res.setHeader('content-type', flagWrap ? 'text/javascript' : mime);
var msg = flagWrap ?
'console.error("[CUBE]",' +
(e.code ? '"'+ e.code.replace(/"/g, '\\"') + ': ' + e.message.replace(/"/g, '\\"') + '",' : '') +
(e.code ? '"'+ e.code.replace(/"/g, '\\"') + ': ' + e.message.replace(/"/g, '\\"') + '",' : e.message.replace(/"/g, '\\"')) +
(e.file ? '"[File]: ' + e.file + '",' : '') +
(e.line ? '"[Line]: ' + e.line + '",' : '') +
(e.column ? '"[Column]: ' + e.column + '"' : '') +
');' :
'[CUBE]\n' +
(e.code ? e.code + ': ' + e.message + '\n' : '') +
(e.code ? e.code + ': ' + e.message + '\n' : e.message) +
(e.file ? 'File: ' + e.file + '\n' : '') +
(e.line ? 'Line: ' + e.line + '\n' : '') +
(e.column ? 'Column: ' + e.column + '\n' : '');
Expand Down
9 changes: 8 additions & 1 deletion test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,13 @@ describe('index.js', function () {
.expect(/^Cube\(/, done);
});

it('should work fine with babel transfer', function (done) {
request.get('/es6.js?m')
.expect(200)
.expect('content-type', /application\/javascript/)
.expect(/^Cube\(/, done);
});

it('should work fine when require override', function (done) {
remoteRequest.get('/test/test_override.js?m')
.expect(200)
Expand Down Expand Up @@ -241,7 +248,7 @@ describe('index.js', function () {
request.get('/test/test_error.js?m')
.expect(200)
.expect(function (res) {
expect(res.text).match(/Js_Parse_Error/ig);
expect(res.text).match(/Unexpected token/ig);
})
.end(done);
});
Expand Down

0 comments on commit 0b606a2

Please sign in to comment.