Commit Graph
73 Commits
Author SHA1 Message Date
Ben NewmanandPaul O’Shannessy 23c5332208 Fix ReactTestUtils.mockComponent so that mockTagName is not ignored.
The `mockTagName` parameter was always optional, and so probably was not
used very often. If you tried to use it, it would be shadowed by the
`var mockTagName` declaration in the `render` method, so only
`module.mockTagName` or `"div"` were ever possible values.
2014-07-18 22:01:36 -07:00
Pete HuntandPaul O’Shannessy c93583c84f Remove bad perf metric
Remove a bad perf metric. Will investigate later.
2014-06-14 20:40:09 -07:00
Pete HuntandPaul O’Shannessy e1c2d02fdd Create ReactEventListener
Per our discussion friday, this creates ReactEventListener and renames variables to use the "handle"
nomenclature.
2014-06-14 20:38:45 -07:00
Josh DuckandPaul O’Shannessy 29f3f74c52 Make perf show all exclusive time, not just render time.
Currently require('ReactDefaultPerf').printExclusive() shows render
time and aggregate componentMount time.

This makes it show exclusive mount time by tracking a stack.
2014-05-12 16:39:09 -07:00
Paul O’Shannessy 8af991f10b Codemod mockReturnValue externally
320024555c didn't update the mocks module
here, just the callsites.
2014-05-08 10:47:44 -07:00
Ben Alpert d5a4d29532 Fix some linty things 2014-04-28 23:30:05 -03:00
Juraj DudakandPaul O’Shannessy 385eb1cef1 Fixed a bug in expectRenderedChildAt
React components have _mountIndex, that looks like it is their order in DOM.
If you swap 2 elements in DOM, their order in children array isn't changed, but their _mountIndex is
2014-04-18 12:57:24 -07:00
Tim YungandPaul O’Shannessy 356e85cd6a Separate performanceNow into own project 2014-04-09 18:50:11 -07:00
Sebastian MarkbageandPaul O’Shannessy c40e06f728 First phase to true descriptors
This moves all convenience constructors to use frozen ReactDescriptors.
2014-03-28 12:32:53 -07:00
Paul O'ShannessyandPaul O’Shannessy fe9cecd507 Clean up assertions on descriptors
By making this fail, we catch a lot of tests that are expecting rendered
instances but are actually operating on descriptors.
2014-03-27 13:41:18 -07:00
Ben Alpert a447d30a2e Rebuild simulators after injecting plugins 2014-02-19 00:28:34 -08:00
Ben Alpert 36e97bac21 Simulate synthetic events using ReactTestUtils
Most of the time this is what you want to do, so I've renamed what was Simulate to be SimulateNative.

Now Simulate.change does what you expect, so this fixes #517 and fixes #519.
2014-02-19 00:04:16 -08:00
Ben Alpert 9f9ee697f3 Simpler ReactTestUtils.simulateEventOnDOMComponent 2014-02-18 23:37:11 -08:00
Paul O’Shannessy 8a47813baa Update copyrights for 2014.
grep -rl 'Copyright 2013 Facebook' static_upstream | xargs perl -pi -w -e s/Copyright 2013 Facebook/Copyright 2013-2014 Facebook/g;'

Not going to check in a script to do this since it will just change every year.
Closes #1006
2014-02-18 17:06:43 -08:00
Josh DuckandPaul O’Shannessy acbba1ae67 Updates to perf
ReactDefaultPerf:

* Show times as float instead of string. This means they're sortable.
* Add count columns to all types and average to exclusive time.
* Include mountComponent where updateComponent time is measured.
* Increment count on _renderValidatedComponent instead of update.

ReactDefaultPerfAnalysis:

