Skip to content

Commit

Permalink
fix(core): infer-projects should work with nx daemon (#383)
Browse files Browse the repository at this point in the history
* fix(core): infer-projects should work with nx daemon

* chore(core): reenable disabled e2e tests
  • Loading branch information
AgentEnder authored Feb 28, 2022
1 parent 266e06c commit acf47cf
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 27 deletions.
47 changes: 22 additions & 25 deletions e2e/core-e2e/tests/nx-dotnet.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
listFiles,
readFile,
readJson,
runCommand,
runNxCommand,
runNxCommandAsync,
tmpProjPath,
Expand All @@ -18,7 +19,7 @@ import { XmlDocument } from 'xmldoc';

import { findProjectFileInPathSync } from '@nx-dotnet/utils';
import { readDependenciesFromNxDepGraph } from '@nx-dotnet/utils/e2e';
import { exec, execSync } from 'child_process';
import { execSync } from 'child_process';
import { ensureDirSync } from 'fs-extra';
import { Workspaces } from '@nrwl/tao/src/shared/workspace';

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

xit('should create apps, libs, and project references', async () => {
it('should create apps, libs, and project references', async () => {
const testApp = uniq('app');
const testLib = uniq('lib');

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

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

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

const output = await runNxCommandAsync('print-affected --target build');

const deps = await readDependenciesFromNxDepGraph(
join(__dirname, '../../../', e2eDir),
testApp,
);

expect(output.stderr).toBeFalsy();
const deps = await readDependenciesFromNxDepGraph(join(e2eDir), testApp);
expect(deps).toContain(testLib);
runCommand('git checkout main');
}, 150000);

xdescribe('nx g app', () => {
describe('nx g app', () => {
it('should obey dry-run', async () => {
const app = uniq('app');
await runNxCommandAsync(
Expand Down Expand Up @@ -157,7 +153,7 @@ describe('nx-dotnet e2e', () => {
});
});

xdescribe('nx g test', () => {
describe('nx g test', () => {
it('should add a reference to the target project', async () => {
const app = uniq('app');
await runNxCommandAsync(
Expand Down Expand Up @@ -203,7 +199,7 @@ describe('nx-dotnet e2e', () => {
});
});

xdescribe('nx g lib', () => {
describe('nx g lib', () => {
it('should obey dry-run', async () => {
const lib = uniq('lib');
await runNxCommandAsync(
Expand All @@ -223,7 +219,7 @@ describe('nx-dotnet e2e', () => {
});
});

xdescribe('nx g import-projects', () => {
describe('nx g import-projects', () => {
it('should import apps, libs, and test', async () => {
const testApp = uniq('app');
const testLib = uniq('lib');
Expand Down Expand Up @@ -257,7 +253,7 @@ describe('nx-dotnet e2e', () => {
});
});

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

xit('should work without workspace.json or project.json', () => {
const workspaceJsonContents = readJson('workspace.json');
it('should work without workspace.json or project.json', () => {
const workspaceJsonContents = readFile('workspace.json');
unlinkSync(join(e2eDir, 'workspace.json'));

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

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

updateFile(join(projectFolder, 'project.json'), projectJsonContents);
writeFileSync(join(projectFolder, 'project.json'), projectJsonContents);
});
});
});

function initializeGitRepo(cwd: string) {
execSync('git init', { cwd });
execSync('git config user.email no-one@some-website.com', { cwd });
execSync('git config user.name CI-Bot', { cwd });
execSync('git add .', { cwd });
execSync('git commit -m "initial commit"', { cwd });
runCommand('git init');
runCommand('git branch -m main');
runCommand('git config user.email no-one@some-website.com');
runCommand('git config user.name CI-Bot');
runCommand('git add .');
runCommand('git commit -m "initial commit"');
}
10 changes: 8 additions & 2 deletions packages/core/src/graph/infer-project.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { TargetConfiguration } from '@nrwl/devkit';
import { appRootPath } from '@nrwl/tao/src/utils/app-root';

import { readFileSync } from 'fs';
import { dirname } from 'path';
import { dirname, resolve } from 'path';

import {
GetBuildExecutorConfiguration,
GetLintExecutorConfiguration,
Expand All @@ -12,7 +15,10 @@ export const projectFilePatterns = ['*.csproj', '*.fsproj', '*.vbproj'];

export const registerProjectTargets = (projectFile: string) => {
const targets: Record<string, TargetConfiguration> = {};
const projectFileContents = readFileSync(projectFile, 'utf8');
const projectFileContents = readFileSync(
resolve(appRootPath, projectFile),
'utf8',
);
if (projectFileContents.includes('Microsoft.NET.Test.Sdk')) {
targets['test'] = GetTestExecutorConfig();
}
Expand Down

0 comments on commit acf47cf

Please sign in to comment.