diff --git a/test/ts_files/class.ts b/test/ts_files/class.ts new file mode 100644 index 0000000000..cad1efd5f6 --- /dev/null +++ b/test/ts_files/class.ts @@ -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() + } +} \ No newline at end of file diff --git a/test/ts_files/wrong_syntax1.1.ts b/test/ts_files/wrong_syntax1.1.ts new file mode 100644 index 0000000000..6fbe79a828 --- /dev/null +++ b/test/ts_files/wrong_syntax1.1.ts @@ -0,0 +1,5 @@ +// #!/usr/bin/fibjs env + +exp ort function add(a: number, b: number) { + return a + b +} diff --git a/test/ts_files/wrong_syntax1.2.ts b/test/ts_files/wrong_syntax1.2.ts new file mode 100644 index 0000000000..a3c6875eb4 --- /dev/null +++ b/test/ts_files/wrong_syntax1.2.ts @@ -0,0 +1,5 @@ +// #!/usr/bin/fibjs env + +export fun ction add(a: number, b: number) { + return a + b +} diff --git a/test/ts_files/wrong_syntax1.3.ts b/test/ts_files/wrong_syntax1.3.ts new file mode 100644 index 0000000000..5e60dae8ac --- /dev/null +++ b/test/ts_files/wrong_syntax1.3.ts @@ -0,0 +1,5 @@ +// #!/usr/bin/fibjs env + +export function ad d(a: number, b: number) { + return a + b +} diff --git a/test/ts_files/wrong_syntax1.4.ts b/test/ts_files/wrong_syntax1.4.ts new file mode 100644 index 0000000000..fc58b0fdd6 --- /dev/null +++ b/test/ts_files/wrong_syntax1.4.ts @@ -0,0 +1,9 @@ +// #!/usr/bin/fibjs env + +export function add(a: number, b: number) { + return a + b +} + +export function ht tp() { + return 'http' +} diff --git a/test/ts_files/wrong_syntax2.ts b/test/ts_files/wrong_syntax2.ts new file mode 100644 index 0000000000..2253b9d635 --- /dev/null +++ b/test/ts_files/wrong_syntax2.ts @@ -0,0 +1,9 @@ +// #!/usr/bin/fibjs env + +export function add(a: number, b: number) { + return a + b +} + +export function add() { + return 'psudo add' +} diff --git a/test/ts_test.js b/test/ts_test.js index bda76c3efe..4c84d8367e 100644 --- a/test/ts_test.js +++ b/test/ts_test.js @@ -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); diff --git a/test/ts_test.ts b/test/ts_test.ts index 6197c105df..62b01f551a 100644 --- a/test/ts_test.ts +++ b/test/ts_test.ts @@ -2,6 +2,7 @@ // / 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);