-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Setup server side unit tests #617
Conversation
@nylen I preferred to setup the unit tests in a separate PR. Any help here is apreciated, since it's the first time I do this. |
.travis.yml
Outdated
- php: 5.6 | ||
env: WP_TRAVISCI=phpcs | ||
- php: 5.3 | ||
env: WP_VERSION=latest |
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.
See https://core.trac.wordpress.org/ticket/40407 - I don't think we need such a large matrix here. We should include:
- PHP 5.2 (minimum supported WP version)
- PHP 5.6 (last 5.x version)
- PHP 7.1 (latest version)
.travis.yml
Outdated
if [[ "$WP_TRAVISCI" == "phpcs" ]] ; then | ||
phpcs --standard=phpcs.ruleset.xml $(find . -name '*.php') | ||
fi | ||
- npm run ci |
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.
Rather than coming at the end of each php job, npm run ci
should be a separate job in the matrix.
tests/bootstrap.php
Outdated
/** | ||
* PHPUnit bootstrap file | ||
* | ||
* @package Guttenberg |
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.
Typo: Guttenberg
→ Gutenberg
phpunit.xml.dist
Outdated
> | ||
<testsuites> | ||
<testsuite> | ||
<directory prefix="test-" suffix=".php">./tests/</directory> |
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.
Since we have both JS and PHP tests, I think we should call this directory something other than tests
. WP core uses tests/phpunit/
and tests/qunit/
, but our JS tests are inline with the files being tested. Maybe we just call ours `phpunit/ instead?
index.php
Outdated
@@ -99,7 +114,7 @@ function do_blocks( $content ) { | |||
global $registered_blocks; | |||
|
|||
// Extract the blocks from the post content | |||
$open_matcher = '/<!--\s*wp:([a-z](?:[a-z0-9\/]+)*)\s+((?:(?!-->).)*)-->.*<!--\s*\/wp:\g1\s+-->/'; | |||
$open_matcher = '/<!--\s*wp:([a-z](?:[a-z0-9\/]+)*)\s+((?:(?!-->).)*)--><!--\s*\/wp:\g1\s+-->/'; |
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.
We need the .*
here, don't we? Or is this intended to match only blocks with no content?
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.
I was thinking we should match only the empty blocks. see #586 (comment)
But with the HTML fallback feature, we need to capture the .*
.
Reintroducing the .*
breaks the unit tests because this
'<!-- wp:core/dummy value:b1 --><!-- /wp:core/dummy -->' .
'between' .
'<!-- wp:core/dummy value:b2 --><!-- /wp:core/dummy -->' .
match only one block, it takes the first and the last opening/closing tags only in consideration and all what's in between is catched by the .*
. I'll take a deeper look and see if I can update the regex to change the priorities.
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.
A non-greedy match .*?
should work here. Are there any cases we need to support that don't have tests?
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.
Are there any cases we need to support that don't have tests?
We're covering everything for now I think. Oh! maybe the register the same block twice.
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.
I've made some requests for .travis.yml
.travis.yml
Outdated
|
||
language: | ||
- php | ||
- node_js |
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.
Only a single language is supported by Travis CI, keep - php
and remove - node_js
.travis.yml
Outdated
env: WP_VERSION=latest | ||
- php: 5.6 | ||
env: TRAVISCI=phpcs | ||
- env: TRAVISCI=js |
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.
I think this is meant to include a PHP version for this matrix job:
- php: 7.1
env: TRAVISCI =js
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.
no it's not, in this case we want to run the JS job only
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.
You still need a "language" to form the base of the build job in the matrix I believe, each job in the matrix should have both a language for the job i.e. - php: 7.1
and its associated environment matrix -env: TRAVISCI =js
If Travis were running jobs against this PR we could take a look 😖
Why isn't Travis CI running build jobs against this PR??? 🤔 |
@ntwb maybe because This PR is not targeting master. I made some changes to the |
.travis.yml
Outdated
branches: | ||
only: | ||
- master | ||
|
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.
The above 3 lines will need to be removed won't they if we want Travis to run against each PR?
.travis.yml
Outdated
env: WP_VERSION=latest | ||
- php: 5.6 | ||
env: TRAVISCI=phpcs | ||
- php: 5.6 |
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.
Let's use the latest PHP 7.1 for this (WP Core uses the latest for its JS only job)
1f1ec98
to
1afeaa3
Compare
.travis.yml
Outdated
- $HOME/.composer/cache | ||
|
||
env: | ||
- TRAVIS_NODE_VERSION="6.10.0" |
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.
No need for the above two lines (see next comment)
.travis.yml
Outdated
env: | ||
- TRAVIS_NODE_VERSION="6.10.0" | ||
|
||
install: |
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.
Change this to 'before_install'
.travis.yml
Outdated
- TRAVIS_NODE_VERSION="6.10.0" | ||
|
||
install: | ||
- rm -rf ~/.nvm && git clone https://github.com/creationix/nvm.git ~/.nvm && (cd ~/.nvm && git checkout `git describe --abbrev=0 --tags`) && source ~/.nvm/nvm.sh && nvm install $TRAVIS_NODE_VERSION |
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.
Change this to '- nvm use 6' for the latest LTS NodeJS 6.x branch release
1afeaa3
to
b39cce6
Compare
@youknowriad See the last 2 comments above on switching to before_install and nvm (PR reviews on mobile are frustrating) |
@ntwb Yep I'm trying to use the |
b39cce6
to
c68c629
Compare
@ntwb oh you mean, nvm is already installed on the |
c68c629
to
967a949
Compare
967a949
to
a60d52e
Compare
There's still no need to install nvm, Travis has full support for nvm these days I'd suggest removing the .nvmrc file, its more than likely not needed, we can and should declare the required node and NPR versions in package.json instead |
Ok, now Travis is running 👌 @youknowriad Take a close look at each of the jobs, there are two showing "green" that they passed, this is false, there's lots of errors on those jobs. It's nearly midnight here, so I'm off until morning |
61784b8
to
378ee1b
Compare
15c7059
to
f0cd860
Compare
🎉 Tests are passing. Any other concern here? |
Disagree, pretty much our whole team uses |
Yes, I just mean that we shouldn't abandon |
* Setup server side unit tests
No description provided.