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

Use rollup for browser builds #3532

Merged
merged 6 commits into from
Jun 28, 2017
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
1 change: 1 addition & 0 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ test:
- nvm alias default 4
- yarn run test-ci-partial
- nvm alias default 8
- yarn run test-ci-es5-build-in-browser
- yarn run test-ci-partial
- cd website && yarn run test

Expand Down
24 changes: 24 additions & 0 deletions integration_tests/browser-support/browser-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* Copyright (c) 2014-present, 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.
*/

/* eslint-disable */
var expect = require('../../packages/jest-matchers/build-es5/index.js');
var mock = require('../../packages/jest-mock/build-es5/index.js');

describe('es5 builds in browser', function() {
it('runs assertions', function() {
expect(1).toBe(1);
});

it('runs mocks', function() {
var someMockFunction = mock.fn();
expect(someMockFunction).not.toHaveBeenCalled();
someMockFunction();
expect(someMockFunction).toHaveBeenCalledTimes(1);
});
});
21 changes: 21 additions & 0 deletions karma.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* Copyright (c) 2014-present, 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.
*/

module.exports = config => {
config.set({
browsers: ['ChromeHeadless'],
files: [
'integration_tests/browser-support/browser-test.js',
],
frameworks: ['mocha', 'browserify'],
plugins: ['karma-browserify', 'karma-chrome-launcher', 'karma-mocha'],
preprocessors: {
'integration_tests/browser-support/browser-test.js': ['browserify'],
},
});
};
16 changes: 16 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"ansi-styles": "^3.0.0",
"babel-core": "^6.23.1",
"babel-eslint": "^7.1.1",
"babel-plugin-external-helpers": "^6.22.0",
"babel-plugin-syntax-trailing-function-commas": "^6.13.0",
"babel-plugin-transform-async-to-generator": "^6.16.0",
"babel-plugin-transform-es2015-destructuring": "^6.23.0",
Expand All @@ -16,6 +17,7 @@
"babel-preset-env": "^1.4.0",
"babel-preset-react": "^6.24.1",
"babel-preset-react-native": "^1.9.1",
"browserify": "^14.4.0",
"chalk": "^1.1.3",
"codecov": "^1.0.1",
"cross-spawn": "^5.1.0",
Expand All @@ -35,10 +37,15 @@
"jasmine-reporters": "^2.2.0",
"jquery": "^3.2.1",
"jsdom": "^9.12.0",
"karma": "^1.7.0",
"karma-browserify": "^5.1.1",
"karma-chrome-launcher": "^2.1.1",
"karma-mocha": "^1.3.0",
"left-pad": "^1.1.1",
"lerna": "2.0.0-rc.4",
"micromatch": "^2.3.11",
"mkdirp": "^0.5.1",
"mocha": "^3.4.2",
"prettier": "1.3.1",
"progress": "^1.1.8",
"react": "15.4.2",
Expand All @@ -47,6 +54,14 @@
"react-test-renderer": "15.4.2",
"regenerator-runtime": "^0.10.3",
"rimraf": "^2.5.4",
"rollup": "^0.41.6",
"rollup-plugin-babel": "^2.7.1",
"rollup-plugin-commonjs": "^8.0.2",
"rollup-plugin-flow": "^1.1.1",
"rollup-plugin-json": "^2.1.1",
"rollup-plugin-node-builtins": "^2.1.1",
"rollup-plugin-node-globals": "^1.1.0",
"rollup-plugin-node-resolve": "^3.0.0",
"slash": "^1.0.0",
"string-length": "^1.0.1",
"strip-ansi": "^3.0.1",
Expand All @@ -64,6 +79,7 @@
"prettier": "node scripts/prettier.js write",
"postinstall": "node ./scripts/postinstall.js && yarn run build --silent && (cd packages/eslint-plugin-jest && yarn link --silent) && yarn link eslint-plugin-jest --silent",
"publish": "yarn run build-clean --silent && yarn run build --silent && lerna publish --silent",
"test-ci-es5-build-in-browser": "karma start --single-run",
"test-ci": "yarn run typecheck --silent && yarn run lint --silent && yarn run lint-es5-build && yarn run jest-coverage --silent -- -i && yarn run test-examples --silent && node scripts/mapCoverage.js && codecov",
"test-ci-partial": "yarn run jest --silent -- -i && yarn run test-examples --silent",
"test-examples": "node scripts/test_examples.js",
Expand Down
4 changes: 2 additions & 2 deletions packages/jest-config/src/__tests__/normalize.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -837,8 +837,8 @@ describe('preset', () => {
});

