1 | import { GQLBase, ModuleParser } from '../es6/lattice'
|
2 | import { SchemaUtils } from '../es6/SchemaUtils'
|
3 |
|
4 | import { YabbaDabbaDo } from './samples/YabbaDabbaDo'
|
5 | import { Yarp } from './samples/Yarp'
|
6 |
|
7 | import path from 'path'
|
8 | import fs from 'fs'
|
9 |
|
10 | let base = path.resolve('.');
|
11 |
|
12 |
|
13 | if (
|
14 | !fs.existsSync(path.join(base, 'samples'))
|
15 | && fs.existsSync(path.join(base, 'test', 'samples'))
|
16 | ) {
|
17 | base = path.resolve(path.join(base, 'test'))
|
18 | }
|
19 |
|
20 |
|
21 | base = path.join(base, 'samples');
|
22 |
|
23 | describe('ModuleParser Tests', () => {
|
24 | it('should be valid when parsing a relative directory', () => {
|
25 | expect(new ModuleParser('.').valid).toBe(true)
|
26 | expect(new ModuleParser('..').valid).toBe(true)
|
27 | })
|
28 |
|
29 | it('should be a valid directory', () => {
|
30 | let stats = fs.statSync(base)
|
31 |
|
32 | expect(stats).not.toBe(null)
|
33 | expect(stats.isDirectory()).toBe(true)
|
34 | })
|
35 |
|
36 | it('should be able to find two files', () => {
|
37 | expect(ModuleParser.walkSync(base).length).toBe(2)
|
38 | })
|
39 |
|
40 | it('should be able to find two files asynchronously', async () => {
|
41 | expect(async () => {
|
42 | let files = await ModuleParser.walk(base)
|
43 |
|
44 | expect(files.length).toBe(2)
|
45 | }).not.toThrow()
|
46 | })
|
47 |
|
48 | it('should be able to identify the two parsed files by name', () => {
|
49 | let parser = new ModuleParser(base)
|
50 | let classes
|
51 |
|
52 | expect(parser.valid).toBe(true)
|
53 | expect(() => {
|
54 | parser.parseSync();
|
55 | }).not.toThrow();
|
56 |
|
57 | classes = parser.classes.map(Class => Class.name && Class.name : null)
|
58 | classes = classes.filter(Class => !!Class)
|
59 | expect(classes).toEqual(expect.arrayContaining([
|
60 | 'Yarp', 'YabbaDabbaDo'
|
61 | ]))
|
62 | })
|
63 | })
|