Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(repo): add eslint and jest plugins to use inferred targets #22946

Merged
merged 12 commits into from
Apr 24, 2024

Conversation

jaysoo
Copy link
Member

@jaysoo jaysoo commented Apr 22, 2024

This PR adds @nx/eslint/plugin and @nx/jest/plugin to use inferred targets for lint and unit tests. The main changes are removing targets from project.json and nx.json. There is a fix in the patch-jest-resolver.js file to ensure that all modules are resolved to an absolute path, which is needed for jest.mock to work. A couple of snapshots are updated too with cwd changes.

Note: We can now run any Jest spec file from IDE since the executor and cwd are no longer assumed.

Copy link

vercel bot commented Apr 22, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Updated (UTC)
nx-dev ⬜️ Ignored (Inspect) Visit Preview Apr 23, 2024 9:36pm

@jaysoo jaysoo changed the title Crystalize jest eslint chore(repo): add eslint and jest plugins to use inferred targets Apr 22, 2024
@jaysoo jaysoo force-pushed the crystalize_jest_eslint branch 3 times, most recently from e548780 to 11fd6bd Compare April 22, 2024 22:44
@jaysoo jaysoo requested a review from a team as a code owner April 22, 2024 22:44
.nxignore Outdated Show resolved Hide resolved
@@ -28,7 +28,8 @@
"storybook/no-uninstalled-addons": [
"error",
{
"ignore": ["@nx/react/plugins/storybook"]
"ignore": ["@nx/react/plugins/storybook"],
"packageJsonLocation": "../../package.json"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to point the Storybook lint rule to the root package.json, or else it'll pick up the package one (e.g. packages/vue/package.json) which results in missing dependencies being reported.

path,
join(options.basedir, 'fake-placeholder.ts'),
compilerOptions,
host
).resolvedModule.resolvedFileName;
if (name.startsWith('..')) {
return path_1.join(options.rootDir, name);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the module is a package outside of the current project, then resolve it to an absolute path.

This ensures that jest.mock('@nx/devkit), for example, resolves to /Users/foo/projects/nx/packages/devkit/src/index.ts and not ../../../devkit/src/index.ts. The relative path is not compatiblewith jest.mock and will lead to modules being unmocked.

.nxignore Outdated Show resolved Hide resolved
nx.json Outdated Show resolved Hide resolved
@jaysoo jaysoo requested review from meeroslav and a team as code owners April 23, 2024 16:02
@@ -90,7 +89,9 @@ export default {
'no-template-curly-in-string': 'warn',
'no-this-before-super': 'warn',
'no-throw-literal': 'warn',
'no-restricted-globals': ['error'].concat(restrictedGlobals),
'no-restricted-globals': ['error'].concat(
require('confusing-browser-globals')
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because we point to source, the transpile here can lead to errors if we use the default import (due to ESM interopt). Safer to just use require since this package is CJS-only.

This is an Nx repo issue only.

@jaysoo jaysoo requested a review from a team as a code owner April 23, 2024 21:21
@jaysoo jaysoo requested a review from a team as a code owner April 23, 2024 21:34
@@ -31,8 +33,11 @@ describe('@nx/jest/plugin', () => {
});
});

test('foo', () => {});
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this.

@FrozenPandaz FrozenPandaz merged commit bc43243 into master Apr 24, 2024
6 checks passed
@FrozenPandaz FrozenPandaz deleted the crystalize_jest_eslint branch April 24, 2024 01:52
Copy link

github-actions bot commented May 1, 2024

This pull request has already been merged/closed. If you experience issues related to these changes, please open a new issue referencing this pull request.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 1, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants