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

Setup server side unit tests #617

Merged
merged 9 commits into from
May 5, 2017
Merged

Conversation

youknowriad
Copy link
Contributor

No description provided.

@youknowriad youknowriad added the [Type] Build Tooling Issues or PRs related to build tooling label May 3, 2017
@youknowriad youknowriad self-assigned this May 3, 2017
@youknowriad
Copy link
Contributor Author

@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
Copy link
Member

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
Copy link
Member

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.

/**
* PHPUnit bootstrap file
*
* @package Guttenberg
Copy link
Member

Choose a reason for hiding this comment

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

Typo: GuttenbergGutenberg

phpunit.xml.dist Outdated
>
<testsuites>
<testsuite>
<directory prefix="test-" suffix=".php">./tests/</directory>
Copy link
Member

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+-->/';
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

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?

Copy link
Contributor Author

@youknowriad youknowriad May 4, 2017

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.

Copy link
Member

@ntwb ntwb left a 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
Copy link
Member

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
Copy link
Member

@ntwb ntwb May 4, 2017

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

Copy link
Contributor Author

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

Copy link
Member

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 😖

@ntwb
Copy link
Member

ntwb commented May 4, 2017

Why isn't Travis CI running build jobs against this PR??? 🤔

@youknowriad
Copy link
Contributor Author

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. Does it look ok for you? I guess we'll check on the other PR once this is merged.

.travis.yml Outdated
branches:
only:
- master

Copy link
Member

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
Copy link
Member

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)

@youknowriad youknowriad force-pushed the add/server-unit-tests branch 2 times, most recently from 1f1ec98 to 1afeaa3 Compare May 4, 2017 13:10
.travis.yml Outdated
- $HOME/.composer/cache

env:
- TRAVIS_NODE_VERSION="6.10.0"
Copy link
Member

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:
Copy link
Member

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
Copy link
Member

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

@youknowriad youknowriad force-pushed the add/server-unit-tests branch from 1afeaa3 to b39cce6 Compare May 4, 2017 13:14
@ntwb
Copy link
Member

ntwb commented May 4, 2017

@youknowriad See the last 2 comments above on switching to before_install and nvm

(PR reviews on mobile are frustrating)

@youknowriad
Copy link
Contributor Author

@ntwb Yep I'm trying to use the .nvmrc from the repo instead

@youknowriad youknowriad force-pushed the add/server-unit-tests branch from b39cce6 to c68c629 Compare May 4, 2017 13:17
@youknowriad
Copy link
Contributor Author

@ntwb oh you mean, nvm is already installed on the php travis machines. Updating 👍

@youknowriad youknowriad force-pushed the add/server-unit-tests branch from c68c629 to 967a949 Compare May 4, 2017 13:19
@youknowriad youknowriad force-pushed the add/server-unit-tests branch from 967a949 to a60d52e Compare May 4, 2017 13:21
@ntwb
Copy link
Member

ntwb commented May 4, 2017

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

@ntwb
Copy link
Member

ntwb commented May 4, 2017

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

@youknowriad youknowriad force-pushed the add/server-unit-tests branch from 61784b8 to 378ee1b Compare May 4, 2017 13:31
@youknowriad youknowriad force-pushed the add/server-unit-tests branch from 15c7059 to f0cd860 Compare May 4, 2017 14:12
@youknowriad
Copy link
Contributor Author

🎉 Tests are passing. Any other concern here?

@nylen
Copy link
Member

nylen commented May 4, 2017

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

Disagree, pretty much our whole team uses nvm during development​. I for example have my shell set up to automatically switch node versions for any project that has a .nvmrc file.

@youknowriad
Copy link
Contributor Author

@nylen using our current .nvmrc is not possible because of this #414. We could fix this in the said issue.

@youknowriad youknowriad merged this pull request into try/dynamic-blocks May 5, 2017
@youknowriad youknowriad deleted the add/server-unit-tests branch May 5, 2017 08:53
@nylen
Copy link
Member

nylen commented May 5, 2017

using our current .nvmrc is not possible because of this #414. We could fix this in the said issue.

Yes, I just mean that we shouldn't abandon .nvmrc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Type] Build Tooling Issues or PRs related to build tooling
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants