Skip to content
This repository has been archived by the owner on Dec 30, 2018. It is now read-only.

Setup testing #8

Open
vesparny opened this issue Jan 7, 2015 · 14 comments
Open

Setup testing #8

vesparny opened this issue Jan 7, 2015 · 14 comments

Comments

@vesparny
Copy link
Owner

vesparny commented Jan 7, 2015

No description provided.

@ghost
Copy link

ghost commented Jan 9, 2015

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

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

@vesparny
Copy link
Owner Author

@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.

  • mocha (test framework)
  • should (assertion)
  • sinon (mock/spy)
  • supertest (for testing routes)

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

ghost commented Jan 11, 2015

@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
Copy link
Owner Author

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

@ghost
Copy link

ghost commented Jan 11, 2015

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
Copy link
Owner Author

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 👍

@ghost
Copy link

ghost commented Jan 12, 2015

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

@jessy1092
Copy link
Contributor

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. 😄

@vesparny
Copy link
Owner Author

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

@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:

  • core
  • api

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

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:

  • content
    • themes
      • blablabla
        • Header.js
      • __test__
        • Header-test.js

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

maybe like:

  • content
    • themes
      • comments
        • block.js
        • __test__
          • block-test.js

@vesparny
Copy link
Owner Author

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
Copy link
Owner Author

@jessy1092 any news here?

@jessy1092
Copy link
Contributor

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants