-
Notifications
You must be signed in to change notification settings - Fork 12k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(new): change
ng new
e2e test to be specific for '--routing'...
Also fixes problem running that test on Windows
- Loading branch information
Showing
2 changed files
with
61 additions
and
60 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import * as path from 'path'; | ||
import * as fs from 'fs'; | ||
import {ng} from '../../../utils/process'; | ||
import {deleteDir} from '../../../utils/fs'; | ||
|
||
export default function() { | ||
const parentTestProjectDir = process.cwd(); | ||
const ngNewProjectName = 'new-test-project'; | ||
|
||
return Promise.resolve() | ||
|
||
// The test setup already creates a project, let's clean that before running `ng new`. | ||
.then(() => disableTestSetupProject(parentTestProjectDir)) | ||
|
||
// Run `ng new` and tests... | ||
.then(() => process.chdir(parentTestProjectDir)) | ||
.then(() => ng('new', ngNewProjectName, '--routing')) | ||
.then(() => process.chdir(path.join(parentTestProjectDir, ngNewProjectName))) | ||
|
||
// Try to run the unit tests. | ||
.then(() => ng('test', '--single-run')) | ||
|
||
// Revert disabling test-setup project, and prepare folder so test cleanup doesn't fail. | ||
.then(() => prepareGitForTestCleanup(parentTestProjectDir, ngNewProjectName)); | ||
} | ||
|
||
const angularCliPaths = ['.git', 'angular-cli.json', 'package.json']; | ||
const pathRenameSuffix = '.ng_new-backup'; | ||
|
||
// Change the project inherited from Setup into normal | ||
// non angular-cli project folder, so we can call `ng new`. | ||
function disableTestSetupProject (parentTestProjectDir: string) { | ||
return Promise.resolve() | ||
.then(() => process.chdir(parentTestProjectDir)) | ||
|
||
// Rename the files that define the folder as an angular-cli project | ||
// and that interfere with creating a child one. | ||
.then(() => | ||
angularCliPaths.forEach(pathname => { | ||
const originalPath = path.join(parentTestProjectDir, pathname); | ||
fs.rename(originalPath, originalPath + pathRenameSuffix); | ||
}) | ||
); | ||
} | ||
|
||
function prepareGitForTestCleanup (parentTestProjectDir: string, projectName: string) { | ||
return Promise.resolve() | ||
// This is needed to unlock the folder created by our `ng new` call. | ||
.then(() => process.chdir(parentTestProjectDir)) | ||
|
||
// The post-test cleanup breaks if there's another git project inside it. | ||
.then(() => deleteDir(path.join(parentTestProjectDir, projectName))) | ||
|
||
// Restore renamed files. | ||
.then(() => | ||
angularCliPaths.forEach(pathname => { | ||
const renamedPath = path.join(parentTestProjectDir, pathname) + pathRenameSuffix; | ||
fs.rename(renamedPath, renamedPath.replace(pathRenameSuffix, '')); | ||
}) | ||
); | ||
} |