test('merges with options and moduleNameMapper preset is overridden by options', () => {
// Object initializer not used for properties as a workaround for
// sort-keys eslint rule while specifing properties in
// Object initializer not used for properties as a workaround for
// sort-keys eslint rule while specifing properties in
// non-alphabetical order for a better test
const moduleNameMapper = {};
moduleNameMapper.e = 'ee';
Expand Down
1 change: 0 additions & 1 deletion packages/jest-diff/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
},
"license": "BSD-3-Clause",
"main": "build/index.js",
"browser": "build-es5/index.js",
"dependencies": {
"chalk": "^1.1.3",
"diff": "^3.2.0",
Expand Down
3 changes: 1 addition & 2 deletions packages/jest-get-type/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@
"url": "https://github.com/facebook/jest.git"
},
"license": "BSD-3-Clause",
"main": "build/index.js",
"browser": "build-es5/index.js"
"main": "build/index.js"
}
14 changes: 7 additions & 7 deletions packages/jest-haste-map/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -533,18 +533,18 @@ mime-types@^2.1.12, mime-types@~2.1.7:
dependencies:
mime-db "~1.27.0"

minimatch@^3.0.0, minimatch@^3.0.2:
version "3.0.3"
resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.0.3.tgz#2a4e4090b96b2db06a9d7df01055a62a77c9b774"
dependencies:
brace-expansion "^1.0.0"

minimatch@^3.0.4:
minimatch@^3.0.0, minimatch@^3.0.4:
version "3.0.4"
resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.0.4.tgz#5166e286457f03306064be5497e8dbb0c3d32083"
dependencies:
brace-expansion "^1.1.7"

minimatch@^3.0.2:
version "3.0.3"
resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.0.3.tgz#2a4e4090b96b2db06a9d7df01055a62a77c9b774"
dependencies:
brace-expansion "^1.0.0"

minimist@0.0.8:
version "0.0.8"
resolved "https://registry.yarnpkg.com/minimist/-/minimist-0.0.8.tgz#857fcabfc3397d2625b8228262e86aa7a011b05d"
Expand Down
1 change: 0 additions & 1 deletion packages/jest-matcher-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
},
"license": "BSD-3-Clause",
"main": "build/index.js",
"browser": "build-es5/index.js",
"dependencies": {
"chalk": "^1.1.3",
"jest-get-type": "^20.0.3",
Expand Down
18 changes: 10 additions & 8 deletions packages/jest-matchers/src/asymmetric_matchers.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,11 +231,13 @@ class StringMatching extends AsymmetricMatcher {
}
}

module.exports = {
any: (expectedObject: any) => new Any(expectedObject),
anything: () => new Anything(),
arrayContaining: (sample: Array<any>) => new ArrayContaining(sample),
objectContaining: (sample: Object) => new ObjectContaining(sample),
stringContaining: (expected: string) => new StringContaining(expected),
stringMatching: (expected: string | RegExp) => new StringMatching(expected),
};
export const any = (expectedObject: any) => new Any(expectedObject);
export const anything = () => new Anything();
export const arrayContaining = (sample: Array<any>) =>
new ArrayContaining(sample);
export const objectContaining = (sample: Object) =>
new ObjectContaining(sample);
export const stringContaining = (expected: string) =>
new StringContaining(expected);
export const stringMatching = (expected: string | RegExp) =>
new StringMatching(expected);
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,4 @@ const extractExpectedAssertionsErrors = () => {
return result;
};

module.exports = extractExpectedAssertionsErrors;
export default extractExpectedAssertionsErrors;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cpojer what this what you proposed? : )

18 changes: 5 additions & 13 deletions packages/jest-matchers/src/jasmine_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
type Tester = (a: any, b: any) => boolean | typeof undefined;

// Extracted out of jasmine 2.5.2
function equals(a: any, b: any, customTesters?: Array<Tester>): boolean {
export function equals(a: any, b: any, customTesters?: Array<Tester>): boolean {
customTesters = customTesters || [];
return eq(a, b, [], [], customTesters);
}
Expand Down Expand Up @@ -229,15 +229,15 @@ function has(obj, key) {
);
}

