mirror of
https://github.com/angular/angular-cli.git
synced 2025-05-16 10:33:43 +08:00
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
This commit is contained in:
parent
155707a1ba
commit
a0e2f28d26
@ -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;
|
||||
@ -65,6 +77,7 @@ export default function (options: E2eOptions): Rule {
|
||||
}),
|
||||
move(root),
|
||||
])),
|
||||
addScriptsToPackageJson(),
|
||||
]);
|
||||
};
|
||||
}
|
||||
|
@ -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');
|
||||
});
|
||||
});
|
||||
|
@ -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": {
|
||||
|
Loading…
x
Reference in New Issue
Block a user