|
| 1 | +import { program } from '../src/cli'; |
| 2 | +import { promises as fs } from 'fs'; |
| 3 | +import * as jsYAML from 'js-yaml'; |
| 4 | +import * as path from 'path'; |
| 5 | +import { runShutdownJobs } from '../src/utils'; |
| 6 | +import * as supertest from 'supertest'; |
| 7 | + |
| 8 | +const projectName = 'test-vulcan-project'; |
| 9 | + |
| 10 | +const workspaceRoot = path.resolve(__dirname, '..', '..', '..'); |
| 11 | +const projectRoot = path.resolve(workspaceRoot, projectName); |
| 12 | + |
| 13 | +beforeAll(async () => { |
| 14 | + await fs.rm(projectRoot, { recursive: true, force: true }); |
| 15 | + await program.parseAsync(['node', 'vulcan', 'init', '-p', projectName]); |
| 16 | + process.chdir(projectRoot); |
| 17 | +}, 30000); |
| 18 | + |
| 19 | +afterAll(async () => { |
| 20 | + await fs.rm(projectRoot, { recursive: true, force: true }); |
| 21 | +}); |
| 22 | + |
| 23 | +afterEach(async () => { |
| 24 | + await runShutdownJobs(); |
| 25 | +}); |
| 26 | + |
| 27 | +it('Init command should create new folder with default config', async () => { |
| 28 | + // Action |
| 29 | + const config: any = jsYAML.load( |
| 30 | + await fs.readFile(path.resolve(projectRoot, 'vulcan.yaml'), 'utf8') |
| 31 | + ); |
| 32 | + // Assert |
| 33 | + expect(config.name).toBe(projectName); |
| 34 | +}); |
| 35 | + |
| 36 | +it('Build command should make result.json', async () => { |
| 37 | + // Action |
| 38 | + await program.parseAsync(['node', 'vulcan', 'build']); |
| 39 | + // Assert |
| 40 | + expect( |
| 41 | + fs.readFile(path.resolve(projectRoot, 'result.json'), 'utf-8') |
| 42 | + ).resolves.not.toThrow(); |
| 43 | +}); |
| 44 | + |
| 45 | +it('Serve command should start Vulcan server', async () => { |
| 46 | + // Action |
| 47 | + await program.parseAsync(['node', 'vulcan', 'build']); |
| 48 | + await program.parseAsync(['node', 'vulcan', 'serve', '-p', '12345']); |
| 49 | + const agent = supertest('http://localhost:12345'); |
| 50 | + const result = await agent.get('/'); |
| 51 | + // Assert |
| 52 | + expect(result.statusCode).toBe(200); |
| 53 | + await runShutdownJobs(); |
| 54 | +}); |
| 55 | + |
| 56 | +it('Start command should build the project and start Vulcan server', async () => { |
| 57 | + // Action |
| 58 | + await program.parseAsync(['node', 'vulcan', 'start', '-p', '12345']); |
| 59 | + const agent = supertest('http://localhost:12345'); |
| 60 | + const result = await agent.get('/'); |
| 61 | + // Assert |
| 62 | + expect(result.statusCode).toBe(200); |
| 63 | + await runShutdownJobs(); |
| 64 | +}); |
0 commit comments