Skip to content

Commit a595052

Browse files
committed
test: add e2e tests
1 parent aa5c1fa commit a595052

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

test/e2e/e2e.test.ts

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import fs from 'node:fs';
2+
import {
3+
afterEach,
4+
beforeAll,
5+
describe,
6+
expect,
7+
it
8+
} from 'vitest';
9+
10+
import { CLI } from './cli.js';
11+
12+
const NEW_APP_PATH = 'generated/test-db-app';
13+
const removeFolder = ( dirPath: string ) => {
14+
if ( fs.existsSync( dirPath ) ) {
15+
fs.rmSync( dirPath, { recursive: true } );
16+
}
17+
};
18+
19+
describe( 'e2e tests', () => {
20+
// Cleanup previous test runs
21+
beforeAll( () => {
22+
removeFolder( NEW_APP_PATH );
23+
} );
24+
25+
afterEach( () => {
26+
removeFolder( NEW_APP_PATH );
27+
} );
28+
29+
it( 'should display the help menu', async() => {
30+
const { stdout } = await CLI.get( [ '--help' ] );
31+
32+
expect( stdout ).toContain( 'USAGE' );
33+
expect( stdout ).toContain( 'ARGUMENTS' );
34+
expect( stdout ).toContain( 'FLAGS' );
35+
expect( stdout ).toContain( 'DESCRIPTION' );
36+
expect( stdout ).toContain( 'EXAMPLES' );
37+
} );
38+
39+
it( 'should request the application\'s name', async() => {
40+
const { stdout } = await CLI.get( [], true );
41+
42+
expect( stdout ).toContain( 'application\'s name' );
43+
} );
44+
45+
it( 'should keep asking for application\'s name when none has been provided', async() => {
46+
const cli = new CLI();
47+
const { stdout } = await cli.userInput( [ '\n', '\n', '\n' ] );
48+
49+
expect( stdout ).toContain( 'application\'s name' );
50+
} );
51+
52+
it( 'should scaffold the project using flags', async() => {
53+
const cli = new CLI( [
54+
NEW_APP_PATH,
55+
'--template=node-vanilla',
56+
'--connection-type=basic',
57+
'--db-hostname=localhost',
58+
'--db-port=80',
59+
'--db-protocol=tcp',
60+
'--db-service-type=sid',
61+
'--db-sid=testSid',
62+
'--db-username=testUser'
63+
] );
64+
const { stdout } = await cli.userInput( [ 'dummyPassword\n' ] );
65+
66+
expect( fs.existsSync( NEW_APP_PATH ) ).toBeTruthy();
67+
expect( stdout ).toMatch( /added \d{1,5} packages/ );
68+
} );
69+
} );

0 commit comments

Comments
 (0)