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

Make resolveToValue consider assignments to identifiers (fixes #58) #128

Merged
merged 2 commits into from
Sep 28, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions bin/__tests__/react-docgen-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@
*
*/

/*global jasmine, jest, describe, it, expect, afterEach*/
/*global jasmine, describe, it, expect, afterEach*/

// NOTE: This test spawns a subprocesses that load the files from dist/, not
// src/. Before running this test run `npm run build` or `npm run watch`.

const TEST_TIMEOUT = 120000;

jasmine.DEFAULT_TIMEOUT_INTERVAL = TEST_TIMEOUT;

jest.disableAutomock();

var fs = require('fs');
var path = require('path');
var rimraf = require('rimraf');
Expand Down Expand Up @@ -96,8 +97,8 @@ describe('react-docgen CLI', () => {

it('reads from stdin', () => {
return run([], component).then(([stdout, stderr]) => {
expect(stdout.length > 0).toBe(true);
expect(stderr.length).toBe(0);
expect(stdout).not.toBe('');
expect(stderr).toBe('');
});
}, TEST_TIMEOUT);

Expand Down Expand Up @@ -238,7 +239,6 @@ describe('react-docgen CLI', () => {
'--resolver='+path.join(__dirname, './example/customResolver.js'),
path.join(__dirname, '../../example/components/Component.js'),
]).then(([stdout, stderr]) => {
console.log(stderr);
expect(stdout).toContain('Custom');
}),
]);
Expand Down
15 changes: 3 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"devDependencies": {
"babel-cli": "^6.9.0",
"babel-eslint": "^6.0.4",
"babel-jest": "^14.1.0",
"babel-jest": "^15.0.0",
"babel-plugin-syntax-flow": "^6.8.0",
"babel-plugin-transform-flow-strip-types": "^6.8.0",
"babel-plugin-transform-runtime": "^6.9.0",
Expand All @@ -48,7 +48,7 @@
"cross-spawn": "^4.0.0",
"eslint": "^3.2.2",
"flow-bin": "^0.31.0",
"jest-cli": "^14.1.0",
"jest-cli": "^15.1.1",
"rimraf": "^2.3.2",
"temp": "^0.8.1"
},
Expand All @@ -58,15 +58,6 @@
"bin",
"src"
],
"testPathIgnorePatterns": [
"/bin/__tests__/example/"
],
"unmockedModulePathPatterns": [
"node_modules",
"tests/utils",
"recast",
"babel",
"babylon"
]
"testRegex": "/__tests__/.*-test\\.js$"
}
}
7 changes: 7 additions & 0 deletions src/__tests__/__snapshots__/main-test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
exports[`main fixtures processes component "component_1.js" without errors 1`] = `
Object {
"description": "The is a component to test the document generation",
"displayName": "Component",
"methods": Array []
}
`;
12 changes: 12 additions & 0 deletions src/__tests__/fixtures/component_1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
var Component, React;

React = require('react');

/**
* The is a component to test the document generation
*/
Component = React.createClass({
displayName: 'Component',
});

module.exports = Component;
27 changes: 19 additions & 8 deletions src/__tests__/main-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,15 @@
*
*/

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

jest.disableAutomock();
import fs from 'fs';
import path from 'path';

