|
| 1 | +import {deleteFile, deleteDir} from '../../utils/fs'; |
| 2 | +import * as path from 'path'; |
| 3 | +import {ng, git} from '../../utils/process'; |
| 4 | +import {gitCommit} from '../../utils/git'; |
| 5 | + |
| 6 | +export default function() { |
| 7 | + const parentTestprojectDir = process.cwd(); |
| 8 | + const projectName = 'new-test-project'; |
| 9 | + |
| 10 | + return Promise.resolve() |
| 11 | + // The test setup already creates a project, lets' clean that before running `ng new` |
| 12 | + .then(() => removeSetupProject(parentTestprojectDir)) |
| 13 | + |
| 14 | + // Run `ng new` |
| 15 | + .then(() => ng('new', projectName)) |
| 16 | + .then(() => process.chdir(path.join(parentTestprojectDir, projectName))) |
| 17 | + |
| 18 | + // Try to run the unit tests. |
| 19 | + .then(() => ng('test', '--single-run')) |
| 20 | + |
| 21 | + // Run post-test steps whether test passes or fails |
| 22 | + .then(prepareGitForTestCleanup, prepareGitForTestCleanup); |
| 23 | +} |
| 24 | + |
| 25 | +// Change the project inherited from Setup into normal |
| 26 | +// non angular-cli project folder, so we can call `ng new` |
| 27 | +function removeSetupProject (parentTestprojectDir: string) { |
| 28 | + return Promise.resolve() |
| 29 | + |
| 30 | + // Change the project inherited from Setup into normal |
| 31 | + // non angular-cli project folder, so we can call `ng new` |
| 32 | + .then(() => process.chdir(parentTestprojectDir)) |
| 33 | + .then(() => deleteDir('.git')) |
| 34 | + .then(() => deleteFile('angular-cli.json')) |
| 35 | + .then(() => deleteFile('package.json')); |
| 36 | +} |
| 37 | + |
| 38 | +// The post-test cleanup breaks if it doesn't have a git repository with a branch and a commit |
| 39 | +function prepareGitForTestCleanup() { |
| 40 | + return Promise.resolve() |
| 41 | + .then(() => git('config', 'user.email', '[email protected]')) |
| 42 | + .then(() => git('config', 'user.name', 'Angular CLI E2e')) |
| 43 | + .then(() => git('config', 'commit.gpgSign', 'false')) |
| 44 | + .then(() => gitCommit('ng-new test')); |
| 45 | +} |
0 commit comments