Problem/Motivation
We agreed on using nightwatch for JS browser testing, see below for more information.
This has been worked on by the JavaScript Initiative and is ready for a review here on d.o 🎉
It requires the patch from #2926633: Provide a script to install a Drupal testsite to be applied first.
Here is a branch which contains both this work and the work from #2926633: Provide a script to install a Drupal testsite:
https://github.com/jsdrupal/nightwatch/pull/1, see more about that on #2869825-48: Leverage JS for JS testing (using nightwatch)
Involved people:
justafish, dawehner, alexpott, drpal, mglaman, and mixologic
How to use it
Follow core/tests/README.md in the patch.
Background information
Since we java javascript test coverage backed upon ower PHPUnit based testing framework we hopefully gained some stability in our JS.
As multiple people discussed though, testing javascript in PHP might not be ideal:
Problems of testing JS in PHP/Advantages of testing JS in JS
- JS developers who want to participate into Drupal don't have to learn PHP / learn the phpunit testing framework as they are already familiar with nightwatch
- The JS world is much bigger than the PHP world now, so they should provide better testing frameworks for their needs
- Nightwatch makes it easy to open up a real browser to see what the test is doing
- By splitting up the programming languages, we make it clear that Drupal is API first. There is no way of communication possible, which traditionally lead to A LOT of insane JS bugs.
Advantages of testing JS in PHP/ Disadvantages of testing JS in JS
- One testing syntax to rule them all
- People are aware of phpunit now already
- We force the current test writers to learn another testing framework and we're seriously lacking people who are interested in writing tests already.
- Jumping from BrowserTestBase to JavascriptTestBase is quite easy right now.
- We split the functional testing into 2 separate frameworks. Upgrading an test to a JavaScript test will be more difficult and I really don't like the split in functional testing.
Will 'the people' really come if we have another testing framework? - Is it really possible to work on JavaScript alone in Drupal core or is it more of a mix-n-match with the php backend?
- It is potentially harder to setup a test in javascript. We don't have the APIs to enable modules in JS ...
This was discussed on a BOF/meeting during Drupalcon Baltimore.
What we will use
We first agreed that testing JS in PHP was a good first step, but to really get serious about it, we have to leverage JS based tools.
As a tool we agreed on using nightwatch for the following reasons: It has a wide usage, it has good documentation. It can not only support end to end testing but also unit testing. It uses the webdriver protocol, which is an open w3c standard, so it is supported by every browser vendor potentially. On top of that it could support multiple sessions, aka. parallel testing.
How it will work
Each test will reinstall Drupal, just like in PHP.
Testbot side of things
After the agreement we talked about what we need on the testbot side of things. We agreed on the following approach:
- Provide a package.json script which runs all tests
- Let the testbot execute it and parse the JSON and call it a day
- Hope that this is really enough ;)
TL;DR
- It doesn't make sense to use PHP to test JS
- Nightwatch is a good tool to do that given its wide usage, support for multiple browsers, its unit testing integration as well as good documentation.
Remaining tasks
- Provide a more detailed example involving forms, an actual login process ..., fiddling with some ajaxy form. Ideally the follow tests:
- Drag-n-drop: \Drupal\Tests\book\FunctionalJavascript\BookJavascriptTest.php
- Dialog: \Drupal\Tests\views_ui\FunctionalJavascript\FilterCriteriaTest
- Dialog:
- Complex test: \Drupal\Tests\outside_in\FunctionalJavascript\OutsideInBlockFormTest
- Provide package.json integration so the testbot just calls this and doesn't care about how to run the test
- Make the setup process for a test as simple as possible
- Provide some basic documentation on drupal.org which points to the right places on the nightwatch documentation
- Maybe do some research around parallel test running (something the current ecosystem can't provide)
API changes
A total new API for writing tests
Data model changes
| Comment | File | Size | Author |
|---|---|---|---|
| #112 | 2869825-112.patch | 164.25 KB | alexpott |
| #112 | 109-112-interdiff.txt | 3.93 KB | alexpott |
| #109 | 2869825-109.patch | 164.27 KB | justafish |
| #107 | 2869825-107.patch | 163.8 KB | justafish |
| #106 | interdiff-2869825-105-106.txt | 1.05 KB | lendude |
Comments
Comment #2
dawehnerHere is some start of an experiment, yes just an experiment.
It consists of a couple of pieces:
Comment #3
dawehnerHere is the current status of the patch, it is not working properly yet, see comment #2.
Comment #4
GrandmaGlassesRopeManComment #5
dawehner#2869839: Move more functionality into \Drupal\Core\Test\FunctionalTestSetupTrait is part of this patch right now.
Comment #6
dawehnerNote: This now actually sets up the browser in a way that the child site can be accessed.
Comment #7
dawehnerYesterday we had a discussion involving mixologic, drpal, justafish, mateu, laurri, infiniteluke, wimleers, dawehner
I put the meeting notes/conclusions into the issue summary.
Comment #8
dawehnerIn case someone wants to try out the patch the issue summary now has a way to describe how to use it.
The documentation is probably not complete yet, but its worth starting to document it :)
Comment #9
dawehnerI had to make some adaptions that it actually works. The steps should be complete now.
Comment #10
martin107 commentedI hope this will be a useful comment,
I agree with
While we evaluate this further can I ask a question about nightwatch's abilities....
Over in #2862510: Convert system/tests/src/Ajax to JavascriptTestBase
we have been looking for a good pattern to use
Is it possible in nightwatch to control the browser to submit invalid form requests, to simulate a bad actor and attack the site.
it is something Mink does not entertain.
In short how would we convert this code segment from FormValuesTest::testSimpleAjaxForm()
Comment #11
michielnugter commentedI'm still not a 100% sure on this but am very interested to see a couple of representative tests converted and working.
My doubts are as follows:
The main pro's I see are:
In short my programming profile so my doubts can be put into perspective:
I'm mainly a Drupal backend PHP programmer and am one of the PHPUnit initiative leads. I have quite a lot of experience with building a JavaScript web-app on top of Drupal (I have built a complex backbone based progressive decoupled web-app). I'm certainly not protective of the JavascriptTestBase and am open to any alternative that integrates well with Drupal and the rest of the testing needs.
I would love to see a something converted that uses drag-n-drop and a dialog or contextual links though, these are the difficult parts to test in the current JavascriptTestBase.
Comment #12
martin107 commentedPatch no longer applies... I have tried a reroll but it is very difficult to untangle all the changes to yarn.lock
#11 is an I interesting perspective...
I am in the process of forming an opinion
For what it is worth ---
1) This stuff was discussed here.
https://www.lullabot.com/podcasts/drupalizeme-podcast/modernizing-javasc...
2) nightwatch's documentation looks very good. and the pattern in the example look just like our Mink code.
http://nightwatchjs.org/
3) "More example of difficult to solve problems" ... would be a good way to go... I will help out where I can :)
Comment #13
droplet commentedI have similar thoughts with @michielnugter.
In most of the cases, we actually testing the UI functionality, not testing the JS code. On another side, PHP developers can't write JS also. You make changes to PHP & JS together. To understand basic PHP is a must in Drupal Core Development.
Also, many of tests get the dynamic data from DB and PHP.
A real case study:
#2725255: Unfiltered data in "Allowed HTML tags"
testJSInjection: ideally, it should provide by PHP Developers. (PHP Developer creates the UI. TDD.)
testParserError: should be a JS UnitTest (mocha)
What discourage our developer to contribute to tests:
[Slightly Off-topic] I think one of the main problems is CORE development always testbots & Core committers first, not contributors first. It squeezed our patience to last minute until you give up. Bug A creates Bug B, Bug B creates C. And Bug E blocked A bring into CORE..etc
- Slow test.
It spent few mins on a simple test in my local env. It easily wasted an hour or so on a random bug.
#2747075: [meta] Improve WebTestCase / BrowserTestBase performance by 50%
- Hard to debug.
Missing visual way to debug:
https://twitter.com/webdriverio/status/806911722682544128
#2857957: Explore a way to provide interactive shell for tests (or use Psysh)
Anyway, what test engines was rejected in the offline meetings?
Comment #14
dawehnerIt would be great if you could all update the arguments in the issue summary. I'll try to do that, but feel free to edit it.
#10
While mink can't, guzzle can certainly generate invalid POST requests. Do you think this would be an okayish solution?
All those browser testing frameworks are about user interaction testing. Attackers use probably not a browser, but rather raw POST requests.
Does that makes sense?
#11
I added all your points to the issue summary.
I think the fact that people call out to the container in the middle of the test is way worse than people actually estimate. If you use the container in the middle of the test, you act on a different state of the world, than what is available via HTTP in the browser.
The setup step can totally call out to php, but once we are done with that, calling to PHP is problematic.
One point I added to the issue summary is that by separating the two layers by actually using a different programming language. In the world of API first, we need to think about those side effects.
Educating people about other technologies aren't a bad thing. People are maybe scared, but I believe career wise its never a bad idea to learn things.
#12
Do you have a partical example of a test in mind? It would be great to list 1-2 examples in the issue summary and provide an example of them in the test.
#13
This is absolutely true. In a functional testing environment though you don't care that much how something is implemented. On the other hand I doubt our current way of rendering will stay like that.
Which is problematic, as written earlier ...
The process is hard, and nearly impossible to understand. I can't agree more. On the other hand there are good reasons for it, like we still try to figure out what keeping BC actually means.
The issue you linked is mostly about optimizing the testbot performance, but of course, it would be really nice, no question, to improve the everyday test experience.
We agreed to go with nightwatch, because it for example had parallel test running built in: https://github.com/nightwatchjs/nightwatch-docs/blob/master/guide/runnin...
Just to be clear in general, BrowserTestBase also needed like basically 1 year to be actually used. Of course when we would switch to whatever new technology, we would not just burn everything else down.
Comment #15
michielnugter commented@dawehner Thanks for the IS update!
I think this should be moved to BrowserTestBase and simulate the request directly, it should be possible there. Doing this in a real-browser env just seems wrong. Still wrong in BrowserTestBase but at least a little less wrong ;)
Mostly it's done to quickly change a setting instead of clicking through the interface. It's a time-saver and makes the test more readable. Should we completely stop doing this? I agree it makes sense to only use the UI but it would mean a significant increase in test-complexity.
Testing from JS would make the impossible.
Oh sure, completely agree! I actually came to Drupal to learn stuff and actually like learning about this a lot. I just have doubts about this switch and if it will really improve Drupal in general. To be clear: doubts don't mean I'm against it, I just see some problems / considerations.
Drag-n-drop: \Drupal\Tests\book\FunctionalJavascript\BookJavascriptTest.php
Dialog: \Drupal\Tests\views_ui\FunctionalJavascript\FilterCriteriaTest
Dialog:
Complex test: \Drupal\Tests\outside_in\FunctionalJavascript\OutsideInBlockFormTest
I updated the IS on this.
The issue is open to move to Webdriver making this possible for the current phpunit JavascriptTestBase as well. Does NightwatchJS offer more?
Do you mean to support both NightwatchJS and JavascriptTestBase together?
To me: if we're going to switch we should deprecate JavaScriptTestBase and move core to the new testing framework.
Comment #16
dawehnerWell, I doubt people really understand the nature of having a different container/state of the system. This time safer argument is totally valid, but we should think more about it. Debugging those hard issues have lead to most probably hundreds of hours of hard to debug tests.
I don't think this is necessarily the case. We could still call out from node to PHP, but the good part, is that we never have state (like a container in some version) in the test process itself. Given the PHP script would bootstrap Drupal to some respect it would be more safe to do the necessary changes. Do you think this makes sense?
Sure, that's exactly why we have a discussion :) We don't want to blindly jump onto something.
Given that this property is purely based upon the fact that its using webdriver. I see a tiny advantage given that unlike JTB we wouldn't implement it for ourselves.
Well, this is what happened with phpunit tests, web tests and browsers tests as well. Unit tests got introduced quite early (2013) but it took time to be leveraged. The same thing happened with BrowserTestBase (which is 2 years old now). Future planning is part of big opensource projects :)
Comment #17
MixologicIm bumping the priority of this.
PhantomJS is broken, and we didnt really run into it until we tried to repurpose some extra hardware in our racks for some testbots. Basically it freezes because the underlying networking subsystem is broken. (https://github.com/ariya/phantomjs/issues/14286) The only options to make it work at this point are upgrade it to a fully unsupported 2.5.0 beta version, and *hope* that fixes the problems, or get rid of it once and for all and convert everything to *not* use phantomjs.
Can we burn phantom js just a little?
Comment #18
michielnugter commented@Mixologic
I think the road for this is still a bit too long to help you out in short term. Also as stated by @dawehner in #16 this issue would not mean removing the current form of JavascriptTestBase in the short run, we'll have to keep supporting JavascriptTestBase at least until 9.x.
I think the most efficient way of getting rid of PhantomJS for the test-bot is getting this issue in: #2775653: JavascriptTests with webDriver.
That's about switching to Webdriver for JavascriptTestBase, after that gets in we could do a follow-up to change the browser to chrome headless?
Comment #19
michielnugter commentedI'm in favor of resetting the priority to normal here and upgrading the priority on the mentioned issue as this is really a huge change that really can't use a lot of pressure to get in, if we're going to switch we want to do it right.
Feel free to disagree ;)
Comment #20
MixologicYes, perhaps this is not the issue that is the shortest path to gutting phantomjs. As long as there is a path forward that has some way that the testbots do not have to have that as an option, thats great (it certainly doesnt have to be this issue).
Comment #21
michielnugter commentedNice to see this change forces us to think about how to test specific situations :)
Clicking through the UI won't make the tests better readable but it may make them better understandable.
Though if we separate environment preparation from the actual tests (could be a get call to a specific URL or a method on the test class itself) sounds like a good idea. It makes documentation better possible and more clear that the purpose is environment preparation.
For sure we have to keep support for JavascriptTestBase but if we change I would like all current tests converted to use the best framework. We don't have that many tests currently so it's still doable.
Comment #22
dawehnerYeah let's be practical and do babysteps:
* Get chrome with webdriver working on the testbot
* We will make most probably run into stability issues again, nothing is ever easy!
* Then continue investigating on this issue here ... I'll try to keep this issue up to date in a state that people can give feedback.
That is fair.
Comment #23
GrandmaGlassesRopeMan👍
Comment #25
dawehnerWe had quite some conversations about that on drupalcon:
I think the next step needed here is a core committer, probably a framework maintainer, to say +1, let's do that. I hope we can do that even if its in an active step.
Comment #26
droplet commentedNext Step, probably to consider if we should use Snapshot for testing.
What is Snapshot?
https://facebook.github.io/jest/docs/en/snapshot-testing.html
Comment #27
dawehner@droplet
Do you mind opening up an issue about that? It sounds like something totally worth exploring, but not necessarily as part of this patch?
Comment #28
droplet commentedDONE: #2912788: [JS] Introduce Snapshot testing into CORE
Comment #29
dawehnerThank you @droplet!
Comment #30
alexpottI'm not sure it matters what testing framework we use as long as:
I have not used nightwatch but regardless I'm +1 because some JS based testing is better than none and nightwatch appears to have consensus. If the JS maintainers all agree I think we should go forward with this.
Comment #31
fubhy commentedI'd like to quickly chime in here and mention TestCafe as an alternative to Nightwatch. We've recently assessed and switched to TestCafe because of its many benefits compared to Nightwatch. That being said, we've happily used Nightwatch in the past. I don't want to derail this discussion and Nightwatch is certainly better than simply having nothing of the sort. Anyway's, I'd like to highlight a few of the benefits that we saw in TestCafe:
There's more. But these are some of the most compelling reasons that sold us.
As I said, I don't want to derail or postpone this issue. Just wanted to mention it and was wondering if anyone has given it a try before.
Comment #32
dawehnerNote: This issue is currently semi-blocked on #2775653: JavascriptTests with webDriver ...
Testcafe sounds interesting. I could imagine relying on some external service could have huge advantages and disadvantages.
Comment #33
leksat commentedJust that you know, TestCafe is a service (https://testcafe.devexpress.com/), but also is an open source library (https://github.com/DevExpress/testcafe). @fubhy talked about the library.
Comment #34
GrandmaGlassesRopeManComment #35
webchickEscalating to major, since this is a blocker for JS testing.
Comment #36
dawehnerI splitted up the PHP changes into this issue: #2926633: Provide a script to install a Drupal testsite
Comment #37
justafishI discussed #2775653 with @dawehner and @laurii today and we came to the conclusion it isn't a blocker for this issue
Regarding TestCafe et al - @drpal, @dawehner, @laurii and myself looked at this and other options today together (directly using Puppeteer + an assertion library of our choice). My thoughts - whilst TestCafe seems very interesting, I believe it's too green at this point for us to depend on it. The other thing which makes me slightly nervous about it is that it uses a URL-rewriting proxy, which is what Selenium used in v1 before moving away from it because of various issues. Puppeteer was an interesting option, but I think it's nice to leave ourselves the option of testing across multiple browsers.
So still +1 for Nightwatch from me
Comment #38
dawehnerComment #39
effulgentsia commentedThanks for #37. Regarding TestCafe's pros from #31:
Would we not be able to with Nightwatch?
How would waiting for async operations to complete be done with Nightwatch?
What do you base that on? That claim does not yet seem to be supported by usage trends.
Given that and #37, I'm +1 to proceeding with Nightwatch for now, so removing the "Needs framework manager review" tag. However, I'm still curious about the above questions, or any other potential challenges with Nightwatch that people want to surface.
Comment #40
droplet commentedES6+,
I think #31 meant the built-in features rather than config babel yourself.
Asynchronous,
In nightwatch, you have to write another custom wrapper inside executeAsync for async, right?
http://nightwatchjs.org/api#executeAsync
In testCafe, it's more elegant, (diff test engine but same thing, it describes the diff better) :
https://github.com/avajs/eslint-plugin-ava/blob/master/docs/rules/prefer...
Ask a stupid question...
1. Do we write JS UnitTest for Core?
2. If Yes, How to test React? Any plan?
3. If Yes, do we need to perform BENCHMARK between different engines against the REAL Drupal env (ANd on a single machine)? (Performance is a matter to encourage the contributions!)
Comment #41
MixologicOne of the key things that has unblocked #2775653: JavascriptTests with webDriver is that there is now a webdriver implementation on the testbots (chromedriver) #2857788: Patch the testbot to start both chrome in webdriver mode and phantomjs in non webdriver mode. Currently the hostname of that container is determined at runtime, and is setting an environment variable in the run-tests.sh command to let the testrunner know where it is. So if/when we implement something, we've already got the chromedriver part working on the testbots.
When I looked into testcafe, this thread had some red flags in it that I think we should actively avoid:
https://testcafe-discuss.devexpress.com/t/why-not-use-selenium/47/2
Specifically, when they say "Selenium" they mean "the W3C standard webdriver API" - there seems to be a *lot* of value in leveraging the webdriver api, and it just feels like they are optimizing for some of the less important use cases, i.e. 'we wanted to simplify setting up the test environment. ' -> afaik, setting up a local chromedriver env to work with nightwatch isn't terribly difficult. And to second what Justafish pointed out earlier, the URL rewriting proxy is a brittle link and bound to introduce subtle errors.
The webdriver api gives us the ability to add a geckodriver, or edgedriver container without needing to do a whole lot to our tests.
I dont think that testcafe offers the right type of solution for testing a codebase that is intended to be run across a wide spectrum of installations.
So, if we do decide to proceed with nightwatch.js, Can somebody please open an issue over at https://drupal.org/project/drupalci_testbot with what steps the ci system should take to ensure that nightwatch is installed? maybe thats this issue? #2874028: Create a Yarn Build step
edit: I just looked and saw that [#12373756-38] is exactly thisAnd also open an issue to let us know *how* those tests are going to run., what kind of output they produce, and where. (i.e. are we going to have run-tests.sh kick off nightwatch tests, and take all of its junit formatted output and put it back into the same result set as everything else, or are we planning on producing output in parallel, with a different runner?)
Comment #42
dawehnerI totally think that testcafe could be a good solution for testing a custom client projects. It turns out though that the requirements for Drupal core / large scale testing can be different. It starts with "How likely is the tool maintained in the longrun" (will projects be around for a long time), continues with things like: "How much adaption of a tool might be out there already" and finally: "The actual problem is not the tech, is the mindset of writing tests".
I think relying on a standard tool like webdriver is better on the longrun, just like mink in a way is at this moment in time. Mink gave us the flexibility that switching the tests in PHP.
Ask a stupid question...
I think this is still an open question. We could use nightwatch built in mechanism, but we could also use one of the million other tools out there. Do you think the JS of Drupal is at a place where unit testing them actually makes sense?
For me it depends on the level of testing. At least for the beginning functional testing, for example using nightwatch, would be good enough.
Once you are able to deal with things on a unit test level this is absolutely true. For functional test coverage I guess that the installation of Drupal and any actual HTTP request outweigh speed differences of different testing frameworks a lot.
There is an issue about that already: #2928962: Run yarn-based core tests on the testbot
Comment #43
martin107 commentedI am motivated to reroll...
This may blow up horribly...the patch is so old.
when this comes back green I will convert to es6
Comment #44
martin107 commentedComment #45
dawehner@martin107
I think we should focus on general discussion and the other related issues first.
Comment #46
martin107 commentedFair enough.
Comment #48
justafishThis has been worked on by the JavaScript Initiative and is ready for a review here on d.o 🎉
It requires the patch from 2926633 to be applied first.
Here is a branch which contains both this work and the work from 292663:
https://github.com/jsdrupal/nightwatch/pull/1
And here is just this patch:
https://github.com/jsdrupal/nightwatch/compare/8.6.x...nightwatch-no-ins...
https://github.com/jsdrupal/nightwatch/compare/8.6.x...nightwatch-no-ins...
We're more than happy to take code reviews on GitHub (or PRs to the nightwatch branch!) if that's easier for anyone reviewing this 👍
This has been worked on by several people in the JavaScript initiative: justafish, dawehner, alexpott, drpal, mglaman, and mixologic
Comment #49
justafishComment #50
dawehnerComment #51
dawehnerComment #52
justafishComment #54
alexpottAdding issue credit using list in #48
Comment #55
lendudeI just followed the steps in the README and it works!! Pretty sweet!
First run through:
when installing I get a : " warning Lockfile has incorrect entry for "glob@^7.1.2". Ignoring it."
The dotenv docs need some love I feel:
'this value' and then we have 3 values. I'm assuming DRUPAL_TEST_BASE_URL but lets be more specific then 'this value'
This could use some explanation as to it's use
This could use some explanation as to it's use and maybe directions to use alternatives to sqlite (if we want to), or else just say you need to leave this alone?
This makes it sound like these settings ar optional, which they are not. So I'd add something like 'When using DRUPAL_TEST_CHROMEDRIVER_AUTOSTART leave this at the default settings.'
Use => use
this could use a little explanation block like the others have. 'Nightwatch generates output files. Use this to specify the location where these files need to be stored. The default location is ignored by git, if you modify the location you will probably want to add this location to your .gitignore.', something like that.
This could use a little explanation as to what it does besides what syntax to use.
When enabling ESLint in PHPStorm, it had something to say about a lot of the .js files getting added here, so might be worth running that to clean some stuff up.
Some stuff I see that ESLint won't pick up:
it's a function so we probably need a docblock
needs => need
missing @param for callback
it's a function so we probably want a docblock
That comment doesn't seem relevant here
Already saw that this was mentioned on the slack channel, but lets rename this to something other then index.js
missing colon at the end.
Comment #56
justafishThanks @Lendude! PR updated and new patch attached (mostly fixed by @dawehner) https://github.com/jsdrupal/nightwatch/pull/1
Interdiff: https://github.com/jsdrupal/nightwatch/compare/2a1d4ceee9a2b65c453610ce0...
Comment #58
justafishSorry, wrong branch :)
This patch update incorporates @Lendude's feedback as well as work @dawehner did on simplifying the install/uninstall commands within Nightwatch.
Interdiff: https://github.com/jsdrupal/nightwatch/compare/4fde987...nightwatch-no-i...
---
https://github.com/jsdrupal/nightwatch/pull/1
https://github.com/jsdrupal/nightwatch/compare/8.6.x...nightwatch-no-ins...
https://github.com/jsdrupal/nightwatch/compare/8.6.x...nightwatch-no-ins...
Comment #60
justafishComment #61
lendudeThis is now not escaping right, the setup class winds up being DrupalTestSiteTestSiteInstallTestScript and so the test fails to run now (for me locally at least), it works when reverted back to
setupClass.replace(/\\/g, '\\\\')(also a little easier on the eyes :-)The rest of the changes look good.
Comment #62
dawehnerI'm wondering whether passing in a filename would be actually easier to use, even the internal implementation might be harder to figure out.
Comment #63
dawehnerRebase against 8.6.x now that the test installation is in.
Comment #64
jibranWe should add a comment why are we adding cookie prefixed simpletest. Maybe @todo with issue ID to remove this as well. When simpletest is gone.
Comment #65
dawehnerSure, let's open up an issue: #2959504: Replace SIMPLETEST_USER_AGENT cookie name
Comment #67
MixologicDrupalci is now noticing that the tests are failing, but the 'build successful' part of things is not doing what it is supposed to do. Im working on improving that.
Comment #68
dawehnerRerolled with a fix which ensures we are not scanning into sites/*/files
Comment #69
alexpottsetupFile now :) Also might be better as
Allow the setupFile argument to be omittedI think this comment is now obsolete
Why a new line here? Is it enforced by eslint?
I'm not sure this comment is needed here.
Comment #70
alexpottForgot to credit myself from the list in #48.
Comment #71
alexpottWe're going to need a change record for this.
Comment #73
dawehnerSure
I totally agree
There is no reason
I addressed the review on https://github.com/jsdrupal/nightwatch/pull/27
Comment #74
justafishInterdiff: https://github.com/jsdrupal/nightwatch/compare/3d2c2c1e4ecd1629f15dfcb17...
Comment #76
dawehnerRerolling against head
Comment #78
dawehnerNote: This is currently failing because sites/*/files doesn't have an executable flag on the testbot. The glob node library still tries to list that directory and fatals.
The glob ignore pattern is applied afterwards.
Comment #79
MixologicThe permission problem we're having is due to a couple of tests in drupal core that deliberately set the directory permissions to 0000 as part of a test, and that one directory then ends up lingering around:
http://cgit.drupalcode.org/drupal/tree/core/modules/file/src/Tests/SaveU...
I've put a hacky fix into drupalci, but ultimately, Im pretty sure that this shouldnt be scanning the whole filesystem, as it's bound to run into other issues elsewhere.
I've started the test and its rerunning now.. results in #76 will reflect the new situation soon.
Comment #80
MixologicRequeued, because, as my other experiments have taught me, FunctionalJavascript tests are kinda fragile.
Comment #81
MixologicThere. we. Go.
Comment #82
mile23Just to point out that the test which checks test-site.php is both buggy and not being run by the testbot: #2962157: TestSiteApplicationTest requires a database despite being a unit test
Comment #83
justafish@Mixologic did you end up excluding the directory with DRUPAL_NIGHTWATCH_IGNORE_DIRECTORIES in .env?
Comment #84
lendudeNits:
.idea/ maybe?
_ => )
teared down => torn down
Not nit:
I tried adding a second test in a different spot to test if the discovery was working. In my case I went to core/modules/views/tests/src/Nightwatch/Tests and copied the example test there. Changed the name of the test but that was it.
Ran nightwatch, discovery was fine, but the test would hang on the second test all the time (which in this case was the original exampleTest). After a couple of minutes I would kill it, second time round, same result.
After some more messing around I've seemed to have killed everything:
But I wouldn't expect problems when having two tests, so that needs a look I think.
Comment #85
dawehner@Lendude
I was not able to reproduce the problematic behaviour you described. I copied the test, renamed it to a new file name and executed the tests.
Both of these tests got executed.
Comment #86
lendudeRebooted, tried again, hangs again on the second test. I’m just literally following the README with a completely unchanged .env file.
I see that chrome goes to localhost:8888 and then keeps waiting. The 'timed out' error above only appeared after I stopped chrome, so the 'waitFor' didn't seem to trigger either after 1000ms.
Comment #87
Mixologic@lendude: if its timing out on
ETIMEDOUT 127.0.0.1:9515, thats nightwatch trying to connect to chromedriver's default port of 9515. Are you running selenium standalone or chromedriver? (do the instructions tell people that its necessary?)@justafish: No, I didn't use
DRUPAL_NIGHTWATCH_IGNORE_DIRECTORIES in .env?, I just did a recursive chmod on the sites directory to avoid the permissions issue. What should I set that to? 'sites' dir?Comment #88
Mixologic@justafish: re #83: I just re-reviewed what drupalci is really doing, and it reads in the
.env.examplefile and it preserves theDRUPAL_NIGHTWATCH_IGNORE_DIRECTORIES.The issue is that its currently set to
node_modules/,vendor/,.git/,sites/*/files, but the folder that it was finding was in/var/www/html/sites/simpletest/66530328/files/dir/tests, so I think we might need to adjustsites/*/filesto besites/**/filesso it ignores those oddball test folders.Comment #89
lauriiiNice work on minimizing the steps required for being able to run JavaScript tests. I was able to run these tests in less than five minutes!
This regex doesn't capture the path.
What does this do? I couldn't find any mentions of this in the documentation.
What is the current behavior in case of an error? Does
this.assert.fail()prevent the tests from continuing? Do we attempt to tear down even if the installation failed?s/(optional_/(optional)
Can we document how to run a single test?
Comment #90
justafishassert.fail is documented here and here - Nightwatch extends node's built in assertion library. It'll fail and stop the tests if used.
Interdiff: https://github.com/jsdrupal/nightwatch/pull/29/files/7c7b305f5189b0affc4...
Comment #91
justafishRe-roll into a unified patch
Comment #92
justafishAddresses feedback from @lauriii in Slack
interdiff: https://github.com/jsdrupal/nightwatch/pull/29/files/f14c7fe06fd241eed7b...
Comment #93
lokapujyaCan it support a minimum engine version or exact version? I was able to get it working with the exact versions, didn't try latest versions.
Comment #94
justafish- Adds more specific engine requirements (latest node 8 security release and latest version of yarn)
- Removes .nvmrc as this will be soon be pulled from package.json, and we don't want to keep it updating versions in 2 places (https://github.com/creationix/nvm/pull/1535)
- Fixes the hang encountered after using the uninstall command
- Refresh yarn lockfile
Interdiff: https://github.com/jsdrupal/nightwatch/pull/35/files https://patch-diff.githubusercontent.com/raw/jsdrupal/nightwatch/pull/35...
Comment #96
lokapujya"Adds more specific engine requirements (latest node 8 security release and latest version of yarn)"
I'm not sure if this was added because of my comment in #93, but I only meant to ask a question, not suggest any change. What I meant to ask was: Can someone use a newer engine version or does it only support the version specified?
Comment #97
MixologicI updated drupalci to have the latest versions of yarn and nodejs, and the php7/mysql5.5 environment is passing. Im not going to retest all the other environments, as Im not sure what those were attempting to establish.
Comment #98
jibranCan we please have a review only patch as well to make reviewers life easier?
Comment #99
alexpott@jibran not sure what you want from a review only patch since everything needs to be reviewed - yes you can ignore some parts of the yarn.lock but the added dependencies should be reviewed along with everything else.
Comment #100
jibranYeah, that's what I meant.
Comment #101
dawehner@jibran
Is this file the same as the previous patch, but without the yarn.lock file?
Comment #102
jibranI used
nightwatchbranch from https://github.com/jsdrupal/nightwatch merged it with 8.6.x and created the patch and didn't include the yarn.lock file.Comment #103
justafishUpdates patch to fix the tests hanging and never exiting in some circumstances, and a command to log out the browser console to a JSON file.
Interdiff from #94: https://github.com/jsdrupal/nightwatch/pull/36.diff
Comment #105
justafishFixes test failure where currentTest.name isn't populated in Nightwatch if there's only 1 test step.
Interdiff: https://patch-diff.githubusercontent.com/raw/jsdrupal/nightwatch/pull/39...
Comment #106
lendudeStill same result. Here is the interdiff to #105 that I'm using.
As you can see the first test runs fine, the time out in the second test only occurs once I close the Chrome window that the test spawned. I've let it run for 5 minutes, but nothing happens, just an empty page that points to
data:,woot!
Ahhhh the old d.o issue queue rubber duck doing its magic, while writing this I got it to run. MAMP PRO is getting in the way. Stopping the services there makes the tests pass. Why this would impact only the second test, not a clue!
Comment #107
justafishRemoves auto-starting of the web server as it's causing problems for me too with the second test @lendude provided. Seems fine when I start it myself and it doesn't seem unreasonable to request the user start the webserver.
interdiff: https://github.com/jsdrupal/nightwatch/pull/29/files/9bafc5faec44d3983f5...
Comment #108
lendudemaybe add 'by running the following command in your Drupal root folder'. Cause the command works fine when .ht.router.php can't be found, the tests just fail with very verbose errors.
It's unclear to me from the documentation what this does and how this would work. Is it just weird indenting?
why just "4", seems more loose then the other packages
It's annoying that we need to do this every time, is there an upstream issue for this, and if so, can we link to this somewhere?
Uhhh this is called as logAndEnd() in the rest of the code. How does that work??
Also not the most descriptive name ever, logErrorsAndEndBrowserSession maybe?
We are missing a @param here.
The param doesn't exist any more
Comment #109
justafishAll feedback addressed, except for logAndEnd which I kept as it is because it's analogous to the built-in "end" command http://nightwatchjs.org/api/end.html
Interdiff: https://github.com/jsdrupal/nightwatch/pull/42/files
Comment #110
lendudeThat is really clear! Great improvement.
that's fair. Good reason to keep it that way.
---------------------------------------------
Ran the whole setup again, ran tests against both the PHP build in web server and Apache (using MAMP) and both worked without issue.
I have no idea if the set up instructions are valid or working in any other OS then OSX, did anyone verify that? I see that a number of people ran this successfully, but don't know on what systems they did so.
But this looks great from my end, all feedback has been addressed, RTBC from me.
Comment #111
alexpottCrediting @michielnugter and @droplet for discussions on the overall state of JS testing.
Crediting @lauriii for reviews and discussions in slack
Crediting @effulgentsia for framework manager review.
Comment #112
alexpottSome coding standards issues:
Patch attached addresses them + @lauriii's comment on https://github.com/jsdrupal/nightwatch/pull/42/files
Comment #113
alexpottCommitted aeb5733 and pushed to 8.6.x. Thanks!
Forgot to update the lock file in #112. Updated it on commit.
Comment #115
lauriii🚀🎉
Comment #117
gábor hojtsy