Skip to content

Commit

Permalink
[@kbn/expect] "fork" expect.js into repo (#33761) (#33794)
Browse files Browse the repository at this point in the history
* [@kbn/expect] "fork" expect.js into repo

* [eslint] autofix references to expect.js

* [tslint] autofix all expect.js imports

* now that expect.js is in strict mode, avoid reassigning fn.length
  • Loading branch information
Spencer authored Mar 25, 2019
1 parent 9086fac commit 883ea31
Show file tree
Hide file tree
Showing 1,118 changed files with 2,680 additions and 1,342 deletions.
9 changes: 9 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ module.exports = {
rules: {
'no-restricted-imports': [2, restrictedModules],
'no-restricted-modules': [2, restrictedModules],
'@kbn/eslint/module_migration': [
'error',
[
{
from: 'expect.js',
to: '@kbn/expect',
},
],
],
},

overrides: [
Expand Down
2 changes: 1 addition & 1 deletion TYPESCRIPT.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ If yarn doesn't find the module it may not have types. For example, our `rison_

1. Contribute types into the DefinitelyTyped repo itself, or
2. Create a top level `types` folder and point to that in the tsconfig. For example, Infra team already handled this for `rison_node` and added: `x-pack/plugins/infra/types/rison_node.d.ts`. Other code uses it too so we will need to pull it up. Or,
3. Add a `// @ts-ignore` line above the import. This should be used minimally, the above options are better. However, sometimes you have to resort to this method. For example, the `expect.js` module will require this line. We don't have type definitions installed for this library. Installing these types would conflict with the jest typedefs for expect, and since they aren't API compatible with each other, it's not possible to make both test frameworks happy. Since we are moving from mocha => jest, we don't see this is a big issue.
3. Add a `// @ts-ignore` line above the import. This should be used minimally, the above options are better. However, sometimes you have to resort to this method.

### TypeScripting react files

Expand Down
6 changes: 3 additions & 3 deletions docs/development/core/development-functional-tests.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ Use the `--help` flag for more options.
[float]
===== Environment

The tests are written in https://mochajs.org[mocha] using https://github.com/Automattic/expect.js[expect] for assertions.
The tests are written in https://mochajs.org[mocha] using https://github.com/elastic/kibana/tree/master/packages/kbn-expect[@kbn/expect] for assertions.

We use https://sites.google.com/a/chromium.org/chromedriver/[chromedriver], https://theintern.github.io/leadfoot[leadfoot], and https://github.com/theintern/digdug[digdug] for automating Chrome. When the `FunctionalTestRunner` launches, digdug opens a `Tunnel` which starts chromedriver and a stripped-down instance of Chrome. It also creates an instance of https://theintern.github.io/leadfoot/module-leadfoot_Command.html[Leadfoot's `Command`] class, which is available via the `remote` service. The `remote` communicates to Chrome through the digdug `Tunnel`. See the https://theintern.github.io/leadfoot/module-leadfoot_Command.html[leadfoot/Command API] docs for all the commands you can use with `remote`.

Expand Down Expand Up @@ -122,11 +122,11 @@ A test suite is a collection of tests defined by calling `describe()`, and then
[float]
===== Anatomy of a test file

The annotated example file below shows the basic structure every test suite uses. It starts by importing https://github.com/Automattic/expect.js[`expect.js`] and defining its default export: an anonymous Test Provider. The test provider then destructures the Provider API for the `getService()` and `getPageObjects()` functions. It uses these functions to collect the dependencies of this suite. The rest of the test file will look pretty normal to mocha.js users. `describe()`, `it()`, `before()` and the lot are used to define suites that happen to automate a browser via services and objects of type `PageObject`.
The annotated example file below shows the basic structure every test suite uses. It starts by importing https://github.com/elastic/kibana/tree/master/packages/kbn-expect[`@kbn/expect`] and defining its default export: an anonymous Test Provider. The test provider then destructures the Provider API for the `getService()` and `getPageObjects()` functions. It uses these functions to collect the dependencies of this suite. The rest of the test file will look pretty normal to mocha.js users. `describe()`, `it()`, `before()` and the lot are used to define suites that happen to automate a browser via services and objects of type `PageObject`.

["source","js"]
----
import expect from 'expect.js';
import expect from '@kbn/expect';
// test files must `export default` a function that defines a test suite
export default function ({ getService, getPageObject }) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@
"@kbn/es": "1.0.0",
"@kbn/eslint-import-resolver-kibana": "2.0.0",
"@kbn/eslint-plugin-eslint": "1.0.0",
"@kbn/expect": "1.0.0",
"@kbn/plugin-generator": "1.0.0",
"@kbn/test": "1.0.0",
"@octokit/rest": "^15.10.0",
Expand Down Expand Up @@ -343,7 +344,6 @@
"eslint-plugin-prefer-object-spread": "^1.2.1",
"eslint-plugin-prettier": "^2.6.2",
"eslint-plugin-react": "^7.11.1",
"expect.js": "0.3.1",
"faker": "1.1.0",
"fetch-mock": "7.3.0",
"geckodriver": "1.12.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/elastic-datemath/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import dateMath from '../src/index';
import moment from 'moment';
import sinon from 'sinon';
import expect from 'expect.js';
import expect from '@kbn/expect';

/**
* Require a new instance of the moment library, bypassing the require cache.
Expand Down
4 changes: 2 additions & 2 deletions packages/kbn-dev-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
},
"devDependencies": {
"@kbn/babel-preset": "1.0.0",
"@kbn/expect": "1.0.0",
"babel-cli": "^6.26.0",
"chance": "1.0.6",
"expect.js": "0.3.1"
"chance": "1.0.6"
}
}
2 changes: 1 addition & 1 deletion packages/kbn-es-query/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
"@babel/preset-typescript": "^7.3.3",
"@kbn/babel-preset": "1.0.0",
"@kbn/dev-utils": "1.0.0",
"@kbn/expect": "1.0.0",
"del": "^3.0.0",
"expect.js": "0.3.1",
"getopts": "^2.2.3",
"supports-color": "^6.1.0",
"typescript": "^3.3.3333"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import expect from 'expect.js';
import expect from '@kbn/expect';
import _ from 'lodash';
import { migrateFilter } from '../migrate_filter';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import expect from 'expect.js';
import expect from '@kbn/expect';
import { buildEsQuery } from '../build_es_query';
import indexPattern from '../../__fixtures__/index_pattern_response.json';
import { fromKueryExpression, toElasticsearchQuery } from '../../kuery';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import expect from 'expect.js';
import expect from '@kbn/expect';
import { decorateQuery } from '../decorate_query';

describe('Query decorator', function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import expect from 'expect.js';
import expect from '@kbn/expect';
import { filterMatchesIndex } from '../filter_matches_index';

describe('filterMatchesIndex', function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import expect from 'expect.js';
import expect from '@kbn/expect';
import { buildQueryFromFilters } from '../from_filters';

describe('build query', function () {
Expand Down
2 changes: 1 addition & 1 deletion packages/kbn-es-query/src/es_query/__tests__/from_kuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import { buildQueryFromKuery } from '../from_kuery';
import indexPattern from '../../__fixtures__/index_pattern_response.json';
import expect from 'expect.js';
import expect from '@kbn/expect';
import { fromKueryExpression, toElasticsearchQuery } from '../../kuery';

describe('build query', function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import expect from 'expect.js';
import expect from '@kbn/expect';
import { buildQueryFromLucene } from '../from_lucene';
import { decorateQuery } from '../decorate_query';
import { luceneStringToDsl } from '../lucene_string_to_dsl';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

import { luceneStringToDsl } from '../lucene_string_to_dsl';
import expect from 'expect.js';
import expect from '@kbn/expect';

describe('build query', function () {

Expand Down
2 changes: 1 addition & 1 deletion packages/kbn-es-query/src/filters/__tests__/phrase.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@


import { buildInlineScriptForPhraseFilter, buildPhraseFilter } from '../phrase';
import expect from 'expect.js';
import expect from '@kbn/expect';
import _ from 'lodash';
import indexPattern from '../../__fixtures__/index_pattern_response.json';
import filterSkeleton from '../../__fixtures__/filter_skeleton';
Expand Down
2 changes: 1 addition & 1 deletion packages/kbn-es-query/src/filters/__tests__/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import { buildQueryFilter } from '../query';
import { cloneDeep } from 'lodash';
import expect from 'expect.js';
import expect from '@kbn/expect';
import indexPattern from '../../__fixtures__/index_pattern_response.json';
import filterSkeleton from '../../__fixtures__/filter_skeleton';

Expand Down
2 changes: 1 addition & 1 deletion packages/kbn-es-query/src/filters/__tests__/range.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

import { buildRangeFilter } from '../range';
import expect from 'expect.js';
import expect from '@kbn/expect';
import _ from 'lodash';
import indexPattern from '../../__fixtures__/index_pattern_response.json';
import filterSkeleton from '../../__fixtures__/filter_skeleton';
Expand Down
2 changes: 1 addition & 1 deletion packages/kbn-es-query/src/kuery/ast/__tests__/ast.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

import * as ast from '../ast';
import expect from 'expect.js';
import expect from '@kbn/expect';
import { nodeTypes } from '../../node_types/index';
import indexPatternResponse from '../../../__fixtures__/index_pattern_response.json';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import expect from 'expect.js';
import expect from '@kbn/expect';
import { convertExistsFilter } from '../exists';

describe('filter to kuery migration', function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

import _ from 'lodash';
import expect from 'expect.js';
import expect from '@kbn/expect';
import { filterToKueryAST } from '../filter_to_kuery';

describe('filter to kuery migration', function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

import _ from 'lodash';
import expect from 'expect.js';
import expect from '@kbn/expect';
import { convertGeoBoundingBox } from '../geo_bounding_box';

describe('filter to kuery migration', function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import expect from 'expect.js';
import expect from '@kbn/expect';
import { convertGeoPolygon } from '../geo_polygon';

describe('filter to kuery migration', function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import expect from 'expect.js';
import expect from '@kbn/expect';
import { convertPhraseFilter } from '../phrase';

describe('filter to kuery migration', function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

import _ from 'lodash';
import expect from 'expect.js';
import expect from '@kbn/expect';
import { convertRangeFilter } from '../range';

describe('filter to kuery migration', function () {
Expand Down
2 changes: 1 addition & 1 deletion packages/kbn-es-query/src/kuery/functions/__tests__/and.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import expect from 'expect.js';
import expect from '@kbn/expect';
import * as and from '../and';
import { nodeTypes } from '../../node_types';
import * as ast from '../../ast';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import expect from 'expect.js';
import expect from '@kbn/expect';
import * as exists from '../exists';
import { nodeTypes } from '../../node_types';
import _ from 'lodash';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import expect from 'expect.js';
import expect from '@kbn/expect';
import * as geoBoundingBox from '../geo_bounding_box';
import { nodeTypes } from '../../node_types';
import indexPatternResponse from '../../../__fixtures__/index_pattern_response.json';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import expect from 'expect.js';
import expect from '@kbn/expect';
import * as geoPolygon from '../geo_polygon';
import { nodeTypes } from '../../node_types';
import indexPatternResponse from '../../../__fixtures__/index_pattern_response.json';
Expand Down
2 changes: 1 addition & 1 deletion packages/kbn-es-query/src/kuery/functions/__tests__/is.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import expect from 'expect.js';
import expect from '@kbn/expect';
import * as is from '../is';
import { nodeTypes } from '../../node_types';
import indexPatternResponse from '../../../__fixtures__/index_pattern_response.json';
Expand Down
2 changes: 1 addition & 1 deletion packages/kbn-es-query/src/kuery/functions/__tests__/not.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import expect from 'expect.js';
import expect from '@kbn/expect';
import * as not from '../not';
import { nodeTypes } from '../../node_types';
import * as ast from '../../ast';
Expand Down
2 changes: 1 addition & 1 deletion packages/kbn-es-query/src/kuery/functions/__tests__/or.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import expect from 'expect.js';
import expect from '@kbn/expect';
import * as or from '../or';
import { nodeTypes } from '../../node_types';
import * as ast from '../../ast';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import expect from 'expect.js';
import expect from '@kbn/expect';
import * as range from '../range';
import { nodeTypes } from '../../node_types';
import indexPatternResponse from '../../../__fixtures__/index_pattern_response.json';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

import { getFields } from '../../utils/get_fields';
import expect from 'expect.js';
import expect from '@kbn/expect';
import indexPatternResponse from '../../../../__fixtures__/index_pattern_response.json';

import { nodeTypes } from '../../..';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import * as functionType from '../function';
import _ from 'lodash';
import expect from 'expect.js';
import expect from '@kbn/expect';
import * as isFunction from '../../functions/is';
import indexPatternResponse from '../../../__fixtures__/index_pattern_response.json';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import expect from 'expect.js';
import expect from '@kbn/expect';
import * as literal from '../literal';

describe('kuery node types', function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import expect from 'expect.js';
import expect from '@kbn/expect';
import * as namedArg from '../named_arg';
import { nodeTypes } from '../../node_types';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import expect from 'expect.js';
import expect from '@kbn/expect';
import * as wildcard from '../wildcard';

describe('kuery node types', function () {
Expand Down
1 change: 1 addition & 0 deletions packages/kbn-eslint-plugin-eslint/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ module.exports = {
'require-license-header': require('./rules/require_license_header'),
'disallow-license-headers': require('./rules/disallow_license_headers'),
'no-default-export': require('./rules/no_default_export'),
module_migration: require('./rules/module_migration'),
},
};
Loading

0 comments on commit 883ea31

Please sign in to comment.