Commit Graph

17 Commits

Author SHA1 Message Date
Christoph Pojer 91b2dbb1de Fix incorrect line numbers in test failures
Reviewed By: voideanvalue

Differential Revision: D4597677

fbshipit-source-id: 9e10fb7aaee16cd902489cd95cfb04a151da2226
2017-02-22 06:51:15 -08:00
Sebastian Markbage c3b25c9059 Patch up for future React Sync
Reviewed By: spicyj, bvaughn

Differential Revision: D4523259

fbshipit-source-id: 317a26ce3e9e48553a7f7c856dd6b48038b4b2ea
2017-02-08 14:50:43 -08:00
Christoph Pojer a2c84d14ce Remove `react-packager` indirection.
Summary:
This moves the `src` directory one level up and removes the `react-packager` folder. Personally, I always disliked this indirection. I'm reorganizing some things in RNP, so this seems to make sense.

Not sure if I forgot to update any paths. Can anyone advice if there are more places that need change?

Reviewed By: jeanlauliac

Differential Revision: D4487867

fbshipit-source-id: d63f9c79d6238300df9632d2e6a4e6a4196d5ccb
2017-02-02 05:44:15 -08:00
Alex Kotliarskyi 2275ca5a7f Add UIManager method mocks to jest/setup.js
Reviewed By: cpojer

Differential Revision: D4420536

fbshipit-source-id: 4fb5c1857974b4d32e21de6d5b5b581213aad87b
2017-01-20 16:43:42 -08:00
David Aurelio 0849f84df2 create better debuggable source maps
Summary:
Introduces a new mechanism to build source maps that allows us to use real mapping segments instead of just mapping line-by-line.

This mechanism is only used when building development bundles to improve the debugging experience in Chrome.

The new mechanism takes advantage of a new feature in babel-generator that exposes raw mapping objects. These raw mapping objects are converted to arrays with 2, 4, or 5 for the most compact representation possible.
We no longer generate a source map for the bundle that maps each line to itself in conjunction with configuring babel generator to retain lines.

Instead, we create a source map with a large mappings object produced from the mappings of each individual file in conjunction with a “carry over” – the number of preceding lines in the bundle.

The implementation makes a couple of assumptions that hold true for babel transform results, e.g. mappings being in the order of the generated code, and that a block of mappings always belongs to the same source file. In addition, the implementation avoids allocation of objects and strings at all costs. All calculations are purely numeric, and base64 vlq produces numeric ascii character codes. These are written to a preallocated buffer objects, which is turned to a string only at the end of the building process. This implementation is ~5x faster than using the source-map library.

In addition to providing development source maps that work better, we can now also produce individual high-quality source maps for production builds and combine them to an “index source map”. This approach is unfeasable for development source maps, because index source map consistently crash Chrome.

Better production source maps are useful to get precise information about source location and symbol names when symbolicating stack traces from crashes in production.

Reviewed By: jeanlauliac

Differential Revision: D4382290

fbshipit-source-id: 365a176fa142729d0a4cef43edeb81084361e54d
2017-01-12 14:28:41 -08:00
Mike Grabowski 8305743725 Fix jest tests
Summary: https://www.facebook.com/groups/reactnativeoss/permalink/1627334037563224/

Differential Revision: D4357483

fbshipit-source-id: 32e9d91c2348e4046a5cfaa08eab34d1f4dd2f7e
2016-12-21 07:58:25 -08:00
Emmanouil Konstantinidis 797506f09f Jest - Support Immutable Objects for ListViewDataSource mock
Summary:
Currently the jest mock for `ListViewDataSource` has a property called `items` which returns the number of items of the data source. Example from a snapshot:

    ListViewDataSource {
      "items": 6,
    }

If the datablob includes immutable Maps like:

    const dataBlob = {
      'alpha': immutable.Map({ name: 'Alpha' }),
      'beta': immutable.Map({ name: 'Beta' }),
    };

then the result is:

    ListViewDataSource {
      "items": NaN,
    }

This PR checks if the properties of the `dataBlob` are immutable Maps and then checks whether they are empty.

The result for the above dataBlob would be:

    ListViewDataSource {
      "items": 2,
    }
Closes https://github.com/facebook/react-native/pull/11567

Differential Revision: D4354977

Pulled By: cpojer

fbshipit-source-id: 9f6bd6ea9896eebd9373344a43ffe97deee5015b
2016-12-20 16:58:29 -08:00
Spencer Ahrens 5537055bf8 Add some `Fake`s for easier interaction snapshot testing
Summary:
`Fake` components are simplified so snapshots are stable and reliable, and references are exported
so that interactions like `onRefresh` and `onScroll` can be called manually. Currently there is just
one global export for each class, but we may change this in the future if we need to manage multiple
`Fake`s of the same type in one render tree.

Right now these must be installed explicitly, but I might move them into `__mocks__` folders if it
seems reasonable to make them defaults.

Reviewed By: cpojer

