vesparny / morpheus

The next generation web publishing platform built with React.js
MIT License
673 stars 42 forks source link

Setup testing #8

Open vesparny opened 9 years ago

ghost commented 9 years ago

Hi,

What kind of setup are we talking about? I use Jasmine for running my tests, and while I'm still learning to write tests, I have put some practice into it, and I'm looking to improve. Could you elaborate on the kind of setup you want?

jessy1092 commented 9 years ago

Maybe use Jest for jsx test? It builts on top of the Jasmine test framework.

vesparny commented 9 years ago

@AJ-Santos the basic idea is to cover the whole codebase with tests. As starting point we could start testing the endpoints for both API and page routes.

I've already included the right dependencies in package.json.

For an example of what I mean you can take a look at the Ghost's functional tests here

After that we can try writing unit tests for services, repositories, config and so on.

I've also created the testing.js configuration file inside the config folder. Every testing specific configuration should live in it.

Some time ago I wrote some test for another node app, you can take some inspiration if you will, here's the link.

@jessy1092 I'm a noob at Jest and have no experience in React testing, any help here would be awesome.

ghost commented 9 years ago

@vesparny I was thinking that it might be better to start by testing the business logic and testing the endpoints later because running those tests from the beginning will eventually make tests take too long to run.

If we start with the more basic business logic we'll get more tests done that run quickly, and test for more use cases that won't reach the endpoints.

vesparny commented 9 years ago

@AJ-Santos you are right, better start from the beginning. Any thoughts on how to structure files and folder?

ghost commented 9 years ago

I'm not familiar with Mocha so my suggestion would be to use this structure, just because I don't know a better way. If you prefer a different structure then let me know.

vesparny commented 9 years ago

I created in another project the basic structure for testing the app with mocha. It's also fully integrated with gulp, take a look here, https://github.com/getPoseidon/Poseidon.

I reused this structure for Morpheus, if you look at the gulp file you'll find the test task.

gulp.task('test', function() {
    return gulp.src(['test/*.js'], {
        read: false
    })
    .pipe($.mocha({
        reporter: 'spec'
    }))
    .on('error', $.util.log);
});

If you run it, one test is executed.

gulp test

So basically the structure is already in place, you just need to write the first test :+1:

ghost commented 9 years ago

I gave it a shot but I have to admit that creating tests for this project is out of my scope.

jessy1092 commented 9 years ago

Jest can write jsx in test, so it is more friendly to test react component. Here some test react component in my project.

Mocha also can test react component, but just more complicated. React test with mocha

Do we need two system for testing? One for business logic, one for components? This is just the opinion.

I don't mind to write the mocha to test react components. :smile:

vesparny commented 9 years ago

@AJ-Santos thanks for you effort, let me know which task do you want to take. :+1:

@jessy1092 we can use mocha to test what is not React, and Jest for testing the template. Please consider that the idea is to have the template completely separate from the basic application. I mean that I don't want to keep Morpheus as a Monolithic application but I'd like to split it in several npm modules:

Morpheus will provide a command line interface which will install a local blog.

So the problem now is: How can we test the template within an isolated scope? Is this doable for you?

jessy1092 commented 9 years ago

Yap, It's mean components would also be separated in several npm modules. Right? It's a very good idea. I like that.

In Jest, we can write the test follow the component and write in the componets' folder. One test file for one component. That can easily separate in the future.

like:

We also can separate components in difference folder first if already know it would be separated in the future.

maybe like:

vesparny commented 9 years ago

For now I'd leave The theme folder only one level deep, no need for subfolders. I'm pretty curious to see your PR ;)

vesparny commented 9 years ago

@jessy1092 any news here?

jessy1092 commented 9 years ago

I just trace the code. I'll write the react test in the weekend. :)