Skip to content

Commit

Permalink
chore(misc): review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
AgentEnder committed May 31, 2024
1 parent 88fa1c4 commit 6f09598
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
3 changes: 0 additions & 3 deletions packages/jest/src/plugins/plugin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { join } from 'path';

import { createNodes } from './plugin';
import { TempFs } from 'nx/src/internal-testing-utils/temp-fs';
import { setWorkspaceRoot } from 'nx/src/utils/workspace-root';

describe('@nx/jest/plugin', () => {
let createNodesFunction = createNodes[1];
Expand All @@ -26,8 +25,6 @@ describe('@nx/jest/plugin', () => {
configFiles: [],
};

setWorkspaceRoot(tempFs.tempDir);

await tempFs.createFiles({
'proj/jest.config.js': `module.exports = {}`,
'proj/src/unit.spec.ts': '',
Expand Down
4 changes: 2 additions & 2 deletions packages/nest/src/generators/filter/filter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ describe('filter generator', () => {

beforeEach(() => {
tree = createTreeWithNestApplication(project);
jest.clearAllMocks();
});

it('should run successfully', async () => {
await filterGenerator(tree, options);
expect(true).toBe(true);
await expect(filterGenerator(tree, options)).resolves.not.toThrowError();
});
});
2 changes: 0 additions & 2 deletions packages/vite/src/plugins/plugin.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { CreateNodesContext } from '@nx/devkit';
import { createNodes } from './plugin';
import { TempFs } from 'nx/src/internal-testing-utils/temp-fs';
import { setWorkspaceRoot } from 'nx/src/utils/workspace-root';

jest.mock('vite', () => ({
resolveConfig: jest.fn().mockImplementation(() => {
Expand Down Expand Up @@ -47,7 +46,6 @@ describe('@nx/vite/plugin', () => {
},
workspaceRoot: tempFs.tempDir,
};
setWorkspaceRoot(tempFs.tempDir);
tempFs.createFileSync('index.html', '');
tempFs.createFileSync('package.json', '');
});
Expand Down
22 changes: 21 additions & 1 deletion scripts/unit-test-setup.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,27 @@
module.exports = () => {
/**
* When the daemon is enabled during unit tests,
* and the daemon is already running, the daemon-client.ts
* code will be used, but it will hit the already running
* daemon which is from the installed version of Nx.
*
* In the vast majority of cases, this is fine. However,
* if a new message type has been added to the daemon in
* the source code, and isn't yet in the installed version,
* any test that hits that codepath will fail. This is because
* the installed version of the daemon doesn't know how to
* handle the new message type.
*
* To prevent this, we disable the daemon during unit tests.
*/
process.env.NX_DAEMON = 'false';

// Prevents tests from relying on the Nx repo project graph
/**
* When `createProjectGraphAsync` is called during tests,
* if its not mocked, it will return the Nx repo's project
* graph. We don't want any unit tests to depend on the structure
* of the Nx repo, so we mock it to return an empty project graph.
*/
jest.doMock('@nx/devkit', () => ({
...jest.requireActual('@nx/devkit'),
createProjectGraphAsync: jest.fn().mockImplementation(async () => {
Expand Down

0 comments on commit 6f09598

Please sign in to comment.