Permalink
Browse files

sandbox, feat: add test cases for internal typescript. (#424)

  • Loading branch information...
richardo2016 authored and xicilion committed Jun 5, 2018
1 parent 50555be commit 29e3901637f42bc489083a0ab8f674b5ea22b66a
View
@@ -0,0 +1,15 @@
import { add, hello } from './basic'
export default class Foo {
static bar = 1;
static bar2 = 'bar';
foo1(...args) {
return add(...args)
}
foo2() {
return hello()
}
}
@@ -0,0 +1,5 @@
// #!/usr/bin/fibjs env
exp ort function add(a: number, b: number) {
return a + b
}
@@ -0,0 +1,5 @@
// #!/usr/bin/fibjs env
export fun ction add(a: number, b: number) {
return a + b
}
@@ -0,0 +1,5 @@
// #!/usr/bin/fibjs env
export function ad d(a: number, b: number) {
return a + b
}
@@ -0,0 +1,9 @@
// #!/usr/bin/fibjs env
export function add(a: number, b: number) {
return a + b
}
export function ht tp() {
return 'http'
}
@@ -0,0 +1,9 @@
// #!/usr/bin/fibjs env
export function add(a: number, b: number) {
return a + b
}
export function add() {
return 'psudo add'
}
View
@@ -46,7 +46,10 @@ describe('typescript', () => {
export function hello () {
return 'hello, world'
}
`, _getOptions())
`, _getOptions({
inlineSourceMap: true,
alwaysStrict: true
}))
assert.isString(compiledJScript)
const sbox = new vm.SandBox({})
@@ -62,7 +65,7 @@ describe('typescript', () => {
assertBasicModule(basic)
})
it('sandbox increasing test', () => {
it('increasing/parallel sandbox', () => {
const iterbase = Array(5).fill(undefined);
function testBody() {
@@ -76,6 +79,39 @@ describe('typescript', () => {
iterbase.forEach(() => testBody());
coroutine.parallel(iterbase, () => testBody());
})
it('wrong syntax', () => {
assert.throws(() => {
const wrongSynTaxt = require('./ts_files/wrong_syntax1.1');
})
assert.throws(() => {
const wrongSynTaxt = require('./ts_files/wrong_syntax1.2');
})
assert.throws(() => {
const wrongSynTaxt = require('./ts_files/wrong_syntax1.3');
})
assert.throws(() => {
const wrongSynTaxt = require('./ts_files/wrong_syntax1.4');
})
const wrongSynTaxt2 = require('./ts_files/wrong_syntax2');
assert.isFunction(wrongSynTaxt2.add)
assert.equal(Object.keys(wrongSynTaxt2).length, 1)
assert.equal(wrongSynTaxt2.add(), 'psudo add')
})
it('class', () => {
const _class = require('./ts_files/class').default
const basic = require('./ts_files/basic')
assert.exist(_class.bar);
assert.exist(_class.bar2);
const ins = new _class()
assert.exist(ins);
assert.equal(ins.foo1(1, 2), basic.add(1, 2))
assert.equal(ins.foo2(), basic.hello())
})
});
require.main === module && test.run(console.DEBUG);
View
@@ -2,6 +2,7 @@
// / <reference path="fib-types/declare/_test_env.d.ts" />
import * as test from "test";
import _class from './ts_files/class';
test.setup();
describe('typescript', () => {
@@ -22,6 +23,25 @@ describe('typescript', () => {
const basic = require('./ts_files/basic')
assertBasicModule(basic)
})
it('class', () => {
const basic = require('./ts_files/basic')
assert.throws(() => {
// not exist
const _classModule = require('./ts_files/_class')
})
const _classModule = require('./ts_files/class')
assert.exist(_class, _classModule.default)
assert.exist(_class.bar);
assert.exist(_class.bar2);
const ins = new _class()
assert.exist(ins);
assert.equal(ins.foo1(1, 2), basic.add(1, 2))
assert.equal(ins.foo2(), basic.hello())
})
});
require.main === module && test.run(console.DEBUG);

0 comments on commit 29e3901

Please sign in to comment.