Skip to content

Commit

Permalink
Improve template testing with newer cookieplone version (0.7.0)
Browse files Browse the repository at this point in the history
  • Loading branch information
ericof committed May 27, 2024
1 parent fd95dfd commit 1d36a31
Show file tree
Hide file tree
Showing 35 changed files with 149 additions and 113 deletions.
3 changes: 1 addition & 2 deletions backend_addon/cookiecutter.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,14 @@
"1",
"0"
],
"__feature_headless": "{{ cookiecutter.feature_headless }}",
"__package_name": "{{ cookiecutter.python_package_name | package_name }}",
"__package_namespace": "{{ cookiecutter.python_package_name | package_namespace }}",
"__folder_name": "{{ cookiecutter.python_package_name }}",
"__python_package_name_upper": "{{ cookiecutter.python_package_name | pascal_case }}",
"__profile_language": "en",
"__version_package": "1.0.0a0",
"__profile_version": "1000",
"__gha_enable": true,
"__generator_date_short": "{% now 'utc', '%Y-%m-%d' %}",
"__generator_date_long": "{% now 'utc', '%Y-%m-%d %H:%M:%S' %}",
"__generator_signature": "This was generated by [cookiecutter-plone](https://github.com/plone/cookieplone-templates/backend_addon) on {{ cookiecutter.__generator_date_long }}",
"__backend_addon_git_initialize": "1",
Expand Down
12 changes: 9 additions & 3 deletions backend_addon/hooks/post_gen_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,15 @@ def handle_git_initialization(context: OrderedDict, output_dir: Path):
def main():
"""Final fixes."""
output_dir = Path().cwd()
remove_headless = not int(context.get("feature_headless"))
initialize_git = bool(int(context.get("__backend_addon_git_initialize")))
backend_format = bool(int(context.get("__backend_addon_format")))
remove_headless = not int(
context.get("feature_headless")
) # {{ cookiecutter.__feature_headless }}
initialize_git = bool(
int(context.get("__backend_addon_git_initialize"))
) # {{ cookiecutter.__backend_addon_git_initialize }}
backend_format = bool(
int(context.get("__backend_addon_format"))
) # {{ cookiecutter.__backend_addon_format }}
# Cleanup / Git
actions = [
[
Expand Down
6 changes: 0 additions & 6 deletions backend_addon/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Pytest configuration."""

import re
from copy import deepcopy
from pathlib import Path
from typing import List
Expand Down Expand Up @@ -73,11 +72,6 @@ def cookieplone_root() -> dict:
return parent


@pytest.fixture(scope="session")
def variable_pattern():
return re.compile("{{( ?cookiecutter)[.](.*?)}}")


@pytest.fixture(scope="session")
def context(cookieplone_root) -> dict:
"""Cookiecutter context."""
Expand Down
14 changes: 14 additions & 0 deletions backend_addon/tests/test_variables.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
ALLOWED_MISSING = []
ALLOWED_NOT_USED = []


def test_no_missing_variables(variables_missing):
"""Test no variable is missing from cookiecutter.json"""
assert len(variables_missing) == len(ALLOWED_MISSING)
assert variables_missing == ALLOWED_MISSING


def test_not_used_variables(variables_not_used):
"""Test variables are used."""
assert len(variables_not_used) == len(ALLOWED_NOT_USED)
assert variables_not_used == ALLOWED_NOT_USED
4 changes: 4 additions & 0 deletions backend_addon/{{ cookiecutter.__folder_name }}/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,7 @@ make create_site
## License

The project is licensed under GPLv2.

## Credits and Acknowledgements 🙏

Crafted with care by **{{ cookiecutter.__generator_signature }}**. A special thanks to all contributors and supporters!
2 changes: 1 addition & 1 deletion backend_addon/{{ cookiecutter.__folder_name }}/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"setuptools",
"Plone",
"plone.api",
{%- if cookiecutter.feature_headless == '1' %}
{%- if cookiecutter.__feature_headless == '1' %}
"plone.restapi",
"plone.volto",
{%- endif %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

<include package=".controlpanel" />
<include package=".indexers" />
{%- if cookiecutter.feature_headless == '1' %}
{%- if cookiecutter.__feature_headless == '1' %}
<include package=".serializers" />
{%- endif %}
<include package=".vocabularies" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<configure xmlns="http://namespaces.zope.org/zope">

<!-- List all packages you depend here -->
{%- if cookiecutter.feature_headless == '1' %}
{%- if cookiecutter.__feature_headless == '1' %}
<include package="plone.volto" />
<include package="plone.restapi" />
{%- endif %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<metadata>
<version>{{ cookiecutter.__profile_version }}</version>
<dependencies>
{%- if cookiecutter.feature_headless == '1' %}
{%- if cookiecutter.__feature_headless == '1' %}
<dependency>profile-plone.restapi:default</dependency>
<dependency>profile-plone.volto:default</dependency>
{%- endif %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def setUpZope(self, app, configurationContext):
# Load any other ZCML that is required for your tests.
# The z3c.autoinclude feature is disabled in the Plone fixture base
# layer.
{%- if cookiecutter.feature_headless == '1' %}
{%- if cookiecutter.__feature_headless == '1' %}
import plone.restapi

self.loadZCML(package=plone.restapi)
Expand Down
4 changes: 1 addition & 3 deletions frontend_addon/cookiecutter.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@
"npm_package_name": "{{ cookiecutter.frontend_addon_name }}",
"volto_version": "{{ 'Yes' | latest_volto }}",
"__folder_name": "{{ cookiecutter.frontend_addon_name }}",
"__gha_enable": true,
"__npm_package_name": "{{ cookiecutter.npm_package_name }}",
"__version_package": "1.0.0-alpha.0",
"__version_plone_volto": "{{ cookiecutter.volto_version }}",
"__version_plone_components": "1.7.0",
"__version_plone_scripts": "^3.6.1",
"__version_mrs_developer": "^2.2.0",
"__version_pnpm": "9.1.1",
"__version_pnpm_major": "9",
"__version_release_it": "^17.1.1",
"__gha_version_node": "20.x",
"__gha_version_checkout": "v4",
Expand All @@ -24,7 +23,6 @@
"__gha_version_background_action": "v1",
"__gha_version_upload_artifact": "v4",
"__gha_version_pages_deploy": "v4",
"__generator_date_short": "{% now 'utc', '%Y-%m-%d' %}",
"__generator_date_long": "{% now 'utc', '%Y-%m-%d %H:%M:%S' %}",
"__generator_signature": "This was generated by [cookiecutter-volto](https://github.com/plone/cookiecutter-volto/frontend_addon) on {{ cookiecutter.__generator_date_long }}",
"__prompts__": {
Expand Down
2 changes: 1 addition & 1 deletion frontend_addon/hooks/pre_gen_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"author": "{{ cookiecutter.author }}",
"email": "{{ cookiecutter.email }}",
"github_organization": "{{ cookiecutter.github_organization }}",
"npm_package_name": "{{ cookiecutter.npm_package_name }}",
"npm_package_name": "{{ cookiecutter.__npm_package_name }}",
}


Expand Down
6 changes: 0 additions & 6 deletions frontend_addon/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
"""Pytest configuration."""

import re
from copy import deepcopy
from pathlib import Path
from typing import List

import pytest


@pytest.fixture(scope="session")
def variable_pattern():
return re.compile("{{( ?cookiecutter)[.](.*?)}}")


@pytest.fixture(scope="session")
def cookieplone_root() -> dict:
"""Cookieplone root dir."""
Expand Down
14 changes: 14 additions & 0 deletions frontend_addon/tests/test_variables.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
ALLOWED_MISSING = []
ALLOWED_NOT_USED = []


def test_no_missing_variables(variables_missing):
"""Test no variable is missing from cookiecutter.json"""
assert len(variables_missing) == len(ALLOWED_MISSING)
assert variables_missing == ALLOWED_MISSING


def test_not_used_variables(variables_not_used):
"""Test variables are used."""
assert len(variables_not_used) == len(ALLOWED_NOT_USED)
assert variables_not_used == ALLOWED_NOT_USED
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module.exports = {
],
['@plone/registry', `${coreLocation}/packages/registry/src`],
[
'{{ cookiecutter.npm_package_name }}',
'{{ cookiecutter.__npm_package_name }}',
'./packages/{{ cookiecutter.frontend_addon_name }}/src',
],
],
Expand Down
2 changes: 1 addition & 1 deletion frontend_addon/{{ cookiecutter.__folder_name }}/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ PLONE_VERSION=6
DOCKER_IMAGE=plone/server-dev:${PLONE_VERSION}
DOCKER_IMAGE_ACCEPTANCE=plone/server-acceptance:${PLONE_VERSION}

ADDON_NAME='{{ cookiecutter.npm_package_name }}'
ADDON_NAME='{{ cookiecutter.__npm_package_name }}'

.PHONY: help
help: ## Show this help
Expand Down
26 changes: 15 additions & 11 deletions frontend_addon/{{ cookiecutter.__folder_name }}/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# {{ cookiecutter.title }} ({{ cookiecutter.npm_package_name }})
# {{ cookiecutter.title }} ({{ cookiecutter.__npm_package_name }})

{{ cookiecutter.description }}

[![npm](https://img.shields.io/npm/v/{{ cookiecutter.npm_package_name }})](https://www.npmjs.com/package/{{ cookiecutter.npm_package_name }})
[![npm](https://img.shields.io/npm/v/{{ cookiecutter.__npm_package_name }})](https://www.npmjs.com/package/{{ cookiecutter.__npm_package_name }})
[![](https://img.shields.io/badge/-Storybook-ff4785?logo=Storybook&logoColor=white&style=flat-square)](https://{{ cookiecutter.github_organization }}.github.io/{{ cookiecutter.frontend_addon_name }}/)
[![Code analysis checks](https://github.com/{{ cookiecutter.github_organization }}/{{ cookiecutter.frontend_addon_name }}/actions/workflows/code.yml/badge.svg)](https://github.com/{{ cookiecutter.github_organization }}/{{ cookiecutter.frontend_addon_name }}/actions/workflows/code.yml)
[![Unit tests](https://github.com/{{ cookiecutter.github_organization }}/{{ cookiecutter.frontend_addon_name }}/actions/workflows/unit.yml/badge.svg)](https://github.com/{{ cookiecutter.github_organization }}/{{ cookiecutter.frontend_addon_name }}/actions/workflows/unit.yml)
Expand All @@ -22,19 +22,19 @@ Create a new Volto project (you can skip this step if you already have one):

```
npm install -g yo @plone/generator-volto
yo @plone/volto my-volto-project --addon {{ cookiecutter.npm_package_name }}
yo @plone/volto my-volto-project --addon {{ cookiecutter.__npm_package_name }}
cd my-volto-project
```

Add `{{ cookiecutter.npm_package_name }}` to your package.json:
Add `{{ cookiecutter.__npm_package_name }}` to your package.json:

```JSON
"addons": [
"{{ cookiecutter.npm_package_name }}"
"{{ cookiecutter.__npm_package_name }}"
],

"dependencies": {
"{{ cookiecutter.npm_package_name }}": "*"
"{{ cookiecutter.__npm_package_name }}": "*"
}
```

Expand All @@ -52,24 +52,24 @@ yarn start

### Volto 18 and later

Add `{{ cookiecutter.npm_package_name }}` to your `package.json`:
Add `{{ cookiecutter.__npm_package_name }}` to your `package.json`:

```json
"dependencies": {
"{{ cookiecutter.npm_package_name }}": "*"
"{{ cookiecutter.__npm_package_name }}": "*"
}
```

Add `{{ cookiecutter.npm_package_name }}` to your `volto.config.js`:
Add `{{ cookiecutter.__npm_package_name }}` to your `volto.config.js`:

```javascript
const addons = ['{{ cookiecutter.npm_package_name }}'];
const addons = ['{{ cookiecutter.__npm_package_name }}'];
```

If this package provides a Volto theme, and you want to activate it, then add the following to your `volto.config.js`:

```javascript
const theme = '{{ cookiecutter.npm_package_name }}';
const theme = '{{ cookiecutter.__npm_package_name }}';
```

## Test installation
Expand Down Expand Up @@ -191,3 +191,7 @@ make test-acceptance
## License

The project is licensed under the MIT license.

## Credits and Acknowledgements 🙏

Crafted with care by **{{ cookiecutter.__generator_signature }}**. A special thanks to all contributors and supporters!
14 changes: 7 additions & 7 deletions frontend_addon/{{ cookiecutter.__folder_name }}/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "{{ cookiecutter.npm_package_name }}-dev",
"name": "{{ cookiecutter.__npm_package_name }}-dev",
"version": "{{ cookiecutter.__version_package }}",
"description": "{{ cookiecutter.description }}",
"author": "{{ cookiecutter.author }}",
Expand All @@ -17,25 +17,25 @@
"start:prod": "pnpm --filter @plone/volto start:prod",
"build": "pnpm build:deps && VOLTOCONFIG=$(pwd)/volto.config.js pnpm --filter @plone/volto build",
"build:deps": "pnpm --filter @plone/registry --filter @plone/components build",
"i18n": "pnpm --filter {{ cookiecutter.npm_package_name }} i18n",
"i18n": "pnpm --filter {{ cookiecutter.__npm_package_name }} i18n",
"test": "RAZZLE_JEST_CONFIG=$(pwd)/jest-addon.config.js pnpm --filter @plone/volto test -- --passWithNoTests",
"lint": "eslint --max-warnings=0 'packages/**/src/**/*.{js,jsx,ts,tsx}'",
"lint:fix": "eslint --fix 'packages/**/src/**/*.{js,jsx,ts,tsx}'",
"prettier": "prettier --check 'packages/**/src/**/*.{js,jsx,ts,tsx}'",
"prettier:fix": "prettier --write 'packages/**/src/**/*.{js,jsx,ts,tsx}' ",
"stylelint": "stylelint 'packages/**/src/**/*.{css,scss,less}' --allow-empty-input",
"stylelint:fix": "stylelint 'packages/**/src/**/*.{css,scss,less}' --fix --allow-empty-input",
"dry-release": "pnpm --filter {{ cookiecutter.npm_package_name }} dry-release",
"release": "pnpm --filter {{ cookiecutter.npm_package_name }} release",
"release-major-alpha": "pnpm --filter {{ cookiecutter.npm_package_name }} release-major-alpha",
"release-alpha": "pnpm --filter {{ cookiecutter.npm_package_name }} release-alpha",
"dry-release": "pnpm --filter {{ cookiecutter.__npm_package_name }} dry-release",
"release": "pnpm --filter {{ cookiecutter.__npm_package_name }} release",
"release-major-alpha": "pnpm --filter {{ cookiecutter.__npm_package_name }} release-major-alpha",
"release-alpha": "pnpm --filter {{ cookiecutter.__npm_package_name }} release-alpha",
"storybook": "pnpm build:deps && VOLTOCONFIG=$(pwd)/volto.config.js pnpm --filter @plone/volto storybook dev -p 6006 -c $(pwd)/.storybook",
"build-storybook": "pnpm build:deps && VOLTOCONFIG=$(pwd)/volto.config.js pnpm --filter @plone/volto build-storybook -c $(pwd)/.storybook"
},
"dependencies": {
"@plone/volto": "workspace:*",
"@plone/registry": "workspace:*",
"{{ cookiecutter.npm_package_name }}": "workspace:*"
"{{ cookiecutter.__npm_package_name }}": "workspace:*"
},
"devDependencies": {
"mrs-developer": "{{ cookiecutter.__version_mrs_developer }}"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "{{ cookiecutter.npm_package_name }}",
"name": "{{ cookiecutter.__npm_package_name }}",
"version": "{{ cookiecutter.__version_package }}",
"description": "{{ cookiecutter.description }}",
"main": "src/index.js",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const addons = ['{{ cookiecutter.npm_package_name }}'];
const addons = ['{{ cookiecutter.__npm_package_name }}'];
const theme = '';

module.exports = {
Expand Down
4 changes: 1 addition & 3 deletions project/cookiecutter.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"1",
"0"
],
"__feature_headless": "1",
"__npm_package_name": "{{ cookiecutter.frontend_addon_name }}",
"__folder_name": "{{ cookiecutter.project_slug }}",
"__python_package_name_upper": "{{ cookiecutter.python_package_name | pascal_case }}",
Expand All @@ -50,10 +51,8 @@
"__generator_date_long": "{% now 'utc', '%Y-%m-%d %H:%M:%S' %}",
"__generator_signature": "This was generated by [cookieplone-templates](https://github.com/plone/cookieplone-templates) on {{ cookiecutter.__generator_date_long }}",
"__pre_commit_version": "3.7.1",
"__gha_enable": true,
"__gha_version_checkout": "v4",
"__gha_version_setup_node": "v4",
"__gha_version_setup_pnpm": "v4",
"__gha_version_cache": "v4",
"__gha_version_docker_stack": "v1.2.0",
"__gha_version_code_analysis": "v2",
Expand All @@ -75,7 +74,6 @@
"__devops_db_password": "{{ random_ascii_string(12) }}",
"__backend_addon_format": "1",
"__backend_addon_git_initialize": "0",
"__frontend_addon_git_initialize": "0",
"__project_git_initialize": "1",
"__prompts__": {
"title": "Project Title",
Expand Down
Loading

0 comments on commit 1d36a31

Please sign in to comment.