Skip to content

Commit 10af890

Browse files
committed
Upgrade to jest v15
See https://facebook.github.io/jest/blog/2016/09/01/jest-15.html for details what changed. I only did some minimal cleanup to make all tests pass.
1 parent 64cc870 commit 10af890

14 files changed

+112
-130
lines changed

bin/__tests__/react-docgen-test.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@
88
*
99
*/
1010

11-
/*global jasmine, jest, describe, it, expect, afterEach*/
11+
/*global jasmine, describe, it, expect, afterEach*/
12+
13+
// NOTE: This test spawns a subprocesses that load the files from dist/, not
14+
// src/. Before running this test run `npm run build` or `npm run watch`.
1215

1316
const TEST_TIMEOUT = 120000;
1417

1518
jasmine.DEFAULT_TIMEOUT_INTERVAL = TEST_TIMEOUT;
1619

17-
jest.disableAutomock();
18-
1920
var fs = require('fs');
2021
var path = require('path');
2122
var rimraf = require('rimraf');
@@ -96,8 +97,8 @@ describe('react-docgen CLI', () => {
9697

9798
it('reads from stdin', () => {
9899
return run([], component).then(([stdout, stderr]) => {
99-
expect(stdout.length > 0).toBe(true);
100-
expect(stderr.length).toBe(0);
100+
expect(stdout).not.toBe('');
101+
expect(stderr).toBe('');
101102
});
102103
}, TEST_TIMEOUT);
103104

@@ -238,7 +239,6 @@ describe('react-docgen CLI', () => {
238239
'--resolver='+path.join(__dirname, './example/customResolver.js'),
239240
path.join(__dirname, '../../example/components/Component.js'),
240241
]).then(([stdout, stderr]) => {
241-
console.log(stderr);
242242
expect(stdout).toContain('Custom');
243243
}),
244244
]);

package.json

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
"devDependencies": {
4040
"babel-cli": "^6.9.0",
4141
"babel-eslint": "^6.0.4",
42-
"babel-jest": "^14.1.0",
42+
"babel-jest": "^15.0.0",
4343
"babel-plugin-syntax-flow": "^6.8.0",
4444
"babel-plugin-transform-flow-strip-types": "^6.8.0",
4545
"babel-plugin-transform-runtime": "^6.9.0",
@@ -48,7 +48,7 @@
4848
"cross-spawn": "^4.0.0",
4949
"eslint": "^3.2.2",
5050
"flow-bin": "^0.31.0",
51-
"jest-cli": "^14.1.0",
51+
"jest-cli": "^15.1.1",
5252
"rimraf": "^2.3.2",
5353
"temp": "^0.8.1"
5454
},
@@ -60,13 +60,6 @@
6060
],
6161
"testPathIgnorePatterns": [
6262
"/bin/__tests__/example/"
63-
],
64-
"unmockedModulePathPatterns": [
65-
"node_modules",
66-
"tests/utils",
67-
"recast",
68-
"babel",
69-
"babylon"
7063
]
7164
}
7265
}

src/handlers/__tests__/componentMethodsJsDocHandler-test.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,16 @@
88
*
99
*/
1010

11-
/*global jest, describe, beforeEach, it, expect*/
11+
/*global describe, beforeEach, it, expect*/
1212

13-
jest.disableAutomock();
13+
import Documentation from '../../Documentation';
14+
import componentMethodsJsDocHandler from '../componentMethodsJsDocHandler';
1415

