Skip to content

Commit a0e2f28

Browse files
timdeschryveralan-agius4
authored andcommitted
fix(@schematics/angular): don't create e2e script when createApplication is false
Bugfix for the ng new --createApplication=false command. Currently, it creates an e2e script in package.json. This change will only add the script when the application is created. Closes #13412
1 parent 155707a commit a0e2f28

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

packages/schematics/angular/e2e/index.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,23 @@ import {
1717
move,
1818
url,
1919
} from '@angular-devkit/schematics';
20+
import { JSONFile } from '../utility/json-file';
2021
import { relativePathToWorkspaceRoot } from '../utility/paths';
2122
import { getWorkspace, updateWorkspace } from '../utility/workspace';
2223
import { Builders } from '../utility/workspace-models';
2324
import { Schema as E2eOptions } from './schema';
2425

26+
function addScriptsToPackageJson(): Rule {
27+
return host => {
28+
const pkgJson = new JSONFile(host, 'package.json');
29+
const e2eScriptPath = ['scripts', 'e2e'];
30+
31+
if (!pkgJson.get(e2eScriptPath)) {
32+
pkgJson.modify(e2eScriptPath, 'ng e2e', false);
33+
}
34+
};
35+
}
36+
2537
export default function (options: E2eOptions): Rule {
2638
return async (host: Tree) => {
2739
const appProject = options.relatedAppName;
@@ -65,6 +77,7 @@ export default function (options: E2eOptions): Rule {
6577
}),
6678
move(root),
6779
])),
80+
addScriptsToPackageJson(),
6881
]);
6982
};
7083
}

packages/schematics/angular/e2e/index_spec.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,11 @@ describe('Application Schematic', () => {
9999
expect(e2eOptions.devServerTarget).toEqual('foo:serve');
100100
});
101101
});
102+
103+
it('should add an e2e script in package.json', async () => {
104+
const tree = await schematicRunner.runSchematicAsync('e2e', defaultOptions, applicationTree)
105+
.toPromise();
106+
const pkg = JSON.parse(tree.readContent('/package.json'));
107+
expect(pkg.scripts['e2e']).toBe('ng e2e');
108+
});
102109
});

packages/schematics/angular/workspace/files/package.json.template

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
"start": "ng serve",
77
"build": "ng build",
88
"test": "ng test",
9-
"lint": "ng lint",
10-
"e2e": "ng e2e"
9+
"lint": "ng lint"
1110
},
1211
"private": true,
1312
"dependencies": {

0 commit comments

Comments
 (0)