* Return counts with all summaries.
2014-02-13 18:21:17 -08:00
Ben Alpert 55be7a71c5 Measure root component render in ReactDefaultPerf
Fixes #1074.
2014-02-13 00:59:02 -08:00
Pete HuntandPaul O’Shannessy 3895353326 [perf] Refactor ReactDefaultPerf and add DOM operation tracing
Split the summary functions into a separate module, and add the ability to view a lot of all DOM operations. Removed DOM timing since it was incorrect. Will potentially replace with a
dropped frame counter in the future.
2014-02-12 16:35:24 -08:00
Pete HuntandPaul O’Shannessy 75b58d2ad2 [perf] Wasted time metrics
This logs DOM ops for a given reconcile. Based on which components rendered and which ones *actually* caused DOM updates we can find
opportunities to add shouldComponentUpdate() methods.
2014-02-12 16:34:37 -08:00
Pete HuntandPaul O’Shannessy 94ef6c51fb [perf] Better inclusive measurements
Inclusive time is still not that helpful w/o looking at what actually resulted in DOM ops. However, this is better than what we have today and will serve as a building block.

I blacklisted everything but composite components -- hopefully that's OK.
2014-02-12 16:34:24 -08:00
Pete HuntandPaul O’Shannessy 439bca78ed [perf] New ReactDefaultPerf
Simplified version of https://github.com/facebook/react/pull/962. More goodies coming soon since the inclusive time isn't very helpful right now.
2014-02-12 12:30:02 -08:00
Pete HuntandPaul O’Shannessy a6749a686f [perf] Change how ReactDefaultPerf is injected
ReactDefaultPerf should inject itself when require()'d. This continues to support the ?react_perf use case for logging on initial page load.
2014-02-12 12:29:00 -08:00
Sebastian MarkbageandPaul O’Shannessy fc2805fe03 Add warnings when accessing properties/methods on unmounted components
This creates a membrane around the React component prototype. It warns if you
try to access properties on the component before it's unmounted. Before it's
mounted, it should be considered a descriptor and not an actual instance.

The workaround, for unknown types, is to access the constructor using
component.type which has static methods on it.
2014-02-11 09:13:03 -08:00
Cheng LouandPaul O’Shannessy 5dabba999b add missing 'use strict' to getTestDocument 2014-02-03 12:52:46 -08:00
Ben NewmanandPaul O’Shannessy ce95c3d042 [React] Don't attach to document in ReactTestUtils.renderIntoDocument. 2014-02-03 12:51:34 -08:00
Andreas Svensson 989eb2e7d9 Fix references to the old ReactID syntax 2014-01-26 21:26:58 +01:00
Pete HuntandPaul O’Shannessy 70a0746e9f Fix react tests 2014-01-06 18:35:54 -08:00
Ben NewmanandPaul O’Shannessy 1ee7f8131c Let components specify tag for ReactTestUtils.mockComponent to use.
If you're writing a test that involves a mocked component that normally
returns a `<li>` tag from its `render` method as the root element, mocking
it with a dummy `<div>` probably won't work, so you'll want to set

  MyListItemComponent.mockTagName = 'li';

The change to the `.mockImplementation` line makes sense because
`ConvenienceConstructor` is more or less synonymous (for these purposes)
with the wrapper that was previously used:

  function() {
    // This `this` used to be `null`, technically, but
    // ConvenienceConstructor doesn't pay attention to `this` anyway.
    return ConvenienceConstructor.apply(this, arguments);
  }
2014-01-02 20:03:55 -08:00
Ben NewmanandPaul O’Shannessy a00e4c840c Support ReactTestUtils.mockComponent. 2014-01-02 20:03:40 -08:00
Tim YungandPaul O’Shannessy 41230ef5dd A new helper for tests: createHierarchyRenderer
We aren't using this in any of the React tests, but we've found it
useful testing product code.
2013-12-17 18:07:53 -08:00
Paul O’Shannessy c2920ba84c Merge pull request #653 from fabiomcosta/patch-3
match -> test
2013-12-12 15:33:31 -08:00
Fabio M. Costa 39037eedd1 URL -> url 2013-12-12 15:29:29 -08:00
cpojer decb49a202 Use rest parameters whenever it makes sense. 2013-12-11 10:30:10 -08:00
Fabio M. Costa c7129fd377 match -> test
Using RegExp method `test` because this is what is wanted
2013-12-11 00:43:31 -08:00
Thomas Aylott 916ee6b394 jsx & JSDOM support 2013-11-27 17:04:40 -05:00
Thomas Aylott f4753030a2 IE support 2013-11-25 16:02:01 -05:00
Thomas Aylott 3bfb687de3 remove warning comment about createHTMLDocument 2013-11-25 15:08:00 -05:00
Thomas Aylott eebad16636 Use an iframe to create a testDocument…
instead of `createHTMLDocument` since it isn't fully support by the browsers we care about.

