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

Migrate pretty-format to TypeScript #7809

Merged
merged 5 commits into from
Feb 6, 2019
Merged
Show file tree
Hide file tree
Changes from 4 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 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
### Chore & Maintenance

- `[*]`: Setup building, linting and testing of TypeScript ([#7808](https://github.com/facebook/jest/pull/7808))
- `[pretty-format]`: Migrate to TypeScript ([#7809](https://github.com/facebook/jest/pull/7809))

### Performance

Expand Down
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ module.exports = {
'\\.snap$',
'/packages/.*/build',
'/packages/.*/build-es5',
'/packages/.*/src/__tests__/getPrettyPrint.js',
'/packages/.*/src/__tests__/setPrettyPrint.ts',
'/packages/jest-cli/src/__tests__/test_root',
'/packages/jest-cli/src/__tests__/__fixtures__/',
'/packages/jest-cli/src/lib/__tests__/fixtures/',
Expand Down
1 change: 1 addition & 0 deletions packages/jest-circus/src/formatNodeAssertErrors.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import type {Event, State} from 'types/Circus';

import {diff, printExpected, printReceived} from 'jest-matcher-utils';
import chalk from 'chalk';
// $FlowFixMe: Converted to TS
import prettyFormat from 'pretty-format';

type AssertionError = {|
Expand Down
1 change: 1 addition & 0 deletions packages/jest-circus/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import co from 'co';

import StackUtils from 'stack-utils';

// $FlowFixMe: Converted to TS
import prettyFormat from 'pretty-format';

import {getState} from './state';
Expand Down
5 changes: 5 additions & 0 deletions packages/pretty-format/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"license": "MIT",
"description": "Stringify any JavaScript value.",
"main": "build/index.js",
"types": "build/index.d.ts",
"browser": "build-es5/index.js",
"author": "James Kyle <me@thejameskyle.com>",
"dependencies": {
Expand All @@ -18,7 +19,11 @@
"devDependencies": {
"@types/ansi-regex": "^4.0.0",
"@types/ansi-styles": "^3.2.1",
"@types/jest": "^24.0.0",
"@types/react": "*",
"@types/react-test-renderer": "*",
"immutable": "4.0.0-rc.9",
"jest-diff": "^24.0.0",
"react": "*",
"react-dom": "*",
"react-test-renderer": "*"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/

import type {OptionsReceived} from 'types/PrettyFormat';
import {OptionsReceived} from '../types';

import prettyFormat from '../';

const prettyFormat = require('../');
const {AsymmetricMatcher} = prettyFormat.plugins;
let options: OptionsReceived;

function fnNameFor(func) {
function fnNameFor(func: Function) {
SimenB marked this conversation as resolved.
Show resolved Hide resolved
if (func.name) {
return func.name;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/

const ansiStyle = require('ansi-styles');
const prettyFormat = require('../');
import ansiStyle from 'ansi-styles';

import prettyFormat from '../';

const {ConvertAnsi} = prettyFormat.plugins;

const prettyFormatResult = (val: string) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,15 @@
* LICENSE file in the root directory of this source tree.
*
* @jest-environment jsdom
* @flow
*/
/* eslint-env browser*/

'use strict';
import prettyFormat from '../';
import setPrettyPrint from './setPrettyPrint';

const prettyFormat = require('../');
const {DOMCollection, DOMElement} = prettyFormat.plugins;
const toPrettyPrintTo = require('./getPrettyPrint').default([
DOMCollection,
DOMElement,
]);

const expect: any = global.expect;
expect.extend({toPrettyPrintTo});
setPrettyPrint([DOMCollection, DOMElement]);

describe('DOMCollection plugin for object properties', () => {
it('supports DOMStringMap', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,15 @@
* LICENSE file in the root directory of this source tree.
*
* @jest-environment jsdom
* @flow
*/
/* eslint-env browser*/

'use strict';
import prettyFormat from '../';
import setPrettyPrint from './setPrettyPrint';

const prettyFormat = require('../');
const {DOMElement} = prettyFormat.plugins;
const toPrettyPrintTo = require('./getPrettyPrint').default([DOMElement]);

const expect: any = global.expect;
expect.extend({toPrettyPrintTo});
setPrettyPrint([DOMElement]);

describe('pretty-format', () => {
// Test is not related to plugin but is related to jsdom testing environment.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,22 @@
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/

'use strict';

import React from 'react';
import Immutable from 'immutable';
import getPrettyPrint from './getPrettyPrint';

const {Immutable: ImmutablePlugin, ReactElement} = require('..').plugins;
import setPrettyPrint from './setPrettyPrint';
import prettyFormat from '..';

const toPrettyPrintTo = getPrettyPrint([ReactElement, ImmutablePlugin]);
const {Immutable: ImmutablePlugin, ReactElement} = prettyFormat.plugins;

const expect = global.expect;
expect.extend({toPrettyPrintTo});
setPrettyPrint([ReactElement, ImmutablePlugin]);

it('does not incorrectly match identity-obj-proxy as Immutable object', () => {
// SENTINEL constant is from https://github.com/facebook/immutable-js
const IS_ITERABLE_SENTINEL = '@@__IMMUTABLE_ITERABLE__@@';
const val = {};
const val: any = {};
val[IS_ITERABLE_SENTINEL] = IS_ITERABLE_SENTINEL; // mock the mock object :)
const expected = `{"${IS_ITERABLE_SENTINEL}": "${IS_ITERABLE_SENTINEL}"}`;
expect(val).toPrettyPrintTo(expected, {min: true});
Expand Down Expand Up @@ -507,7 +502,7 @@ describe('Immutable.OrderedMap', () => {
});

it('supports non-string keys', () => {
const val = Immutable.OrderedMap([
const val = Immutable.OrderedMap<any, any>([
[false, 'boolean'],
['false', 'string'],
[0, 'number'],
Expand Down Expand Up @@ -871,7 +866,7 @@ describe('Immutable.Seq', () => {
});

it('supports a non-empty sequence from arguments', () => {
function returnArguments(...args) {
function returnArguments(..._args: Array<any>) {
return arguments;
}
expect(Immutable.Seq(returnArguments(0, 1, 2))).toPrettyPrintTo(
Expand Down Expand Up @@ -933,7 +928,7 @@ describe('Immutable.Seq', () => {
describe('Immutable.Seq lazy entries', () => {
const expected = 'Immutable.Seq {…}';
const object = {key0: '', key1: '1'};
const filterer = value => value.length !== 0;
const filterer = (value: string) => value.length !== 0;

// undefined size confirms correct criteria for lazy Seq
test('from object properties', () => {
Expand All @@ -951,7 +946,7 @@ describe('Immutable.Seq lazy entries', () => {
describe('Immutable.Seq lazy values', () => {
const expected = 'Immutable.Seq […]';
const array = ['', '1', '22'];
const filterer = item => item.length !== 0;
const filterer = (item: string) => item.length !== 0;

test('from Immutable.Range', () => {
const val = Immutable.Range(1, Infinity);
Expand All @@ -961,7 +956,7 @@ describe('Immutable.Seq lazy values', () => {

// undefined size confirms correct criteria for lazy Seq
test('from iterator', () => {
function returnIterator(values) {
function returnIterator(values: Array<string>) {
let i = 0;
return {
next() {
Expand Down
48 changes: 0 additions & 48 deletions packages/pretty-format/src/__tests__/getPrettyPrint.js

This file was deleted.

Loading