-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(plugin-eslint): integration test for Nx helper with mock monorepo
- Loading branch information
1 parent
003e0c1
commit 6c1edb0
Showing
22 changed files
with
311 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# exclude mock Nx monorepos used for testing | ||
mocks |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.nx/cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"pluginsConfig": { | ||
"@nrwl/js": { | ||
"analyzeSourceFiles": true | ||
} | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
packages/plugin-eslint/mocks/fixtures/nx-monorepo/packages/cli/.eslintrc.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"extends": ["../../.eslintrc.json"], | ||
"ignorePatterns": ["!**/*"], | ||
"overrides": [ | ||
{ | ||
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"], | ||
"rules": {} | ||
}, | ||
{ | ||
"files": ["*.ts", "*.tsx"], | ||
"rules": {} | ||
}, | ||
{ | ||
"files": ["*.js", "*.jsx"], | ||
"rules": {} | ||
}, | ||
{ | ||
"files": ["*.json"], | ||
"parser": "jsonc-eslint-parser", | ||
"rules": { | ||
"@nx/dependency-checks": ["error"] | ||
} | ||
} | ||
] | ||
} |
17 changes: 17 additions & 0 deletions
17
packages/plugin-eslint/mocks/fixtures/nx-monorepo/packages/cli/project.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"name": "cli", | ||
"sourceRoot": "packages/cli/src", | ||
"projectType": "application", | ||
"targets": { | ||
"lint": { | ||
"executor": "@nx/linter:eslint", | ||
"outputs": ["{options.outputFile}"], | ||
"options": { | ||
"lintFilePatterns": [ | ||
"packages/cli/**/*.ts", | ||
"packages/cli/package.json" | ||
] | ||
} | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
packages/plugin-eslint/mocks/fixtures/nx-monorepo/packages/cli/src/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { exampleCore } from '@example/core'; | ||
|
||
exampleCore(); |
3 changes: 3 additions & 0 deletions
3
packages/plugin-eslint/mocks/fixtures/nx-monorepo/packages/cli/tsconfig.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"extends": "../../tsconfig.base.json" | ||
} |
25 changes: 25 additions & 0 deletions
25
packages/plugin-eslint/mocks/fixtures/nx-monorepo/packages/core/.eslintrc.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"extends": ["../../.eslintrc.json"], | ||
"ignorePatterns": ["!**/*"], | ||
"overrides": [ | ||
{ | ||
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"], | ||
"rules": {} | ||
}, | ||
{ | ||
"files": ["*.ts", "*.tsx"], | ||
"rules": {} | ||
}, | ||
{ | ||
"files": ["*.js", "*.jsx"], | ||
"rules": {} | ||
}, | ||
{ | ||
"files": ["*.json"], | ||
"parser": "jsonc-eslint-parser", | ||
"rules": { | ||
"@nx/dependency-checks": ["error"] | ||
} | ||
} | ||
] | ||
} |
17 changes: 17 additions & 0 deletions
17
packages/plugin-eslint/mocks/fixtures/nx-monorepo/packages/core/project.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"name": "core", | ||
"sourceRoot": "packages/core/src", | ||
"projectType": "library", | ||
"targets": { | ||
"lint": { | ||
"executor": "@nx/linter:eslint", | ||
"outputs": ["{options.outputFile}"], | ||
"options": { | ||
"lintFilePatterns": [ | ||
"packages/core/**/*.ts", | ||
"packages/core/package.json" | ||
] | ||
} | ||
} | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
packages/plugin-eslint/mocks/fixtures/nx-monorepo/packages/core/src/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { exampleSharedUtil } from '@example/utils'; | ||
|
||
export function exampleCore() { | ||
exampleSharedUtil(); | ||
} |
3 changes: 3 additions & 0 deletions
3
packages/plugin-eslint/mocks/fixtures/nx-monorepo/packages/core/tsconfig.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"extends": "../../tsconfig.base.json" | ||
} |
32 changes: 32 additions & 0 deletions
32
packages/plugin-eslint/mocks/fixtures/nx-monorepo/packages/nx-plugin/.eslintrc.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
"extends": ["../../.eslintrc.json"], | ||
"ignorePatterns": ["!**/*"], | ||
"overrides": [ | ||
{ | ||
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"], | ||
"rules": {} | ||
}, | ||
{ | ||
"files": ["*.ts", "*.tsx"], | ||
"rules": {} | ||
}, | ||
{ | ||
"files": ["*.js", "*.jsx"], | ||
"rules": {} | ||
}, | ||
{ | ||
"files": ["*.json"], | ||
"parser": "jsonc-eslint-parser", | ||
"rules": { | ||
"@nx/dependency-checks": ["error"] | ||
} | ||
}, | ||
{ | ||
"files": ["./package.json", "./generators.json"], | ||
"parser": "jsonc-eslint-parser", | ||
"rules": { | ||
"@nx/nx-plugin-checks": "error" | ||
} | ||
} | ||
] | ||
} |
18 changes: 18 additions & 0 deletions
18
packages/plugin-eslint/mocks/fixtures/nx-monorepo/packages/nx-plugin/project.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"name": "nx-plugin", | ||
"sourceRoot": "packages/nx-plugin/src", | ||
"projectType": "library", | ||
"targets": { | ||
"lint": { | ||
"executor": "@nx/linter:eslint", | ||
"outputs": ["{options.outputFile}"], | ||
"options": { | ||
"lintFilePatterns": [ | ||
"packages/nx-plugin/**/*.ts", | ||
"packages/nx-plugin/package.json", | ||
"packages/nx-plugin/generators.json" | ||
] | ||
} | ||
} | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
packages/plugin-eslint/mocks/fixtures/nx-monorepo/packages/nx-plugin/src/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { exampleSharedUtil } from '@example/utils'; | ||
|
||
export function exampleNxPlugin() { | ||
exampleSharedUtil(); | ||
} |
3 changes: 3 additions & 0 deletions
3
packages/plugin-eslint/mocks/fixtures/nx-monorepo/packages/nx-plugin/tsconfig.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"extends": "../../tsconfig.base.json" | ||
} |
17 changes: 17 additions & 0 deletions
17
packages/plugin-eslint/mocks/fixtures/nx-monorepo/packages/utils/project.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"name": "utils", | ||
"sourceRoot": "packages/utils/src", | ||
"projectType": "library", | ||
"targets": { | ||
"lint": { | ||
"executor": "@nx/linter:eslint", | ||
"outputs": ["{options.outputFile}"], | ||
"options": { | ||
"lintFilePatterns": [ | ||
"packages/utils/**/*.ts", | ||
"packages/utils/package.json" | ||
] | ||
} | ||
} | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
packages/plugin-eslint/mocks/fixtures/nx-monorepo/packages/utils/src/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export function exampleSharedUtil() {} |
3 changes: 3 additions & 0 deletions
3
packages/plugin-eslint/mocks/fixtures/nx-monorepo/packages/utils/tsconfig.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"extends": "../../tsconfig.base.json" | ||
} |
25 changes: 25 additions & 0 deletions
25
packages/plugin-eslint/mocks/fixtures/nx-monorepo/tsconfig.base.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"compileOnSave": false, | ||
"compilerOptions": { | ||
"rootDir": ".", | ||
"sourceMap": true, | ||
"declaration": false, | ||
"moduleResolution": "node", | ||
"emitDecoratorMetadata": true, | ||
"experimentalDecorators": true, | ||
"importHelpers": true, | ||
"target": "es2015", | ||
"module": "esnext", | ||
"lib": ["es2020", "dom"], | ||
"skipLibCheck": true, | ||
"skipDefaultLibCheck": true, | ||
"baseUrl": ".", | ||
"paths": { | ||
"@example/cli": ["packages/cli/src/index.ts"], | ||
"@example/core": ["packages/core/src/index.ts"], | ||
"@example/nx-plugin": ["packages/nx-plugin/src/index.ts"], | ||
"@example/utils": ["packages/utils/src/index.ts"] | ||
} | ||
}, | ||
"exclude": ["node_modules", "tmp"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import { setWorkspaceRoot } from 'nx/src/utils/workspace-root'; | ||
import { dirname, join } from 'path'; | ||
import { fileURLToPath } from 'url'; | ||
import type { SpyInstance } from 'vitest'; | ||
import { ESLintPluginConfig } from './config'; | ||
import { eslintConfigFromNxProjects } from './nx'; | ||
|
||
describe('Nx helpers', () => { | ||
let cwdSpy: SpyInstance; | ||
|
||
beforeAll(() => { | ||
const workspaceDir = join( | ||
fileURLToPath(dirname(import.meta.url)), | ||
'..', | ||
'..', | ||
'mocks', | ||
'fixtures', | ||
'nx-monorepo', | ||
); | ||
cwdSpy = vi.spyOn(process, 'cwd').mockReturnValue(workspaceDir); | ||
|
||
process.env['NX_DAEMON'] = 'false'; | ||
|
||
setWorkspaceRoot(workspaceDir); | ||
}); | ||
|
||
afterAll(() => { | ||
cwdSpy.mockRestore(); | ||
}); | ||
|
||
describe('create config from all Nx projects', () => { | ||
it('should include eslintrc and patterns of each project', async () => { | ||
await expect(eslintConfigFromNxProjects()).resolves.toEqual({ | ||
eslintrc: { | ||
root: true, | ||
overrides: [ | ||
{ | ||
files: ['packages/cli/**/*.ts', 'packages/cli/package.json'], | ||
extends: './packages/cli/.eslintrc.json', | ||
}, | ||
{ | ||
files: ['packages/core/**/*.ts', 'packages/core/package.json'], | ||
extends: './packages/core/.eslintrc.json', | ||
}, | ||
{ | ||
files: [ | ||
'packages/nx-plugin/**/*.ts', | ||
'packages/nx-plugin/package.json', | ||
'packages/nx-plugin/generators.json', | ||
], | ||
extends: './packages/nx-plugin/.eslintrc.json', | ||
}, | ||
{ | ||
files: ['packages/utils/**/*.ts', 'packages/utils/package.json'], | ||
extends: './packages/utils/.eslintrc.json', | ||
}, | ||
], | ||
}, | ||
patterns: [ | ||
'packages/cli/**/*.ts', | ||
'packages/cli/package.json', | ||
'packages/cli/src/*.spec.ts', | ||
'packages/cli/src/*.cy.ts', | ||
'packages/cli/src/*.stories.ts', | ||
'packages/cli/src/.storybook/main.ts', | ||
|
||
'packages/core/**/*.ts', | ||
'packages/core/package.json', | ||
'packages/core/src/*.spec.ts', | ||
'packages/core/src/*.cy.ts', | ||
'packages/core/src/*.stories.ts', | ||
'packages/core/src/.storybook/main.ts', | ||
|
||
'packages/nx-plugin/**/*.ts', | ||
'packages/nx-plugin/package.json', | ||
'packages/nx-plugin/generators.json', | ||
'packages/nx-plugin/src/*.spec.ts', | ||
'packages/nx-plugin/src/*.cy.ts', | ||
'packages/nx-plugin/src/*.stories.ts', | ||
'packages/nx-plugin/src/.storybook/main.ts', | ||
|
||
'packages/utils/**/*.ts', | ||
'packages/utils/package.json', | ||
'packages/utils/src/*.spec.ts', | ||
'packages/utils/src/*.cy.ts', | ||
'packages/utils/src/*.stories.ts', | ||
'packages/utils/src/.storybook/main.ts', | ||
], | ||
} satisfies ESLintPluginConfig); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters