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

Native Integration for Running Unit Tests in CodeSandbox #445

Merged
merged 17 commits into from
Jan 16, 2018

Conversation

gautamarora
Copy link
Contributor

@gautamarora gautamarora commented Jan 12, 2018

What kind of change does this PR introduce?
This PR adds native integration of unit testing using jest packages as discussed in this issue

What is the current behavior?
Currently, there is no support for unit testing.

What is the new behavior?
For a project with unit tests, Code Sandbox will run those tests and show the results in a new Tests tab (next to the Console tab)

Feature Checklist (v1):

  • Basic Unit testing
    • test, it
    • describe
  • Component testing
    • Shallow rendering
    • Mock functions
  • Auto test detection
  • Typescript support
  • Test Summary reporting

Checklist:

  • Documentation
  • Tests
  • Ready to be merged
  • Added myself to contributors table

@gautamarora gautamarora changed the title Adding native integration for unit tests [WIP] Adding native integration for unit tests Jan 12, 2018
@gautamarora
Copy link
Contributor Author

👋 @CompuIves - as you mentioned here

But we should add functionality to specify globals. I can do this, so you can specify an object like this:

{
  it,
  expect,
  // etc
}

could you help add it, expect, describe, jestMock from runner to globals

});

debug(`Test Evaluation time: ${Date.now() - tt}ms`);
dispatch({
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@CompuIves - the messages being dispatched from here do not seem to be showing up for me in the handleMessage of Console/index.js

@CompuIves
Copy link
Member

Great! I've added the globals 😄 . Implementation looks really good so far.

@gautamarora
Copy link
Contributor Author

gautamarora commented Jan 12, 2018

@CompuIves - I've created a new TestManger TestRunner class and we now have a nice api to run tests from compile...

let testRunner = manager.testRunner;
testRunner.resetResults();
testRunner.findTests(modules);
await testRunner.transpileTests();
let testResults = testRunner.runTests();
console.log(testResults);

Next, I will look into why the dispatch results are not making their way to the Console.

@gautamarora
Copy link
Contributor Author

dispatching results to Console now works!

@CompuIves
Copy link
Member

This is sooo cool! I love how clean it is. Do you need help with the tab for the tests in the DevTools? I could work on that in the meantime if that makes sense.

Also, do you have a test sandbox with test files? Would love to play with it a bit 😄

@gautamarora
Copy link
Contributor Author

@CompuIves - Thank You!
Yes, I could use your help for the Tests tab, both in adding one and thinking through how it should render the test output. One of the amazing things about the Code Sandbox experience is how clean and intuitive the UI is. I was thinking that the Tests tab should reflect that as well. Maybe we think of the Tests tab as a beautiful intuitive & helpful test reporter. Please go ahead and spin your magic! 😄

Here are 2 test sandboxes that you can try out:
Simple sandbox with 1 file and 1 test: http://pr445.cs.lbogdan.tk/s/ll4nxm6olq
React Redux TodoMVC App (all tests pass!): http://pr445.cs.lbogdan.tk/s/github/reactjs/redux/tree/master/examples/todomvc

@CompuIves
Copy link
Member

Maan this is so impressive!

I'll try my hand at the tab, it would be great if every test result had 2 extra properties: a property with an array called something like describe that specifies which describes it is in and a property called file with the file name. I want to try something with grouping the tests in the devtools.

@gautamarora
Copy link
Contributor Author

@CompuIves - yes totally agree with grouping of tests using describe (right now i ignore describe but i can fix that easily) and with adding file names (not 100% sure how to do that, but will find a way).

@gautamarora gautamarora changed the title [WIP] Adding native integration for unit tests [WIP] Native Integration for Running Unit Tests in CodeSandbox Jan 14, 2018
@gautamarora
Copy link
Contributor Author

gautamarora commented Jan 15, 2018

@CompuIves - looks like all of the v1 functionality work for this is done. I will rebase this soon.

When you merge this to master, will you also be releasing a new version of the site, or is that only going to happen with v2.5 later? If this is not going to be released immediately after merging, then I can create another PR later to add test cases for the test runner.

In the meanwhile, let me know if you have any feedback on the code.

@CompuIves
Copy link
Member

When you merge this to master, will you also be releasing a new version of the site, or is that only going to happen with v2.5 later? If this is not going to be released immediately after merging, then I can create another PR later to add test cases for the test runner.

It will be immediately released. I'll do a review now!

Copy link
Member

@CompuIves CompuIves left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks very good, clear and easy to read!

I left one question, also I think it's be best if the console.log comments are removed before merging. Other than that I'm eager to merge this!


let summaryEmoji =
aggregatedResults.totalTestSuites === aggregatedResults.passedTestSuites
? '😎'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hahaha I love this

@@ -0,0 +1,210 @@
// @flow
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's with this file?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, not sure. checking.

@@ -661,7 +663,8 @@ export default class TranspiledModule {
this.source.compiledCode,
require,
this.compilation,
manager.envVariables
manager.envVariables,
TestRunner.testGlobals()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great!

@gautamarora
Copy link
Contributor Author

@CompuIves - i removed the console logs and that odd file.

@gautamarora gautamarora changed the title [WIP] Native Integration for Running Unit Tests in CodeSandbox Native Integration for Running Unit Tests in CodeSandbox Jan 16, 2018
@gautamarora
Copy link
Contributor Author

@CompuIves - what sort of documentation (if any for now) should I add. I can add Tests for this over the next few days if you are ok merging without them.

@CompuIves
Copy link
Member

CompuIves commented Jan 16, 2018

It would be great to have documentation ready for the 25th, you can create docs here: /~https://github.com/CompuIves/codesandbox-client/blob/master/packages/homepage/content/docs/. In the meantime we can merge it in 😄 .

Thank you very much for this immense help. This is a very big feature to have!

@CompuIves
Copy link
Member

Hmm, something strange happens with the jest test, I'm not sure why...

@CompuIves CompuIves merged commit ecf05f9 into codesandbox:master Jan 16, 2018
gautamarora added a commit to gautamarora/codesandbox-client that referenced this pull request Jan 16, 2018
* upstream/master:
  Fix test
  Native Integration for Running Unit Tests in CodeSandbox (codesandbox#445)
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

Successfully merging this pull request may close these issues.

2 participants