Skip to content

Commit

Permalink
Merge remote-tracking branch 'jester/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Natan LaFontaine committed Apr 11, 2017
2 parents ec3a6a0 + b93f9c6 commit 33d2633
Show file tree
Hide file tree
Showing 38 changed files with 311 additions and 384 deletions.
4 changes: 3 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
"parser": "babel-eslint",
"rules": {
"no-multiple-empty-lines": 1,
"flowtype/require-valid-file-annotation": 2
"flowtype/require-valid-file-annotation": 2,
"flowtype/boolean-style": 2,
"flowtype/no-primitive-constructor-types": 2
},
"plugins": [
"markdown"
Expand Down
2 changes: 1 addition & 1 deletion .flowconfig
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ module.name_mapper='^types/\(.*\)$' -> '<PROJECT_ROOT>/types/\1.js'
module.name_mapper='\(jest-[^/]*\)' -> '<PROJECT_ROOT>/packages/\1/src/index.js'

[version]
^0.41.0
^0.43.0
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ Jest can be used in projects that use [webpack](https://webpack.github.io/) to m

### Using TypeScript

To use TypeScript in your tests, install the `ts-jest` package:
To use TypeScript in your tests, install the `ts-jest` package and the types for Jest.

```
npm install --save-dev ts-jest
npm install --save-dev ts-jest @types/jest
```

then modify your `package.json` so the `jest` section looks something like:
Expand Down
6 changes: 4 additions & 2 deletions docs/GettingStarted.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ test('adds 1 + 2 to equal 3', () => {
Add the following section to your `package.json`:

```json
"scripts": {
"test": "jest"
{
"scripts": {
"test": "jest"
}
}
```

Expand Down
2 changes: 1 addition & 1 deletion docs/MigrationGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ layout: docs
category: Guides
permalink: docs/migration-guide.html
previous: webpack
next: troubleshooting
next: testing-frameworks
---

If you'd like to try out Jest with an existing codebase, there are a number of ways to convert to Jest:
Expand Down
16 changes: 15 additions & 1 deletion docs/TestingAsyncCode.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,24 @@ If `done()` is never called, the test will fail, which is what you want to happe

### Promises

If your code uses promises, there is a simpler way to handle asynchronous tests. Just use the `resolves` keyword in your expect statement, and Jest will wait for that promise to resolve. If the promise is rejected, the test will automatically fail.
If your code uses promises, there is a simpler way to handle asynchronous tests. Just return a promise from your test, and Jest will wait for that promise to resolve. If the promise is rejected, the test will automatically fail.

For example, let's say that `fetchData`, instead of using a callback, returns a promise that is supposed to resolve to the string `"peanut butter"`. We could test it with:

```js
test('the data is peanut butter', () => {
return fetchData().then(data => {
expect(data).toBe('peanut butter');
});
});
```

Be sure to return the promise - if you omit this `return` statement, your test will complete before `fetchData` completes.

##### available in Jest **20.0.0+**

You can also use the `resolves` keyword in your expect statement, and Jest will wait for that promise to resolve. If the promise is rejected, the test will automatically fail.

```js
test('the data is peanut butter', () => {
return expect(fetchData()).resolves.toBe('peanut butter');
Expand Down
31 changes: 31 additions & 0 deletions docs/TestingFrameworks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
id: testing-frameworks
title: Testing other frameworks
layout: docs
category: Guides
permalink: docs/testing-frameworks.html
previous: migration-guide
next: troubleshooting
---

Although Jest may be considered React-specific test runner, in fact it is a universal testing platform, with the ability to adapt to any JavaScript library or framework. In this section we'd like to link to community posts and articles about integrating Jest into other popular JS libraries.

## Vue.js

* [Jest for all: Episode 1 — Vue.js](https://medium.com/@kentaromiura_the_js_guy/jest-for-all-episode-1-vue-js-d616bccbe186#.d573vrce2) by Cristian Carlesso ([@kentaromiura](https://twitter.com/kentaromiura))

## AngularJS

* [Testing an AngularJS app with Jest](https://medium.com/aya-experience/testing-an-angularjs-app-with-jest-3029a613251) by Matthieu Lux ([@Swiip](https://twitter.com/Swiip))

## Angular

* [Testing Angular faster with Jest](https://www.xfive.co/blog/testing-angular-faster-jest/) by Michał Pierzchała ([@thymikee](https://twitter.com/thymikee))

## MobX

* [How to Test React and MobX with Jest](https://semaphoreci.com/community/tutorials/how-to-test-react-and-mobx-with-jest) by Will Stern ([@willsterndev](https://twitter.com/willsterndev))

## Redux

* [Writing Tests](http://redux.js.org/docs/recipes/WritingTests.html) by Redux docs
2 changes: 1 addition & 1 deletion docs/Troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ title: Troubleshooting
layout: docs
category: Guides
permalink: docs/troubleshooting.html
previous: migration-guide
previous: testing-frameworks
---

Uh oh, something went wrong? Use this guide to resolve issues with Jest.
Expand Down
2 changes: 1 addition & 1 deletion docs/TutorialAsync.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export default function request(url) {
}
```

Now let's write a test for our async functionality. Using the `resolves` keyword
Now let's write a test for our async functionality. Using the `resolves` keyword (available in Jest **20.0.0+**)
```js
// __tests__/user-test.js
jest.mock('../request');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ Ran all test suites.
exports[`only with expand arg 1`] = `
" PASS __tests__/only-constructs-test.js
○ it
✓ test.only
✓ it.only
✓ fit
○ it
fdescribe
✓ it
✓ test
Expand Down

This file was deleted.

2 changes: 1 addition & 1 deletion integration_tests/__tests__/coverage-remapping-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ skipOnWindows.suite();

it('maps code coverage against original source', () => {
const dir = path.resolve(__dirname, '../coverage-remapping');
run('npm install', dir);
run('yarn --no-lockfile', dir);
runJest(dir, ['--coverage', '--mapCoverage', '--no-cache']);

const coverageMapFile = path.join(
Expand Down
16 changes: 4 additions & 12 deletions integration_tests/__tests__/failures-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,11 @@ const stripInconsistentStackLines = summary => {
test('throwing not Error objects', () => {
let stderr;
stderr = runJest(dir, ['throw-number-test.js']).stderr;
expect(stripInconsistentStackLines(
extractSummary(stderr),
)).toMatchSnapshot();
expect(stripInconsistentStackLines(extractSummary(stderr))).toMatchSnapshot();
stderr = runJest(dir, ['throw-string-test.js']).stderr;
expect(stripInconsistentStackLines(
extractSummary(stderr),
)).toMatchSnapshot();
expect(stripInconsistentStackLines(extractSummary(stderr))).toMatchSnapshot();
stderr = runJest(dir, ['throw-object-test.js']).stderr;
expect(stripInconsistentStackLines(
extractSummary(stderr),
)).toMatchSnapshot();
expect(stripInconsistentStackLines(extractSummary(stderr))).toMatchSnapshot();
stderr = runJest(dir, ['assertion-count-test.js']).stderr;
expect(stripInconsistentStackLines(
extractSummary(stderr),
)).toMatchSnapshot();
expect(stripInconsistentStackLines(extractSummary(stderr))).toMatchSnapshot();
});
9 changes: 7 additions & 2 deletions integration_tests/__tests__/native-async-mock-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,16 @@ skipOnWindows.suite();
const dir = path.resolve(__dirname, '..', 'native-async-mock');

test('mocks async functions', () => {
if (process.versions.node < '7.6.0') {
return;
}
if (process.platform !== 'win32') {
run('npm install', dir);
run('yarn --no-lockfile', dir);
linkJestPackage('babel-jest', dir);
}
// --no-cache because babel can cache stuff and result in false green
const {stderr} = runJest(dir, ['--no-cache']);
expect(extractSummary(stderr)).toMatchSnapshot();
expect(extractSummary(stderr).summary).toMatch(
'Test Suites: 1 passed, 1 total',
);
});
4 changes: 2 additions & 2 deletions integration_tests/__tests__/transform-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('babel-jest', () => {

beforeEach(() => {
if (process.platform !== 'win32') {
run('npm install', dir);
run('yarn --no-lockfile', dir);
linkJestPackage('babel-jest', dir);
}
});
Expand Down Expand Up @@ -88,7 +88,7 @@ describe('multiple-transformers', () => {

beforeEach(() => {
if (process.platform !== 'win32') {
run('npm install', dir);
run('yarn --no-lockfile', dir);
linkJestPackage('babel-jest', dir);
}
});
Expand Down
2 changes: 1 addition & 1 deletion integration_tests/__tests__/typescript-coverage-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ skipOnWindows.suite();

it('instruments and collects coverage for typescript files', () => {
const dir = path.resolve(__dirname, '../typescript-coverage');
run('npm install', dir);
run('yarn --no-lockfile', dir);
const {stdout} = runJest(dir, ['--coverage', '--no-cache']);
expect(stdout).toMatchSnapshot();
});
3 changes: 1 addition & 2 deletions integration_tests/native-async-mock/.babelrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{
"presets": ["es2015"],
"plugins": ["transform-async-to-generator"]
"presets": ["es2015"]
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"eslint-plugin-flowtype": "^2.30.3",
"eslint-plugin-markdown": "^1.0.0-beta.4",
"eslint-plugin-react": "^6.7.1",
"flow-bin": "^0.41.0",
"flow-bin": "^0.43.0",
"glob": "^7.1.1",
"graceful-fs": "^4.1.11",
"immutable": "^4.0.0-rc.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ Array [
Watch Usage
› Press o to only run tests related to changed files.
› Press p to filter by a filename regex pattern.
› Press t to filter by a test name regex pattern.
› Press q to quit watch mode.
› Press Enter to trigger a test run.
",
Expand Down
6 changes: 5 additions & 1 deletion packages/jest-cli/src/reporters/SummaryReporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,14 @@ class SummareReporter extends BaseReporter {
let updateCommand;
const event = process.env.npm_lifecycle_event;
const prefix = NPM_EVENTS.has(event) ? '' : 'run ';
const client = typeof process.env.npm_config_user_agent === 'string' &&
process.env.npm_config_user_agent.match('yarn') !== null
? 'yarn'
: 'npm';
if (config.watch) {
updateCommand = 'press `u`';
} else if (event) {
updateCommand = `run with \`npm ${prefix + event} -- -u\``;
updateCommand = `run with \`${client + ' ' + prefix + event} -- -u\``;
} else {
updateCommand = 're-run with `-u`';
}
Expand Down
3 changes: 0 additions & 3 deletions packages/jest-cli/src/watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,9 +286,6 @@ const usage = (argv, snapshotFailure, delimiter = '\n') => {
chalk.dim(' \u203A Press ') +
'p' +
chalk.dim(' to filter by a filename regex pattern.'),
chalk.dim(' \u203A Press ') +
't' +
chalk.dim(' to filter by a test name regex pattern.'),
chalk.dim(' \u203A Press ') + 'q' + chalk.dim(' to quit watch mode.'),
chalk.dim(' \u203A Press ') +
'Enter' +
Expand Down
3 changes: 0 additions & 3 deletions packages/jest-config/src/normalize.js
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,6 @@ function normalize(config: InitialConfig, argv: Object = {}) {
case 'cache':
case 'clearMocks':
case 'collectCoverage':
case 'coverageCollector':
case 'coverageReporters':
case 'coverageThreshold':
case 'globals':
Expand All @@ -359,7 +358,6 @@ function normalize(config: InitialConfig, argv: Object = {}) {
case 'name':
case 'noStackTrace':
case 'notify':
case 'persistModuleRegistryBetweenSpecs':
case 'preset':
case 'replname':
case 'resetMocks':
Expand All @@ -368,7 +366,6 @@ function normalize(config: InitialConfig, argv: Object = {}) {
case 'testMatch':
case 'testEnvironment':
case 'testRegex':
case 'testReporter':
case 'testRunner':
case 'testURL':
case 'timers':
Expand Down
3 changes: 1 addition & 2 deletions packages/jest-editor-support/src/parsers/BabylonParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ const cache = Object.create(null);
// This is a copy of babel-jest's parser, but it takes create-react-app
// into account, and will return an empty JSON object instead of "".
const getBabelRC = (filename, {useCache}) => {

// Special case for create-react-app, which hides the .babelrc
const paths: string[] = ['node_modules/react-scripts/'];
let directory = filename;
Expand Down Expand Up @@ -128,7 +127,7 @@ const parse = (file: string) => {
if (!isFunctionCall(node)) {
return false;
}
let name: string;
let name: string = '';
let element = node.expression.callee;
while (!name) {
name = element.name;
Expand Down
Loading

0 comments on commit 33d2633

Please sign in to comment.