Skip to content

Commit

Permalink
chore(core): update e2e tests to read from dep-graph --file instead…
Browse files Browse the repository at this point in the history
… of unstable cache file

Signed-off-by: AgentEnder <craigorycoppola@gmail.com>
  • Loading branch information
AgentEnder committed Sep 27, 2021
1 parent 992216d commit 2da1169
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
6 changes: 2 additions & 4 deletions e2e/core-e2e/tests/nx-dotnet.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { join } from 'path';
import { XmlDocument } from 'xmldoc';

import { findProjectFileInPathSync } from '@nx-dotnet/utils';
import { readDependenciesFromNxCache } from '@nx-dotnet/utils/e2e';
import { readDependenciesFromNxDepGraph } from '@nx-dotnet/utils/e2e';
import { execSync } from 'child_process';
import { ensureDirSync } from 'fs-extra';

Expand Down Expand Up @@ -65,7 +65,7 @@ describe('nx-dotnet e2e', () => {
'print-affected --target build --base HEAD~1',
);

const deps = await readDependenciesFromNxCache(
const deps = await readDependenciesFromNxDepGraph(
join(__dirname, '../../../', e2eDir),
testApp,
);
Expand Down Expand Up @@ -224,8 +224,6 @@ describe('nx-dotnet e2e', () => {

const workspace = readJson<WorkspaceJsonConfiguration>('workspace.json');

console.log('workspace', workspace);

expect(workspace.projects[testApp].targets?.serve).toBeDefined();
expect(workspace.projects[testApp].targets?.build).toBeDefined();
expect(workspace.projects[testApp].targets?.lint).toBeDefined();
Expand Down
25 changes: 15 additions & 10 deletions packages/utils/src/lib/utility-functions/e2e/nx.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
import { readJson } from 'fs-extra';
import { readJson, remove } from 'fs-extra';
import { join } from 'path';
import { execSync } from 'child_process';

export async function readDependenciesFromNxCache(
export async function readDependenciesFromNxDepGraph(
workspaceRoot: string,
project: string,
) {
const depGraphCachePath = join(
workspaceRoot,
'node_modules/.cache/nx/nxdeps.json',
);
const depGraphFile = join('tmp', 'dep-graph.json');
execSync(`npx nx dep-graph --file ${depGraphFile}`, {
cwd: workspaceRoot,
stdio: 'inherit',
});
const absolutePath = join(workspaceRoot, depGraphFile);
const { graph } = await readJson(absolutePath);
await remove(absolutePath);

const files: Array<{ file: string; deps: string[] }> = (
await readJson(depGraphCachePath)
).nodes[project].data.files;
return new Set(files.flatMap((x) => x.deps));
const deps: Array<{ source: string; target: string }> =
graph.dependencies[project];
console.log('[E2E]: Found dependencies', deps);
return new Set(deps.map((x) => x.target));
}
4 changes: 2 additions & 2 deletions smoke/core/tests/nx-dotnet.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ensureDirSync } from 'fs-extra';
import { join } from 'path';

import { rimraf } from '@nx-dotnet/utils';
import { readDependenciesFromNxCache } from '@nx-dotnet/utils/e2e';
import { readDependenciesFromNxDepGraph } from '@nx-dotnet/utils/e2e';

const smokeDirectory = 'tmp/smoke-core';
const execSyncOptions: ExecSyncOptions = {
Expand Down Expand Up @@ -49,7 +49,7 @@ describe('nx-dotnet smoke', () => {
stdio: 'ignore',
});

const deps = await readDependenciesFromNxCache(
const deps = await readDependenciesFromNxDepGraph(
join(smokeDirectory, 'test'),
testApp,
);
Expand Down

0 comments on commit 2da1169

Please sign in to comment.