e2e.dev.ts 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import { dirname, join } from 'path';
  2. import { readFileSync } from 'fs';
  3. import { task } from 'gulp';
  4. import { ES_2015, PROJECT_ROOT } from '../constants';
  5. import { createTempTsConfig, getFolderInfo, runAppScriptsServe } from '../util';
  6. task('e2e.watch', ['e2e.prepare'], (done: Function) => {
  7. const folderInfo = getFolderInfo();
  8. if (!folderInfo || !folderInfo.componentName || !folderInfo.componentTest) {
  9. done(new Error(`Usage: gulp e2e.watch --folder nav/basic`));
  10. return;
  11. }
  12. serveTest(folderInfo, folderInfo.devApp).then(() => {
  13. done();
  14. }).catch((err: Error) => {
  15. done(err);
  16. });
  17. });
  18. function serveTest(folderInfo: any, devApp: boolean) {
  19. const ionicAngularDir = join(PROJECT_ROOT, 'src');
  20. const srcTestRoot = join(PROJECT_ROOT, 'src', 'components', folderInfo.componentName, 'test', folderInfo.componentTest);
  21. const distTestRoot = join(PROJECT_ROOT, 'dist', 'e2e', 'components', folderInfo.componentName, 'test', folderInfo.componentTest);
  22. const includeGlob = [ join(ionicAngularDir, '**', '*.ts')];
  23. const pathToWriteFile = join(distTestRoot, 'tsconfig.json');
  24. const pathToReadFile = join(PROJECT_ROOT, 'tsconfig.json');
  25. createTempTsConfig(includeGlob, ES_2015, ES_2015, pathToReadFile, pathToWriteFile, { removeComments: true});
  26. const sassConfigPath = join('scripts', 'e2e', 'sass.config.js');
  27. const copyConfigPath = join('scripts', 'e2e', 'copy.config.js');
  28. let appEntryPoint = join(srcTestRoot, 'app', 'main.ts');
  29. try {
  30. // check if the entry point exists, otherwise fall back to the legacy entry point without 'app' folder
  31. readFileSync(appEntryPoint);
  32. } catch (ex) {
  33. // the file doesn't exist, so use the legacy entry point
  34. appEntryPoint = join(srcTestRoot, 'main.ts');
  35. }
  36. // this assume that app.module.ts and main.ts are peers, which they should be no matter what
  37. const appNgModulePath = join(dirname(appEntryPoint), 'app.module.ts');
  38. const distDir = join(distTestRoot, 'www');
  39. return runAppScriptsServe(join(folderInfo.componentName, folderInfo.componentTest), appEntryPoint, appNgModulePath, ionicAngularDir, distDir, pathToWriteFile, ionicAngularDir, sassConfigPath, copyConfigPath, null, devApp);
  40. }