Skip to content
This repository was archived by the owner on Apr 27, 2026. It is now read-only.

Commit acf47cf

Browse files
authored
fix(core): infer-projects should work with nx daemon (#383)
* fix(core): infer-projects should work with nx daemon * chore(core): reenable disabled e2e tests
1 parent 266e06c commit acf47cf

2 files changed

Lines changed: 30 additions & 27 deletions

File tree

e2e/core-e2e/tests/nx-dotnet.spec.ts

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
listFiles,
66
readFile,
77
readJson,
8+
runCommand,
89
runNxCommand,
910
runNxCommandAsync,
1011
tmpProjPath,
@@ -18,7 +19,7 @@ import { XmlDocument } from 'xmldoc';
1819

1920
import { findProjectFileInPathSync } from '@nx-dotnet/utils';
2021
import { readDependenciesFromNxDepGraph } from '@nx-dotnet/utils/e2e';
21-
import { exec, execSync } from 'child_process';
22+
import { execSync } from 'child_process';
2223
import { ensureDirSync } from 'fs-extra';
2324
import { Workspaces } from '@nrwl/tao/src/shared/workspace';
2425

@@ -30,7 +31,7 @@ describe('nx-dotnet e2e', () => {
3031
initializeGitRepo(e2eDir);
3132
}, 1500000);
3233

33-
xit('should create apps, libs, and project references', async () => {
34+
it('should create apps, libs, and project references', async () => {
3435
const testApp = uniq('app');
3536
const testLib = uniq('lib');
3637

@@ -49,9 +50,10 @@ describe('nx-dotnet e2e', () => {
4950
expect(output.stdout).toMatch(/Reference .* added to the project/);
5051
});
5152

52-
xit('should work with affected', async () => {
53+
it('should work with affected', async () => {
5354
const testApp = uniq('app');
5455
const testLib = uniq('lib');
56+
runCommand('git checkout -b "affected-tests"');
5557

5658
await runNxCommandAsync(
5759
`generate @nx-dotnet/core:app ${testApp} --language="C#" --template="webapi"`,
@@ -65,18 +67,12 @@ describe('nx-dotnet e2e', () => {
6567
`generate @nx-dotnet/core:project-reference ${testApp} ${testLib}`,
6668
);
6769

68-
const output = await runNxCommandAsync('print-affected --target build');
69-
70-
const deps = await readDependenciesFromNxDepGraph(
71-
join(__dirname, '../../../', e2eDir),
72-
testApp,
73-
);
74-
75-
expect(output.stderr).toBeFalsy();
70+
const deps = await readDependenciesFromNxDepGraph(join(e2eDir), testApp);
7671
expect(deps).toContain(testLib);
72+
runCommand('git checkout main');
7773
}, 150000);
7874

79-
xdescribe('nx g app', () => {
75+
describe('nx g app', () => {
8076
it('should obey dry-run', async () => {
8177
const app = uniq('app');
8278
await runNxCommandAsync(
@@ -157,7 +153,7 @@ describe('nx-dotnet e2e', () => {
157153
});
158154
});
159155

160-
xdescribe('nx g test', () => {
156+
describe('nx g test', () => {
161157
it('should add a reference to the target project', async () => {
162158
const app = uniq('app');
163159
await runNxCommandAsync(
@@ -203,7 +199,7 @@ describe('nx-dotnet e2e', () => {
203199
});
204200
});
205201

206-
xdescribe('nx g lib', () => {
202+
describe('nx g lib', () => {
207203
it('should obey dry-run', async () => {
208204
const lib = uniq('lib');
209205
await runNxCommandAsync(
@@ -223,7 +219,7 @@ describe('nx-dotnet e2e', () => {
223219
});
224220
});
225221

226-
xdescribe('nx g import-projects', () => {
222+
describe('nx g import-projects', () => {
227223
it('should import apps, libs, and test', async () => {
228224
const testApp = uniq('app');
229225
const testLib = uniq('lib');
@@ -257,7 +253,7 @@ describe('nx-dotnet e2e', () => {
257253
});
258254
});
259255

260-
xdescribe('solution handling', () => {
256+
describe('solution handling', () => {
261257
// For solution handling, defaults fall back to if a file exists.
262258
// This ensures that the tests are ran in a clean state, without previous
263259
// test projects interfering with the test.
@@ -360,11 +356,11 @@ describe('nx-dotnet e2e', () => {
360356
expect(() => runNxCommand(`build ${api}`)).not.toThrow();
361357
});
362358

363-
xit('should work without workspace.json or project.json', () => {
364-
const workspaceJsonContents = readJson('workspace.json');
359+
it('should work without workspace.json or project.json', () => {
360+
const workspaceJsonContents = readFile('workspace.json');
365361
unlinkSync(join(e2eDir, 'workspace.json'));
366362

367-
const projectJsonContents = readJson(
363+
const projectJsonContents = readFile(
368364
joinPathFragments('apps', api, 'project.json'),
369365
);
370366
unlinkSync(join(projectFolder, 'project.json'));
@@ -373,15 +369,16 @@ describe('nx-dotnet e2e', () => {
373369

374370
writeFileSync(join(e2eDir, 'workspace.json'), workspaceJsonContents);
375371

376-
updateFile(join(projectFolder, 'project.json'), projectJsonContents);
372+
writeFileSync(join(projectFolder, 'project.json'), projectJsonContents);
377373
});
378374
});
379375
});
380376

381377
function initializeGitRepo(cwd: string) {
382-
execSync('git init', { cwd });
383-
execSync('git config user.email no-one@some-website.com', { cwd });
384-
execSync('git config user.name CI-Bot', { cwd });
385-
execSync('git add .', { cwd });
386-
execSync('git commit -m "initial commit"', { cwd });
378+
runCommand('git init');
379+
runCommand('git branch -m main');
380+
runCommand('git config user.email no-one@some-website.com');
381+
runCommand('git config user.name CI-Bot');
382+
runCommand('git add .');
383+
runCommand('git commit -m "initial commit"');
387384
}

packages/core/src/graph/infer-project.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { TargetConfiguration } from '@nrwl/devkit';
2+
import { appRootPath } from '@nrwl/tao/src/utils/app-root';
3+
24
import { readFileSync } from 'fs';
3-
import { dirname } from 'path';
5+
import { dirname, resolve } from 'path';
6+
47
import {
58
GetBuildExecutorConfiguration,
69
GetLintExecutorConfiguration,
@@ -12,7 +15,10 @@ export const projectFilePatterns = ['*.csproj', '*.fsproj', '*.vbproj'];
1215

1316
export const registerProjectTargets = (projectFile: string) => {
1417
const targets: Record<string, TargetConfiguration> = {};
15-
const projectFileContents = readFileSync(projectFile, 'utf8');
18+
const projectFileContents = readFileSync(
19+
resolve(appRootPath, projectFile),
20+
'utf8',
21+
);
1622
if (projectFileContents.includes('Microsoft.NET.Test.Sdk')) {
1723
targets['test'] = GetTestExecutorConfig();
1824
}

0 commit comments

Comments
 (0)