function isA(typeName: string, value: any) {
export function isA(typeName: string, value: any) {
return Object.prototype.toString.apply(value) === '[object ' + typeName + ']';
}

function isDomNode(obj) {
return obj.nodeType > 0;
}

function fnNameFor(func: Function) {
export function fnNameFor(func: Function) {
if (func.name) {
return func.name;
}
Expand All @@ -246,7 +246,7 @@ function fnNameFor(func: Function) {
return matches ? matches[1] : '<anonymous>';
}

function isUndefined(obj: any) {
export function isUndefined(obj: any) {
return obj === void 0;
}

Expand All @@ -262,7 +262,7 @@ function getPrototype(obj) {
return obj.constructor.prototype;
}

function hasProperty(obj: Object | null, property: string) {
export function hasProperty(obj: Object | null, property: string) {
if (!obj) {
return false;
}
Expand All @@ -273,11 +273,3 @@ function hasProperty(obj: Object | null, property: string) {

return hasProperty(getPrototype(obj), property);
}

module.exports = {
equals,
fnNameFor,
hasProperty,
isA,
isUndefined,
};
15 changes: 4 additions & 11 deletions packages/jest-matchers/src/jest_matchers_object.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,14 @@ if (!global[JEST_MATCHERS_OBJECT]) {
});
}

const getState = () => global[JEST_MATCHERS_OBJECT].state;
export const getState = () => global[JEST_MATCHERS_OBJECT].state;

const setState = (state: Object) => {
export const setState = (state: Object) => {
Object.assign(global[JEST_MATCHERS_OBJECT].state, state);
};

const getMatchers = () => global[JEST_MATCHERS_OBJECT].matchers;
export const getMatchers = () => global[JEST_MATCHERS_OBJECT].matchers;

const setMatchers = (matchers: MatchersObject) => {
export const setMatchers = (matchers: MatchersObject) => {
Object.assign(global[JEST_MATCHERS_OBJECT].matchers, matchers);
};

module.exports = {
getMatchers,
getState,
setMatchers,
setState,
};
2 changes: 1 addition & 1 deletion packages/jest-matchers/src/matchers.js
Original file line number Diff line number Diff line change
Expand Up @@ -654,4 +654,4 @@ const matchers: MatchersObject = {
},
};

module.exports = matchers;
export default matchers;
2 changes: 1 addition & 1 deletion packages/jest-matchers/src/spy_matchers.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,4 +198,4 @@ const formatReceivedCalls = (calls, limit, options) => {
}
};

module.exports = spyMatchers;
export default spyMatchers;
2 changes: 1 addition & 1 deletion packages/jest-matchers/src/to_throw_matchers.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,4 +190,4 @@ const printActualErrorMessage = error => {
return `But it didn't throw anything.`;
};

module.exports = matchers;
export default matchers;
15 changes: 4 additions & 11 deletions packages/jest-matchers/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ type GetPath = {
value?: any,
};

const hasOwnProperty = (object: Object, value: string) =>
export const hasOwnProperty = (object: Object, value: string) =>
Object.prototype.hasOwnProperty.call(object, value);

const getPath = (
export const getPath = (
object: Object,
propertyPath: string | Array<string>,
): GetPath => {
Expand Down Expand Up @@ -66,7 +66,7 @@ const getPath = (

// Strip properties from object that are not present in the subset. Useful for
// printing the diff for toMatchObject() without adding unrelated noise.
const getObjectSubset = (object: Object, subset: Object) => {
export const getObjectSubset = (object: Object, subset: Object) => {
if (Array.isArray(object)) {
if (Array.isArray(subset) && subset.length === object.length) {
return subset.map((sub, i) => getObjectSubset(object[i], sub));
Expand Down Expand Up @@ -96,7 +96,7 @@ const getObjectSubset = (object: Object, subset: Object) => {
const IteratorSymbol = Symbol.iterator;

const hasIterator = object => !!(object != null && object[IteratorSymbol]);
const iterableEquality = (a: any, b: any) => {
export const iterableEquality = (a: any, b: any) => {
if (
typeof a !== 'object' ||
typeof b !== 'object' ||
Expand All @@ -123,10 +123,3 @@ const iterableEquality = (a: any, b: any) => {
}
return true;
};

module.exports = {
getObjectSubset,
getPath,
hasOwnProperty,
iterableEquality,
};
1 change: 0 additions & 1 deletion packages/jest-message-util/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
},
"license": "BSD-3-Clause",
"main": "build/index.js",
"browser": "build-es5/index.js",
"dependencies": {
"chalk": "^1.1.3",
"micromatch": "^2.3.11",
Expand Down
3 changes: 1 addition & 2 deletions packages/jest-regex-util/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@
"url": "https://github.com/facebook/jest.git"
},
"license": "BSD-3-Clause",
"main": "build/index.js",
"browser": "build-es5/index.js"
"main": "build/index.js"
}
1 change: 0 additions & 1 deletion packages/jest-util/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
},
"license": "BSD-3-Clause",
"main": "build/index.js",
"browser": "build-es5/index.js",
"dependencies": {
"chalk": "^1.1.3",
"graceful-fs": "^4.1.11",
Expand Down
1 change: 0 additions & 1 deletion packages/jest-validate/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
},
"license": "BSD-3-Clause",
"main": "build/index.js",
"browser": "build-es5/index.js",
"dependencies": {
"chalk": "^1.1.3",
"jest-get-type": "^20.0.3",
Expand Down
1 change: 0 additions & 1 deletion packages/pretty-format/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"license": "BSD-3-Clause",
"description": "Stringify any JavaScript value.",
"main": "build/index.js",
"browser": "build-es5/index.js",
"author": "James Kyle <me@thejameskyle.com>",
"dependencies": {
"ansi-regex": "^2.1.1",
Expand Down
Loading