Skip to content

Commit

Permalink
chore(new): change ng new e2e test to be specific for '--routing'...
Browse files Browse the repository at this point in the history
Also fixes problem running that test on Windows
  • Loading branch information
Meligy committed Nov 25, 2016
1 parent bd261ff commit 2131fbf
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 60 deletions.
60 changes: 0 additions & 60 deletions tests/e2e/tests/commands/new.ts

This file was deleted.

61 changes: 61 additions & 0 deletions tests/e2e/tests/commands/new/new-routing.ts
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, ''));
})
);
}

0 comments on commit 2131fbf

Please sign in to comment.