Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CI: Run package/date unit tests in different timezones #27552

Merged
merged 7 commits into from
Dec 8, 2020
Merged
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 51 additions & 1 deletion .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,57 @@ jobs:
npx lerna run build

- name: Running the tests
run: npm run test-unit -- --ci --maxWorkers=2 --cacheDirectory="$HOME/.jest-cache"
run: |
npm run test-unit -- --ci --maxWorkers=2 --cacheDirectory="$HOME/.jest-cache"
ockham marked this conversation as resolved.
Show resolved Hide resolved

unit-js-date:
name: JavaScript / Date functions

runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
timezone: ['EST', 'GMT', 'CET', 'JST']
locale: ['en_US', 'en_GB', 'fr_FR', 'ja_JP']

steps:
- uses: actions/checkout@v2

- name: Cache node modules
uses: actions/cache@v2
env:
cache-name: cache-node-modules
with:
# npm cache files are stored in `~/.npm` on Linux/macOS
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-

- name: Use Node.js 14.x
uses: actions/setup-node@v1
with:
node-version: 14.x

- name: Npm install and build
# It's not necessary to run the full build, since Jest can interpret
# source files with `babel-jest`. Some packages have their own custom
# build tasks, however. These must be run.
run: |
npm ci
npx lerna run build

- name: Running the tests
env:
TZ: ${{ matrix.timezone }}
david-szabo97 marked this conversation as resolved.
Show resolved Hide resolved
LANG: ${{ matrix.locale }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way to achieve the same thing without creating a big number of jobs? Maybe by hooking into jsdom or something? We have limited resources on the WP org github running and this is going to hurt :(

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The other "easy" alternative is to just do the same thing that is done here but using a loop after the end of the unit-test job (without creating new jobs).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One more (easy) alternative that comes to mind: We could limit these tests to be only run if files in packages/date/ are touched 🤔

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'd miss package upgrades and things like that and if we do include package-lock.json they'd be triggering very often.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about a bash file or npm script which these tests?

#!/bin/bash

timezones=(EST GMT CET)
locales=(en_US ja_JP)

for timezone in "${timezones[@]}"; do
    for locale in "${locales[@]}"; do
        ( TZ=$timezone LANG=$locale npm run test-unit -- packages/date )
    done
done

npm script would become horribly long:

"unit-test:date": "TZ=EST LANG=en_US npm run test-unit -- packages/date && TZ=CET LANG=en_US npm run test-unit -- packages/date ......." 

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Draft here: #27600


run: |
npm run test-unit -- --ci --maxWorkers=2 --cacheDirectory="$HOME/.jest-cache" \
--testPathPattern="packages/date/"

unit-php:
name: PHP
Expand Down