-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathmaven-runner.test.ts
126 lines (94 loc) · 4.91 KB
/
maven-runner.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import * as path from 'path';
import { getMavenProjectDirectory, getMavenSettingsFile } from './utils/test-util';
import { MavenRunner } from './maven-runner';
import {describe, it, expect} from 'vitest';
describe('maven-runner', () => {
describe('create', () => {
it('should create a runner without a wrapper', async () => {
const projectDir = getMavenProjectDirectory('simple');
const runner = new MavenRunner(projectDir);
expect(runner.configuration.executable).toBeDefined();
expect(runner.configuration.executable).toBe('mvn');
expect(runner.configuration.settingsFile).toBeUndefined();
}, 20000);
it('should create a runner with wrapper', async () => {
const projectDir = getMavenProjectDirectory('maven-wrapper');
const runner = new MavenRunner(projectDir);
expect(runner.configuration.executable).toBeDefined();
expect(runner.configuration.executable).toBe(path.join(projectDir, 'mvnw'));
expect(runner.configuration.settingsFile).toBeUndefined();
}, 20000);
describe('with settings', () => {
it('should create a runner without a wrapper', async () => {
const projectDir = getMavenProjectDirectory('simple');
const settings = getMavenSettingsFile();
const runner = new MavenRunner(projectDir, settings);
expect(runner.configuration.executable).toBeDefined();
expect(runner.configuration.executable).toBe('mvn');
expect(runner.configuration.settingsFile).toBe(settings);
});
})
});
describe('#exec()', () => {
it('should run path provided maven', async () => {
const projectDir = getMavenProjectDirectory('simple');
const runner = new MavenRunner(projectDir);
const results = await runner.exec(projectDir, ['--version']);
expect(results.exitCode).toBe(0);
expect(results.stdout).toContain('Apache Maven');
});
it('should run wrapper provided maven', async () => {
const projectDir = getMavenProjectDirectory('maven-wrapper');
const runner = new MavenRunner(projectDir);
const results = await runner.exec(projectDir, ['--version']);
expect(results.exitCode).toBe(0);
expect(results.stdout).toContain('Apache Maven');
expect(results.stdout).toContain('3.8.6');
});
it('should run wrapper provided maven with validate phase', async () => {
const projectDir = getMavenProjectDirectory('maven-wrapper');
const runner = new MavenRunner(projectDir);
const results = await runner.exec(projectDir, ['validate']);
expect(results.exitCode).toBe(0);
});
describe('with additional arguments', () => {
it('should run path provided maven with additional arguments', async () => {
const projectDir = getMavenProjectDirectory('simple');
const additionalMavenArgs = ' -DskipTests -q';
const runner = new MavenRunner(projectDir, undefined, false, additionalMavenArgs);
const results = await runner.exec(projectDir, ['validate']);
expect(results.exitCode).toBe(0);
// by running with quiet mode there should be no output
expect(results.stdout.length).toBe(0);
});
it('should run path provided maven with additional arguments', async () => {
const projectDir = getMavenProjectDirectory('simple');
const additionalMavenArgs = ' -X -B -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn';
const runner = new MavenRunner(projectDir, undefined, false, additionalMavenArgs);
const results = await runner.exec(projectDir, ['validate']);
expect(results.exitCode).toBe(0);
expect(results.stdout.length).toBeGreaterThan(7000);
});
});
describe('with settings', () => {
it('should run path provided maven with settings file', async () => {
const projectDir = getMavenProjectDirectory('simple');
const settingsFile = getMavenSettingsFile();
const runner = new MavenRunner(projectDir, settingsFile);
const results = await runner.exec(projectDir, ['-X', 'validate']);
expect(results.exitCode).toBe(0);
// When running in debug mode the settings files that are loaded are displayed in the stdout
expect(results.stdout).toContain(`Reading user settings from ${path.resolve(settingsFile)}`);
});
it('should run wrapper provided maven with settings file', async () => {
const projectDir = getMavenProjectDirectory('maven-wrapper');
const settingsFile = getMavenSettingsFile();
const runner = new MavenRunner(projectDir, settingsFile);
const results = await runner.exec(projectDir, ['-X', 'validate']);
expect(results.exitCode).toBe(0);
// When running in debug mode the settings files that are loaded are displayed in the stdout
expect(results.stdout).toContain(`Reading user settings from ${path.resolve(settingsFile)}`);
});
});
});
});