[@kbn/expect] "fork" expect.js into repo (#33761)

* [@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
This commit is contained in:
Spencer 2019-03-25 09:56:48 -07:00 committed by GitHub
parent 2c48da2417
commit 2e232c2e31
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
1117 changed files with 2679 additions and 1341 deletions

View file

@ -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: [

View file

@ -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

View file

@ -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`.
@ -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 }) {

View file

@ -258,6 +258,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",
@ -346,7 +347,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",

View file

@ -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.

View file

@ -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"
}
}

View file

@ -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"

View file

@ -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';

View file

@ -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';

View file

@ -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 () {

View file

@ -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 () {

View file

@ -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 () {

View file

@ -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 () {

View file

@ -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';

View file

@ -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 () {

View file

@ -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';

View file

@ -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';

View file

@ -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';

View file

@ -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';

View file

@ -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 () {

View file

@ -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 () {

View file

@ -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 () {

View file

@ -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 () {

View file

@ -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 () {

View file

@ -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 () {

View file

@ -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';

View file

@ -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';

View file

@ -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';

View file

@ -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';

View file

@ -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';

View file

@ -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';

View file

@ -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';

View file

@ -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';

View file

@ -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 '../../..';

View file

@ -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';

View file

@ -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 () {

View file

@ -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';

View file

@ -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 () {

View file

@ -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'),
},
};

View file

@ -0,0 +1,82 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
function checkModuleNameNode(context, mappings, node) {
const mapping = mappings.find(
mapping => mapping.from === node.value || mapping.from.startsWith(node.value + '/')
);
if (!mapping) {
return;
}
const newSource = node.value.replace(mapping.from, mapping.to);
context.report({
message: `Imported module "${node.value}" should be "${newSource}"`,
loc: node.loc,
fix(fixer) {
return fixer.replaceText(node, `'${newSource}'`);
},
});
}
module.exports = {
meta: {
fixable: 'code',
schema: [
{
type: 'array',
items: {
type: 'object',
properties: {
from: {
type: 'string',
},
to: {
type: 'string',
},
},
required: ['from', 'to'],
additionalProperties: false,
},
default: [],
minItems: 1,
},
],
},
create: context => {
const mappings = context.options[0];
return {
ImportDeclaration(node) {
checkModuleNameNode(context, mappings, node.source);
},
CallExpression(node) {
if (
node.callee.type === 'Identifier' &&
node.callee.name === 'require' &&
node.arguments.length === 1 &&
node.arguments[0].type === 'Literal'
) {
checkModuleNameNode(context, mappings, node.arguments[0]);
}
},
};
},
};

View file

@ -0,0 +1,22 @@
(The MIT License)
Copyright (c) 2011 Guillermo Rauch <guillermo@learnboost.com>
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View file

@ -0,0 +1,191 @@
> NOTE: This is a local fork of https://github.com/Automattic/expect.js
# @kbn/expect
Minimalistic BDD assertion toolkit based on
[should.js](http://github.com/visionmedia/should.js)
```js
expect(window.r).to.be(undefined);
expect({ a: 'b' }).to.eql({ a: 'b' })
expect(5).to.be.a('number');
expect([]).to.be.an('array');
expect(window).not.to.be.an(Image);
```
## Features
- Cross-browser: works on IE6+, Firefox, Safari, Chrome, Opera.
- Compatible with all test frameworks.
- Node.JS ready (`require('@kbn/expect')`).
## API
**ok**: asserts that the value is _truthy_ or not
```js
expect(1).to.be.ok();
expect(true).to.be.ok();
expect({}).to.be.ok();
expect(0).to.not.be.ok();
```
**be** / **equal**: asserts `===` equality
```js
expect(1).to.be(1)
expect(NaN).not.to.equal(NaN);
expect(1).not.to.be(true)
expect('1').to.not.be(1);
```
**eql**: asserts loose equality that works with objects
```js
expect({ a: 'b' }).to.eql({ a: 'b' });
expect(1).to.eql('1');
```
**a**/**an**: asserts `typeof` with support for `array` type and `instanceof`
```js
// typeof with optional `array`
expect(5).to.be.a('number');
expect([]).to.be.an('array'); // works
expect([]).to.be.an('object'); // works too, since it uses `typeof`
// constructors
expect([]).to.be.an(Array);
expect(tobi).to.be.a(Ferret);
expect(person).to.be.a(Mammal);
```
**match**: asserts `String` regular expression match
```js
expect(program.version).to.match(/[0-9]+\.[0-9]+\.[0-9]+/);
```
**contain**: asserts indexOf for an array or string
```js
expect([1, 2]).to.contain(1);
expect('hello world').to.contain('world');
```
**length**: asserts array `.length`
```js
expect([]).to.have.length(0);
expect([1,2,3]).to.have.length(3);
```
**empty**: asserts that an array is empty or not
```js
expect([]).to.be.empty();
expect({}).to.be.empty();
expect({ length: 0, duck: 'typing' }).to.be.empty();
expect({ my: 'object' }).to.not.be.empty();
expect([1,2,3]).to.not.be.empty();
```
**property**: asserts presence of an own property (and value optionally)
```js
expect(window).to.have.property('expect')
expect(window).to.have.property('expect', expect)
expect({a: 'b'}).to.have.property('a');
```
**key**/**keys**: asserts the presence of a key. Supports the `only` modifier
```js
expect({ a: 'b' }).to.have.key('a');
expect({ a: 'b', c: 'd' }).to.only.have.keys('a', 'c');
expect({ a: 'b', c: 'd' }).to.only.have.keys(['a', 'c']);
expect({ a: 'b', c: 'd' }).to.not.only.have.key('a');
```
**throw**/**throwException**/**throwError**: asserts that the `Function` throws or not when called
```js
expect(fn).to.throw(); // synonym of throwException
expect(fn).to.throwError(); // synonym of throwException
expect(fn).to.throwException(function (e) { // get the exception object
expect(e).to.be.a(SyntaxError);
});
expect(fn).to.throwException(/matches the exception message/);
expect(fn2).to.not.throwException();
```
**withArgs**: creates anonymous function to call fn with arguments
```js
expect(fn).withArgs(invalid, arg).to.throwException();
expect(fn).withArgs(valid, arg).to.not.throwException();
```
**within**: asserts a number within a range
```js
expect(1).to.be.within(0, Infinity);
```
**greaterThan**/**above**: asserts `>`
```js
expect(3).to.be.above(0);
expect(5).to.be.greaterThan(3);
```
**lessThan**/**below**: asserts `<`
```js
expect(0).to.be.below(3);
expect(1).to.be.lessThan(3);
```
**fail**: explicitly forces failure.
```js
expect().fail()
expect().fail("Custom failure message")
```
## Using with a test framework
For example, if you create a test suite with
[mocha](http://github.com/visionmedia/mocha).
Let's say we wanted to test the following program:
**math.js**
```js
function add (a, b) { return a + b; };
```
Our test file would look like this:
```js
describe('test suite', function () {
it('should expose a function', function () {
expect(add).to.be.a('function');
});
it('should do math', function () {
expect(add(1, 3)).to.equal(4);
});
});
```
If a certain expectation fails, an exception will be raised which gets captured
and shown/processed by the test runner.
## Differences with should.js
- No need for static `should` methods like `should.strictEqual`. For example,
`expect(obj).to.be(undefined)` works well.
- Some API simplifications / changes.
- API changes related to browser compatibility.

View file

@ -0,0 +1,971 @@
/* eslint-disable */
var exports = module.exports;
/**
* Exports.
*/
module.exports = expect;
expect.Assertion = Assertion;
/**
* Exports version.
*/
expect.version = '0.3.1';
/**
* Possible assertion flags.
*/
var flags = {
not: ['to', 'be', 'have', 'include', 'only']
, to: ['be', 'have', 'include', 'only', 'not']
, only: ['have']
, have: ['own']
, be: ['an']
};
function expect (obj) {
return new Assertion(obj);
}
/**
* Constructor
*
* @api private
*/
function Assertion (obj, flag, parent) {
this.obj = obj;
this.flags = {};
if (undefined != parent) {
this.flags[flag] = true;
for (var i in parent.flags) {
if (parent.flags.hasOwnProperty(i)) {
this.flags[i] = true;
}
}
}
var $flags = flag ? flags[flag] : keys(flags)
, self = this;
if ($flags) {
for (var i = 0, l = $flags.length; i < l; i++) {
// avoid recursion
if (this.flags[$flags[i]]) continue;
var name = $flags[i]
, assertion = new Assertion(this.obj, name, this)
if ('function' == typeof Assertion.prototype[name]) {
// clone the function, make sure we dont touch the prot reference
var old = this[name];
this[name] = function () {
return old.apply(self, arguments);
};
for (var fn in Assertion.prototype) {
if (Assertion.prototype.hasOwnProperty(fn) && fn != name) {
if (typeof this[name] === 'function' && fn === 'length') {
continue;
}
this[name][fn] = bind(assertion[fn], assertion);
}
}
} else {
this[name] = assertion;
}
}
}
}
/**
* Performs an assertion
*
* @api private
*/
Assertion.prototype.assert = function (truth, msg, error, expected) {
var msg = this.flags.not ? error : msg
, ok = this.flags.not ? !truth : truth
, err;
if (!ok) {
err = new Error(msg.call(this));
if (arguments.length > 3) {
err.actual = this.obj;
err.expected = expected;
err.showDiff = true;
}
throw err;
}
this.and = new Assertion(this.obj);
};
/**
* Check if the value is truthy
*
* @api public
*/
Assertion.prototype.ok = function () {
this.assert(
!!this.obj
, function(){ return 'expected ' + i(this.obj) + ' to be truthy' }
, function(){ return 'expected ' + i(this.obj) + ' to be falsy' });
};
/**
* Creates an anonymous function which calls fn with arguments.
*
* @api public
*/
Assertion.prototype.withArgs = function() {
expect(this.obj).to.be.a('function');
var fn = this.obj;
var args = Array.prototype.slice.call(arguments);
return expect(function() { fn.apply(null, args); });
};
/**
* Assert that the function throws.
*
* @param {Function|RegExp} callback, or regexp to match error string against
* @api public
*/
Assertion.prototype['throw'] =
Assertion.prototype.throwError =
Assertion.prototype.throwException = function (fn) {
expect(this.obj).to.be.a('function');
var thrown = false
, not = this.flags.not;
try {
this.obj();
} catch (e) {
if (isRegExp(fn)) {
var subject = 'string' == typeof e ? e : e.message;
if (not) {
expect(subject).to.not.match(fn);
} else {
expect(subject).to.match(fn);
}
} else if ('function' == typeof fn) {
fn(e);
}
thrown = true;
}
if (isRegExp(fn) && not) {
// in the presence of a matcher, ensure the `not` only applies to
// the matching.
this.flags.not = false;
}
var name = this.obj.name || 'fn';
this.assert(
thrown
, function(){ return 'expected ' + name + ' to throw an exception' }
, function(){ return 'expected ' + name + ' not to throw an exception' });
};
/**
* Checks if the array is empty.
*
* @api public
*/
Assertion.prototype.empty = function () {
var expectation;
if ('object' == typeof this.obj && null !== this.obj && !isArray(this.obj)) {
if ('number' == typeof this.obj.length) {
expectation = !this.obj.length;
} else {
expectation = !keys(this.obj).length;
}
} else {
if ('string' != typeof this.obj) {
expect(this.obj).to.be.an('object');
}
expect(this.obj).to.have.property('length');
expectation = !this.obj.length;
}
this.assert(
expectation
, function(){ return 'expected ' + i(this.obj) + ' to be empty' }
, function(){ return 'expected ' + i(this.obj) + ' to not be empty' });
return this;
};
/**
* Checks if the obj exactly equals another.
*
* @api public
*/
Assertion.prototype.be =
Assertion.prototype.equal = function (obj) {
this.assert(
obj === this.obj
, function(){ return 'expected ' + i(this.obj) + ' to equal ' + i(obj) }
, function(){ return 'expected ' + i(this.obj) + ' to not equal ' + i(obj) });
return this;
};
/**
* Checks if the obj sortof equals another.
*
* @api public
*/
Assertion.prototype.eql = function (obj) {
this.assert(
expect.eql(this.obj, obj)
, function(){ return 'expected ' + i(this.obj) + ' to sort of equal ' + i(obj) }
, function(){ return 'expected ' + i(this.obj) + ' to sort of not equal ' + i(obj) }
, obj);
return this;
};
/**
* Assert within start to finish (inclusive).
*
* @param {Number} start
* @param {Number} finish
* @api public
*/
Assertion.prototype.within = function (start, finish) {
var range = start + '..' + finish;
this.assert(
this.obj >= start && this.obj <= finish
, function(){ return 'expected ' + i(this.obj) + ' to be within ' + range }
, function(){ return 'expected ' + i(this.obj) + ' to not be within ' + range });
return this;
};
/**
* Assert typeof / instance of
*
* @api public
*/
Assertion.prototype.a =
Assertion.prototype.an = function (type) {
if ('string' == typeof type) {
// proper english in error msg
var n = /^[aeiou]/.test(type) ? 'n' : '';
// typeof with support for 'array'
this.assert(
'array' == type ? isArray(this.obj) :
'regexp' == type ? isRegExp(this.obj) :
'object' == type
? 'object' == typeof this.obj && null !== this.obj
: type == typeof this.obj
, function(){ return 'expected ' + i(this.obj) + ' to be a' + n + ' ' + type }
, function(){ return 'expected ' + i(this.obj) + ' not to be a' + n + ' ' + type });
} else {
// instanceof
var name = type.name || 'supplied constructor';
this.assert(
this.obj instanceof type
, function(){ return 'expected ' + i(this.obj) + ' to be an instance of ' + name }
, function(){ return 'expected ' + i(this.obj) + ' not to be an instance of ' + name });
}
return this;
};
/**
* Assert numeric value above _n_.
*
* @param {Number} n
* @api public
*/
Assertion.prototype.greaterThan =
Assertion.prototype.above = function (n) {
this.assert(
this.obj > n
, function(){ return 'expected ' + i(this.obj) + ' to be above ' + n }
, function(){ return 'expected ' + i(this.obj) + ' to be below ' + n });
return this;
};
/**
* Assert numeric value below _n_.
*
* @param {Number} n
* @api public
*/
Assertion.prototype.lessThan =
Assertion.prototype.below = function (n) {
this.assert(
this.obj < n
, function(){ return 'expected ' + i(this.obj) + ' to be below ' + n }
, function(){ return 'expected ' + i(this.obj) + ' to be above ' + n });
return this;
};
/**
* Assert string value matches _regexp_.
*
* @param {RegExp} regexp
* @api public
*/
Assertion.prototype.match = function (regexp) {
this.assert(
regexp.exec(this.obj)
, function(){ return 'expected ' + i(this.obj) + ' to match ' + regexp }
, function(){ return 'expected ' + i(this.obj) + ' not to match ' + regexp });
return this;
};
/**
* Assert property "length" exists and has value of _n_.
*
* @param {Number} n
* @api public
*/
Assertion.prototype.length = function (n) {
expect(this.obj).to.have.property('length');
var len = this.obj.length;
this.assert(
n == len
, function(){ return 'expected ' + i(this.obj) + ' to have a length of ' + n + ' but got ' + len }
, function(){ return 'expected ' + i(this.obj) + ' to not have a length of ' + len });
return this;
};
/**
* Assert property _name_ exists, with optional _val_.
*
* @param {String} name
* @param {Mixed} val
* @api public
*/
Assertion.prototype.property = function (name, val) {
if (this.flags.own) {
this.assert(
Object.prototype.hasOwnProperty.call(this.obj, name)
, function(){ return 'expected ' + i(this.obj) + ' to have own property ' + i(name) }
, function(){ return 'expected ' + i(this.obj) + ' to not have own property ' + i(name) });
return this;
}
if (this.flags.not && undefined !== val) {
if (undefined === this.obj[name]) {
throw new Error(i(this.obj) + ' has no property ' + i(name));
}
} else {
var hasProp;
try {
hasProp = name in this.obj
} catch (e) {
hasProp = undefined !== this.obj[name]
}
this.assert(
hasProp
, function(){ return 'expected ' + i(this.obj) + ' to have a property ' + i(name) }
, function(){ return 'expected ' + i(this.obj) + ' to not have a property ' + i(name) });
}
if (undefined !== val) {
this.assert(
val === this.obj[name]
, function(){ return 'expected ' + i(this.obj) + ' to have a property ' + i(name)
+ ' of ' + i(val) + ', but got ' + i(this.obj[name]) }
, function(){ return 'expected ' + i(this.obj) + ' to not have a property ' + i(name)
+ ' of ' + i(val) });
}
this.obj = this.obj[name];
return this;
};
/**
* Assert that the array contains _obj_ or string contains _obj_.
*
* @param {Mixed} obj|string
* @api public
*/
Assertion.prototype.string =
Assertion.prototype.contain = function (obj) {
if ('string' == typeof this.obj) {
this.assert(
~this.obj.indexOf(obj)
, function(){ return 'expected ' + i(this.obj) + ' to contain ' + i(obj) }
, function(){ return 'expected ' + i(this.obj) + ' to not contain ' + i(obj) });
} else {
this.assert(
~indexOf(this.obj, obj)
, function(){ return 'expected ' + i(this.obj) + ' to contain ' + i(obj) }
, function(){ return 'expected ' + i(this.obj) + ' to not contain ' + i(obj) });
}
return this;
};
/**
* Assert exact keys or inclusion of keys by using
* the `.own` modifier.
*
* @param {Array|String ...} keys
* @api public
*/
Assertion.prototype.key =
Assertion.prototype.keys = function ($keys) {
var str
, ok = true;
$keys = isArray($keys)
? $keys
: Array.prototype.slice.call(arguments);
if (!$keys.length) throw new Error('keys required');
var actual = keys(this.obj)
, len = $keys.length;
// Inclusion
ok = every($keys, function (key) {
return ~indexOf(actual, key);
});
// Strict
if (!this.flags.not && this.flags.only) {
ok = ok && $keys.length == actual.length;
}
// Key string
if (len > 1) {
$keys = map($keys, function (key) {
return i(key);
});
var last = $keys.pop();
str = $keys.join(', ') + ', and ' + last;
} else {
str = i($keys[0]);
}
// Form
str = (len > 1 ? 'keys ' : 'key ') + str;
// Have / include
str = (!this.flags.only ? 'include ' : 'only have ') + str;
// Assertion
this.assert(
ok
, function(){ return 'expected ' + i(this.obj) + ' to ' + str }
, function(){ return 'expected ' + i(this.obj) + ' to not ' + str });
return this;
};
/**
* Assert a failure.
*
* @param {String ...} custom message
* @api public
*/
Assertion.prototype.fail = function (msg) {
var error = function() { return msg || "explicit failure"; }
this.assert(false, error, error);
return this;
};
/**
* Function bind implementation.
*/
function bind (fn, scope) {
return function () {
return fn.apply(scope, arguments);
}
}
/**
* Array every compatibility
*
* @see bit.ly/5Fq1N2
* @api public
*/
function every (arr, fn, thisObj) {
var scope = thisObj || global;
for (var i = 0, j = arr.length; i < j; ++i) {
if (!fn.call(scope, arr[i], i, arr)) {
return false;
}
}
return true;
}
/**
* Array indexOf compatibility.
*
* @see bit.ly/a5Dxa2
* @api public
*/
function indexOf (arr, o, i) {
if (Array.prototype.indexOf) {
return Array.prototype.indexOf.call(arr, o, i);
}
if (arr.length === undefined) {
return -1;
}
for (var j = arr.length, i = i < 0 ? i + j < 0 ? 0 : i + j : i || 0
; i < j && arr[i] !== o; i++);
return j <= i ? -1 : i;
}
// https://gist.github.com/1044128/
var getOuterHTML = function(element) {
if ('outerHTML' in element) return element.outerHTML;
var ns = "http://www.w3.org/1999/xhtml";
var container = document.createElementNS(ns, '_');
var xmlSerializer = new XMLSerializer();
var html;
if (document.xmlVersion) {
return xmlSerializer.serializeToString(element);
} else {
container.appendChild(element.cloneNode(false));
html = container.innerHTML.replace('><', '>' + element.innerHTML + '<');
container.innerHTML = '';
return html;
}
};
// Returns true if object is a DOM element.
var isDOMElement = function (object) {
if (typeof HTMLElement === 'object') {
return object instanceof HTMLElement;
} else {
return object &&
typeof object === 'object' &&
object.nodeType === 1 &&
typeof object.nodeName === 'string';
}
};
/**
* Inspects an object.
*
* @see taken from node.js `util` module (copyright Joyent, MIT license)
* @api private
*/
function i (obj, showHidden, depth) {
var seen = [];
function stylize (str) {
return str;
}
function format (value, recurseTimes) {
// Provide a hook for user-specified inspect functions.
// Check that value is an object with an inspect function on it
if (value && typeof value.inspect === 'function' &&
// Filter out the util module, it's inspect function is special
value !== exports &&
// Also filter out any prototype objects using the circular check.
!(value.constructor && value.constructor.prototype === value)) {
return value.inspect(recurseTimes);
}
// Primitive types cannot have properties
switch (typeof value) {
case 'undefined':
return stylize('undefined', 'undefined');
case 'string':
var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '')
.replace(/'/g, "\\'")
.replace(/\\"/g, '"') + '\'';
return stylize(simple, 'string');
case 'number':
return stylize('' + value, 'number');
case 'boolean':
return stylize('' + value, 'boolean');
}
// For some reason typeof null is "object", so special case here.
if (value === null) {
return stylize('null', 'null');
}
if (isDOMElement(value)) {
return getOuterHTML(value);
}
// Look up the keys of the object.
var visible_keys = keys(value);
var $keys = showHidden ? Object.getOwnPropertyNames(value) : visible_keys;
// Functions without properties can be shortcutted.
if (typeof value === 'function' && $keys.length === 0) {
if (isRegExp(value)) {
return stylize('' + value, 'regexp');
} else {
var name = value.name ? ': ' + value.name : '';
return stylize('[Function' + name + ']', 'special');
}
}
// Dates without properties can be shortcutted
if (isDate(value) && $keys.length === 0) {
return stylize(value.toUTCString(), 'date');
}
// Error objects can be shortcutted
if (value instanceof Error) {
return stylize("["+value.toString()+"]", 'Error');
}
var base, type, braces;
// Determine the object type
if (isArray(value)) {
type = 'Array';
braces = ['[', ']'];
} else {
type = 'Object';
braces = ['{', '}'];
}
// Make functions say that they are functions
if (typeof value === 'function') {
var n = value.name ? ': ' + value.name : '';
base = (isRegExp(value)) ? ' ' + value : ' [Function' + n + ']';
} else {
base = '';
}
// Make dates with properties first say the date
if (isDate(value)) {
base = ' ' + value.toUTCString();
}
if ($keys.length === 0) {
return braces[0] + base + braces[1];
}
if (recurseTimes < 0) {
if (isRegExp(value)) {
return stylize('' + value, 'regexp');
} else {
return stylize('[Object]', 'special');
}
}
seen.push(value);
var output = map($keys, function (key) {
var name, str;
if (value.__lookupGetter__) {
if (value.__lookupGetter__(key)) {
if (value.__lookupSetter__(key)) {
str = stylize('[Getter/Setter]', 'special');
} else {
str = stylize('[Getter]', 'special');
}
} else {
if (value.__lookupSetter__(key)) {
str = stylize('[Setter]', 'special');
}
}
}
if (indexOf(visible_keys, key) < 0) {
name = '[' + key + ']';
}
if (!str) {
if (indexOf(seen, value[key]) < 0) {
if (recurseTimes === null) {
str = format(value[key]);
} else {
str = format(value[key], recurseTimes - 1);
}
if (str.indexOf('\n') > -1) {
if (isArray(value)) {
str = map(str.split('\n'), function (line) {
return ' ' + line;
}).join('\n').substr(2);
} else {
str = '\n' + map(str.split('\n'), function (line) {
return ' ' + line;
}).join('\n');
}
}
} else {
str = stylize('[Circular]', 'special');
}
}
if (typeof name === 'undefined') {
if (type === 'Array' && key.match(/^\d+$/)) {
return str;
}
name = JSON.stringify('' + key);
if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) {
name = name.substr(1, name.length - 2);
name = stylize(name, 'name');
} else {
name = name.replace(/'/g, "\\'")
.replace(/\\"/g, '"')
.replace(/(^"|"$)/g, "'");
name = stylize(name, 'string');
}
}
return name + ': ' + str;
});
seen.pop();
var numLinesEst = 0;
var length = reduce(output, function (prev, cur) {
numLinesEst++;
if (indexOf(cur, '\n') >= 0) numLinesEst++;
return prev + cur.length + 1;
}, 0);
if (length > 50) {
output = braces[0] +
(base === '' ? '' : base + '\n ') +
' ' +
output.join(',\n ') +
' ' +
braces[1];
} else {
output = braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1];
}
return output;
}
return format(obj, (typeof depth === 'undefined' ? 2 : depth));
}
expect.stringify = i;
function isArray (ar) {
return Object.prototype.toString.call(ar) === '[object Array]';
}
function isRegExp(re) {
var s;
try {
s = '' + re;
} catch (e) {
return false;
}
return re instanceof RegExp || // easy case
// duck-type for context-switching evalcx case
typeof(re) === 'function' &&
re.constructor.name === 'RegExp' &&
re.compile &&
re.test &&
re.exec &&
s.match(/^\/.*\/[gim]{0,3}$/);
}
function isDate(d) {
return d instanceof Date;
}
function keys (obj) {
if (Object.keys) {
return Object.keys(obj);
}
var keys = [];
for (var i in obj) {
if (Object.prototype.hasOwnProperty.call(obj, i)) {
keys.push(i);
}
}
return keys;
}
function map (arr, mapper, that) {
if (Array.prototype.map) {
return Array.prototype.map.call(arr, mapper, that);
}
var other= new Array(arr.length);
for (var i= 0, n = arr.length; i<n; i++)
if (i in arr)
other[i] = mapper.call(that, arr[i], i, arr);
return other;
}
function reduce (arr, fun) {
if (Array.prototype.reduce) {
return Array.prototype.reduce.apply(
arr
, Array.prototype.slice.call(arguments, 1)
);
}
var len = +this.length;
if (typeof fun !== "function")
throw new TypeError();
// no value to return if no initial value and an empty array
if (len === 0 && arguments.length === 1)
throw new TypeError();
var i = 0;
if (arguments.length >= 2) {
var rv = arguments[1];
} else {
do {
if (i in this) {
rv = this[i++];
break;
}
// if array contains no values, no initial value to return
if (++i >= len)
throw new TypeError();
} while (true);
}
for (; i < len; i++) {
if (i in this)
rv = fun.call(null, rv, this[i], i, this);
}
return rv;
}
/**
* Asserts deep equality
*
* @see taken from node.js `assert` module (copyright Joyent, MIT license)
* @api private
*/
expect.eql = function eql(actual, expected) {
// 7.1. All identical values are equivalent, as determined by ===.
if (actual === expected) {
return true;
} else if ('undefined' != typeof Buffer
&& Buffer.isBuffer(actual) && Buffer.isBuffer(expected)) {
if (actual.length != expected.length) return false;
for (var i = 0; i < actual.length; i++) {
if (actual[i] !== expected[i]) return false;
}
return true;
// 7.2. If the expected value is a Date object, the actual value is
// equivalent if it is also a Date object that refers to the same time.
} else if (actual instanceof Date && expected instanceof Date) {
return actual.getTime() === expected.getTime();
// 7.3. Other pairs that do not both pass typeof value == "object",
// equivalence is determined by ==.
} else if (typeof actual != 'object' && typeof expected != 'object') {
return actual == expected;
// If both are regular expression use the special `regExpEquiv` method
// to determine equivalence.
} else if (isRegExp(actual) && isRegExp(expected)) {
return regExpEquiv(actual, expected);
// 7.4. For all other Object pairs, including Array objects, equivalence is
// determined by having the same number of owned properties (as verified
// with Object.prototype.hasOwnProperty.call), the same set of keys
// (although not necessarily the same order), equivalent values for every
// corresponding key, and an identical "prototype" property. Note: this
// accounts for both named and indexed properties on Arrays.
} else {
return objEquiv(actual, expected);
}
};
function isUndefinedOrNull (value) {
return value === null || value === undefined;
}
function isArguments (object) {
return Object.prototype.toString.call(object) == '[object Arguments]';
}
function regExpEquiv (a, b) {
return a.source === b.source && a.global === b.global &&
a.ignoreCase === b.ignoreCase && a.multiline === b.multiline;
}
function objEquiv (a, b) {
if (isUndefinedOrNull(a) || isUndefinedOrNull(b))
return false;
// an identical "prototype" property.
if (a.prototype !== b.prototype) return false;
//~~~I've managed to break Object.keys through screwy arguments passing.
// Converting to array solves the problem.
if (isArguments(a)) {
if (!isArguments(b)) {
return false;
}
a = pSlice.call(a);
b = pSlice.call(b);
return expect.eql(a, b);
}
try{
var ka = keys(a),
kb = keys(b),
key, i;
} catch (e) {//happens when one is a string literal and the other isn't
return false;
}
// having the same number of owned properties (keys incorporates hasOwnProperty)
if (ka.length != kb.length)
return false;
//the same set of keys (although not necessarily the same order),
ka.sort();
kb.sort();
//~~~cheap key test
for (i = ka.length - 1; i >= 0; i--) {
if (ka[i] != kb[i])
return false;
}
//equivalent values for every corresponding key, and
//~~~possibly expensive deep test
for (i = ka.length - 1; i >= 0; i--) {
key = ka[i];
if (!expect.eql(a[key], b[key]))
return false;
}
return true;
}

221
packages/kbn-expect/expect.js.d.ts vendored Normal file
View file

@ -0,0 +1,221 @@
// tslint:disable
// Type definitions for expect.js 0.3.1
// Project: https://github.com/Automattic/expect.js
// Definitions by: Teppei Sato <https://github.com/teppeis>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// License: MIT
export default function expect(target?: any): Root;
interface Assertion {
/**
* Assert typeof / instanceof.
*/
an: An;
/**
* Check if the value is truthy
*/
ok(): void;
/**
* Creates an anonymous function which calls fn with arguments.
*/
withArgs(...args: any[]): Root;
/**
* Assert that the function throws.
*
* @param fn callback to match error string against
*/
throwError(fn?: (exception: any) => void): void;
/**
* Assert that the function throws.
*
* @param fn callback to match error string against
*/
throwException(fn?: (exception: any) => void): void;
/**
* Assert that the function throws.
*
* @param regexp regexp to match error string against
*/
throwError(regexp: RegExp): void;
/**
* Assert that the function throws.
*
* @param fn callback to match error string against
*/
throwException(regexp: RegExp): void;
/**
* Checks if the array is empty.
*/
empty(): Assertion;
/**
* Checks if the obj exactly equals another.
*/
equal(obj: any): Assertion;
/**
* Checks if the obj sortof equals another.
*/
eql(obj: any): Assertion;
/**
* Assert within start to finish (inclusive).
*
* @param start
* @param finish
*/
within(start: number, finish: number): Assertion;
/**
* Assert typeof.
*/
a(type: string): Assertion;
/**
* Assert instanceof.
*/
a(type: Function): Assertion;
/**
* Assert numeric value above n.
*/
greaterThan(n: number): Assertion;
/**
* Assert numeric value above n.
*/
above(n: number): Assertion;
/**
* Assert numeric value below n.
*/
lessThan(n: number): Assertion;
/**
* Assert numeric value below n.
*/
below(n: number): Assertion;
/**
* Assert string value matches regexp.
*
* @param regexp
*/
match(regexp: RegExp): Assertion;
/**
* Assert property "length" exists and has value of n.
*
* @param n
*/
length(n: number): Assertion;
/**
* Assert property name exists, with optional val.
*
* @param name
* @param val
*/
property(name: string, val?: any): Assertion;
/**
* Assert that string contains str.
*/
contain(str: string): Assertion;
string(str: string): Assertion;
/**
* Assert that the array contains obj.
*/
contain(obj: any): Assertion;
string(obj: any): Assertion;
/**
* Assert exact keys or inclusion of keys by using the `.own` modifier.
*/
key(keys: string[]): Assertion;
/**
* Assert exact keys or inclusion of keys by using the `.own` modifier.
*/
key(...keys: string[]): Assertion;
/**
* Assert exact keys or inclusion of keys by using the `.own` modifier.
*/
keys(keys: string[]): Assertion;
/**
* Assert exact keys or inclusion of keys by using the `.own` modifier.
*/
keys(...keys: string[]): Assertion;
/**
* Assert a failure.
*/
fail(message?: string): Assertion;
}
interface Root extends Assertion {
not: Not;
to: To;
only: Only;
have: Have;
be: Be;
}
interface Be extends Assertion {
/**
* Checks if the obj exactly equals another.
*/
(obj: any): Assertion;
an: An;
}
interface An extends Assertion {
/**
* Assert typeof.
*/
(type: string): Assertion;
/**
* Assert instanceof.
*/
(type: Function): Assertion;
}
interface Not extends NotBase {
to: ToBase;
}
interface NotBase extends Assertion {
be: Be;
have: Have;
include: Assertion;
only: Only;
}
interface To extends ToBase {
not: NotBase;
}
interface ToBase extends Assertion {
be: Be;
have: Have;
include: Assertion;
only: Only;
}
interface Only extends Assertion {
have: Have;
}
interface Have extends Assertion {
own: Assertion;
}

View file

@ -0,0 +1,7 @@
{
"name": "@kbn/expect",
"main": "./expect.js",
"version": "1.0.0",
"license": "MIT",
"private": true
}

View file

@ -0,0 +1,6 @@
{
"extends": "../../tsconfig.json",
"include": [
"expect.js.d.ts"
]
}

View file

@ -25,6 +25,7 @@
"devDependencies": {
"@elastic/eslint-config-kibana": "link:../../kibana/packages/eslint-config-kibana",
"@elastic/eslint-import-resolver-kibana": "link:../../kibana/packages/kbn-eslint-import-resolver-kibana",
"@kbn/expect": "1.0.0",
"@kbn/plugin-helpers": "link:../../kibana/packages/kbn-plugin-helpers",
"babel-eslint": "^9.0.0",
"eslint": "^5.6.0",
@ -35,7 +36,6 @@
"eslint-plugin-mocha": "^5.2.0",
"eslint-plugin-no-unsanitized": "^3.0.2",
"eslint-plugin-prefer-object-spread": "^1.2.1",
"eslint-plugin-react": "^7.11.1",
"expect.js": "^0.3.1"
"eslint-plugin-react": "^7.11.1"
}
}

View file

@ -1,4 +1,4 @@
import expect from 'expect.js';
import expect from '@kbn/expect';
describe('suite', () => {
it('is a test', () => {

View file

@ -1,4 +1,4 @@
import expect from 'expect.js';
import expect from '@kbn/expect';
describe('suite', () => {
it('is a test', () => {

View file

@ -10,7 +10,7 @@
"author": "Spencer Alger <email@spalger.com>",
"license": "Apache-2.0",
"devDependencies": {
"expect.js": "^0.3.1",
"@kbn/expect": "1.0.0",
"mocha": "^2.3.4"
}
}

View file

@ -18,7 +18,7 @@
*/
const testSubjSelector = require('../');
const expect = require('expect.js');
const expect = require('@kbn/expect');
describe('testSubjSelector()', function() {
it('converts subjectSelectors to cssSelectors', function() {

View file

@ -2,5 +2,4 @@
Shared types used by different parts of the tests
- **`expect.js.d.ts`**: This is a fork of the expect.js types that have been slightly modified to only expose a module type for `import expect from 'expect.js'` statements. The `@types/expect.js` includes types for the `expect` global, which is useful for some uses of the library but conflicts with the jest types we use. Making the type "module only" prevents them from conflicting.
- **`ftr.d.ts`**: These types are generic types for using the functional test runner. They are here because we plan to move the functional test runner into the `@kbn/test` package at some point and having them here makes them a lot easier to import from all over the place like we do.

View file

@ -1,225 +0,0 @@
// tslint:disable
// Type definitions for expect.js 0.3.1
// Project: https://github.com/Automattic/expect.js
// Definitions by: Teppei Sato <https://github.com/teppeis>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// License: MIT
declare module 'expect.js' {
function expect(target?: any): Root;
interface Assertion {
/**
* Assert typeof / instanceof.
*/
an: An;
/**
* Check if the value is truthy
*/
ok(): void;
/**
* Creates an anonymous function which calls fn with arguments.
*/
withArgs(...args: any[]): Root;
/**
* Assert that the function throws.
*
* @param fn callback to match error string against
*/
throwError(fn?: (exception: any) => void): void;
/**
* Assert that the function throws.
*
* @param fn callback to match error string against
*/
throwException(fn?: (exception: any) => void): void;
/**
* Assert that the function throws.
*
* @param regexp regexp to match error string against
*/
throwError(regexp: RegExp): void;
/**
* Assert that the function throws.
*
* @param fn callback to match error string against
*/
throwException(regexp: RegExp): void;
/**
* Checks if the array is empty.
*/
empty(): Assertion;
/**
* Checks if the obj exactly equals another.
*/
equal(obj: any): Assertion;
/**
* Checks if the obj sortof equals another.
*/
eql(obj: any): Assertion;
/**
* Assert within start to finish (inclusive).
*
* @param start
* @param finish
*/
within(start: number, finish: number): Assertion;
/**
* Assert typeof.
*/
a(type: string): Assertion;
/**
* Assert instanceof.
*/
a(type: Function): Assertion;
/**
* Assert numeric value above n.
*/
greaterThan(n: number): Assertion;
/**
* Assert numeric value above n.
*/
above(n: number): Assertion;
/**
* Assert numeric value below n.
*/
lessThan(n: number): Assertion;
/**
* Assert numeric value below n.
*/
below(n: number): Assertion;
/**
* Assert string value matches regexp.
*
* @param regexp
*/
match(regexp: RegExp): Assertion;
/**
* Assert property "length" exists and has value of n.
*
* @param n
*/
length(n: number): Assertion;
/**
* Assert property name exists, with optional val.
*
* @param name
* @param val
*/
property(name: string, val?: any): Assertion;
/**
* Assert that string contains str.
*/
contain(str: string): Assertion;
string(str: string): Assertion;
/**
* Assert that the array contains obj.
*/
contain(obj: any): Assertion;
string(obj: any): Assertion;
/**
* Assert exact keys or inclusion of keys by using the `.own` modifier.
*/
key(keys: string[]): Assertion;
/**
* Assert exact keys or inclusion of keys by using the `.own` modifier.
*/
key(...keys: string[]): Assertion;
/**
* Assert exact keys or inclusion of keys by using the `.own` modifier.
*/
keys(keys: string[]): Assertion;
/**
* Assert exact keys or inclusion of keys by using the `.own` modifier.
*/
keys(...keys: string[]): Assertion;
/**
* Assert a failure.
*/
fail(message?: string): Assertion;
}
interface Root extends Assertion {
not: Not;
to: To;
only: Only;
have: Have;
be: Be;
}
interface Be extends Assertion {
/**
* Checks if the obj exactly equals another.
*/
(obj: any): Assertion;
an: An;
}
interface An extends Assertion {
/**
* Assert typeof.
*/
(type: string): Assertion;
/**
* Assert instanceof.
*/
(type: Function): Assertion;
}
interface Not extends NotBase {
to: ToBase;
}
interface NotBase extends Assertion {
be: Be;
have: Have;
include: Assertion;
only: Only;
}
interface To extends ToBase {
not: NotBase;
}
interface ToBase extends Assertion {
be: Be;
have: Have;
include: Assertion;
only: Only;
}
interface Only extends Assertion {
have: Have;
}
interface Have extends Assertion {
own: Assertion;
}
export default expect;
}

View file

@ -19,7 +19,7 @@
import { resolve, sep } from 'path';
import expect from 'expect.js';
import expect from '@kbn/expect';
import { File } from '../file';

View file

@ -21,7 +21,7 @@ import fs from 'fs';
import { engines } from '../../../package.json';
import { promisify } from 'util';
const readFile = promisify(fs.readFile);
import expect from 'expect.js';
import expect from '@kbn/expect';
describe('All configs should use a single version of Node', () => {
it('should compare .node-version and .nvmrc', async () => {

View file

@ -17,7 +17,7 @@
* under the License.
*/
import expect from 'expect.js';
import expect from '@kbn/expect';
import sinon from 'sinon';
import { createBuild } from '../build';

View file

@ -19,7 +19,7 @@
import { resolve } from 'path';
import expect from 'expect.js';
import expect from '@kbn/expect';
import pkg from '../../../../../package.json';
import { getConfig } from '../config';

View file

@ -17,7 +17,7 @@
* under the License.
*/
import expect from 'expect.js';
import expect from '@kbn/expect';
import { isErrorLogged, markErrorLogged } from '../errors';

View file

@ -21,7 +21,7 @@ import { resolve } from 'path';
import { chmodSync, statSync } from 'fs';
import del from 'del';
import expect from 'expect.js';
import expect from '@kbn/expect';
import { mkdirp, write, read, getChildPaths, copy, copyAll, getFileHash, untar } from '../fs';

View file

@ -17,7 +17,7 @@
* under the License.
*/
import expect from 'expect.js';
import expect from '@kbn/expect';
import { createPlatform } from '../platform';

View file

@ -18,7 +18,7 @@
*/
import sinon from 'sinon';
import expect from 'expect.js';
import expect from '@kbn/expect';
import { ToolingLog } from '@kbn/dev-utils';
import { createRunner } from '../runner';

View file

@ -17,7 +17,7 @@
* under the License.
*/
import expect from 'expect.js';
import expect from '@kbn/expect';
import pkg from '../../../../../package.json';
import { getVersionInfo } from '../version_info';

View file

@ -23,7 +23,7 @@ import { readFileSync } from 'fs';
import del from 'del';
import sinon from 'sinon';
import expect from 'expect.js';
import expect from '@kbn/expect';
import Wreck from 'wreck';
import { ToolingLog } from '@kbn/dev-utils';

View file

@ -18,7 +18,7 @@
*/
import sinon from 'sinon';
import expect from 'expect.js';
import expect from '@kbn/expect';
import * as NodeShasumsNS from '../node_shasums';
import * as NodeDownloadInfoNS from '../node_download_info';

View file

@ -17,7 +17,7 @@
* under the License.
*/
import expect from 'expect.js';
import expect from '@kbn/expect';
import { getNodeShasums } from '../node_shasums';

View file

@ -18,7 +18,7 @@
*/
import sinon from 'sinon';
import expect from 'expect.js';
import expect from '@kbn/expect';
import * as NodeShasumsNS from '../node_shasums';
import * as NodeDownloadInfoNS from '../node_download_info';

View file

@ -19,7 +19,7 @@
import { resolve } from 'path';
import expect from 'expect.js';
import expect from '@kbn/expect';
import { assertLicensesValid } from '../valid';

View file

@ -24,7 +24,7 @@ import { fromNode as fcb } from 'bluebird';
import { parseString } from 'xml2js';
import del from 'del';
import Mocha from 'mocha';
import expect from 'expect.js';
import expect from '@kbn/expect';
import { setupJUnitReportGeneration } from '../junit_report_generation';

View file

@ -20,7 +20,7 @@
import { resolve, sep } from 'path';
import { uniq } from 'lodash';
import expect from 'expect.js';
import expect from '@kbn/expect';
import { getInstalledPackages } from '../installed_packages';

View file

@ -0,0 +1,59 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
const Lint = require('tslint');
class ModuleMigrationWalker extends Lint.RuleWalker {
visitImportDeclaration(node) {
const moduleId = node.moduleSpecifier.text;
const mapping = this.options.find(
mapping => mapping.from === moduleId || mapping.from.startsWith(moduleId + '/')
);
if (!mapping) {
return;
}
const newSource = moduleId.replace(mapping.from, mapping.to);
const start = node.moduleSpecifier.getStart();
const width = node.moduleSpecifier.getWidth();
this.addFailure(
this.createFailure(
start,
width,
`Imported module "${moduleId}" should be "${newSource}"`,
this.createReplacement(
start,
width,
`'${newSource}'`
)
)
);
super.visitImportDeclaration(node);
}
}
exports.Rule = class extends Lint.Rules.AbstractRule {
apply(sourceFile) {
return this.applyWithWalker(new ModuleMigrationWalker(sourceFile, this.getOptions()));
}
};

View file

@ -17,7 +17,7 @@
* under the License.
*/
import expect from 'expect.js';
import expect from '@kbn/expect';
import { uniq } from 'lodash';
import sinon from 'sinon';

View file

@ -20,7 +20,7 @@
import Stream from 'stream';
import { createGunzip } from 'zlib';
import expect from 'expect.js';
import expect from '@kbn/expect';
import {
createListStream,

View file

@ -20,7 +20,7 @@
import Stream, { PassThrough, Transform } from 'stream';
import { createGzip } from 'zlib';
import expect from 'expect.js';
import expect from '@kbn/expect';
import {
createConcatStream,

View file

@ -18,7 +18,7 @@
*/
import sinon from 'sinon';
import expect from 'expect.js';
import expect from '@kbn/expect';
import { delay } from 'bluebird';
import {

View file

@ -17,7 +17,7 @@
* under the License.
*/
import expect from 'expect.js';
import expect from '@kbn/expect';
import { delay } from 'bluebird';
import {

View file

@ -17,7 +17,7 @@
* under the License.
*/
import expect from 'expect.js';
import expect from '@kbn/expect';
import sinon from 'sinon';
import Chance from 'chance';

View file

@ -18,7 +18,7 @@
*/
import sinon from 'sinon';
import expect from 'expect.js';
import expect from '@kbn/expect';
import {
createListStream,

View file

@ -18,7 +18,7 @@
*/
import Chance from 'chance';
import expect from 'expect.js';
import expect from '@kbn/expect';
import {
createListStream,

View file

@ -17,7 +17,7 @@
* under the License.
*/
import expect from 'expect.js';
import expect from '@kbn/expect';
export default () => {
describe('app one', () => {

View file

@ -20,7 +20,7 @@
import { spawnSync } from 'child_process';
import { resolve } from 'path';
import expect from 'expect.js';
import expect from '@kbn/expect';
const SCRIPT = resolve(__dirname, '../../../../scripts/functional_test_runner.js');
const BASIC_CONFIG = resolve(__dirname, '../fixtures/simple_project/config.js');

View file

@ -21,7 +21,7 @@ import { spawnSync } from 'child_process';
import { resolve } from 'path';
import stripAnsi from 'strip-ansi';
import expect from 'expect.js';
import expect from '@kbn/expect';
const SCRIPT = resolve(__dirname, '../../../../scripts/functional_test_runner.js');
const FAILURE_HOOKS_CONFIG = resolve(__dirname, '../fixtures/failure_hooks/config.js');

View file

@ -17,7 +17,7 @@
* under the License.
*/
import expect from 'expect.js';
import expect from '@kbn/expect';
import { ToolingLog } from '@kbn/dev-utils';
import { readConfigFile } from '../read_config_file';

View file

@ -18,7 +18,7 @@
*/
import { Deprecations } from '../../../deprecation';
import expect from 'expect.js';
import expect from '@kbn/expect';
import index from '../index';
import { noop } from 'lodash';
import sinon from 'sinon';

View file

@ -17,7 +17,7 @@
* under the License.
*/
import expect from 'expect.js';
import expect from '@kbn/expect';
import utils from '../utils';

View file

@ -17,7 +17,7 @@
* under the License.
*/
import expect from 'expect.js';
import expect from '@kbn/expect';
import moment from 'moment';
import fs from 'fs';
import { promisify } from 'bluebird';

View file

@ -19,7 +19,7 @@
/* eslint-env mocha */
import expect from 'expect.js';
import expect from '@kbn/expect';
import sinon from 'sinon';
import fs from 'fs';
import https, { Agent as HttpsAgent } from 'https';

View file

@ -19,7 +19,7 @@
/* eslint-env mocha */
import expect from 'expect.js';
import expect from '@kbn/expect';
import sinon from 'sinon';
import fs from 'fs';
import { Agent as HttpsAgent } from 'https';

View file

@ -19,7 +19,7 @@
import sinon from 'sinon';
import Wreck from 'wreck';
import expect from 'expect.js';
import expect from '@kbn/expect';
import { Server } from 'hapi';
import { createProxyRoute } from '../../';

View file

@ -21,7 +21,7 @@ import { request } from 'http';
import sinon from 'sinon';
import Wreck from 'wreck';
import expect from 'expect.js';
import expect from '@kbn/expect';
import { Server } from 'hapi';
import { createProxyRoute } from '../../';

View file

@ -21,7 +21,7 @@ import { Agent } from 'http';
import sinon from 'sinon';
import Wreck from 'wreck';
import expect from 'expect.js';
import expect from '@kbn/expect';
import { Server } from 'hapi';
import { createProxyRoute } from '../../';

View file

@ -19,7 +19,7 @@
import sinon from 'sinon';
import Wreck from 'wreck';
import expect from 'expect.js';
import expect from '@kbn/expect';
import { Server } from 'hapi';
import { createProxyRoute } from '../../';

View file

@ -17,7 +17,7 @@
* under the License.
*/
import expect from 'expect.js';
import expect from '@kbn/expect';
import { setHeaders } from '../set_headers';
describe('#set_headers', function () {

View file

@ -20,7 +20,7 @@
import _ from 'lodash';
import Promise from 'bluebird';
import sinon from 'sinon';
import expect from 'expect.js';
import expect from '@kbn/expect';
import { esTestConfig } from '@kbn/test';
import { ensureEsVersion } from '../ensure_es_version';

View file

@ -19,7 +19,7 @@
import Promise from 'bluebird';
import sinon from 'sinon';
import expect from 'expect.js';
import expect from '@kbn/expect';
const NoConnections = require('elasticsearch').errors.NoConnections;

View file

@ -17,7 +17,7 @@
* under the License.
*/
import expect from 'expect.js';
import expect from '@kbn/expect';
import isEsCompatibleWithKibana from '../is_es_compatible_with_kibana';

View file

@ -17,7 +17,7 @@
* under the License.
*/
import expect from 'expect.js';
import expect from '@kbn/expect';
import { Control } from './control';
function createControlParams(id, label) {

View file

@ -17,7 +17,7 @@
* under the License.
*/
import expect from 'expect.js';
import expect from '@kbn/expect';
import { FilterManager } from './filter_manager';
describe('FilterManager', function () {

View file

@ -17,7 +17,7 @@
* under the License.
*/
import expect from 'expect.js';
import expect from '@kbn/expect';
import { PhraseFilterManager } from './phrase_filter_manager';
describe('PhraseFilterManager', function () {

View file

@ -17,7 +17,7 @@
* under the License.
*/
import expect from 'expect.js';
import expect from '@kbn/expect';
import { RangeFilterManager } from './range_filter_manager';
describe('RangeFilterManager', function () {

View file

@ -17,7 +17,7 @@
* under the License.
*/
import expect from 'expect.js';
import expect from '@kbn/expect';
import { getLineageMap } from './lineage_map';
import {
CONTROL_TYPES,

Some files were not shown because too many files have changed in this diff Show more