-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(testing): add lint target for playwright (#18233)
- Loading branch information
Showing
10 changed files
with
161 additions
and
14 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
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
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
1 change: 1 addition & 0 deletions
1
packages/playwright/src/generators/configuration/files/playwright.config.ts.template
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import { | ||
addDependenciesToPackageJson, | ||
GeneratorCallback, | ||
joinPathFragments, | ||
readProjectConfiguration, | ||
runTasksInSerial, | ||
Tree, | ||
updateJson, | ||
} from '@nx/devkit'; | ||
import { Linter, lintProjectGenerator } from '@nx/linter'; | ||
import { globalJavaScriptOverrides } from '@nx/linter/src/generators/init/global-eslint-config'; | ||
import { eslintPluginPlaywrightVersion } from './versions'; | ||
|
||
export interface PlaywrightLinterOptions { | ||
project: string; | ||
linter: Linter; | ||
setParserOptionsProject: boolean; | ||
skipPackageJson: boolean; | ||
rootProject: boolean; | ||
js?: boolean; | ||
/** | ||
* Directory from the project root, where the playwright files will be located. | ||
**/ | ||
directory: string; | ||
} | ||
|
||
export async function addLinterToPlaywrightProject( | ||
tree: Tree, | ||
options: PlaywrightLinterOptions | ||
): Promise<GeneratorCallback> { | ||
if (options.linter === Linter.None) { | ||
return () => {}; | ||
} | ||
|
||
const tasks: GeneratorCallback[] = []; | ||
const projectConfig = readProjectConfiguration(tree, options.project); | ||
|
||
if (!tree.exists(joinPathFragments(projectConfig.root, '.eslintrc.json'))) { | ||
tasks.push( | ||
await lintProjectGenerator(tree, { | ||
project: options.project, | ||
linter: options.linter, | ||
skipFormat: true, | ||
tsConfigPaths: [joinPathFragments(projectConfig.root, 'tsconfig.json')], | ||
eslintFilePatterns: [ | ||
`${projectConfig.root}/**/*.${options.js ? 'js' : '{js,ts}'}`, | ||
], | ||
setParserOptionsProject: options.setParserOptionsProject, | ||
skipPackageJson: options.skipPackageJson, | ||
rootProject: options.rootProject, | ||
}) | ||
); | ||
} | ||
|
||
if (!options.linter || options.linter !== Linter.EsLint) { | ||
return runTasksInSerial(...tasks); | ||
} | ||
|
||
tasks.push( | ||
!options.skipPackageJson | ||
? addDependenciesToPackageJson( | ||
tree, | ||
{}, | ||
{ 'eslint-plugin-playwright': eslintPluginPlaywrightVersion } | ||
) | ||
: () => {} | ||
); | ||
|
||
updateJson( | ||
tree, | ||
joinPathFragments(projectConfig.root, '.eslintrc.json'), | ||
(json) => { | ||
if (options.rootProject) { | ||
json.plugins = ['@nx']; | ||
json.extends = ['plugin:playwright/recommended']; | ||
} else { | ||
json.extends = ['plugin:playwright/recommended', ...json.extends]; | ||
} | ||
json.overrides ??= []; | ||
const globals = options.rootProject ? [globalJavaScriptOverrides] : []; | ||
const override = { | ||
files: ['*.ts', '*.tsx', '*.js', '*.jsx'], | ||
parserOptions: !options.setParserOptionsProject | ||
? undefined | ||
: { | ||
project: `${projectConfig.root}/tsconfig.*?.json`, | ||
}, | ||
rules: {}, | ||
}; | ||
const palywrightFiles = [ | ||
{ | ||
...override, | ||
files: [`${options.directory}/**/*.{ts,js,tsx,jsx}`], | ||
}, | ||
]; | ||
json.overrides.push(...globals); | ||
json.overrides.push(...palywrightFiles); | ||
return json; | ||
} | ||
); | ||
|
||
return runTasksInSerial(...tasks); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export const nxVersion = require('../../package.json').version; | ||
export const playwrightVersion = '^1.36.0'; | ||
export const eslintPluginPlaywrightVersion = '^0.15.3'; |
8407d7a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
nx-dev – ./
nx-dev-git-master-nrwl.vercel.app
nx-five.vercel.app
nx-dev-nrwl.vercel.app
nx.dev