Differential Revision: D4318207

fbshipit-source-id: 62802353a98b09ca1c80804ef7201ea63091f94a
2016-12-20 15:58:30 -08:00
Nelen 2190221c44 Added mocked functions to StatusBarManager
Summary:
**Description:**
Jest tests that use that StatusBar failing because the status bar functions aren't mocked.
Errors I ran into:
`TypeError: StatusBarManager. setNetworkActivityIndicatorVisible is not a function`
`TypeError: StatusBarManager. setHidden is not a function`
`TypeError: StatusBarManager. setStyle is not a function`

**Fix:**
Added mocks for all the functions that the StatusBar offers according to the docs: https://facebook.github.io/react-native/docs/statusbar.html

**Test plan (required)**
Verify that the tests using StatusBar and its functions succeed.
Closes https://github.com/facebook/react-native/pull/11322

Differential Revision: D4284536

Pulled By: cpojer

fbshipit-source-id: b67be8c0595d91ee9aca4784f457c0959d7e45d5
2016-12-06 05:58:32 -08:00
mlanter 39554ab32c Fix missing mock for StatusBarManager
Summary:
Fix an issue when running Jest unit tests due to a missing mock for StatusBarManger.

**More info:**
In one of my files I have:
```
export const STATUS_BAR_HEIGHT = (StatusBar.currentHeight || 0);
```
When I run the tests it gives this error, which seems to be because StatusBarManager is undefined (https://github.com/facebook/react-native/blob/master/Libraries/Components/StatusBar/StatusBar.js#L20)

```
TypeError: Cannot read property 'HEIGHT' of undefined
  at Object.<anonymous> (node_modules/react-native/Libraries/Components/StatusBar/StatusBar.js:395:1823)
  at Object.StatusBar (node_modules/react-native/Libraries/react-native/react-native.js:55:24)
```

**Test plan (required)**
Verify that with this change tests that use StatusBar pass.
Closes https://github.com/facebook/react-native/pull/11198

Differential Revision: D4246367

Pulled By: cpojer

fbshipit-source-id: ee9406d2566688d235a11cab8f24b0583698e93a
2016-11-29 22:13:44 -08:00
Kevin Cooper 00f888a318 Add missing mock for AppState
Summary:
**Description**

In the same vein as https://github.com/facebook/react-native/pull/11198, this adds a mock for the native module `AppState`.

**Test plan**

Create a component that uses `AppState`, e.g.

```jsx
import React, { Component } from 'react';
import { AppState } from 'react-native';

class TestComponent extends Component {
  componentDidMount() {
    AppState.addEventListener('change', this.stateChangeListener);
  }
}
```
Closes https://github.com/facebook/react-native/pull/11199

Differential Revision: D4246668

Pulled By: cpojer

fbshipit-source-id: e3a73a98963a0e152a70aba78ef3461b86da0f6c
2016-11-29 14:43:38 -08:00
Tim Yung 23331df5a4 RN: Cleanup OSS JS & Flow Declarations
Reviewed By: vjeux

Differential Revision: D4210763

fbshipit-source-id: 5abaa547100b8badd13bcf311ceffc5b4098d252
2016-11-20 17:58:29 -08:00
Cristian Carlesso 6d3e074dd4 Adding Jest preset so that people can configure Jest using react-native as preset
Reviewed By: cpojer

Differential Revision: D4081817

fbshipit-source-id: 43cf2ec467ea69651705162b6a58e0b3f1ad1dbf
2016-10-31 12:58:35 -07:00
Cristian Carlesso 9833e1bd34 Fixes typo
Reviewed By: bestander

Differential Revision: D4103918

fbshipit-source-id: 1176f97cf489180490e497be7deca331ed26e730
2016-10-31 09:28:36 -07:00
Cristian Carlesso 45275e30b9 Fixes Components with prefixes in mock
Reviewed By: bestander

Differential Revision: D4096027

fbshipit-source-id: 342677a27c6d03dc7d2d6eb53970a504fb62d63b
2016-10-28 10:58:39 -07:00
Christoph Pojer 487171fd89 Mock requireNativeComponent so manual mocking of UIManager properties isn't needed
Summary:
Fixes warnings such as `Warning: Native component for "RCTView" does not exist` when you don't mock the native view class on `UIManager`.

**Test plan (required)**

Run `npm test` with it and without it, notice that warnings are gone and results are the same.

cc cpojer
Closes https://github.com/facebook/react-native/pull/10486

Differential Revision: D4063500

Pulled By: cpojer

fbshipit-source-id: f6bdda1fdd1ad87958f435071d353684cb812af4
2016-10-22 20:28:42 -07:00
Cristian Carlesso 6a462fb085 Moving the jest configuration from jest-react-native to react native.
Reviewed By: cpojer

Differential Revision: D3923609

fbshipit-source-id: 62804df81b064871b499ae8c091e13dd1e0f229b
2016-10-17 08:44:05 -07:00