-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathtest-app.js
More file actions
112 lines (97 loc) · 3.96 KB
/
Copy pathtest-app.js
File metadata and controls
112 lines (97 loc) · 3.96 KB
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
'use strict';
let path = require('path'),
helpers = require('yeoman-test'),
read = require('fs-readdir-recursive'),
util = require('util'),
execFile = util.promisify(require('child_process').execFile),
fs = require('fs-extra'),
appPath = path.join(__dirname, '../app'),
targetPath = path.join(__dirname, 'temp');
function remapFiles(dir, target = 'testlib/') {
// append generated project sub-dir
return read(dir).map(val => target + val)
}
function dotfile(file) {
return file.replace(/^_|\/_|\\_/, '/.').replace(/^\//, '')
}
function repackage(file) {
return file.replace(/(^|\/|\\)package(\/|\\|$)/, '$1com/johnd/testlib$2')
}
function subdir(dir) {
return function (file) {
return dir + "/" + file;
}
}
async function runGradle(targetDir, done) {
const isWin = /^win/.test(process.platform),
targetFile = (isWin ? '': (targetDir + '/')) + 'gradlew' + (isWin ? '.bat' : '');
const { stdout, stderr } = await execFile(targetFile, ['check'], {cwd: targetDir});
console.log(stdout);
console.log(stderr);
if (done) {
done();
}
}
describe('check simple app generation', () => {
let result
before(async () => {
result = await helpers.run(appPath)
.inDir(targetPath)
.withOptions({offline: true})
.withPrompts({
multiModule: false,
githubUser: 'johnd',
authorName: 'John Doe',
authorEmail: 'johnd@somemail.com',
libName: 'testlib',
libGroup: 'com.johnd',
libPackage: 'com.johnd.testlib',
libVersion: '0.1.0',
libDesc: 'Test library',
enableQualityChecks: true
});
});
it('creates files on initial generation', () => {
result.assertFile(remapFiles(appPath + '/templates/gradle-base'));
result.assertFile(remapFiles(appPath + '/templates/project-base').map(dotfile));
result.assertFile(remapFiles(appPath + '/templates/project-single'));
result.assertFile(remapFiles(appPath + '/templates/sources').map(dotfile).map(repackage));
});
it('creates valid project', async () => {
fs.copySync(path.join(__dirname, 'sources'), targetPath + '/testlib/src/main/java');
await runGradle(targetPath + '/testlib');
}).timeout(300000); //5 min should be enough to download everything
});
describe('check multi-module app generation', () => {
let result
before(async () => {
result = await helpers.run(appPath)
.inDir(targetPath)
.withOptions({offline: true})
.withPrompts({
multiModule: true,
modulePrefix: 'foo',
moduleName: 'sample',
githubUser: 'johnd',
authorName: 'John Doe',
authorEmail: 'johnd@somemail.com',
libName: 'testlib',
libGroup: 'com.johnd',
libPackage: 'com.johnd.testlib',
libVersion: '0.1.0',
libDesc: 'Test library',
enableQualityChecks: true
});
});
it('creates files on initial generation', () => {
result.assertFile(remapFiles(appPath + '/templates/gradle-base'));
result.assertFile(remapFiles(appPath + '/templates/project-base').map(dotfile));
result.assertFile(remapFiles(appPath + '/templates/project-multi').map(dotfile));
result.assertFile(read(appPath + '/templates/project-multi-modules/module').map(subdir('testlib/foo-sample')));
result.assertFile(read(appPath + '/templates/sources').map(dotfile).map(repackage).map(subdir('testlib/foo-sample')));
});
it('creates valid project', async () => {
fs.copySync(path.join(__dirname, 'sources'), targetPath + '/testlib/foo-sample/src/main/java');
await runGradle(targetPath + '/testlib');
}).timeout(300000); //5 min should be enough to download everything
});