Skip to content

Commit

Permalink
feat(misc): init wip
Browse files Browse the repository at this point in the history
  • Loading branch information
FrozenPandaz committed Apr 12, 2024
1 parent 2cb43ca commit 123da37
Show file tree
Hide file tree
Showing 171 changed files with 1,433 additions and 1,031 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ jobs:
NX_NATIVE_LOGGING: 'false'
NX_E2E_RUN_E2E: 'true'
NX_CI_EXECUTION_ENV: 'linux'
NX_CLOUD_DTE_V2: 'true'
NX_CLOUD_DTE_V2: 'false'
steps:
- checkout
- nx/set-shas:
Expand Down
2 changes: 1 addition & 1 deletion packages/angular/plugins/component-testing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export function nxComponentTestingPreset(
pathToConfig: string,
options?: NxComponentTestingOptions
) {
if (global.NX_GRAPH_CREATION || global.NX_CYPRESS_INIT_GENERATOR_RUNNING) {
if (global.NX_GRAPH_CREATION) {
// this is only used by plugins, so we don't need the component testing
// options, cast to any to avoid type errors
return nxBaseCypressPreset(pathToConfig, {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'nx/src/internal-testing-utils/mock-project-graph';

import {
ProjectConfiguration,
Tree,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ jest.mock('@nx/devkit', () => {
return {
...original,
ensurePackage: (pkg: string) => jest.requireActual(pkg),
createProjectGraphAsync: jest.fn().mockResolvedValue({
nodes: {},
dependencies: {},
}),
};
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'nx/src/internal-testing-utils/mock-project-graph';

import { installedCypressVersion } from '@nx/cypress/src/utils/cypress-version';
import type { Tree } from '@nx/devkit';
import * as devkit from '@nx/devkit';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'nx/src/internal-testing-utils/mock-project-graph';

import type { Tree } from '@nx/devkit';
import * as devkit from '@nx/devkit';
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'nx/src/internal-testing-utils/mock-project-graph';

import { assertMinimumCypressVersion } from '@nx/cypress/src/utils/cypress-version';
import { Tree } from '@nx/devkit';
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,21 @@ import {
updateProjectConfiguration,
} from '@nx/devkit';
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
import { componentGenerator } from '../component/component';
import { librarySecondaryEntryPointGenerator } from '../library-secondary-entry-point/library-secondary-entry-point';
import { generateTestApplication, generateTestLibrary } from '../utils/testing';
import { cypressComponentConfiguration } from './cypress-component-configuration';

let projectGraph: ProjectGraph = { nodes: {}, dependencies: {} };
jest.mock('@nx/cypress/src/utils/cypress-version');
jest.mock('@nx/devkit', () => ({
...jest.requireActual<any>('@nx/devkit'),
createProjectGraphAsync: jest
.fn()
.mockImplementation(async () => projectGraph),
}));

import { componentGenerator } from '../component/component';
import { librarySecondaryEntryPointGenerator } from '../library-secondary-entry-point/library-secondary-entry-point';
import { generateTestApplication, generateTestLibrary } from '../utils/testing';
import { cypressComponentConfiguration } from './cypress-component-configuration';

jest.mock('@nx/cypress/src/utils/cypress-version');
// nested code imports graph from the repo, which might have innacurate graph version
jest.mock('nx/src/project-graph/project-graph', () => ({
...jest.requireActual<any>('nx/src/project-graph/project-graph'),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'nx/src/internal-testing-utils/mock-project-graph';

import { getProjects } from '@nx/devkit';
import { Schema } from './schema';
import { Schema as remoteSchma } from '../remote/schema';
Expand Down
2 changes: 2 additions & 0 deletions packages/angular/src/generators/host/host.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'nx/src/internal-testing-utils/mock-project-graph';

import { readJson, updateJson } from '@nx/devkit';
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
import {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'nx/src/internal-testing-utils/mock-project-graph';

import * as devkit from '@nx/devkit';
import { addProjectConfiguration, readJson, Tree } from '@nx/devkit';
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
Expand Down
2 changes: 2 additions & 0 deletions packages/angular/src/generators/library/library.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'nx/src/internal-testing-utils/mock-project-graph';

import {
getProjects,
NxJsonConfiguration,
Expand Down
2 changes: 2 additions & 0 deletions packages/angular/src/generators/move/move.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'nx/src/internal-testing-utils/mock-project-graph';

import * as devkit from '@nx/devkit';
import { ProjectGraph, readJson, Tree } from '@nx/devkit';
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import type { Tree } from '@nx/devkit';
import 'nx/src/internal-testing-utils/mock-project-graph';

import { Tree } from '@nx/devkit';
import {
readJson,
readProjectConfiguration,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'nx/src/internal-testing-utils/mock-project-graph';

import type {
ProjectConfiguration,
TargetConfiguration,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'nx/src/internal-testing-utils/mock-project-graph';

// mock so we can test multiple versions
jest.mock('@nx/cypress/src/utils/cypress-version');
// mock bc the nxE2EPreset uses fs for path normalization
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'nx/src/internal-testing-utils/mock-project-graph';

import type { Tree } from '@nx/devkit';
import { readJson } from '@nx/devkit';
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'nx/src/internal-testing-utils/mock-project-graph';

import type { Tree } from '@nx/devkit';
import { readJson } from '@nx/devkit';
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
Expand Down
2 changes: 2 additions & 0 deletions packages/angular/src/generators/ngrx/ngrx.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'nx/src/internal-testing-utils/mock-project-graph';

import type { Tree } from '@nx/devkit';
import * as devkit from '@nx/devkit';
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
Expand Down
2 changes: 2 additions & 0 deletions packages/angular/src/generators/remote/remote.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'nx/src/internal-testing-utils/mock-project-graph';

import { E2eTestRunner } from '../../utils/test-runners';
import {
getProjects,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'nx/src/internal-testing-utils/mock-project-graph';

import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
import scamGenerator from '../scam/scam';
import { generateTestApplication } from '../utils/testing';
Expand Down
2 changes: 2 additions & 0 deletions packages/angular/src/generators/setup-ssr/setup-ssr.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'nx/src/internal-testing-utils/mock-project-graph';

import {
NxJsonConfiguration,
readJson,
Expand Down
2 changes: 2 additions & 0 deletions packages/angular/src/generators/stories/stories-app.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'nx/src/internal-testing-utils/mock-project-graph';

import { installedCypressVersion } from '@nx/cypress/src/utils/cypress-version';
import type { Tree } from '@nx/devkit';
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
Expand Down
2 changes: 2 additions & 0 deletions packages/angular/src/generators/stories/stories-lib.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'nx/src/internal-testing-utils/mock-project-graph';

import { installedCypressVersion } from '@nx/cypress/src/utils/cypress-version';
import { Tree } from '@nx/devkit';
import { writeJson } from '@nx/devkit';
Expand Down
2 changes: 2 additions & 0 deletions packages/angular/src/generators/web-worker/web-worker.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'nx/src/internal-testing-utils/mock-project-graph';

import type { Tree } from '@nx/devkit';
import * as devkit from '@nx/devkit';
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'nx/src/internal-testing-utils/mock-project-graph';

import { readJson, updateJson } from '@nx/devkit';
import * as devkit from '@nx/devkit';
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'nx/src/internal-testing-utils/mock-project-graph';

import type { Tree } from '@nx/devkit';
import * as devkit from '@nx/devkit';
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'nx/src/internal-testing-utils/mock-project-graph';

import type { Tree } from '@nx/devkit';
import { logger, visitNotIgnoredFiles } from '@nx/devkit';
import { basename } from 'path';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'nx/src/internal-testing-utils/mock-project-graph';

import {
readJson,
readProjectConfiguration,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'nx/src/internal-testing-utils/mock-project-graph';

import * as devkit from '@nx/devkit';
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
import { Builders } from '@schematics/angular/utility/workspace-models';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'nx/src/internal-testing-utils/mock-project-graph';

import {
addProjectConfiguration,
ProjectConfiguration,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'nx/src/internal-testing-utils/mock-project-graph';

import {
addProjectConfiguration,
ProjectConfiguration,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export async function configurationGeneratorInternal(
opts.addPlugin ??= process.env.NX_ADD_PLUGINS !== 'false';
const tasks: GeneratorCallback[] = [];

const projectGraph = await createProjectGraphAsync();
if (!installedCypressVersion()) {
tasks.push(await jsInitGenerator(tree, { ...options, skipFormat: true }));
tasks.push(
Expand All @@ -79,10 +80,9 @@ export async function configurationGeneratorInternal(
})
);
} else if (opts.addPlugin) {
addPlugin(tree);
await addPlugin(tree, projectGraph, false);
}

const projectGraph = await createProjectGraphAsync();
const nxJson = readNxJson(tree);
const hasPlugin = nxJson.plugins?.some((p) =>
typeof p === 'string'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'nx/src/internal-testing-utils/mock-project-graph';

import {
addProjectConfiguration,
readJson,
Expand Down
2 changes: 2 additions & 0 deletions packages/cypress/src/generators/init/init.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'nx/src/internal-testing-utils/mock-project-graph';

import { NxJsonConfiguration, readJson, Tree, updateJson } from '@nx/devkit';
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';

Expand Down
65 changes: 33 additions & 32 deletions packages/cypress/src/generators/init/init.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import {
addDependenciesToPackageJson,
createProjectGraphAsync,
formatFiles,
GeneratorCallback,
ProjectGraph,
readNxJson,
removeDependenciesFromPackageJson,
runTasksInSerial,
Tree,
updateNxJson,
} from '@nx/devkit';
import { updatePackageScripts } from '@nx/devkit/src/utils/update-package-scripts';
import {
addPlugin as _addPlugin,
generateCombinations,
} from '@nx/devkit/src/utils/add-plugin';
import { createNodes } from '../../plugins/plugin';
import { cypressVersion, nxVersion } from '../../utils/versions';
import { Schema } from './schema';
Expand Down Expand Up @@ -55,30 +60,28 @@ function updateDependencies(tree: Tree, options: Schema) {
return runTasksInSerial(...tasks);
}

export function addPlugin(tree: Tree) {
const nxJson = readNxJson(tree);
nxJson.plugins ??= [];

for (const plugin of nxJson.plugins) {
if (
typeof plugin === 'string'
? plugin === '@nx/cypress/plugin'
: plugin.plugin === '@nx/cypress/plugin'
) {
return;
}
}

nxJson.plugins.push({
plugin: '@nx/cypress/plugin',
options: {
targetName: 'e2e',
componentTestingTargetName: 'component-test',
ciTargetName: 'e2e-ci',
openTargetName: 'open-cypress',
} as CypressPluginOptions,
});
updateNxJson(tree, nxJson);
export function addPlugin(
tree: Tree,
graph: ProjectGraph,
updatePackageScripts: boolean
) {
return _addPlugin(
tree,
graph,
'@nx/cypress/plugin',
createNodes,
{
ciTargetName: ['e2e-ci', 'cypress:e2e-ci', 'cypress-e2e-ci'],
openTargetName: ['open-cypress', 'cypress-open'],
componentTestingTargetName: [
'component-test',
'cypress:component-test',
'cypress-component-test',
],
targetName: ['e2e', 'cypress:e2e', 'cypress-e2e'],
},
updatePackageScripts
);
}

function updateProductionFileset(tree: Tree) {
Expand Down Expand Up @@ -115,7 +118,11 @@ export async function cypressInitGeneratorInternal(
nxJson.useInferencePlugins !== false;

if (options.addPlugin) {
addPlugin(tree);
await addPlugin(
tree,
await createProjectGraphAsync(),
options.updatePackageScripts
);
} else {
setupE2ETargetDefaults(tree);
}
Expand All @@ -125,12 +132,6 @@ export async function cypressInitGeneratorInternal(
installTask = updateDependencies(tree, options);
}

if (options.updatePackageScripts) {
global.NX_CYPRESS_INIT_GENERATOR_RUNNING = true;
await updatePackageScripts(tree, createNodes);
global.NX_CYPRESS_INIT_GENERATOR_RUNNING = false;
}

if (!options.skipFormat) {
await formatFiles(tree);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'nx/src/internal-testing-utils/mock-project-graph';

import {
addProjectConfiguration,
joinPathFragments,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'nx/src/internal-testing-utils/mock-project-graph';

import {
addProjectConfiguration,
readProjectConfiguration,
Expand All @@ -8,6 +10,7 @@ import { libraryGenerator } from '@nx/js';
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
import updateToCypress11 from './cypress-11';
import { installedCypressVersion } from '../../utils/cypress-version';

jest.mock('../../utils/cypress-version');
import cypressComponentConfiguration from '../../generators/component-configuration/component-configuration';

Expand All @@ -21,7 +24,6 @@ describe('Cypress 11 Migration', () => {

beforeEach(() => {
tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });
jest.resetAllMocks();
});

it('should not update if cypress <v10 is used', async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'nx/src/internal-testing-utils/mock-project-graph';

import {
Tree,
readJson,
Expand Down
2 changes: 2 additions & 0 deletions packages/detox/src/generators/application/application.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'nx/src/internal-testing-utils/mock-project-graph';

import {
addProjectConfiguration,
readJson,
Expand Down

0 comments on commit 123da37

Please sign in to comment.