|
| 1 | +const gulp = require('gulp'); |
| 2 | +const { exec } = require('child_process'); |
| 3 | +const shell = require('gulp-shell'); |
| 4 | + |
| 5 | +// Helper function to run Angular CLI commands |
| 6 | +function runNgTest(options = []) { |
| 7 | + return new Promise((resolve, reject) => { |
| 8 | + const command = `ng test ${options.join(' ')}`; |
| 9 | + const child = exec(command); |
| 10 | + |
| 11 | + child.stdout.on('data', (data) => { |
| 12 | + process.stdout.write(data); |
| 13 | + }); |
| 14 | + |
| 15 | + child.stderr.on('data', (data) => { |
| 16 | + process.stderr.write(data); |
| 17 | + }); |
| 18 | + |
| 19 | + child.on('close', (code) => { |
| 20 | + if (code === 0) { |
| 21 | + resolve(); |
| 22 | + } else { |
| 23 | + reject(new Error(`ng test failed with code ${code}`)); |
| 24 | + } |
| 25 | + }); |
| 26 | + }); |
| 27 | +} |
| 28 | + |
| 29 | +// Task to run all tests in CI mode |
| 30 | +gulp.task('test:ci', async () => { |
| 31 | + try { |
| 32 | + await runNgTest([ |
| 33 | + '--no-watch', |
| 34 | + '--browsers=ChromeHeadless', |
| 35 | + '--code-coverage', |
| 36 | + '--source-map=true', |
| 37 | + '--progress=false', |
| 38 | + '--reporters=junit,coverage', |
| 39 | + '--karma-config=karma.conf.ci.js' |
| 40 | + ]); |
| 41 | + } catch (error) { |
| 42 | + console.error('CI Test execution failed:', error); |
| 43 | + process.exit(1); // Ensure pipeline fails on test errors |
| 44 | + } |
| 45 | +}); |
| 46 | + |
| 47 | +// Task to run all tests including VF components |
| 48 | +gulp.task('test:all', async () => { |
| 49 | + try { |
| 50 | + await runNgTest([ |
| 51 | + '--watch=false', |
| 52 | + '--browsers=ChromeHeadless', |
| 53 | + '--code-coverage', |
| 54 | + '--source-map=true' |
| 55 | + ]); |
| 56 | + } catch (error) { |
| 57 | + console.error('Test execution failed:', error); |
| 58 | + throw error; |
| 59 | + } |
| 60 | +}); |
| 61 | + |
| 62 | +// Task to run tests for a specific VF component |
| 63 | +gulp.task('test:vf-component', async () => { |
| 64 | + const componentArg = process.argv.find(arg => arg.startsWith('--component=')); |
| 65 | + if (!componentArg) { |
| 66 | + throw new Error('Please specify a component: gulp test:vf-component --component=vf-badge'); |
| 67 | + } |
| 68 | + |
| 69 | + const componentName = componentArg.split('=')[1]; |
| 70 | + const testFile = `node_modules/@visual-framework/${componentName}/${componentName}.angular/**/*.spec.ts`; |
| 71 | + |
| 72 | + try { |
| 73 | + await runNgTest([ |
| 74 | + '--no-watch', |
| 75 | + '--browsers=ChromeHeadless', |
| 76 | + `--include=${testFile}` |
| 77 | + ]); |
| 78 | + } catch (error) { |
| 79 | + console.error('Test execution failed:', error); |
| 80 | + throw error; |
| 81 | + } |
| 82 | +}); |
| 83 | + |
| 84 | +// Task to run tests in watch mode (development only) |
| 85 | +gulp.task('test:watch', async () => { |
| 86 | + try { |
| 87 | + await runNgTest(['--browsers=Chrome']); |
| 88 | + } catch (error) { |
| 89 | + console.error('Test execution failed:', error); |
| 90 | + throw error; |
| 91 | + } |
| 92 | +}); |
| 93 | + |
| 94 | +// Watch folders for changes |
| 95 | +gulp.task('watch', shell.task([ |
| 96 | + 'ng build --watch --configuration development' |
| 97 | +])); |
| 98 | + |
| 99 | +// run ng in build mode |
| 100 | +gulp.task('build', shell.task([ |
| 101 | + 'ng build' |
| 102 | +])); |
| 103 | + |
| 104 | +// run ng in dev mode |
| 105 | +gulp.task('dev', shell.task([ |
| 106 | + 'ng serve' |
| 107 | +])); |
| 108 | + |
| 109 | +// Just build the assets, CSS and JS for VF components |
| 110 | +gulp.task('build-vf-assets', gulp.series( |
| 111 | + 'build' |
| 112 | +)); |
| 113 | + |
| 114 | +// Build and watch things during dev |
| 115 | +gulp.task('dev', gulp.series( |
| 116 | + gulp.parallel('dev', 'watch') |
| 117 | +)); |
0 commit comments