-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgulpfile.js
More file actions
117 lines (102 loc) · 2.79 KB
/
gulpfile.js
File metadata and controls
117 lines (102 loc) · 2.79 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
113
114
115
116
117
const gulp = require('gulp');
const { exec } = require('child_process');
const shell = require('gulp-shell');
// Helper function to run Angular CLI commands
function runNgTest(options = []) {
return new Promise((resolve, reject) => {
const command = `ng test ${options.join(' ')}`;
const child = exec(command);
child.stdout.on('data', (data) => {
process.stdout.write(data);
});
child.stderr.on('data', (data) => {
process.stderr.write(data);
});
child.on('close', (code) => {
if (code === 0) {
resolve();
} else {
reject(new Error(`ng test failed with code ${code}`));
}
});
});
}
// Task to run all tests in CI mode
gulp.task('test:ci', async () => {
try {
await runNgTest([
'--no-watch',
'--browsers=ChromeHeadless',
'--code-coverage',
'--source-map=true',
'--progress=false',
'--reporters=junit,coverage',
'--karma-config=karma.conf.ci.js'
]);
} catch (error) {
console.error('CI Test execution failed:', error);
process.exit(1); // Ensure pipeline fails on test errors
}
});
// Task to run all tests including VF components
gulp.task('test:all', async () => {
try {
await runNgTest([
'--watch=false',
'--browsers=ChromeHeadless',
'--code-coverage',
'--source-map=true'
]);
} catch (error) {
console.error('Test execution failed:', error);
throw error;
}
});
// Task to run tests for a specific VF component
gulp.task('test:vf-component', async () => {
const componentArg = process.argv.find(arg => arg.startsWith('--component='));
if (!componentArg) {
throw new Error('Please specify a component: gulp test:vf-component --component=vf-badge');
}
const componentName = componentArg.split('=')[1];
const testFile = `node_modules/@visual-framework/${componentName}/${componentName}.angular/**/*.spec.ts`;
try {
await runNgTest([
'--no-watch',
'--browsers=ChromeHeadless',
`--include=${testFile}`
]);
} catch (error) {
console.error('Test execution failed:', error);
throw error;
}
});
// Task to run tests in watch mode (development only)
gulp.task('test:watch', async () => {
try {
await runNgTest(['--browsers=Chrome']);
} catch (error) {
console.error('Test execution failed:', error);
throw error;
}
});
// Watch folders for changes
gulp.task('watch', shell.task([
'ng build --watch --configuration development'
]));
// run ng in build mode
gulp.task('build', shell.task([
'ng build'
]));
// run ng in dev mode
gulp.task('dev', shell.task([
'ng serve'
]));
// Just build the assets, CSS and JS for VF components
gulp.task('build-vf-assets', gulp.series(
'build'
));
// Build and watch things during dev
gulp.task('dev', gulp.series(
gulp.parallel('dev', 'watch')
));