Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

testing recommendation #24

Open
bobzoller opened this issue Mar 17, 2016 · 3 comments
Open

testing recommendation #24

bobzoller opened this issue Mar 17, 2016 · 3 comments

Comments

@bobzoller
Copy link
Contributor

I think it'd be cool to have some sort of recommendation around testing. Since the build tool bullshit lives in rwb, it seems we could benefit from a bit of coordination to reuse it all for tests.

As a concrete example, here's what I've started within my own rwb project. I like enzyme and mocha, and I like fast tests so I opted for the node flavor rather than karma, etc. But this means I need to babel myself, stub out webpack CSS requires (which is naive and will certainly break), and generally do things that follow a different flow than my production code will.

install deps

$ npm install --save-dev mocha chai enzyme chai-enzyme

package.json

[..snip..]
"scripts": {
  "test": "mocha -r babel-core/register -r ./mocha-compilers *.test.js"
}
[..snip..]

mocha-compilers.js

function noop() {
  return {};
}

require.extensions['.css'] = noop;

MyComponent.test.js

import React from 'react';
import chai, {expect} from 'chai';
import chaiEnzyme from 'chai-enzyme';
chai.use(chaiEnzyme());
import {shallow} from 'enzyme';

import MyComponent from './MyComponent';

describe('<MyComponent />', () => {
  it('renders hello world', () => {
    const wrapper = shallow(<MyComponent />);
    expect(wrapper).to.have.text('Hello, world!');
  });
});

Thoughts on how we could make this better? I'm happy to work on a PR once there's a plan.

@petermoresi
Copy link
Contributor

Mocha is a great tool. I use tape. Mocha is valid but not everybody wants to standardize on a test framework.

@bobzoller
Copy link
Contributor Author

yeah sorry, I was probably a little confusing. I threw out the example of
my own setup just for context. my point behind this PR is not to bless a
testing stack, but rather to discuss/discover a good way to test rwb apps
using the same build tooling that my rwb app uses.

On Thu, Mar 17, 2016 at 3:32 PM, Peter Moresi notifications@github.com
wrote:

Mocha is a great tool. I use tape. Mocha is valid but not everybody wants
to standardize on a test framework.


You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub
#24 (comment)

@bobzoller
Copy link
Contributor Author

a coworker just showed me how in test, he uses a webpack dev server configured exactly the same as development except that it doesn't include the app entrypoint -- and then karma runs the test file(s) itself and depends on that webpack bundle.

so the question I've yet to answer: is it useful (in a test framework independent way, per @petermoresi's comment) to bake-in the building of that test asset to rwb?

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

No branches or pull requests

2 participants