fixes #606
fixes #454
2013-11-25 15:05:35 -05:00
Ben Alpert af95b35f27 Have faith in var hoisting 2013-11-21 10:31:20 -08:00
Ben Alpert c7bb3af760 Mock modules properly in test runner
As an added bonus, the jasmine web interface now groups tests by file.

Test Plan:
grunt test passes on b2507066, the parent of 566f8b2e (which committed a workaround for buggy module mocking).
2013-11-21 00:39:37 -08:00
Christoph PojerandPaul O’Shannessy 2fe2cd5337 Ensure ReactPerf always uses a string as a URL 2013-11-20 14:19:13 -08:00
Ben Newman 5d878ce914 Merge pull request #550 from subtleGradient/subtlegradient/code-coverage
Code coverage grunt tasks.
2013-11-18 14:03:56 -08:00
Thomas Aylott ef5a02c164 enable coverage logging from the worker 2013-11-18 16:37:46 -05:00
Marshall RochandPaul O’Shannessy b91396be8e Contexts
Summary:
adds `this.context` which you can think of as implicit props, which are passed automatically down the //ownership// hierarchy.

Contexts should be used sparingly, since they essentially allow components to communicate with descendants (in the ownership sense, not parenthood sense), which is not usually a good idea. You probably would only use contexts in places where you'd normally use a global, but contexts allow you to override them for certain view subtrees which you can't do with globals.

The context starts out `null`:

  var RootComponent = React.createClass({
    render: function() {
      // this.context === null
    }
  });

You should **never** mutate the context directly, just like props and state.

You can change the context of your children (the ones you own, not `this.props.children` or via other props) using the new `withContext` method on `React`:

  var RootComponent = React.createClass({
    render: function() {
      // this.context === null
      var children = React.withContext({foo: 'a', bar: 'b'}, () => (
        // In ChildComponent#render, this.context === {foo: 'a', bar: 'b'}
        <ChildComponent />
      ));
      // this.context === null
    }
  });

Contexts are merged, so a component can override its owner's context **for its children**:

  var ChildComponent = React.createClass({
    render: function() {
      // this.context === {foo: 'a', bar: 'b'} (for the caller above)
      var children = React.withContext({foo: 'c'},() => (
        // In GrandchildComponent#render,
        // this.context === {foo: 'c', bar: 'b'}
        <GrandchildComponent />
      ));
      // this.context === {foo: 'a', bar: 'b'}
    }
  });
2013-11-18 10:56:24 -08:00
Thomas Aylott 8205c681eb serve worker.js from its actual relative path 2013-11-06 15:30:49 -05:00
Paul O'ShannessyandPaul O’Shannessy 46713c3d7d Fix Lint
Enabling bitwise linting caught another user. Also fixed a semicolon
misuse.
2013-10-15 17:59:14 -07:00
Jan KassensandPaul O’Shannessy c99d6a8013 Make the injection of ReactPerf work
The injection was only evaluated when ReactCompositeComponent was first loaded.
This made it impossible to inject a custom measure and the injection pointless.
2013-10-09 11:27:40 -07:00
Ben Newman f8c5752472 Merge pull request #374 from spicyj/workers
Test that React loads properly in a web worker.

Most of this code is open source-only, so I think it's safe to merge without figuring out how to translate it upstream first.
2013-10-09 08:50:41 -07:00
Paul O'ShannessyandPaul O’Shannessy f43449d333 ReactNativeComponent -> ReactDOMComponent
In an effort to break the DOMy parts of React away from the non-DOMy parts, I'm renaming this.
2013-10-01 16:31:32 -07:00
Ben Alpert 3dc1074908 Test that React loads properly in a web worker
This should catch top-level uses of `window` and `document`, while lint rules catch `global`.
2013-09-27 14:38:11 -07:00
Timothy Yung aa765e8fa3 Merge pull request #287 from spicyj/noglobal
Remove all uses of ExecutionEnvironment.global
2013-09-09 16:23:20 -07:00