chore(angular): fix angular tests (#13483)
This commit is contained in:
parent
2e544177ea
commit
f39d73cce6
@ -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);
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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 });
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user