describe('main', () => {
var docgen, ERROR_MISSING_DEFINITION;
import * as docgen from '../main';
import {ERROR_MISSING_DEFINITION} from '../parse';

beforeEach(() => {
docgen = require('../main');
({ERROR_MISSING_DEFINITION} = require('../parse'));
});
describe('main', () => {

function test(source) {
it('parses with default resolver/handlers', () => {
Expand Down Expand Up @@ -225,4 +223,17 @@ describe('main', () => {
expect(() => docgen.parse(source)).toThrowError(ERROR_MISSING_DEFINITION);
});
});

describe('fixtures', () => {
const fixturePath = path.join(__dirname, 'fixtures');
const fileNames = fs.readdirSync(fixturePath);
for (let i = 0; i < fileNames.length; i++) {
const fileContent = fs.readFileSync(path.join(fixturePath, fileNames[i]));

it(`processes component "${fileNames[i]}" without errors`, () => {
expect(() => docgen.parse(fileContent)).not.toThrowError();
expect(docgen.parse(fileContent)).toMatchSnapshot();
});
}
});
});
9 changes: 4 additions & 5 deletions src/handlers/__tests__/componentMethodsJsDocHandler-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,16 @@
*
*/

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

jest.disableAutomock();
import Documentation from '../../Documentation';
import componentMethodsJsDocHandler from '../componentMethodsJsDocHandler';

describe('componentMethodsHandler', () => {
let documentation;
let componentMethodsJsDocHandler;

beforeEach(() => {
documentation = new (require('../../Documentation'));
componentMethodsJsDocHandler = require('../componentMethodsJsDocHandler').default;
documentation = new Documentation();
});

it('stays the same when no docblock is present', () => {
Expand Down
17 changes: 7 additions & 10 deletions src/handlers/__tests__/propTypeHandler-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,20 @@

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

jest.disableAutomock();
jest.mock('../../Documentation');
jest.mock('../../utils/getPropType', () => jest.fn(() => ({})));

import {statement, expression} from '../../../tests/utils';
import Documentation from '../../Documentation';
import propTypeHandler from '../propTypeHandler';

describe('propTypeHandler', () => {
var statement, expression;
var getPropTypeMock;
var documentation;
var propTypeHandler;

beforeEach(() => {
({statement, expression} = require('../../../tests/utils'));
getPropTypeMock = jest.genMockFunction().mockImplementation(() => ({}));
jest.setMock('../../utils/getPropType', getPropTypeMock);
jest.mock('../../utils/getPropType');

documentation = new (require('../../Documentation'));
propTypeHandler = require('../propTypeHandler').default;
getPropTypeMock = require('../../utils/getPropType');
documentation = new Documentation();
});

function template(src) {
Expand Down
17 changes: 5 additions & 12 deletions src/resolver/__tests__/findAllComponentDefinitions-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,21 @@
*
*/

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

jest.disableAutomock();
import recast from 'recast';
import * as utils from '../../../tests/utils';
import findAllComponentDefinitions from '../findAllComponentDefinitions';

describe('findAllComponentDefinitions', () => {
var findAllComponentDefinitions;
var recast;
var utils;

function parse(source) {
return findAllComponentDefinitions(
utils.parse(source),
utils.parse(source, recast),
recast
);
}

beforeEach(() => {
findAllComponentDefinitions = require('../findAllComponentDefinitions').default;
utils = require('../../../tests/utils');
recast = require('recast');
});

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

it('finds React.createClass', () => {
Expand Down
17 changes: 4 additions & 13 deletions src/resolver/__tests__/findAllExportedComponentDefinitions-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,13 @@
*
*/

/*global jest, describe, beforeEach, it, expect*/
/*global describe, it, expect*/
import recast from 'recast';
import * as utils from '../../../tests/utils';

jest.disableAutomock();
import findAllExportedComponentDefinitions from '../findAllExportedComponentDefinitions';

describe('findAllExportedComponentDefinitions', () => {
var findAllExportedComponentDefinitions;
var utils;
var recast;

function parse(source) {
return utils.parse(source);
}
Expand All @@ -25,13 +23,6 @@ describe('findAllExportedComponentDefinitions', () => {
return findAllExportedComponentDefinitions(path, recast);
}

beforeEach(() => {
findAllExportedComponentDefinitions =
require('../findAllExportedComponentDefinitions').default;
utils = require('../../../tests/utils');
recast = require('recast');
});

describe('CommonJS module exports', () => {

describe('React.createClass', () => {
Expand Down
17 changes: 4 additions & 13 deletions src/resolver/__tests__/findExportedComponentDefinition-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,20 @@
*
*/

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

jest.disableAutomock();
import recast from 'recast';
import * as utils from '../../../tests/utils';
import findExportedComponentDefinition from '../findExportedComponentDefinition';

describe('findExportedComponentDefinition', () => {
var findExportedComponentDefinition;
var utils;
var recast;

function parse(source) {
return findExportedComponentDefinition(
utils.parse(source),
recast
);
}

beforeEach(() => {
findExportedComponentDefinition =
require('../findExportedComponentDefinition').default;
utils = require('../../../tests/utils');
recast = require('recast');
});

describe('CommonJS module exports', () => {

describe('React.createClass', () => {
Expand Down
24 changes: 7 additions & 17 deletions src/utils/__tests__/docblock-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,17 @@
*
*/

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

jest.unmock('../docblock');
import {getDoclets, getDocblock} from '../docblock';

const EOL = os.EOL;

describe('docblock', () => {

describe('getDoclets', () => {
let getDoclets;

beforeEach(() => {
({getDoclets} = require('../docblock'));
});

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

});

describe('getDocblock', () => {
Expand All @@ -49,14 +47,6 @@ describe('docblock', () => {
'foo;',
];

let getDocblock;
let statement;

beforeEach(() => {
({getDocblock} = require('../docblock'));
({statement} = require('../../../tests/utils'));
});

it('gets the closest docblock of the given node', () => {
let node = statement(source.join(EOL));
expect(getDocblock(node)).toEqual(comment.join(EOL));
Expand Down
8 changes: 4 additions & 4 deletions src/utils/__tests__/getMemberExpressionRoot-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@
*
*/

/*global jest, describe, it, expect*/
/*global describe, it, expect*/

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

jest.unmock('../getMemberExpressionRoot');

var getMemberExpressionRoot = require('../getMemberExpressionRoot').default;
import getMemberExpressionRoot from '../getMemberExpressionRoot';

describe('getMemberExpressionRoot', () => {

it('returns the root of a member expression', () => {
var root = getMemberExpressionRoot(expression('foo.bar.baz'));
expect(root.node).toEqualASTNode(expression('foo').node);
});

});
Loading