test(include): 补充用例

This commit is contained in:
zhongguoxin 2017-11-07 20:48:49 +08:00
parent 40f976aaeb
commit 2c451f0473
2 changed files with 50 additions and 1 deletions

View File

@ -4,7 +4,7 @@
"description": "",
"main": "src/index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "tsc && mocha"
},
"repository": {
"url": "https://github.com/windwhinny/thrift-ts.git",
@ -16,8 +16,10 @@
"@types/chai": "^3.5.0",
"@types/mocha": "^2.2.40",
"@types/node": "^7.0.13",
"@types/sinon": "^2.3.7",
"chai": "^3.5.0",
"mocha": "^3.2.0",
"sinon": "^4.1.1",
"typescript": "^2.2.2"
},
"bin": {

47
test/BaseCompiler.test.ts Normal file
View File

@ -0,0 +1,47 @@
import BaseCompiler from '../src/BaseCompiler';
import * as sinon from 'sinon';
import * as chai from 'chai';
chai.should();
describe('src/BaseCompiler', () => {
let baseCompiler: BaseCompiler | null;
const stubs = sinon.stub;
beforeEach(() => {
baseCompiler = new BaseCompiler();
});
afterEach(() => {
baseCompiler = null;
});
it('writeInclude, should transfer include to import', () => {
type Include = {
[key: string]: { path: string}
};
const includes: Include = {
0: { path: 'test.thrift' },
1: { path: './test.thrift' },
2: { path: '/test/test.thrift' },
3: { path: './test/test.thrift' },
4: { path: '../test.thrift' },
5: { path: '../test/test.thrift' }
};
const result:string[] = [];
const expectResult = (key: string) => `import * as ${key} from './test_types';\n`;
if (baseCompiler) {
stubs(baseCompiler, 'write').callsFake(function(){
result.push(Array.prototype.join.call(arguments,''));
})
baseCompiler.writeInclude(includes);
for (let key in includes) {
result[Number(key)].should.eql(expectResult(key));
}
}
});
});