chore(angular): fix angular tests (#13483)

This commit is contained in:
Jason Jean 2022-11-29 17:23:30 -05:00 committed by GitHub
parent 2e544177ea
commit f39d73cce6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 6 deletions

View File

@ -12,7 +12,7 @@ import { normalizeOptions } from './lib/normalize-options';
import type { NormalizedSchema, Schema } from './schema';
export async function componentGenerator(tree: Tree, rawOptions: Schema) {
const options = normalizeOptions(tree, rawOptions);
const options = await normalizeOptions(tree, rawOptions);
const { projectSourceRoot, ...schematicOptions } = options;
checkPathUnderProjectRoot(tree, options);

View File

@ -1,5 +1,6 @@
import type { Tree } from '@nrwl/devkit';
import {
createProjectGraphAsync,
joinPathFragments,
readCachedProjectGraph,
readProjectConfiguration,
@ -11,15 +12,19 @@ import {
findProjectForPath,
} from 'nx/src/project-graph/utils/find-project-for-path';
export function normalizeOptions(
async function findProjectFromOptions(options: Schema) {
const projectGraph = await createProjectGraphAsync();
const projectRootMappings = createProjectRootMappings(projectGraph.nodes);
return findProjectForPath(options.path, projectRootMappings);
}
export async function normalizeOptions(
tree: Tree,
options: Schema
): NormalizedSchema {
const projectGraph = readCachedProjectGraph();
const projectRootMappings = createProjectRootMappings(projectGraph.nodes);
): Promise<NormalizedSchema> {
const project =
options.project ??
findProjectForPath(options.path, projectRootMappings) ??
(await findProjectFromOptions(options)) ??
readWorkspaceConfiguration(tree).defaultProject;
const { projectType, root, sourceRoot } = readProjectConfiguration(
tree,

View File

@ -2,6 +2,7 @@ import {
getProjects,
NxJsonConfiguration,
parseJson,
ProjectGraph,
readJson,
readProjectConfiguration,
Tree,
@ -24,6 +25,14 @@ import libraryGenerator from './library';
import { Schema } from './schema';
import applicationGenerator from '../application/application';
let projectGraph: ProjectGraph;
jest.mock('@nrwl/devkit', () => {
return {
...jest.requireActual('@nrwl/devkit'),
createProjectGraphAsync: jest.fn().mockImplementation(() => projectGraph),
};
});
describe('lib', () => {
let tree: Tree;
@ -1441,6 +1450,21 @@ describe('lib', () => {
});
describe('--standalone', () => {
beforeEach(() => {
projectGraph = {
nodes: {
'my-lib': {
name: 'my-lib',
type: 'lib',
data: {
root: 'libs/my-lib',
},
},
},
dependencies: {},
};
});
it('should generate a library with a standalone component as entry point', async () => {
await runLibraryGeneratorWithOpts({ standalone: true });