Skip to content

Commit

Permalink
Make the tests run fast.
Browse files Browse the repository at this point in the history
  • Loading branch information
cpojer committed Mar 11, 2016
1 parent 8359ab5 commit c767268
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 15 deletions.
4 changes: 4 additions & 0 deletions .babelrc
@@ -0,0 +1,4 @@
{
"presets": ["es2015"],
"plugins": ["transform-object-rest-spread"]
}
11 changes: 6 additions & 5 deletions jest/env.js
Expand Up @@ -25,14 +25,15 @@ global.test = (transformName, testFileName, options, fakeOptions) => {
let path = testFileName + '.js';
const source = read(testFileName + '.js');
const output = read(testFileName + '.output.js');
const transform = require(
let transform = require(
p.join(global.baseDir, '/transforms/', transformName)
);
if (transform.default) {
transform = transform.default;
}

if (fakeOptions) {
if (fakeOptions.path) {
path = fakeOptions.path;
}
if (fakeOptions && fakeOptions.path) {
path = fakeOptions.path;
}

expect(
Expand Down
15 changes: 8 additions & 7 deletions package.json
Expand Up @@ -9,16 +9,17 @@
"lint": "eslint ."
},
"dependencies": {
"jscodeshift": "^0.3.8",
"babel-eslint": "^4.1.3",
"babel-jest": "^5.3.0",
"jscodeshift": "^0.3.14",
"babel-eslint": "^5.0.0",
"babel-plugin-transform-object-rest-spread": "^6.6.5",
"babel-preset-es2015": "^6.6.0",
"babel-jest": "^9.0.2",
"eslint": "^1.7.3",
"fbjs-scripts": "^0.3.0",
"jest-cli": "^0.6.1"
"fbjs-scripts": "^0.5.0",
"jest-cli": "^0.9.1"
},
"jest": {
"scriptPreprocessor": "./node_modules/babel-jest",
"setupEnvScriptFile": "jest/env.js",
"setupFiles": ["jest/env.js"],
"globals": {
"baseDir": "../"
},
Expand Down
4 changes: 2 additions & 2 deletions test/__tests__/create-element-to-jsx-test.js
Expand Up @@ -52,7 +52,7 @@ describe('create-element-to-jsx', () => {
test('create-element-to-jsx', 'create-element-to-jsx-gt-lt-entities');
});

it('raises when it does not recognize a property type', () => {
it('throws when it does not recognize a property type', () => {
const jscodeshift = require('jscodeshift');
const transform = require('../../transforms/create-element-to-jsx');
const source = `
Expand All @@ -61,7 +61,7 @@ describe('create-element-to-jsx', () => {
`;

expect(() => transform({source}, {jscodeshift}, {}))
.toThrow('Unexpected attribute of type "Literal"');
.toThrowError('Unexpected attribute of type "Literal"');
});

});
10 changes: 10 additions & 0 deletions test/__tests__/sort-comp-test.js
@@ -1,3 +1,13 @@
/**
* Copyright 2013-2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/

'use strict';

describe('sort-comp', () => {
Expand Down
14 changes: 13 additions & 1 deletion transforms/create-element-to-jsx.js
@@ -1,3 +1,15 @@
/**
* Copyright 2013-2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/

'use strict';

module.exports = function(file, api, options) {
const j = api.jscodeshift;
const root = j(file.source);
Expand Down Expand Up @@ -118,7 +130,7 @@ module.exports = function(file, api, options) {
}
};

if (
if (
options['explicit-require'] === false ||
ReactUtils.hasReact(root)
) {
Expand Down
12 changes: 12 additions & 0 deletions transforms/pure-component.js
@@ -1,3 +1,15 @@
/**
* Copyright 2013-2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/

'use strict';

module.exports = function(file, api, options) {
const j = api.jscodeshift;
const ReactUtils = require('./utils/ReactUtils')(j);
Expand Down
13 changes: 13 additions & 0 deletions transforms/sort-comp.js
@@ -1,3 +1,15 @@
/**
* Copyright 2013-2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/

'use strict';

/**
* Reorders React component methods to match the [ESLint](http://eslint.org/)
* [react/sort-comp rule](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/sort-comp.md),
Expand All @@ -15,6 +27,7 @@
* ]
* }],
*/

module.exports = function(fileInfo, api, options) {
const j = api.jscodeshift;

Expand Down

0 comments on commit c767268

Please sign in to comment.