Skip to content

Commit

Permalink
Merge pull request #14 from dman926/e2e-completion
Browse files Browse the repository at this point in the history
E2E Completion
  • Loading branch information
dman926 authored Nov 24, 2023
2 parents 62e0f23 + e36ac37 commit 3701576
Show file tree
Hide file tree
Showing 20 changed files with 2,296 additions and 258 deletions.
7 changes: 6 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
"overrides": [
{
"files": ["*.ts", "*.tsx"],
"rules": {}
"rules": {
"@typescript-eslint/no-unused-vars": [
"error",
{ "varsIgnorePattern": "^_" }
]
}
},
{
"files": ["*.js", "*.jsx"],
Expand Down
24 changes: 9 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# @dman926/nx-python-pdm

[![LICENSE](https://img.shields.io/badge/license-MIT-green)](https://github.com/dman926/nx-python-pdm/blob/main/LICENSE)
[![CI](https://github.com/dman926/nx-python-pdm/actions/workflows/ci.yml/badge.svg)](https://github.com/dman926/nx-python-pdm/actions/workflows/ci.yml)
[![npm (scoped with tag)](https://img.shields.io/npm/v/%40dman926/nx-python-pdm/latest)](https://www.npmjs.com/package/@dman926/nx-python-pdm)
[![GitHub package.json version (branch)](https://img.shields.io/github/package-json/v/dman926/nx-python-pdm/main)](https://github.com/dman926/nx-python-pdm/blob/main/package.json)
[![CI](https://github.com/dman926/nx-python-pdm/actions/workflows/ci.yml/badge.svg)](https://github.com/dman926/nx-python-pdm/actions/workflows/ci.yml)

Use Python in NX workspaces with PDM

Expand Down Expand Up @@ -49,10 +50,9 @@ yarn add -D @dman926/nx-python-pdm
- setuptools
- flot
- hatchling
- ~~separateE2eProject: Scaffold the E2E configuration in a separate project. Defaults to `true`.~~ _In progress_
- e2eTestRunner: The tool to use for running E2E tests.
- _In progress. This technically works for having a runner and target added to the project directly, but it is untested and needs a flag and a generator to be added to create it as a separate E2E project. Also the generator will not create the e2e target if you pick robotframework, but it will install it._
- cypress
- playwright
- robotframework
- linter: The tool to use for running lint checks.
- pylint
Expand All @@ -67,25 +67,19 @@ yarn add -D @dman926/nx-python-pdm
- unitTestRunner: The tool to use for running unit tests.
- unittest (default)
- pytest
- directory: A diretory where the project is placed.
- directory: A directory where the project is placed.
- e2eDirectory: A directory where the E2E project is placed, Only used when separateE2eProject is used.
- separateE2eProject: Scaffold the E2E configuration in a separate project. Defaults to `true`.
- e2eBundler: The bundler to use for running E2E tests. Only applies to cypress and playwright.
- tags: Add tags to the project (used for linting).

### Targets

- build: Build the project with PDM and move the built files to `dist/{project}/`
- serve: Run `src/main.py` with PDM.
- build: Build the project with PDM and move the built files to `dist/{projectRoot}/`
- serve: Run `src` with PDM.
- test: Run unit tests with the selected unit test runner.
- lint: Run lint checks with the selected linter.
- typeCheck: Run type checks with the selected tool.
- e2e: Run end-to-end tests with the selected test runner.
- _In progress. It technically works, but it is missing tests. It's also not created automatically by the python generator except for cypress_
- pdm: Allows running arbitrary PDM commands in the project through NX.
- See [Executors](#Executors) for examples.

### TODOs

- Add [monorepo support](https://pdm.fming.dev/latest/usage/advanced/#use-pdm-to-manage-a-monorepo)
- Complete work for E2E configurations.
- In-project cypress configuration is included
- In-project robotframework is installed, but not configured
- External E2E projects feature is not included.
75 changes: 72 additions & 3 deletions e2e/tests/generator/python.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@ projectTypes.forEach((projectType) => {
const baseOptions = {
name: '',
projectType,
separateE2eProject: false,
tags: ['E2E-TESTING'],
};

// I'm lazy
const options = () => getOptionString(baseOptions);
const options = (overrides: object = {}) =>
getOptionString({ ...baseOptions, ...overrides });

beforeAll(() => {
ensureNxProject('@dman926/nx-python-pdm', 'dist/@dman926/nx-python-pdm');
Expand Down Expand Up @@ -57,7 +60,7 @@ projectTypes.forEach((projectType) => {
const baseDir = await getProjectRoot(name);
expect(() => {
checkFilesExist(
...['src/main.py', 'pyproject.toml'].map((el) =>
...['src/__main__.py', 'pyproject.toml'].map((el) =>
joinPathFragments(baseDir, el)
)
);
Expand Down Expand Up @@ -237,7 +240,73 @@ projectTypes.forEach((projectType) => {
});

describe('e2e target', () => {
// TODO
[
{
testName: 'when no E2E test runner is specified',
projectName: 'no-e2e-target',
command: '',
},
{
testName: 'when e2eTestRunner: "none" is specified',
projectName: 'no-e2e-target',
command: ' --e2eTestRunner none',
},
].forEach(({ testName, projectName, command }) => {
it(`should not include an e2e target ${testName}`, async () => {
const name = uniq(`${projectName}-target-test`);
baseOptions.name = name;
await runNxCommandAsync(
`generate @dman926/nx-python-pdm:python ${options()}${command} --no-interactive`
);
names.push(name);

let output = '';
// Disable the console as it is expected to throw and NX will log it
// eslint-disable-next-line @typescript-eslint/no-empty-function
jest.spyOn(console, 'log').mockImplementation(() => {});
expect(() => {
output = runNxCommand(`e2e ${name}`);
}).toThrowWithAdditional(undefined, output);

jest.spyOn(console, 'log').mockRestore();
});
});

['cypress', 'playwright', 'robotframework'].forEach((e2eTestRunner) => {
[true, false].forEach((doSeparateE2eProject) => {
it(
`should be able to run E2E on generated projects with ${e2eTestRunner} ${
doSeparateE2eProject
? 'in a separate project'
: 'in the same project'
}`,
async () => {
const name = uniq(
`${e2eTestRunner}-${doSeparateE2eProject}-e2e-target-test`
);
baseOptions.name = name;
await runNxCommandAsync(
`generate @dman926/nx-python-pdm:python ${options({
separateE2eProject: doSeparateE2eProject,
})} --e2eTestRunner ${e2eTestRunner} --no-interactive`
);
names.push(name);

let desiredName = name;
if (doSeparateE2eProject) {
desiredName = `${name}-e2e`;
names.push(desiredName);
}

let output = '';
expect(() => {
output = runNxCommand(`e2e ${desiredName} --quiet`);
}).not.toThrowWithAdditional(undefined, output);
},
25 * 1000
);
});
});
});
});
});
3 changes: 2 additions & 1 deletion nx.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"cache": true,
"inputs": ["default", "^production", "{workspaceRoot}/jest.preset.js"],
"options": {
"passWithNoTests": true
"passWithNoTests": true,
"coverageReporters": ["clover", "json", "lcov", "text"]
},
"configurations": {
"ci": {
Expand Down
9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
"@nx/eslint-plugin": "17.1.3",
"@nx/jest": "17.1.3",
"@nx/js": "17.1.3",
"@nx/playwright": "^17.1.3",
"@nx/plugin": "17.1.3",
"@nx/workspace": "17.1.3",
"@playwright/test": "^1.40.0",
"@swc-node/register": "1.6.8",
"@swc/cli": "~0.1.63",
"@swc/core": "1.3.95",
Expand All @@ -30,6 +32,7 @@
"@typescript-eslint/eslint-plugin": "6.12.0",
"@typescript-eslint/parser": "6.12.0",
"chalk": "^5.3.0",
"cypress": "^13.6.0",
"eslint": "8.46.0",
"eslint-config-prettier": "9.0.0",
"jest": "^29.7.0",
Expand All @@ -39,11 +42,13 @@
"prettier": "^2.8.8",
"ts-jest": "^29.1.1",
"ts-node": "10.9.1",
"typescript": "5.2.2"
"typescript": "5.2.2",
"vite": "^5.0.2"
},
"peerDependencies": {
"@nx/cypress": "17.1.3",
"@nx/eslint": "17.1.3"
"@nx/eslint": "17.1.3",
"@nx/playwright": "17.1.3"
},
"peerDependenciesMeta": {
"@nx/cypress": {
Expand Down
Loading

0 comments on commit 3701576

Please sign in to comment.