Skip to content

Commit

Permalink
feat(core): add memfs util, add rust install for macos on circle
Browse files Browse the repository at this point in the history
  • Loading branch information
Cammisuli authored and FrozenPandaz committed Jan 30, 2023
1 parent 025d986 commit 7a9e952
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 10 deletions.
1 change: 1 addition & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ jobs:
NX_E2E_CI_CACHE_KEY: e2e-circleci-macos
NX_DAEMON: 'true'
steps:
- rust/install
- run:
name: Set dynamic nx run variable
command: |
Expand Down
2 changes: 1 addition & 1 deletion nx.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
"outputs": ["{options.outputPath}"]
},
"test": {
"dependsOn": ["^build-native"],
"dependsOn": ["build-native", "^build-native"],
"inputs": ["default", "^production", "{workspaceRoot}/jest.preset.js"],
"executor": "@nrwl/jest:jest",
"options": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'nx/src/utils/testing/mock-fs';

import type { FileData, ProjectGraph } from '@nrwl/devkit';
import { DependencyType } from '@nrwl/devkit';
import * as parser from '@typescript-eslint/parser';
Expand All @@ -9,8 +11,6 @@ import enforceModuleBoundaries, {
} from '../../src/rules/enforce-module-boundaries';
import { createProjectRootMappings } from 'nx/src/project-graph/utils/find-project-for-path';

jest.mock('fs', () => require('memfs').fs);

jest.mock('@nrwl/devkit', () => ({
...jest.requireActual<any>('@nrwl/devkit'),
workspaceRoot: '/root',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'nx/src/utils/testing/mock-fs';

import {
getUpdatedPackageJsonContent,
updatePackageJson,
Expand All @@ -10,7 +12,6 @@ import { DependentBuildableProjectNode } from '@nrwl/workspace/src/utilities/bui
jest.mock('nx/src/utils/workspace-root', () => ({
workspaceRoot: '/root',
}));
jest.mock('fs', () => require('memfs').fs);

describe('getUpdatedPackageJsonContent', () => {
it('should update fields for commonjs only (default)', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/next/src/utils/config.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'nx/src/utils/testing/mock-fs';
import { createWebpackConfig, prepareConfig } from './config';
import { NextBuildBuilderOptions } from '@nrwl/next';
import { dirname } from 'path';
Expand All @@ -15,7 +16,6 @@ jest.mock('next/dist/server/config', () => ({
webpack: () => ({}),
}),
}));
jest.mock('fs', () => require('memfs').fs);

describe('Next.js webpack config builder', () => {
beforeEach(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import '../../utils/testing/mock-fs';
import { buildExplicitPackageJsonDependencies } from './explicit-package-json-dependencies';
import { vol } from 'memfs';
import { createProjectFileMap } from '../file-map-utils';
Expand All @@ -8,7 +9,6 @@ import {
} from '../../config/project-graph';
import { ProjectGraphBuilder } from '../project-graph-builder';

jest.mock('fs', () => require('memfs').fs);
jest.mock('nx/src/utils/workspace-root', () => ({
workspaceRoot: '/root',
}));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import '../../utils/testing/mock-fs';
import { vol } from 'memfs';
import { defaultFileHasher } from '../../hasher/file-hasher';
import { createProjectFileMap } from '../file-map-utils';
import { ProjectGraphBuilder } from '../project-graph-builder';
import { buildExplicitTypeScriptDependencies } from './explicit-project-dependencies';

jest.mock('fs', () => require('memfs').fs);
jest.mock('nx/src/utils/workspace-root', () => ({
workspaceRoot: '/root',
}));
Expand Down
5 changes: 3 additions & 2 deletions packages/nx/src/project-graph/build-project-graph.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import '../utils/testing/mock-fs';

import { vol, fs } from 'memfs';

jest.mock('fs', () => require('memfs').fs);
jest.mock('../utils/workspace-root', () => ({
jest.mock('nx/src/utils/workspace-root', () => ({
workspaceRoot: '/root',
}));
import { buildProjectGraph } from './build-project-graph';
Expand Down
14 changes: 14 additions & 0 deletions packages/nx/src/utils/testing/mock-fs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// @ts-ignore
jest.mock('fs', (): Partial<typeof import('fs')> => {
const mockFs = require('memfs').fs;
return {
...mockFs,
existsSync(path: string) {
if (path.endsWith('.node')) {
return true;
} else {
return mockFs.existsSync(path);
}
},
};
});
3 changes: 2 additions & 1 deletion packages/nx/tsconfig.spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"**/*.spec.js",
"**/*.spec.jsx",
"**/*.d.ts",
"jest.config.ts"
"jest.config.ts",
"src/utils/testing/mock-fs.ts"
]
}

0 comments on commit 7a9e952

Please sign in to comment.