diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 4fd86c8c19..30ea49f6e7 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -73,7 +73,7 @@ jobs: - name: Running translation tests run: pipenv run python -m scripts.extract_translation_templates --test - name: Python linting - run: pipenv run ./scripts/run_lint_python.sh + run: make lint-python - name: Get yarn cache id: get-yarn-cache run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT @@ -88,7 +88,7 @@ jobs: - name: Functional tests spec lint run: ./scripts/lint_functional_test_specs.sh - name: Javascript linting - run: yarn lint + run: make lint-js test-unit: needs: python-dependencies runs-on: ubuntu-22.04 @@ -121,7 +121,7 @@ jobs: - name: Link env vars run: ln -sf .development.env .env - name: Running unit tests - run: pipenv run ./scripts/run_tests_unit.sh + run: make test-unit validate-schemas: runs-on: ubuntu-22.04 steps: @@ -129,7 +129,7 @@ jobs: - name: Run validator run: ./scripts/run_validator.sh - name: Running schema tests - run: ./scripts/validate_test_schemas.sh + run: make validate-test-schemas test-functional: needs: [python-dependencies, node-dependencies] strategy: @@ -169,7 +169,7 @@ jobs: - name: Docker compose run: docker-compose --version && RUNNER_ENV_FILE=.functional-tests.env docker-compose up --build -d - name: Functional tests - run: ./scripts/run_tests_functional.sh ${{ matrix.suite }} + run: make test-functional-suite SUITE=${{ matrix.suite }} - name: Docker compose shutdown run: RUNNER_ENV_FILE=.functional-tests.env docker-compose kill docker-push: diff --git a/.prettierignore b/.prettierignore index b3bd224028..8eb11fc6b6 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1 +1,2 @@ -tests/functional/generated_pages/ \ No newline at end of file +# Exclude generated_pages directory +tests/functional/generated_pages/ diff --git a/Makefile b/Makefile index 670c25ee31..9be19e4b91 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,7 @@ SCHEMAS_VERSION=`cat .schemas-version` DESIGN_SYSTEM_VERSION=`cat .design-system-version` RUNNER_ENV_FILE?=.development.env +SCHEMA_PATH=./schemas/test/en/ clean: find schemas/* -prune | grep -v "schemas/test" | xargs rm -r @@ -16,14 +17,17 @@ load-design-system-templates: build: load-design-system-templates load-schemas translate -lint: lint-python - yarn lint +generate-pages: + yarn generate_pages + +lint: lint-python lint-js lint-python: pipenv run ./scripts/run_lint_python.sh -format: format-python - yarn format +lint-test-python: lint-python test-unit + +format: format-python format-js format-python: pipenv run isort . @@ -35,11 +39,32 @@ test: test-unit: pipenv run ./scripts/run_tests_unit.sh -test-functional: - pipenv run ./scripts/run_tests_functional.sh +test-functional: generate-pages + yarn test_functional + +test-functional-headless: generate-pages + EQ_RUN_FUNCTIONAL_TESTS_HEADLESS='True' make test-functional + +test-functional-spec: generate-pages + yarn test_functional --spec ./tests/functional/spec/$(SPEC) + +test-functional-suite: generate-pages + yarn test_functional --suite $(SUITE) + +lint-js: + yarn lint + +format-js: + yarn format + +generate-spec: + pipenv run python -m tests.functional.generate_pages schemas/test/en/$(SCHEMA).json ./tests/functional/generated_pages/$(patsubst test_%,%,$(SCHEMA)) -r '../../base_pages' -s tests/functional/spec/$(SCHEMA).spec.js validate-test-schemas: - pipenv run ./scripts/validate_test_schemas.sh + ./scripts/validate_test_schemas.sh + +validate-test-schema: + ./scripts/validate_test_schemas.sh $(SCHEMA_PATH)$(SCHEMA).json translation-templates: pipenv run python -m scripts.extract_translation_templates diff --git a/README.md b/README.md index e1b694724c..bd4d45d318 100644 --- a/README.md +++ b/README.md @@ -217,11 +217,11 @@ yarn Available commands: | Command | Task | -| ---------------------- | --------------------------------------------------------------------------------------------------------- | -| `yarn test_functional` | Runs the functional tests through Webdriver (requires app running on localhost:5000 and generated pages). | -| `yarn generate_pages` | Generates the functional test pages. | -| `yarn lint` | Lints the JS, reporting errors/warnings. | -| `yarn format` | Format the json schemas. | +|------------------------| --------------------------------------------------------------------------------------------------------- | +| `make test-functional` | Runs the functional tests through Webdriver (requires app running on localhost:5000 and generated pages). | +| `make generate-pages` | Generates the functional test pages. | +| `make lint-js` | Lints the JS, reporting errors/warnings. | +| `make format-js` | Format the json schemas. | --- @@ -241,21 +241,18 @@ RUNNER_ENV_FILE=.functional-tests.env make run This will set the correct environment variables for running the functional tests. -Then you can run: +Then you can run either: ``` shell make test-functional ``` - -This will delete the `tests/functional/generated_pages` directory and regenerate all the files in it from the schemas. - -You can also individually run the `generate_pages` and `test_functional` yarn scripts: +or ``` shell -yarn generate_pages -yarn test_functional +make test-functional-headless ``` +This will delete the `tests/functional/generated_pages` directory and regenerate all the files in it from the schemas. To generate the pages manually you can run the `generate_pages` scripts with the schema directory. Run it from the `tests/functional` directory as follows: @@ -263,22 +260,21 @@ To generate the pages manually you can run the `generate_pages` scripts with the ./generate_pages.py ../../schemas/test/en/ ./generated_pages -r "../../base_pages" ``` -To generate a spec file with the imports included, you can use the `generate_pages.py` script on a single schema with the `-s` argument. - +To generate a spec file with the imports included, you can pass the schema name as an argument without the file extension, e.g. `SCHEMA=test_address`: ``` shell -./generate_pages.py ../../schemas/test/en/test_multiple_piping.json ./temp_directory -r "../../base_pages" -s spec/test_multiple_piping.spec.js +make generate-spec SCHEMA= ``` If you have already built the generated pages, then the functional tests can be executed with: ``` shell -yarn test_functional +make test-functional ``` -This can be limited to a single spec using: +This can be limited to a single spec where argument needed is the remainder of the path after `./tests/functional/spec/` (which is included in the command): ``` shell -yarn test_functional --spec ./tests/functional/spec/exit.spec.js +make test-functional-spec SPEC= ``` To run a single test, add `.only` into the name of any `describe` or `it` function: @@ -288,10 +284,16 @@ To run a single test, add `.only` into the name of any `describe` or `it` functi `it.only('Given this is a test', function() {...}` Test suites are configured in the `wdio.conf.js` file. -An individual test suite can be run using: +An individual test suite can be run using the suite names as the argument to this command. The suites that can be used with command below are: +* timeout_modal_expired +* timeout_modal_extended +* timeout_modal_extended_new_window +* features +* general +* components ``` shell -yarn test_functional --suite +make test-functional-suite SUITE= ``` To run the tests against a remote deployment you will need to specify the environment variable of EQ_FUNCTIONAL_TEST_ENV eg: diff --git a/package.json b/package.json index a51657cbd3..7470ecc575 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "lint": "yarn generate_pages && yarn lint:tests && yarn lint:test-schemas", "lint:tests": "prettier --check \"tests/functional/**/*.js\" && eslint \"tests/functional/**/*.js\"", "lint:test-schemas": "prettier --check \"schemas/test/*/*.json\" && eslint \"schemas/test/**/*.json\"", - "test_functional": "./node_modules/.bin/wdio tests/functional/wdio.conf.js --suite $1", + "test_functional": "./node_modules/.bin/wdio tests/functional/wdio.conf.js", "generate_pages": "rm -rf ./tests/functional/generated_pages && pipenv run python -m tests.functional.generate_pages schemas/test/en/ ./tests/functional/generated_pages -r '../../base_pages'", "format": "yarn format:tests && yarn format:test-schemas", "format:tests": "prettier \"tests/functional/**/*.js\" --write && eslint --fix \"tests/functional/**/*.js\"", diff --git a/scripts/run_tests_functional.sh b/scripts/run_tests_functional.sh deleted file mode 100755 index f02dfa5069..0000000000 --- a/scripts/run_tests_functional.sh +++ /dev/null @@ -1,31 +0,0 @@ -#!/bin/bash -# -# Run functional tests -# -# NOTE: This script expects to be run from the project root with -# ./scripts/run_tests_functional.sh - -set -o pipefail - -function display_result { - RESULT=$1 - EXIT_STATUS=$2 - TEST=$3 - - if [ $RESULT -ne 0 ]; then - echo -e "\033[31m$TEST failed\033[0m" - exit $EXIT_STATUS - else - echo -e "\033[32m$TEST passed\033[0m" - fi -} - -# Run Functional tests -echo "Generating functional test pages" -yarn generate_pages - -echo "Running front end functional tests" -yarn test_functional $1 - -display_result $? 5 "Front end functional tests" - diff --git a/setup.cfg b/setup.cfg index 8af620026f..2518f8258d 100644 --- a/setup.cfg +++ b/setup.cfg @@ -6,3 +6,8 @@ filterwarnings= ignore:.*formatargspec.*:DeprecationWarning ignore:.*isAlive.*:PendingDeprecationWarning +[flake8] +# Ignore node_modules and cloned repos when not in a virtual environment +exclude = node_modules/*,tests/*,src/* +max-line-length = 160 +ignore = C815,C816,W503,E203 diff --git a/tox.ini b/tox.ini deleted file mode 100644 index a60575d8f7..0000000000 --- a/tox.ini +++ /dev/null @@ -1,5 +0,0 @@ -[flake8] -# Ignore node_modules and cloned repos when not in a virtual environment -exclude = node_modules/*,tests/*,src/* -max-line-length = 160 -ignore = C815,C816,W503,E203