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';
|
import type { NormalizedSchema, Schema } from './schema';
|
||||||
|
|
||||||
export async function componentGenerator(tree: Tree, rawOptions: Schema) {
|
export async function componentGenerator(tree: Tree, rawOptions: Schema) {
|
||||||
const options = normalizeOptions(tree, rawOptions);
|
const options = await normalizeOptions(tree, rawOptions);
|
||||||
const { projectSourceRoot, ...schematicOptions } = options;
|
const { projectSourceRoot, ...schematicOptions } = options;
|
||||||
|
|
||||||
checkPathUnderProjectRoot(tree, options);
|
checkPathUnderProjectRoot(tree, options);
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
import type { Tree } from '@nrwl/devkit';
|
import type { Tree } from '@nrwl/devkit';
|
||||||
import {
|
import {
|
||||||
|
createProjectGraphAsync,
|
||||||
joinPathFragments,
|
joinPathFragments,
|
||||||
readCachedProjectGraph,
|
readCachedProjectGraph,
|
||||||
readProjectConfiguration,
|
readProjectConfiguration,
|
||||||
@ -11,15 +12,19 @@ import {
|
|||||||
findProjectForPath,
|
findProjectForPath,
|
||||||
} from 'nx/src/project-graph/utils/find-project-for-path';
|
} 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,
|
tree: Tree,
|
||||||
options: Schema
|
options: Schema
|
||||||
): NormalizedSchema {
|
): Promise<NormalizedSchema> {
|
||||||
const projectGraph = readCachedProjectGraph();
|
|
||||||
const projectRootMappings = createProjectRootMappings(projectGraph.nodes);
|
|
||||||
const project =
|
const project =
|
||||||
options.project ??
|
options.project ??
|
||||||
findProjectForPath(options.path, projectRootMappings) ??
|
(await findProjectFromOptions(options)) ??
|
||||||
readWorkspaceConfiguration(tree).defaultProject;
|
readWorkspaceConfiguration(tree).defaultProject;
|
||||||
const { projectType, root, sourceRoot } = readProjectConfiguration(
|
const { projectType, root, sourceRoot } = readProjectConfiguration(
|
||||||
tree,
|
tree,
|
||||||
|
|||||||
@ -2,6 +2,7 @@ import {
|
|||||||
getProjects,
|
getProjects,
|
||||||
NxJsonConfiguration,
|
NxJsonConfiguration,
|
||||||
parseJson,
|
parseJson,
|
||||||
|
ProjectGraph,
|
||||||
readJson,
|
readJson,
|
||||||
readProjectConfiguration,
|
readProjectConfiguration,
|
||||||
Tree,
|
Tree,
|
||||||
@ -24,6 +25,14 @@ import libraryGenerator from './library';
|
|||||||
import { Schema } from './schema';
|
import { Schema } from './schema';
|
||||||
import applicationGenerator from '../application/application';
|
import applicationGenerator from '../application/application';
|
||||||
|
|
||||||
|
let projectGraph: ProjectGraph;
|
||||||
|
jest.mock('@nrwl/devkit', () => {
|
||||||
|
return {
|
||||||
|
...jest.requireActual('@nrwl/devkit'),
|
||||||
|
createProjectGraphAsync: jest.fn().mockImplementation(() => projectGraph),
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
describe('lib', () => {
|
describe('lib', () => {
|
||||||
let tree: Tree;
|
let tree: Tree;
|
||||||
|
|
||||||
@ -1441,6 +1450,21 @@ describe('lib', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('--standalone', () => {
|
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 () => {
|
it('should generate a library with a standalone component as entry point', async () => {
|
||||||
await runLibraryGeneratorWithOpts({ standalone: true });
|
await runLibraryGeneratorWithOpts({ standalone: true });
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user