Skip to content

Commit 2131fbf

Browse files
committed
chore(new): change ng new e2e test to be specific for '--routing'...
Also fixes problem running that test on Windows
1 parent bd261ff commit 2131fbf

File tree

2 files changed

+61
-60
lines changed

2 files changed

+61
-60
lines changed

tests/e2e/tests/commands/new.ts

Lines changed: 0 additions & 60 deletions
This file was deleted.
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import * as path from 'path';
2+
import * as fs from 'fs';
3+
import {ng} from '../../../utils/process';
4+
import {deleteDir} from '../../../utils/fs';
5+
6+
export default function() {
7+
const parentTestProjectDir = process.cwd();
8+
const ngNewProjectName = 'new-test-project';
9+
10+
return Promise.resolve()
11+
12+
// The test setup already creates a project, let's clean that before running `ng new`.
13+
.then(() => disableTestSetupProject(parentTestProjectDir))
14+
15+
// Run `ng new` and tests...
16+
.then(() => process.chdir(parentTestProjectDir))
17+
.then(() => ng('new', ngNewProjectName, '--routing'))
18+
.then(() => process.chdir(path.join(parentTestProjectDir, ngNewProjectName)))
19+
20+
// Try to run the unit tests.
21+
.then(() => ng('test', '--single-run'))
22+
23+
// Revert disabling test-setup project, and prepare folder so test cleanup doesn't fail.
24+
.then(() => prepareGitForTestCleanup(parentTestProjectDir, ngNewProjectName));
25+
}
26+
27+
const angularCliPaths = ['.git', 'angular-cli.json', 'package.json'];
28+
const pathRenameSuffix = '.ng_new-backup';
29+
30+
// Change the project inherited from Setup into normal
31+
// non angular-cli project folder, so we can call `ng new`.
32+
function disableTestSetupProject (parentTestProjectDir: string) {
33+
return Promise.resolve()
34+
.then(() => process.chdir(parentTestProjectDir))
35+
36+
// Rename the files that define the folder as an angular-cli project
37+
// and that interfere with creating a child one.
38+
.then(() =>
39+
angularCliPaths.forEach(pathname => {
40+
const originalPath = path.join(parentTestProjectDir, pathname);
41+
fs.rename(originalPath, originalPath + pathRenameSuffix);
42+
})
43+
);
44+
}
45+
46+
function prepareGitForTestCleanup (parentTestProjectDir: string, projectName: string) {
47+
return Promise.resolve()
48+
// This is needed to unlock the folder created by our `ng new` call.
49+
.then(() => process.chdir(parentTestProjectDir))
50+
51+
// The post-test cleanup breaks if there's another git project inside it.
52+
.then(() => deleteDir(path.join(parentTestProjectDir, projectName)))
53+
54+
// Restore renamed files.
55+
.then(() =>
56+
angularCliPaths.forEach(pathname => {
57+
const renamedPath = path.join(parentTestProjectDir, pathname) + pathRenameSuffix;
58+
fs.rename(renamedPath, renamedPath.replace(pathRenameSuffix, ''));
59+
})
60+
);
61+
}

0 commit comments

Comments
 (0)