Skip to content

Conversation

@mattheu
Copy link
Contributor

@mattheu mattheu commented Feb 29, 2016

The JS tests rely on some core WP JS. The solution so far was to bundle a copy of the scripts.

This is obviously a pain.
They get out of date easily.
We depend on quite a few, and may need more in future.

I'd much rather just reference the core files so we can run the tests against whichever version of WP you have.

PROBLEM - how to determine the relative path to these files? I've used an abspath variable in the Gruntfile, which you can modify as needed. EG if Shortcake is bundled in a theme on WP VIP.

Is there a better solution to this problem? Should I just keep bundling the files and keep them all updated?

Would love some thoughts on this.

@mattheu
Copy link
Contributor Author

mattheu commented Feb 29, 2016

One idea - we can use the test WP install used by PHP unit.

This does add a barrier to running the tests though, so I've removed them from the standard 'scripts' task. We will have it running on Travis so I think this is OK.

@mattheu
Copy link
Contributor Author

mattheu commented Feb 29, 2016

OK I think I've got a solution. Use grunt option to pass the custom path.

eg
grunt jasmine --abspath="/srv/www/wp-test" to run the tests using a test install.
grunt jasmine --abspath="../../../" to run the tests using the current install, if shortcake is in the plugins directory.

It will default to /tmp/wordpress

@mattheu mattheu added this to the v0.7.0 milestone Mar 2, 2016
@mattheu
Copy link
Contributor Author

mattheu commented Mar 30, 2016

This is updated and will read the location from the environment variable if not explicitly passed.

Also note that the test for dashes in an attribute was previously unsupported by WordPress, but using the scripts from core means we've got this fix.

Anything further need doing here?

Gruntfile.js Outdated
if ( grunt.option( "abspath" ) ) {
abspath = grunt.option( "abspath" );
} else if ( 'WP_DEVELOP_DIR' in process.env ) {
abspath = process.env.WP_DEVELOP_DIR;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this needs to be process.env.WP_DEVELOP_DIR + '/src/'

$ echo $WP_DEVELOP_DIR
/srv/www/wordpress-develop.dev/

@danielbachhuber
Copy link
Contributor

I get this error when I try to run the tests locally:

local ➜  shortcake git:(dont-bundle-wp-scripts) ✗ grunt jasmine
/srv/www/wordpress-develop.dev/src
Running "jasmine:shortcodeUI" (jasmine) task
Testing jasmine specs via PhantomJS

>> TypeError: 'undefined' is not an object (evaluating 'Backbone.Model') at
>> js-tests/build/specs.js:557
>> js-tests/build/specs.js:568
>> js-tests/build/specs.js:1 s
>> js-tests/build/specs.js:1
>> js-tests/build/specs.js:2
>> js-tests/build/specs.js:1 s
>> js-tests/build/specs.js:1 e
>> js-tests/build/specs.js:1210
Warning: No specs executed, is there a configuration error? Use --force to continue.

What am I doing wrong?

@mattheu
Copy link
Contributor Author

mattheu commented Apr 4, 2016

I've updated this to include a task that will perform the check, and throw a fatal if the path isn't found.

I've also added a grunt tests command that will run this check first.

Finally I've updated the docs to indicate how to run these tests.

@mattheu
Copy link
Contributor Author

mattheu commented Jun 7, 2016

@danielbachhuber I'd like to get this one live - so am interested in checking whether you are still having problems.

Regarding your error, it looks like WP core files are not found. If you run grunt test instead of grunt jasmine there is an additional check to ensure the location is correct. I'm don't think its possible to hook this in on the standard grunt jasmine command. We will document this.

The current logic is as follows

  • pass path like so: grunt test --abspath="/path/to/wp/install"`
  • Reads environment variable WP_CORE_DIR
  • Reads environment variable WP_DEVELOP_DIR and looks in WP_DEVELOP_DIR + '/src'
  • Defaults to /tmp/wordpress

Let me know if you think this needs to be improved.

@danielbachhuber
Copy link
Contributor

Let me know if you think this needs to be improved.

Given the additional complexity involved in getting the test suite to run, I still think it's better to just copy the core files into the test suite.

@mattheu
Copy link
Contributor Author

mattheu commented Jun 7, 2016

OK. The big problem with this is keeping them up to date with the latest code, as there's quite a few and we may need even more in future. How about a grunt task to automate updating them instead? We can just commit these changes.

@danielbachhuber
Copy link
Contributor

How about a grunt task to automate updating them instead? We can just commit these changes.

💯

I think this is a much better solution to the general problem. This way, it's just us that have to deal with the burden of the dependency, not everyone that wants to contribute / write tests.

@mattheu
Copy link
Contributor Author

mattheu commented Jun 7, 2016

Updated the PR to add this task and include all the necessary scripts.

.travis.yml Outdated
before_script:
- |
if [[ "$WP_TRAVISCI" == "travis:phpunit" ]] ; then
if [[ "$WP_TRAVISCI" == "travis:phpunit" ]] || [[ "$WP_TRAVISCI" == "travis:js-tests" ]]; then
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this still need to run for js-tests?

@danielbachhuber
Copy link
Contributor

@mattheu Noted a few things

@mattheu
Copy link
Contributor Author

mattheu commented Jun 7, 2016

Updated to fix issues - I knew I should have just closed this and opened a new PR ;)

@danielbachhuber
Copy link
Contributor

Updated to fix issues - I knew I should have just closed this and opened a new PR ;)

:)

@danielbachhuber danielbachhuber merged commit 3ce2206 into master Jun 7, 2016
@danielbachhuber danielbachhuber deleted the dont-bundle-wp-scripts branch June 7, 2016 16:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants