UNPKG

3.36 kBJavaScriptView Raw
1const fs = require('fs')
2const path = require('path')
3const { expect } = require('chai')
4const typeConverter = require('./type-converter')
5
6const src = fs.readFileSync(path.join(__dirname, '../fixtures/typescript/entity.ts'), 'utf-8')
7
8const interface1 = require('../fixtures/typescript/interface1')
9const interface2 = require('../fixtures/typescript/interface2')
10const interface3 = require('../fixtures/typescript/interface3')
11
12const type1 = require('../fixtures/typescript/type1')
13const type2 = require('../fixtures/typescript/type2')
14const type3 = require('../fixtures/typescript/type3')
15const type4 = require('../fixtures/typescript/type4')
16const type5 = require('../fixtures/typescript/type5')
17const type6 = require('../fixtures/typescript/type6')
18const type7 = require('../fixtures/typescript/type7')
19const staticMember = require('../fixtures/typescript/static-member')
20const protectedMember = require('../fixtures/typescript/protected-member')
21
22describe('.typeConverter', function () {
23 describe('@typedef', function () {
24 it('parses type 1', function () {
25 type1.outputs.forEach(out => {
26 expect(typeConverter(type1.input)).to.have.string(out)
27 })
28 })
29
30 it('parses type 2: [key]: string', function () {
31 type2.outputs.forEach(out => {
32 expect(typeConverter(type2.input)).to.have.string(out)
33 })
34 })
35
36 it('parses type 3: Array<{key: string}>', function () {
37 type3.outputs.forEach(out => {
38 expect(typeConverter(type3.input)).to.have.string(out)
39 })
40 })
41
42 it('parses type 4: inline function', function () {
43 type4.outputs.forEach(out => {
44 expect(typeConverter(type4.input)).to.have.string(out)
45 })
46 })
47
48 it('parses type 5: one line comment', function () {
49 type5.outputs.forEach(out => {
50 expect(typeConverter(type5.input)).to.have.string(out)
51 })
52 })
53
54 it('parses type 6: joined by && types', function () {
55 type6.outputs.forEach(out => {
56 expect(typeConverter(type6.input)).to.have.string(out)
57 })
58 })
59
60 it('parses type 7: object types', function () {
61 type7.outputs.forEach(out => {
62 expect(typeConverter(type7.input)).to.have.string(out)
63 })
64 })
65 })
66
67 describe('@interface', function () {
68 it('parses interface 1', function () {
69 interface1.outputs.forEach(out => {
70 expect(typeConverter(interface1.input)).to.have.string(out)
71 })
72 })
73
74 it('parses interface 2 - with nested array defined as []', function () {
75 interface2.outputs.forEach(out => {
76 expect(typeConverter(interface2.input)).to.have.string(out)
77 })
78 })
79
80 it('parses interface 3 - with methods', function () {
81 interface3.outputs.forEach(out => {
82 expect(typeConverter(interface3.input)).to.have.string(out)
83 })
84 })
85 })
86
87 describe('class members', function () {
88 it('parses static member', function () {
89 staticMember.outputs.forEach(out => {
90 expect(typeConverter(staticMember.input)).to.have.string(out)
91 })
92 })
93
94 it('parses protected', function () {
95 protectedMember.outputs.forEach(out => {
96 expect(typeConverter(protectedMember.input)).to.have.string(out)
97 })
98 })
99 })
100
101
102 // it.only('parses test', function() {
103 // console.log(typeConverter(src, '../fixtures/interface.ts'))
104 // })
105})
\No newline at end of file