TheLarkInn / webpack-developer-kit

webpack dev kit for writing custom plugins and loaders on the fly. Education/Exploration tool as well.
227 stars 42 forks source link

Write decent test suite #4

Open TheLarkInn opened 8 years ago

TheLarkInn commented 8 years ago
zhaoshengjun commented 8 years ago

Hi @TheLarkInn, I am interested in writing some tests.

Just to confirm that what you need is to test the npm script result, not the car.js,engine.js etc. Right?

If so, I will probably go with yeoman-test and yeoman-assert, they are used to test yeoman generators. So I think it's probably a good fit for this kind of task.

Do you have any opinions/suggestions?

TheLarkInn commented 8 years ago

Correct, you could use whatever you would like. Since these are kind of like integration tests which take a bit more time. I was interested in something like ava to run the commands against, but I'm really unopinionated about it. So I think that would be fine.

It would be nice to organize the suite also so that we can write (for developers) mini test suites for the custom loader and (if we externalized it) the custom plugin. Setting up fixtures and integration tests for loaders and plugins great because you run it against a real webpack build (which we have readily available in this case.

TheLarkInn commented 8 years ago

For the individual plugin and loader mini-test-suites, while you work on this for the package, I'll externalize both the plugin and loader in the project.

TheLarkInn commented 8 years ago

I created #16 which I will try to do atleast part of this when I have some time. This way once we have those tests, our 10 greenkeper.io PR's will actually be worth while to test and help really manage dependencies.

zhaoshengjun commented 8 years ago

Hi @TheLarkInn ,

I have some trouble in writing testing. Hope you can give some advice.

The issue is I can only assert the npm run command result, but I have some trouble to ensure the contents are correct. For example: After npm run dev command, I can get everything from the command line output, which I can assert whether the build is correct or has some errors. But I cannot sure the car.bundle.js is correct. I tried to use karma to start a web browser and do some work, but I cannot make it work.

Basically, unit testing can be done. But E2E testing is harder than I thought. Care to share some advices?

TheLarkInn commented 8 years ago

Maybe instead we just validate that the config is valid and runs. You could also look at the test suite that the angular CLI uses. https://github.com/angular/angular-cli/tree/master/tests/e2e/setup

zhaoshengjun commented 8 years ago

Hi @TheLarkInn ,

I think I may have made it. I will upload a WIP repo to show you.

Basically, I use selenium-webdriver to call a web browser, go to the dev serverlocalhost:8080, grab the html page and do my assertions.

I think it can satisfy our needs for testing.

vutran commented 8 years ago

We should remove jasmine since the API is available inside of jest itself.

zhaoshengjun commented 8 years ago

I leave it there because the E2E testing is driven by jasmine. And install jest doesn't create the jasmine command in the .bin folder.