Skip to content

Commit

Permalink
fix(@schematics/angular): don't create e2e script when createApplicat…
Browse files Browse the repository at this point in the history
…ion 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
  • Loading branch information
timdeschryver authored and alan-agius4 committed Aug 14, 2020
1 parent 155707a commit a0e2f28
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
13 changes: 13 additions & 0 deletions packages/schematics/angular/e2e/index.ts
Expand Up @@ -17,11 +17,23 @@ import {
move,
url,
} from '@angular-devkit/schematics';
import { JSONFile } from '../utility/json-file';
import { relativePathToWorkspaceRoot } from '../utility/paths';
import { getWorkspace, updateWorkspace } from '../utility/workspace';
import { Builders } from '../utility/workspace-models';
import { Schema as E2eOptions } from './schema';

function addScriptsToPackageJson(): Rule {
return host => {
const pkgJson = new JSONFile(host, 'package.json');
const e2eScriptPath = ['scripts', 'e2e'];

if (!pkgJson.get(e2eScriptPath)) {
pkgJson.modify(e2eScriptPath, 'ng e2e', false);
}
};
}

export default function (options: E2eOptions): Rule {
return async (host: Tree) => {
const appProject = options.relatedAppName;
Expand Down Expand Up @@ -65,6 +77,7 @@ export default function (options: E2eOptions): Rule {
}),
move(root),
])),
addScriptsToPackageJson(),
]);
};
}
7 changes: 7 additions & 0 deletions packages/schematics/angular/e2e/index_spec.ts
Expand Up @@ -99,4 +99,11 @@ describe('Application Schematic', () => {
expect(e2eOptions.devServerTarget).toEqual('foo:serve');
});
});

it('should add an e2e script in package.json', async () => {
const tree = await schematicRunner.runSchematicAsync('e2e', defaultOptions, applicationTree)
.toPromise();
const pkg = JSON.parse(tree.readContent('/package.json'));
expect(pkg.scripts['e2e']).toBe('ng e2e');
});
});
Expand Up @@ -6,8 +6,7 @@
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
"lint": "ng lint"
},
"private": true,
"dependencies": {
Expand Down

0 comments on commit a0e2f28

Please sign in to comment.