1516
describe('componentMethodsHandler', () => {
1617
let documentation;
17-
let componentMethodsJsDocHandler;
1818

1919
beforeEach(() => {
20-
documentation = new (require('../../Documentation'));
21-
componentMethodsJsDocHandler = require('../componentMethodsJsDocHandler').default;
20+
documentation = new Documentation();
2221
});
2322

2423
it('stays the same when no docblock is present', () => {

src/handlers/__tests__/propTypeHandler-test.js

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,20 @@
1010

1111
/*global jest, describe, it, expect, beforeEach*/
1212

13-
jest.disableAutomock();
1413
jest.mock('../../Documentation');
14+
jest.mock('../../utils/getPropType', () => jest.fn(() => ({})));
15+
16+
import {statement, expression} from '../../../tests/utils';
17+
import Documentation from '../../Documentation';
18+
import propTypeHandler from '../propTypeHandler';
1519

1620
describe('propTypeHandler', () => {
17-
var statement, expression;
1821
var getPropTypeMock;
1922
var documentation;
20-
var propTypeHandler;
2123

2224
beforeEach(() => {
23-
({statement, expression} = require('../../../tests/utils'));
24-
getPropTypeMock = jest.genMockFunction().mockImplementation(() => ({}));
25-
jest.setMock('../../utils/getPropType', getPropTypeMock);
26-
jest.mock('../../utils/getPropType');
27-
28-
documentation = new (require('../../Documentation'));
29-
propTypeHandler = require('../propTypeHandler').default;
25+
getPropTypeMock = require('../../utils/getPropType');
26+
documentation = new Documentation();
3027
});
3128

3229
function template(src) {

src/resolver/__tests__/findAllComponentDefinitions-test.js

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,21 @@
88
*
99
*/
1010

11-
/*global jest, describe, beforeEach, it, expect*/
11+
/*global describe, it, expect*/
1212

13-
jest.disableAutomock();
13+
import recast from 'recast';
14+
import * as utils from '../../../tests/utils';
15+
import findAllComponentDefinitions from '../findAllComponentDefinitions';
1416

1517
describe('findAllComponentDefinitions', () => {
16-
var findAllComponentDefinitions;
17-
var recast;
18-
var utils;
1918

2019
function parse(source) {
2120
return findAllComponentDefinitions(
22-
utils.parse(source),
21+
utils.parse(source, recast),
2322
recast
2423
);
2524
}
2625

27-
beforeEach(() => {
28-
findAllComponentDefinitions = require('../findAllComponentDefinitions').default;
29-
utils = require('../../../tests/utils');
30-
recast = require('recast');
31-
});
32-
3326
describe('React.createClass', () => {
3427

3528
it('finds React.createClass', () => {

src/resolver/__tests__/findAllExportedComponentDefinitions-test.js

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,13 @@
88
*
99
*/
1010

11-
/*global jest, describe, beforeEach, it, expect*/
11+
/*global describe, it, expect*/
12+
import recast from 'recast';
13+
import * as utils from '../../../tests/utils';
1214

13-
jest.disableAutomock();
15+
import findAllExportedComponentDefinitions from '../findAllExportedComponentDefinitions';
1416

1517
describe('findAllExportedComponentDefinitions', () => {
16-
var findAllExportedComponentDefinitions;
17-
var utils;
18-
var recast;
19-
2018
function parse(source) {
2119
return utils.parse(source);
2220
}
@@ -25,13 +23,6 @@ describe('findAllExportedComponentDefinitions', () => {
2523
return findAllExportedComponentDefinitions(path, recast);
2624
}
2725

28-
beforeEach(() => {
29-
findAllExportedComponentDefinitions =
30-
require('../findAllExportedComponentDefinitions').default;
31-
utils = require('../../../tests/utils');
32-
recast = require('recast');
33-
});
34-
3526
describe('CommonJS module exports', () => {
3627

3728
describe('React.createClass', () => {

src/resolver/__tests__/findExportedComponentDefinition-test.js

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,20 @@
88
*
99
*/
1010

11-
/*global jest, describe, beforeEach, it, expect*/
11+
/*global describe, it, expect*/
1212

13-
jest.disableAutomock();
13+
import recast from 'recast';
14+
import * as utils from '../../../tests/utils';
15+
import findExportedComponentDefinition from '../findExportedComponentDefinition';
1416

1517
describe('findExportedComponentDefinition', () => {
16-
var findExportedComponentDefinition;
17-
var utils;
18-
var recast;
19-
2018
function parse(source) {
2119
return findExportedComponentDefinition(
2220
utils.parse(source),
2321
recast
2422
);
2523
}
2624

27-
beforeEach(() => {
28-
findExportedComponentDefinition =
29-
require('../findExportedComponentDefinition').default;
30-
utils = require('../../../tests/utils');
31-
recast = require('recast');
32-
});
33-
3425
describe('CommonJS module exports', () => {
3526

3627
describe('React.createClass', () => {

src/utils/__tests__/docblock-test.js

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,17 @@
88
*
99
*/
1010

11-
/*global jest, describe, beforeEach, it, expect*/
12-
var os = require('os');
13-
var EOL = os.EOL;
11+
/*global describe, it, expect*/
12+
import os from 'os';
13+
import {statement} from '../../../tests/utils';
1414

15-
jest.unmock('../docblock');
15+
import {getDoclets, getDocblock} from '../docblock';
16+
17+
const EOL = os.EOL;
1618

1719
describe('docblock', () => {
1820

1921
describe('getDoclets', () => {
20-
let getDoclets;
21-
22-
beforeEach(() => {
23-
({getDoclets} = require('../docblock'));
24-
});
2522

2623
it('extracts single line doclets', () => {
2724
expect(getDoclets('@foo bar\n@bar baz'))
@@ -37,6 +34,7 @@ describe('docblock', () => {
3734
expect(getDoclets('@foo bar\nbaz\n@abc\n@bar baz'))
3835
.toEqual({foo: 'bar\nbaz', abc: true, bar: 'baz'});
3936
});
37+
4038
});
4139

4240
describe('getDocblock', () => {
@@ -49,14 +47,6 @@ describe('docblock', () => {
4947
'foo;',
5048
];
5149

52-
let getDocblock;
53-
let statement;
54-
55-
beforeEach(() => {
56-
({getDocblock} = require('../docblock'));
57-
({statement} = require('../../../tests/utils'));
58-
});
59-
6050
it('gets the closest docblock of the given node', () => {
6151
let node = statement(source.join(EOL));
6252
expect(getDocblock(node)).toEqual(comment.join(EOL));

src/utils/__tests__/getMemberExpressionRoot-test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@
88
*
99
*/
1010

11-
/*global jest, describe, it, expect*/
11+
/*global describe, it, expect*/
1212

1313
import {expression} from '../../../tests/utils';
1414

15-
jest.unmock('../getMemberExpressionRoot');
16-
17-
var getMemberExpressionRoot = require('../getMemberExpressionRoot').default;
15+
import getMemberExpressionRoot from '../getMemberExpressionRoot';
1816

1917
describe('getMemberExpressionRoot', () => {
18+
2019
it('returns the root of a member expression', () => {
2120
var root = getMemberExpressionRoot(expression('foo.bar.baz'));
2221
expect(root.node).toEqualASTNode(expression('foo').node);
2322
});
23+
2424
});

src/utils/__tests__/getMemberValuePath-test.js

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,46 +8,41 @@
88
*
99
*/
1010

11-
/*global jest, describe, beforeEach, it, expect*/
11+
/*global jest, describe, it, expect*/
1212

13-
jest.unmock('../getMemberValuePath');
13+
jest.mock('../getPropertyValuePath');
14+
jest.mock('../getClassMemberValuePath');
1415

15-
describe('getMemberValuePath', () => {
16-
var getMemberValuePath;
17-
var expression, statement;
16+
import {expression, statement} from '../../../tests/utils';
1817

19-
beforeEach(() => {
20-
({expression, statement} = require('../../../tests/utils'));
21-
getMemberValuePath = require('../getMemberValuePath').default;
22-
});
18+
import getPropertyValuePath from '../getPropertyValuePath';
19+
import getClassMemberValuePath from '../getClassMemberValuePath';
20+
import getMemberValuePath from '../getMemberValuePath';
21+
22+
describe('getMemberValuePath', () => {
2323

2424
it('handles ObjectExpresisons', () => {
25-
var getPropertyValuePath = require('../getPropertyValuePath').default;
2625
var path = expression('{}');
2726

2827
getMemberValuePath(path, 'foo');
2928
expect(getPropertyValuePath).toBeCalledWith(path, 'foo');
3029
});
3130

3231
it('handles ClassDeclarations', () => {
33-
var getClassMemberValuePath = require('../getClassMemberValuePath').default;
3432
var path = statement('class Foo {}');
3533

3634
getMemberValuePath(path, 'foo');
3735
expect(getClassMemberValuePath).toBeCalledWith(path, 'foo');
3836
});
3937

4038
it('handles ClassExpressions', () => {
41-
var getClassMemberValuePath = require('../getClassMemberValuePath').default;
4239
var path = expression('class {}');
4340

4441
getMemberValuePath(path, 'foo');
4542
expect(getClassMemberValuePath).toBeCalledWith(path, 'foo');
4643
});
4744

4845
it('tries synonyms', () => {
49-
var getPropertyValuePath = require('../getPropertyValuePath').default;
50-
var getClassMemberValuePath = require('../getClassMemberValuePath').default;
5146
var path = expression('{}');
5247

5348
getMemberValuePath(path, 'defaultProps');
@@ -62,8 +57,6 @@ describe('getMemberValuePath', () => {
6257
});
6358

6459
it('returns the result of getPropertyValuePath and getClassMemberValuePath', () => {
65-
var getPropertyValuePath = require('../getPropertyValuePath').default;
66-
var getClassMemberValuePath = require('../getClassMemberValuePath').default;
6760
getPropertyValuePath.mockReturnValue(42);
6861
getClassMemberValuePath.mockReturnValue(21);
6962
var path = expression('{}');
@@ -74,4 +67,5 @@ describe('getMemberValuePath', () => {
7467

7568
expect(getMemberValuePath(path, 'defaultProps')).toBe(21);
7669
});
70+
7771
});

0 commit comments

Comments
 (0)