mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
Merge remote-tracking branch 'origin/master' into feature/merge-code
This commit is contained in:
commit
aa8ab4544c
1433 changed files with 10159 additions and 6902 deletions
|
@ -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: [
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
* <<development-dependencies>>
|
||||
* <<development-modules>>
|
||||
* <<development-elasticsearch>>
|
||||
* <<development-unit-tests>>
|
||||
* <<development-functional-tests>>
|
||||
|
||||
include::core/development-basepath.asciidoc[]
|
||||
|
@ -15,4 +16,6 @@ include::core/development-modules.asciidoc[]
|
|||
|
||||
include::core/development-elasticsearch.asciidoc[]
|
||||
|
||||
include::core/development-unit-tests.asciidoc[]
|
||||
|
||||
include::core/development-functional-tests.asciidoc[]
|
||||
|
|
|
@ -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 }) {
|
||||
|
||||
|
|
83
docs/development/core/development-unit-tests.asciidoc
Normal file
83
docs/development/core/development-unit-tests.asciidoc
Normal file
|
@ -0,0 +1,83 @@
|
|||
[[development-unit-tests]]
|
||||
=== Unit Testing
|
||||
|
||||
We use unit tests to make sure that individual software units of {kib} perform as they were designed to.
|
||||
|
||||
[float]
|
||||
=== Current Frameworks
|
||||
|
||||
{kib} is migrating unit testing from `Mocha` to `Jest`. Legacy unit tests still exist in `Mocha` but all new unit tests should be written in `Jest`.
|
||||
|
||||
[float]
|
||||
==== Mocha (legacy)
|
||||
|
||||
Mocha tests are contained in `__tests__` directories.
|
||||
|
||||
*Running Mocha Unit Tests*
|
||||
|
||||
["source","shell"]
|
||||
-----------
|
||||
yarn test:mocha
|
||||
-----------
|
||||
|
||||
[float]
|
||||
==== Jest
|
||||
Jest tests are stored in the same directory as source code files with the `.test.{js,ts,tsx}` suffix.
|
||||
|
||||
*Running Jest Unit Tests*
|
||||
|
||||
["source","shell"]
|
||||
-----------
|
||||
yarn test:jest
|
||||
-----------
|
||||
|
||||
[float]
|
||||
===== Writing Jest Unit Tests
|
||||
|
||||
In order to write those tests there are two main things you need to be aware of.
|
||||
The first one is the different between `jest.mock` and `jest.doMock`
|
||||
and the second one our `jest mocks file pattern`. As we are running `js` and `ts`
|
||||
test files with `babel-jest` both techniques are needed
|
||||
specially for the tests implemented on Typescript in order to benefit from the
|
||||
auto-inference types feature.
|
||||
|
||||
[float]
|
||||
===== Jest.mock vs Jest.doMock
|
||||
|
||||
Both methods are essentially the same on their roots however the `jest.mock`
|
||||
calls will get hoisted to the top of the file and can only reference variables
|
||||
prefixed with `mock`. On the other hand, `jest.doMock` won't be hoisted and can
|
||||
reference pretty much any variable we want, however we have to assure those referenced
|
||||
variables are instantiated at the time we need them which lead us to the next
|
||||
section where we'll talk about our jest mock files pattern.
|
||||
|
||||
[float]
|
||||
===== Jest Mock Files Pattern
|
||||
|
||||
Specially on typescript it is pretty common to have in unit tests
|
||||
`jest.doMock` calls which reference for example imported types. Any error
|
||||
will thrown from doing that however the test will fail. The reason behind that
|
||||
is because despite the `jest.doMock` isn't being hoisted by `babel-jest` the
|
||||
import with the types we are referencing will be hoisted to the top and at the
|
||||
time we'll call the function that variable would not be defined.
|
||||
|
||||
In order to prevent that we develop a protocol that should be followed:
|
||||
|
||||
- Each module could provide a standard mock in `mymodule.mock.ts` in case
|
||||
there are other tests that could benefit from using definitions here.
|
||||
This file would not have any `jest.mock` calls, just dummy objects.
|
||||
|
||||
- Each test defines its mocks in `mymodule.test.mocks.ts`. This file
|
||||
could import relevant mocks from the generalised module's mocks
|
||||
file `(*.mock.ts)` and call `jest.mock` for each of them. If there is
|
||||
any relevant dummy mock objects to generalise (and to be used by
|
||||
other tests), the dummy objects could be defined directly on this file.
|
||||
|
||||
- Each test would import its mocks from the test mocks
|
||||
file mymodule.test.mocks.ts. `mymodule.test.ts` has an import
|
||||
like: `import * as Mocks from './mymodule.test.mocks'`,
|
||||
`import { mockX } from './mymodule.test.mocks'`
|
||||
or just `import './mymodule.test.mocks'` if there isn't anything
|
||||
exported to be used.
|
||||
|
||||
|
|
@ -3,12 +3,16 @@
|
|||
|
||||
This tutorial requires three data sets:
|
||||
|
||||
* The complete works of William Shakespeare, suitably parsed into fields. Download
|
||||
https://download.elastic.co/demos/kibana/gettingstarted/shakespeare_6.0.json[`shakespeare.json`].
|
||||
* A set of fictitious accounts with randomly generated data. Download
|
||||
https://download.elastic.co/demos/kibana/gettingstarted/accounts.zip[`accounts.zip`].
|
||||
* A set of randomly generated log files. Download
|
||||
https://download.elastic.co/demos/kibana/gettingstarted/logs.jsonl.gz[`logs.jsonl.gz`].
|
||||
* The complete works of William Shakespeare, suitably parsed into fields
|
||||
* A set of fictitious accounts with randomly generated data
|
||||
* A set of randomly generated log files
|
||||
|
||||
Create a new working directory where you want to download the files. From that directory, run the following commands:
|
||||
|
||||
[source,shell]
|
||||
curl -O https://download.elastic.co/demos/kibana/gettingstarted/8.x/shakespeare.json
|
||||
curl -O https://download.elastic.co/demos/kibana/gettingstarted/8.x/accounts.zip
|
||||
curl -O https://download.elastic.co/demos/kibana/gettingstarted/8.x/logs.jsonl.gz
|
||||
|
||||
Two of the data sets are compressed. To extract the files, use these commands:
|
||||
|
||||
|
@ -73,16 +77,14 @@ In Kibana *Dev Tools > Console*, set up a mapping for the Shakespeare data set:
|
|||
[source,js]
|
||||
PUT /shakespeare
|
||||
{
|
||||
"mappings": {
|
||||
"doc": {
|
||||
"properties": {
|
||||
"mappings": {
|
||||
"properties": {
|
||||
"speaker": {"type": "keyword"},
|
||||
"play_name": {"type": "keyword"},
|
||||
"line_id": {"type": "integer"},
|
||||
"speech_number": {"type": "integer"}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//CONSOLE
|
||||
|
@ -100,13 +102,11 @@ as geographic locations by applying the `geo_point` type.
|
|||
PUT /logstash-2015.05.18
|
||||
{
|
||||
"mappings": {
|
||||
"log": {
|
||||
"properties": {
|
||||
"geo": {
|
||||
"properties": {
|
||||
"coordinates": {
|
||||
"type": "geo_point"
|
||||
}
|
||||
"properties": {
|
||||
"geo": {
|
||||
"properties": {
|
||||
"coordinates": {
|
||||
"type": "geo_point"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -120,13 +120,11 @@ PUT /logstash-2015.05.18
|
|||
PUT /logstash-2015.05.19
|
||||
{
|
||||
"mappings": {
|
||||
"log": {
|
||||
"properties": {
|
||||
"geo": {
|
||||
"properties": {
|
||||
"coordinates": {
|
||||
"type": "geo_point"
|
||||
}
|
||||
"properties": {
|
||||
"geo": {
|
||||
"properties": {
|
||||
"coordinates": {
|
||||
"type": "geo_point"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -140,13 +138,11 @@ PUT /logstash-2015.05.19
|
|||
PUT /logstash-2015.05.20
|
||||
{
|
||||
"mappings": {
|
||||
"log": {
|
||||
"properties": {
|
||||
"geo": {
|
||||
"properties": {
|
||||
"coordinates": {
|
||||
"type": "geo_point"
|
||||
}
|
||||
"properties": {
|
||||
"geo": {
|
||||
"properties": {
|
||||
"coordinates": {
|
||||
"type": "geo_point"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -165,13 +161,13 @@ API to load the data sets:
|
|||
|
||||
[source,shell]
|
||||
curl -H 'Content-Type: application/x-ndjson' -XPOST 'localhost:9200/bank/account/_bulk?pretty' --data-binary @accounts.json
|
||||
curl -H 'Content-Type: application/x-ndjson' -XPOST 'localhost:9200/shakespeare/doc/_bulk?pretty' --data-binary @shakespeare_6.0.json
|
||||
curl -H 'Content-Type: application/x-ndjson' -XPOST 'localhost:9200/shakespeare/_bulk?pretty' --data-binary @shakespeare.json
|
||||
curl -H 'Content-Type: application/x-ndjson' -XPOST 'localhost:9200/_bulk?pretty' --data-binary @logs.jsonl
|
||||
|
||||
Or for Windows users, in Powershell:
|
||||
[source,shell]
|
||||
Invoke-RestMethod "http://localhost:9200/bank/account/_bulk?pretty" -Method Post -ContentType 'application/x-ndjson' -InFile "accounts.json"
|
||||
Invoke-RestMethod "http://localhost:9200/shakespeare/doc/_bulk?pretty" -Method Post -ContentType 'application/x-ndjson' -InFile "shakespeare_6.0.json"
|
||||
Invoke-RestMethod "http://localhost:9200/shakespeare/_bulk?pretty" -Method Post -ContentType 'application/x-ndjson' -InFile "shakespeare.json"
|
||||
Invoke-RestMethod "http://localhost:9200/_bulk?pretty" -Method Post -ContentType 'application/x-ndjson' -InFile "logs.jsonl"
|
||||
|
||||
These commands might take some time to execute, depending on the available computing resources.
|
||||
|
@ -187,8 +183,8 @@ Your output should look similar to this:
|
|||
|
||||
[source,shell]
|
||||
health status index pri rep docs.count docs.deleted store.size pri.store.size
|
||||
yellow open bank 5 1 1000 0 418.2kb 418.2kb
|
||||
yellow open shakespeare 5 1 111396 0 17.6mb 17.6mb
|
||||
yellow open logstash-2015.05.18 5 1 4631 0 15.6mb 15.6mb
|
||||
yellow open logstash-2015.05.19 5 1 4624 0 15.7mb 15.7mb
|
||||
yellow open logstash-2015.05.20 5 1 4750 0 16.4mb 16.4mb
|
||||
yellow open bank 1 1 1000 0 418.2kb 418.2kb
|
||||
yellow open shakespeare 1 1 111396 0 17.6mb 17.6mb
|
||||
yellow open logstash-2015.05.18 1 1 4631 0 15.6mb 15.6mb
|
||||
yellow open logstash-2015.05.19 1 1 4624 0 15.7mb 15.7mb
|
||||
yellow open logstash-2015.05.20 1 1 4750 0 16.4mb 16.4mb
|
||||
|
|
45
package.json
45
package.json
|
@ -90,11 +90,13 @@
|
|||
"**/@types/*/**",
|
||||
"**/grunt-*",
|
||||
"**/grunt-*/**",
|
||||
"x-pack/typescript",
|
||||
"kbn_tp_*/**"
|
||||
"x-pack/typescript"
|
||||
]
|
||||
},
|
||||
"dependencies": {
|
||||
"@babel/core": "^7.3.4",
|
||||
"@babel/polyfill": "^7.2.5",
|
||||
"@babel/register": "^7.0.0",
|
||||
"@elastic/datemath": "5.0.2",
|
||||
"@elastic/eui": "9.5.0",
|
||||
"@elastic/filesaver": "1.1.2",
|
||||
|
@ -124,10 +126,7 @@
|
|||
"angular-sanitize": "1.6.5",
|
||||
"angular-sortable-view": "0.0.15",
|
||||
"autoprefixer": "^9.1.0",
|
||||
"babel-core": "6.26.3",
|
||||
"babel-loader": "7.1.5",
|
||||
"babel-polyfill": "6.26.0",
|
||||
"babel-register": "6.26.0",
|
||||
"babel-loader": "8.0.5",
|
||||
"bluebird": "3.5.3",
|
||||
"boom": "^7.2.0",
|
||||
"brace": "0.11.1",
|
||||
|
@ -259,12 +258,13 @@
|
|||
"@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",
|
||||
"@types/angular": "1.6.50",
|
||||
"@types/angular-mocks": "^1.7.0",
|
||||
"@types/babel-core": "^6.25.5",
|
||||
"@types/babel__core": "^7.1.0",
|
||||
"@types/bluebird": "^3.1.1",
|
||||
"@types/boom": "^7.2.0",
|
||||
"@types/chance": "^1.0.0",
|
||||
|
@ -277,7 +277,7 @@
|
|||
"@types/delete-empty": "^2.0.0",
|
||||
"@types/elasticsearch": "^5.0.30",
|
||||
"@types/enzyme": "^3.1.12",
|
||||
"@types/eslint": "^4.16.2",
|
||||
"@types/eslint": "^4.16.6",
|
||||
"@types/execa": "^0.9.0",
|
||||
"@types/fetch-mock": "7.2.1",
|
||||
"@types/getopts": "^2.0.0",
|
||||
|
@ -322,8 +322,8 @@
|
|||
"@types/zen-observable": "^0.8.0",
|
||||
"angular-mocks": "1.4.7",
|
||||
"archiver": "^3.0.0",
|
||||
"babel-eslint": "^9.0.0",
|
||||
"babel-jest": "^23.6.0",
|
||||
"babel-eslint": "^10.0.1",
|
||||
"babel-jest": "^24.1.0",
|
||||
"backport": "4.4.1",
|
||||
"chai": "3.5.0",
|
||||
"chance": "1.0.10",
|
||||
|
@ -337,18 +337,18 @@
|
|||
"enzyme-adapter-react-16": "^1.9.0",
|
||||
"enzyme-adapter-utils": "^1.10.0",
|
||||
"enzyme-to-json": "^3.3.4",
|
||||
"eslint": "^5.6.0",
|
||||
"eslint-config-prettier": "^3.1.0",
|
||||
"eslint-plugin-babel": "^5.2.0",
|
||||
"eslint-plugin-import": "^2.14.0",
|
||||
"eslint-plugin-jest": "^21.26.2",
|
||||
"eslint-plugin-jsx-a11y": "^6.1.2",
|
||||
"eslint-plugin-mocha": "^5.2.0",
|
||||
"eslint": "^5.15.1",
|
||||
"eslint-config-prettier": "^4.1.0",
|
||||
"eslint-plugin-babel": "^5.3.0",
|
||||
"eslint-plugin-import": "^2.16.0",
|
||||
"eslint-plugin-jest": "^22.3.0",
|
||||
"eslint-plugin-jsx-a11y": "^6.2.1",
|
||||
"eslint-plugin-mocha": "^5.3.0",
|
||||
"eslint-plugin-no-unsanitized": "^3.0.2",
|
||||
"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",
|
||||
"eslint-plugin-prettier": "^3.0.1",
|
||||
"eslint-plugin-react": "^7.12.4",
|
||||
"eslint-plugin-react-hooks": "^1.6.0",
|
||||
"faker": "1.1.0",
|
||||
"fetch-mock": "7.3.0",
|
||||
"geckodriver": "1.12.2",
|
||||
|
@ -359,7 +359,7 @@
|
|||
"grunt-karma": "2.0.0",
|
||||
"grunt-peg": "^2.0.1",
|
||||
"grunt-run": "0.7.0",
|
||||
"gulp-babel": "^7.0.1",
|
||||
"gulp-babel": "^8.0.0",
|
||||
"gulp-sourcemaps": "2.6.4",
|
||||
"has-ansi": "^3.0.0",
|
||||
"image-diff": "1.6.0",
|
||||
|
@ -405,9 +405,6 @@
|
|||
"supertest": "^3.1.0",
|
||||
"supertest-as-promised": "^4.0.2",
|
||||
"tree-kill": "^1.1.0",
|
||||
"ts-jest": "^23.1.4",
|
||||
"ts-loader": "^5.2.2",
|
||||
"ts-node": "^7.0.1",
|
||||
"tslint": "^5.11.0",
|
||||
"tslint-config-prettier": "^1.15.0",
|
||||
"tslint-microsoft-contrib": "^6.0.0",
|
||||
|
|
|
@ -1,13 +1,16 @@
|
|||
{
|
||||
"presets": [["env", {
|
||||
"targets": {
|
||||
"node": "current",
|
||||
"browsers": [
|
||||
"last 2 versions",
|
||||
"> 5%",
|
||||
"Safari 7",
|
||||
]
|
||||
"presets": [
|
||||
["@babel/preset-env", {
|
||||
"targets": {
|
||||
"node": "current",
|
||||
"browsers": [
|
||||
"last 2 versions",
|
||||
"> 5%",
|
||||
"Safari 7"
|
||||
]
|
||||
}
|
||||
}
|
||||
}]],
|
||||
]
|
||||
],
|
||||
"plugins": ["add-module-exports"]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,9 +11,9 @@
|
|||
"kbn:watch": "yarn build --watch"
|
||||
},
|
||||
"devDependencies": {
|
||||
"babel-cli": "^6.26.0",
|
||||
"babel-plugin-add-module-exports": "^0.2.1",
|
||||
"babel-preset-env": "^1.7.0",
|
||||
"@babel/cli": "^7.2.3",
|
||||
"@babel/preset-env": "^7.3.4",
|
||||
"babel-plugin-add-module-exports": "^1.0.0",
|
||||
"moment": "^2.13.0"
|
||||
},
|
||||
"dependencies": {
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -10,6 +10,7 @@ module.exports = {
|
|||
'mocha',
|
||||
'babel',
|
||||
'react',
|
||||
'react-hooks',
|
||||
'import',
|
||||
'no-unsanitized',
|
||||
'prefer-object-spread',
|
||||
|
@ -127,6 +128,8 @@ module.exports = {
|
|||
arrow: true,
|
||||
}],
|
||||
'react/jsx-first-prop-new-line': ['error', 'multiline-multiprop'],
|
||||
'react-hooks/rules-of-hooks': 'error', // Checks rules of Hooks
|
||||
'react-hooks/exhaustive-deps': 'warn', // Checks effect dependencies
|
||||
'jsx-a11y/accessible-emoji': 'error',
|
||||
'jsx-a11y/alt-text': 'error',
|
||||
'jsx-a11y/anchor-has-content': 'error',
|
||||
|
|
|
@ -15,15 +15,16 @@
|
|||
},
|
||||
"homepage": "https://github.com/elastic/eslint-config-kibana#readme",
|
||||
"peerDependencies": {
|
||||
"babel-eslint": "^9.0.0",
|
||||
"eslint": "^5.6.0",
|
||||
"eslint-plugin-babel": "^5.2.0",
|
||||
"eslint-plugin-jsx-a11y": "^6.1.2",
|
||||
"eslint-plugin-import": "^2.14.0",
|
||||
"eslint-plugin-jest": "^21.22.1",
|
||||
"eslint-plugin-mocha": "^5.2.0",
|
||||
"babel-eslint": "^10.0.1",
|
||||
"eslint": "^5.14.1",
|
||||
"eslint-plugin-babel": "^5.3.0",
|
||||
"eslint-plugin-jsx-a11y": "^6.2.1",
|
||||
"eslint-plugin-import": "^2.16.0",
|
||||
"eslint-plugin-jest": "^22.3.0",
|
||||
"eslint-plugin-mocha": "^5.3.0",
|
||||
"eslint-plugin-no-unsanitized": "^3.0.2",
|
||||
"eslint-plugin-prefer-object-spread": "^1.2.1",
|
||||
"eslint-plugin-react": "^7.11.1"
|
||||
"eslint-plugin-react": "^7.12.4",
|
||||
"eslint-plugin-react-hooks": "^1.6.0"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
"kbn:watch": "yarn build --watch"
|
||||
},
|
||||
"devDependencies": {
|
||||
"babel-cli": "^6.26.0"
|
||||
"@babel/cli": "^7.2.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"@kbn/babel-preset": "1.0.0",
|
||||
|
|
|
@ -19,20 +19,33 @@
|
|||
|
||||
module.exports = {
|
||||
presets: [
|
||||
require.resolve('babel-preset-react'),
|
||||
require.resolve('@babel/preset-typescript'),
|
||||
require.resolve('@babel/preset-react')
|
||||
],
|
||||
plugins: [
|
||||
require.resolve('babel-plugin-add-module-exports'),
|
||||
// stage 3
|
||||
require.resolve('babel-plugin-transform-async-generator-functions'),
|
||||
require.resolve('babel-plugin-transform-object-rest-spread'),
|
||||
|
||||
// the class properties proposal was merged with the private fields proposal
|
||||
// The class properties proposal was merged with the private fields proposal
|
||||
// into the "class fields" proposal. Babel doesn't support this combined
|
||||
// proposal yet, which includes private field, so this transform is
|
||||
// TECHNICALLY stage 2, but for all intents and purposes it's stage 3
|
||||
//
|
||||
// See https://github.com/babel/proposals/issues/12 for progress
|
||||
require.resolve('babel-plugin-transform-class-properties'),
|
||||
require.resolve('@babel/plugin-proposal-class-properties'),
|
||||
],
|
||||
overrides: [
|
||||
{
|
||||
// Babel 7 don't support the namespace feature on typescript code.
|
||||
// With namespaces only used for type declarations, we can securely
|
||||
// strip them off for babel on x-pack infra plugin
|
||||
//
|
||||
// See https://github.com/babel/babel/issues/8244#issuecomment-466548733
|
||||
test: /x-pack[\/\\]plugins[\/\\]infra[\/\\].*[\/\\]graphql/,
|
||||
plugins: [
|
||||
[
|
||||
require.resolve('babel-plugin-typescript-strip-namespaces'),
|
||||
],
|
||||
]
|
||||
}
|
||||
]
|
||||
};
|
||||
|
|
|
@ -1,39 +0,0 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
presets: [
|
||||
require.resolve('@babel/preset-react'),
|
||||
require.resolve('@babel/preset-typescript'),
|
||||
],
|
||||
plugins: [
|
||||
require.resolve('babel7-plugin-add-module-exports'),
|
||||
// stage 3
|
||||
require.resolve('@babel/plugin-proposal-async-generator-functions'),
|
||||
require.resolve('@babel/plugin-proposal-object-rest-spread'),
|
||||
|
||||
// the class properties proposal was merged with the private fields proposal
|
||||
// into the "class fields" proposal. Babel doesn't support this combined
|
||||
// proposal yet, which includes private field, so this transform is
|
||||
// TECHNICALLY stage 2, but for all intents and purposes it's stage 3
|
||||
//
|
||||
// See https://github.com/babel/proposals/issues/12 for progress
|
||||
require.resolve('@babel/plugin-proposal-class-properties'),
|
||||
],
|
||||
};
|
|
@ -17,34 +17,37 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
presets: [
|
||||
[
|
||||
require.resolve('babel-preset-env'),
|
||||
{
|
||||
targets: {
|
||||
// only applies the necessary transformations based on the
|
||||
// current node.js processes version. For example: running
|
||||
// `nvm install 8 && node ./src/cli` will run kibana in node
|
||||
// version 8 and babel will stop transpiling async/await
|
||||
// because they are supported in the "current" version of node
|
||||
node: 'current',
|
||||
},
|
||||
module.exports = () => {
|
||||
return {
|
||||
presets: [
|
||||
[
|
||||
require.resolve('@babel/preset-env'),
|
||||
{
|
||||
targets: {
|
||||
// only applies the necessary transformations based on the
|
||||
// current node.js processes version. For example: running
|
||||
// `nvm install 8 && node ./src/cli` will run kibana in node
|
||||
// version 8 and babel will stop transpiling async/await
|
||||
// because they are supported in the "current" version of node
|
||||
node: 'current',
|
||||
},
|
||||
|
||||
// replaces `import "babel-polyfill"` with a list of require statements
|
||||
// for just the polyfills that the target versions don't already supply
|
||||
// on their own
|
||||
useBuiltIns: true,
|
||||
},
|
||||
// replaces `import "@babel/polyfill"` with a list of require statements
|
||||
// for just the polyfills that the target versions don't already supply
|
||||
// on their own
|
||||
useBuiltIns: 'entry',
|
||||
modules: 'cjs'
|
||||
},
|
||||
],
|
||||
require('./common_preset'),
|
||||
],
|
||||
require('./common_preset'),
|
||||
],
|
||||
plugins: [
|
||||
[
|
||||
require.resolve('babel-plugin-transform-define'),
|
||||
{
|
||||
'global.__BUILT_WITH_BABEL__': 'true'
|
||||
}
|
||||
plugins: [
|
||||
[
|
||||
require.resolve('babel-plugin-transform-define'),
|
||||
{
|
||||
'global.__BUILT_WITH_BABEL__': 'true'
|
||||
}
|
||||
]
|
||||
]
|
||||
]
|
||||
};
|
||||
};
|
||||
|
|
|
@ -1,50 +0,0 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
module.exports = () => ({
|
||||
presets: [
|
||||
[
|
||||
require.resolve('@babel/preset-env'),
|
||||
{
|
||||
targets: {
|
||||
// only applies the necessary transformations based on the
|
||||
// current node.js processes version. For example: running
|
||||
// `nvm install 8 && node ./src/cli` will run kibana in node
|
||||
// version 8 and babel will stop transpiling async/await
|
||||
// because they are supported in the "current" version of node
|
||||
node: 'current',
|
||||
},
|
||||
|
||||
// replaces `import "babel-polyfill"` with a list of require statements
|
||||
// for just the polyfills that the target versions don't already supply
|
||||
// on their own
|
||||
useBuiltIns: 'entry',
|
||||
},
|
||||
],
|
||||
require('./common_preset_7'),
|
||||
],
|
||||
plugins: [
|
||||
[
|
||||
require.resolve('babel-plugin-transform-define'),
|
||||
{
|
||||
'global.__BUILT_WITH_BABEL__': 'true'
|
||||
}
|
||||
]
|
||||
]
|
||||
});
|
|
@ -4,20 +4,12 @@
|
|||
"version": "1.0.0",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@babel/core": "^7.3.4",
|
||||
"@babel/plugin-proposal-async-generator-functions": "^7.2.0",
|
||||
"@babel/plugin-proposal-class-properties": "^7.3.4",
|
||||
"@babel/plugin-proposal-object-rest-spread": "^7.3.4",
|
||||
"@babel/preset-react":"^7.0.0",
|
||||
"@babel/preset-env": "^7.3.4",
|
||||
"@babel/preset-react": "^7.0.0",
|
||||
"@babel/preset-typescript": "^7.3.3",
|
||||
"babel-plugin-add-module-exports": "^0.2.1",
|
||||
"babel-plugin-transform-async-generator-functions": "^6.24.1",
|
||||
"babel-plugin-transform-class-properties": "^6.24.1",
|
||||
"babel-plugin-add-module-exports": "^1.0.0",
|
||||
"babel-plugin-transform-define": "^1.3.1",
|
||||
"babel-plugin-transform-object-rest-spread": "^6.26.0",
|
||||
"babel-preset-env": "^1.7.0",
|
||||
"babel-preset-react": "^6.24.1",
|
||||
"babel7-plugin-add-module-exports": "npm:babel-plugin-add-module-exports@^1.0.0"
|
||||
"babel-plugin-typescript-strip-namespaces": "^1.1.1"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,21 +17,24 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
presets: [
|
||||
[
|
||||
require.resolve('babel-preset-env'),
|
||||
{
|
||||
targets: {
|
||||
browsers: [
|
||||
'last 2 versions',
|
||||
'> 5%',
|
||||
'Safari 7', // for PhantomJS support: https://github.com/elastic/kibana/issues/27136
|
||||
],
|
||||
module.exports = () => {
|
||||
return {
|
||||
presets: [
|
||||
[
|
||||
require.resolve('@babel/preset-env'),
|
||||
{
|
||||
targets: {
|
||||
browsers: [
|
||||
'last 2 versions',
|
||||
'> 5%',
|
||||
'Safari 7', // for PhantomJS support: https://github.com/elastic/kibana/issues/27136
|
||||
],
|
||||
},
|
||||
useBuiltIns: 'entry',
|
||||
modules: 'cjs'
|
||||
},
|
||||
useBuiltIns: true,
|
||||
},
|
||||
],
|
||||
require('./common_preset'),
|
||||
]
|
||||
],
|
||||
require('./common_preset'),
|
||||
]
|
||||
};
|
||||
};
|
||||
|
|
|
@ -19,9 +19,9 @@
|
|||
"tslib": "^1.9.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/cli": "^7.2.3",
|
||||
"@kbn/babel-preset": "1.0.0",
|
||||
"babel-cli": "^6.26.0",
|
||||
"chance": "1.0.6",
|
||||
"expect.js": "0.3.1"
|
||||
"@kbn/expect": "1.0.0",
|
||||
"chance": "1.0.6"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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';
|
||||
|
||||
|
|
|
@ -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';
|
||||
|
|
|
@ -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 () {
|
||||
|
|
|
@ -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 () {
|
||||
|
|
|
@ -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 () {
|
||||
|
|
|
@ -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 () {
|
||||
|
|
|
@ -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';
|
||||
|
|
|
@ -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 () {
|
||||
|
||||
|
|
|
@ -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';
|
||||
|
|
|
@ -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';
|
||||
|
||||
|
|
|
@ -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';
|
||||
|
|
|
@ -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';
|
||||
|
||||
|
|
|
@ -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 () {
|
||||
|
|
|
@ -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 () {
|
||||
|
|
|
@ -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 () {
|
||||
|
|
|
@ -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 () {
|
||||
|
|
|
@ -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 () {
|
||||
|
|
|
@ -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 () {
|
||||
|
|
|
@ -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';
|
||||
|
|
|
@ -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';
|
||||
|
|
|
@ -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';
|
||||
|
|
|
@ -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';
|
||||
|
|
|
@ -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';
|
||||
|
|
|
@ -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';
|
||||
|
|
|
@ -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';
|
||||
|
|
|
@ -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';
|
||||
|
|
|
@ -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 '../../..';
|
||||
|
|
|
@ -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';
|
||||
|
||||
|
|
|
@ -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 () {
|
||||
|
|
|
@ -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';
|
||||
|
||||
|
|
|
@ -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 () {
|
||||
|
|
|
@ -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'),
|
||||
},
|
||||
};
|
||||
|
|
|
@ -4,8 +4,8 @@
|
|||
"private": true,
|
||||
"license": "Apache-2.0",
|
||||
"peerDependencies": {
|
||||
"eslint": "^5.6.0",
|
||||
"babel-eslint": "^9.0.0"
|
||||
"eslint": "^5.14.1",
|
||||
"babel-eslint": "^10.0.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"dedent": "^0.7.0"
|
||||
|
|
82
packages/kbn-eslint-plugin-eslint/rules/module_migration.js
Normal file
82
packages/kbn-eslint-plugin-eslint/rules/module_migration.js
Normal 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]);
|
||||
}
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
22
packages/kbn-expect/LICENSE.txt
Normal file
22
packages/kbn-expect/LICENSE.txt
Normal 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.
|
191
packages/kbn-expect/README.md
Normal file
191
packages/kbn-expect/README.md
Normal 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.
|
971
packages/kbn-expect/expect.js
Normal file
971
packages/kbn-expect/expect.js
Normal 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
221
packages/kbn-expect/expect.js.d.ts
vendored
Normal 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;
|
||||
}
|
7
packages/kbn-expect/package.json
Normal file
7
packages/kbn-expect/package.json
Normal file
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"name": "@kbn/expect",
|
||||
"main": "./expect.js",
|
||||
"version": "1.0.0",
|
||||
"license": "MIT",
|
||||
"private": true
|
||||
}
|
6
packages/kbn-expect/tsconfig.json
Normal file
6
packages/kbn-expect/tsconfig.json
Normal file
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"extends": "../../tsconfig.json",
|
||||
"include": [
|
||||
"expect.js.d.ts"
|
||||
]
|
||||
}
|
|
@ -1,20 +1,20 @@
|
|||
{
|
||||
"extends": "../../tsconfig.json",
|
||||
"include": [
|
||||
"src/**/*.ts",
|
||||
"src/**/*.tsx",
|
||||
"types/intl_format_cache.d.ts",
|
||||
"types/intl_relativeformat.d.ts"
|
||||
],
|
||||
"exclude": [
|
||||
"target"
|
||||
],
|
||||
"compilerOptions": {
|
||||
"declaration": true,
|
||||
"declarationDir": "./target/types",
|
||||
"types": [
|
||||
"jest",
|
||||
"node"
|
||||
]
|
||||
}
|
||||
}
|
||||
{
|
||||
"extends": "../../tsconfig.json",
|
||||
"include": [
|
||||
"src/**/*.ts",
|
||||
"src/**/*.tsx",
|
||||
"types/intl_format_cache.d.ts",
|
||||
"types/intl_relativeformat.d.ts"
|
||||
],
|
||||
"exclude": [
|
||||
"target"
|
||||
],
|
||||
"compilerOptions": {
|
||||
"declaration": true,
|
||||
"declarationDir": "./target/types",
|
||||
"types": [
|
||||
"jest",
|
||||
"node"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
{
|
||||
"presets": ["@kbn/babel-preset/webpack_preset"],
|
||||
"plugins": [
|
||||
["babel-plugin-transform-runtime", {
|
||||
"polyfill": false,
|
||||
["@babel/plugin-transform-runtime", {
|
||||
"regenerator": true
|
||||
}]
|
||||
]
|
||||
|
|
|
@ -9,19 +9,20 @@
|
|||
"kbn:watch": "node scripts/build --dev --watch"
|
||||
},
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.3.4",
|
||||
"@kbn/i18n": "1.0.0",
|
||||
"lodash": "npm:@elastic/lodash@3.10.1-kibana1",
|
||||
"lodash.clone": "^4.5.0",
|
||||
"uuid": "3.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/cli": "^7.2.3",
|
||||
"@babel/core": "7.3.4",
|
||||
"@babel/plugin-transform-runtime": "^7.3.4",
|
||||
"@babel/polyfill": "7.2.5",
|
||||
"@kbn/babel-preset": "1.0.0",
|
||||
"@kbn/dev-utils": "1.0.0",
|
||||
"babel-cli": "^6.26.0",
|
||||
"babel-core": "6.26.3",
|
||||
"babel-loader": "7.1.5",
|
||||
"babel-plugin-transform-runtime": "^6.23.0",
|
||||
"babel-polyfill": "6.20.0",
|
||||
"babel-loader": "8.0.5",
|
||||
"copy-webpack-plugin": "^4.6.0",
|
||||
"css-loader": "1.0.0",
|
||||
"del": "^3.0.0",
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
|
||||
const { extname } = require('path');
|
||||
|
||||
const { transform } = require('babel-core');
|
||||
const { transform } = require('@babel/core');
|
||||
|
||||
exports.createServerCodeTransformer = (sourceMaps) => {
|
||||
return (content, path) => {
|
||||
|
|
|
@ -28,15 +28,14 @@ describe('js support', () => {
|
|||
it('transpiles js file', () => {
|
||||
const transformer = createServerCodeTransformer();
|
||||
expect(transformer(JS_FIXTURE, JS_FIXTURE_PATH)).toMatchInlineSnapshot(`
|
||||
"'use strict';
|
||||
"\\"use strict\\";
|
||||
|
||||
var _util = require('util');
|
||||
|
||||
var _util2 = _interopRequireDefault(_util);
|
||||
var _util = _interopRequireDefault(require(\\"util\\"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
console.log(_util2.default.format('hello world')); /* eslint-disable */"
|
||||
/* eslint-disable */
|
||||
console.log(_util.default.format('hello world'));"
|
||||
`);
|
||||
});
|
||||
|
||||
|
|
|
@ -8,9 +8,9 @@
|
|||
"templateVersion": "<%= templateVersion %>"
|
||||
},
|
||||
"scripts": {
|
||||
"preinstall": "node ../../kibana/preinstall_check",
|
||||
"kbn": "node ../../kibana/scripts/kbn",
|
||||
"es": "node ../../kibana/scripts/es",
|
||||
"preinstall": "node ../../preinstall_check",
|
||||
"kbn": "node ../../scripts/kbn",
|
||||
"es": "node ../../scripts/es",
|
||||
"lint": "eslint .",
|
||||
"start": "plugin-helpers start",
|
||||
"test:server": "plugin-helpers test:server",
|
||||
|
@ -19,23 +19,23 @@
|
|||
},
|
||||
<%_ if (generateTranslations) { _%>
|
||||
"dependencies": {
|
||||
"@kbn/i18n": "link:../../kibana/packages/kbn-i18n"
|
||||
"@kbn/i18n": "link:../../packages/kbn-i18n"
|
||||
},
|
||||
<%_ } _%>
|
||||
"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/plugin-helpers": "link:../../kibana/packages/kbn-plugin-helpers",
|
||||
"babel-eslint": "^9.0.0",
|
||||
"eslint": "^5.6.0",
|
||||
"eslint-plugin-babel": "^5.2.0",
|
||||
"eslint-plugin-import": "^2.14.0",
|
||||
"eslint-plugin-jest": "^21.26.2",
|
||||
"eslint-plugin-jsx-a11y": "^6.1.2",
|
||||
"eslint-plugin-mocha": "^5.2.0",
|
||||
"@elastic/eslint-config-kibana": "link:../../packages/eslint-config-kibana",
|
||||
"@elastic/eslint-import-resolver-kibana": "link:../../packages/kbn-eslint-import-resolver-kibana",
|
||||
"@kbn/expect": "1.0.0",
|
||||
"@kbn/plugin-helpers": "link:../../packages/kbn-plugin-helpers",
|
||||
"babel-eslint": "^10.0.1",
|
||||
"eslint": "^5.14.1",
|
||||
"eslint-plugin-babel": "^5.3.0",
|
||||
"eslint-plugin-import": "^2.16.0",
|
||||
"eslint-plugin-jest": "^22.3.0",
|
||||
"eslint-plugin-jsx-a11y": "^6.2.1",
|
||||
"eslint-plugin-mocha": "^5.3.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.12.4"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import expect from 'expect.js';
|
||||
import expect from '@kbn/expect';
|
||||
|
||||
describe('suite', () => {
|
||||
it('is a test', () => {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import expect from 'expect.js';
|
||||
import expect from '@kbn/expect';
|
||||
|
||||
describe('suite', () => {
|
||||
it('is a test', () => {
|
||||
|
|
|
@ -25,7 +25,7 @@ function babelRegister() {
|
|||
const plugin = pluginConfig();
|
||||
|
||||
try {
|
||||
// add support for moved babel-register source: https://github.com/elastic/kibana/pull/13973
|
||||
// add support for moved @babel/register source: https://github.com/elastic/kibana/pull/13973
|
||||
require(resolve(plugin.kibanaRoot, 'src/setup_node_env/babel_register')); // eslint-disable-line import/no-dynamic-require
|
||||
} catch (error) {
|
||||
if (error.code === 'MODULE_NOT_FOUND') {
|
||||
|
|
|
@ -1,10 +1,14 @@
|
|||
{
|
||||
"presets": [
|
||||
"stage-3",
|
||||
["env", {
|
||||
"@babel/typescript",
|
||||
["@babel/preset-env", {
|
||||
"targets": {
|
||||
"node": "current"
|
||||
}
|
||||
}]
|
||||
],
|
||||
"plugins": [
|
||||
"@babel/proposal-class-properties",
|
||||
"@babel/proposal-object-rest-spread"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
3584
packages/kbn-pm/dist/index.js
vendored
3584
packages/kbn-pm/dist/index.js
vendored
File diff suppressed because it is too large
Load diff
|
@ -10,6 +10,11 @@
|
|||
"prettier": "prettier --write './src/**/*.ts'"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.3.4",
|
||||
"@babel/plugin-proposal-class-properties": "^7.3.4",
|
||||
"@babel/plugin-proposal-object-rest-spread": "^7.3.4",
|
||||
"@babel/preset-env": "^7.3.4",
|
||||
"@babel/preset-typescript": "^7.3.3",
|
||||
"@types/cmd-shim": "^2.0.0",
|
||||
"@types/cpy": "^5.1.0",
|
||||
"@types/dedent": "^0.7.0",
|
||||
|
@ -32,10 +37,7 @@
|
|||
"@types/tempy": "^0.1.0",
|
||||
"@types/wrap-ansi": "^2.0.14",
|
||||
"@types/write-pkg": "^3.1.0",
|
||||
"babel-core": "^6.26.3",
|
||||
"babel-loader": "^7.1.5",
|
||||
"babel-preset-env": "^1.7.0",
|
||||
"babel-preset-stage-3": "^6.24.1",
|
||||
"babel-loader": "^8.0.5",
|
||||
"chalk": "^2.4.1",
|
||||
"cmd-shim": "^2.0.2",
|
||||
"cpy": "^7.0.1",
|
||||
|
@ -60,7 +62,6 @@
|
|||
"strip-ansi": "^4.0.0",
|
||||
"strong-log-transformer": "^2.1.0",
|
||||
"tempy": "^0.2.1",
|
||||
"ts-loader": "^5.2.2",
|
||||
"typescript": "^3.3.3333",
|
||||
"unlazy-loader": "^0.1.3",
|
||||
"webpack": "^4.23.1",
|
||||
|
|
|
@ -4,10 +4,11 @@
|
|||
"private": true,
|
||||
"main": "./target/index.js",
|
||||
"devDependencies": {
|
||||
"babel-cli": "^6.26.0",
|
||||
"babel-preset-env": "^1.6.1"
|
||||
"@babel/cli": "^7.2.3",
|
||||
"@babel/core": "^7.3.4",
|
||||
"@babel/preset-env": "^7.3.4"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "babel --presets env --out-dir target src"
|
||||
"build": "babel --presets=@babel/preset-env --out-dir target src"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,11 +7,12 @@
|
|||
"@elastic/bar": "link:../bar"
|
||||
},
|
||||
"devDependencies": {
|
||||
"babel-cli": "^6.26.0",
|
||||
"babel-preset-env": "^1.6.1",
|
||||
"@babel/core": "^7.3.4",
|
||||
"@babel/cli": "^7.2.3",
|
||||
"@babel/preset-env": "^7.3.4",
|
||||
"moment": "2.20.1"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "babel --presets env --out-dir target src"
|
||||
"build": "babel --presets=@babel/preset-env --out-dir target src"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,14 +20,15 @@ Array [
|
|||
exports[`kbn-pm production builds and copies projects for production: packages/bar/package.json 1`] = `
|
||||
Object {
|
||||
"devDependencies": Object {
|
||||
"babel-cli": "^6.26.0",
|
||||
"babel-preset-env": "^1.6.1",
|
||||
"@babel/cli": "^7.2.3",
|
||||
"@babel/core": "^7.3.4",
|
||||
"@babel/preset-env": "^7.3.4",
|
||||
},
|
||||
"main": "./target/index.js",
|
||||
"name": "@elastic/bar",
|
||||
"private": true,
|
||||
"scripts": Object {
|
||||
"build": "babel --presets env --out-dir target src",
|
||||
"build": "babel --presets=@babel/preset-env --out-dir target src",
|
||||
},
|
||||
"version": "1.0.0",
|
||||
}
|
||||
|
@ -47,15 +48,16 @@ Object {
|
|||
"@elastic/bar": "link:../bar",
|
||||
},
|
||||
"devDependencies": Object {
|
||||
"babel-cli": "^6.26.0",
|
||||
"babel-preset-env": "^1.6.1",
|
||||
"@babel/cli": "^7.2.3",
|
||||
"@babel/core": "^7.3.4",
|
||||
"@babel/preset-env": "^7.3.4",
|
||||
"moment": "2.20.1",
|
||||
},
|
||||
"main": "./target/index.js",
|
||||
"name": "@elastic/foo",
|
||||
"private": true,
|
||||
"scripts": Object {
|
||||
"build": "babel --presets env --out-dir target src",
|
||||
"build": "babel --presets=@babel/preset-env --out-dir target src",
|
||||
},
|
||||
"version": "1.0.0",
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
"dist"
|
||||
],
|
||||
"include": [
|
||||
"./src/**/*.ts"
|
||||
"./src/**/*.ts",
|
||||
],
|
||||
"compilerOptions": {
|
||||
"types": [
|
||||
|
|
|
@ -44,15 +44,6 @@ module.exports = {
|
|||
{
|
||||
loader: 'babel-loader',
|
||||
},
|
||||
{
|
||||
loader: 'ts-loader',
|
||||
options: {
|
||||
compilerOptions: {
|
||||
// enable esnext modules so webpack can do its thing better
|
||||
module: 'esnext',
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
exclude: /node_modules/,
|
||||
},
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -18,6 +18,6 @@
|
|||
*/
|
||||
|
||||
module.exports = {
|
||||
presets: ['@kbn/babel-preset/node_preset_7'],
|
||||
presets: ['@kbn/babel-preset/node_preset'],
|
||||
ignore: ['**/*.test.js'],
|
||||
};
|
||||
|
|
|
@ -10,9 +10,9 @@
|
|||
"kbn:watch": "yarn build --watch"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/cli": "^7.2.3",
|
||||
"@kbn/babel-preset": "1.0.0",
|
||||
"@kbn/dev-utils": "1.0.0",
|
||||
"@babel/cli": "^7.2.3"
|
||||
"@kbn/dev-utils": "1.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"chalk": "^2.4.1",
|
||||
|
|
|
@ -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.
|
225
packages/kbn-test/types/expect.js.d.ts
vendored
225
packages/kbn-test/types/expect.js.d.ts
vendored
|
@ -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;
|
||||
}
|
|
@ -19,7 +19,7 @@
|
|||
|
||||
require('./main.scss');
|
||||
|
||||
import 'babel-polyfill';
|
||||
import '@babel/polyfill';
|
||||
import React from 'react';
|
||||
import ReactDOM from 'react-dom';
|
||||
import { Provider } from 'react-redux';
|
||||
|
|
|
@ -26,16 +26,16 @@
|
|||
"uuid": "3.0.1"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"enzyme": "3.2.0",
|
||||
"enzyme-adapter-react-16": "^1.1.1"
|
||||
"enzyme": "^3.8.0",
|
||||
"enzyme-adapter-react-16": "^1.9.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.3.4",
|
||||
"@babel/polyfill": "^7.2.5",
|
||||
"@elastic/eui": "0.0.23",
|
||||
"@kbn/babel-preset": "1.0.0",
|
||||
"autoprefixer": "6.5.4",
|
||||
"babel-core": "^6.26.3",
|
||||
"babel-loader": "^7.1.5",
|
||||
"babel-polyfill": "^6.26.0",
|
||||
"babel-loader": "^8.0.5",
|
||||
"brace": "0.10.0",
|
||||
"chalk": "^2.4.1",
|
||||
"chokidar": "1.6.0",
|
||||
|
@ -43,7 +43,7 @@
|
|||
"expose-loader": "^0.7.5",
|
||||
"file-loader": "^2.0.0",
|
||||
"grunt": "1.0.3",
|
||||
"grunt-babel": "^7.0.0",
|
||||
"grunt-babel": "^8.0.0",
|
||||
"grunt-contrib-clean": "^1.1.0",
|
||||
"grunt-contrib-copy": "^1.0.0",
|
||||
"highlight.js": "9.0.0",
|
||||
|
|
92
src/core/public/core_system.test.mocks.ts
Normal file
92
src/core/public/core_system.test.mocks.ts
Normal file
|
@ -0,0 +1,92 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
import { basePathServiceMock } from './base_path/base_path_service.mock';
|
||||
import { chromeServiceMock } from './chrome/chrome_service.mock';
|
||||
import { fatalErrorsServiceMock } from './fatal_errors/fatal_errors_service.mock';
|
||||
import { httpServiceMock } from './http/http_service.mock';
|
||||
import { i18nServiceMock } from './i18n/i18n_service.mock';
|
||||
import { injectedMetadataServiceMock } from './injected_metadata/injected_metadata_service.mock';
|
||||
import { legacyPlatformServiceMock } from './legacy/legacy_service.mock';
|
||||
import { notificationServiceMock } from './notifications/notifications_service.mock';
|
||||
import { uiSettingsServiceMock } from './ui_settings/ui_settings_service.mock';
|
||||
|
||||
export const MockLegacyPlatformService = legacyPlatformServiceMock.create();
|
||||
export const LegacyPlatformServiceConstructor = jest
|
||||
.fn()
|
||||
.mockImplementation(() => MockLegacyPlatformService);
|
||||
jest.doMock('./legacy', () => ({
|
||||
LegacyPlatformService: LegacyPlatformServiceConstructor,
|
||||
}));
|
||||
|
||||
export const MockInjectedMetadataService = injectedMetadataServiceMock.create();
|
||||
export const InjectedMetadataServiceConstructor = jest
|
||||
.fn()
|
||||
.mockImplementation(() => MockInjectedMetadataService);
|
||||
jest.doMock('./injected_metadata', () => ({
|
||||
InjectedMetadataService: InjectedMetadataServiceConstructor,
|
||||
}));
|
||||
|
||||
export const MockFatalErrorsService = fatalErrorsServiceMock.create();
|
||||
export const FatalErrorsServiceConstructor = jest
|
||||
.fn()
|
||||
.mockImplementation(() => MockFatalErrorsService);
|
||||
jest.doMock('./fatal_errors', () => ({
|
||||
FatalErrorsService: FatalErrorsServiceConstructor,
|
||||
}));
|
||||
|
||||
export const MockI18nService = i18nServiceMock.create();
|
||||
export const I18nServiceConstructor = jest.fn().mockImplementation(() => MockI18nService);
|
||||
jest.doMock('./i18n', () => ({
|
||||
I18nService: I18nServiceConstructor,
|
||||
}));
|
||||
|
||||
export const MockNotificationsService = notificationServiceMock.create();
|
||||
export const NotificationServiceConstructor = jest
|
||||
.fn()
|
||||
.mockImplementation(() => MockNotificationsService);
|
||||
jest.doMock('./notifications', () => ({
|
||||
NotificationsService: NotificationServiceConstructor,
|
||||
}));
|
||||
|
||||
export const MockHttpService = httpServiceMock.create();
|
||||
export const HttpServiceConstructor = jest.fn().mockImplementation(() => MockHttpService);
|
||||
jest.doMock('./http', () => ({
|
||||
HttpService: HttpServiceConstructor,
|
||||
}));
|
||||
|
||||
export const MockBasePathService = basePathServiceMock.create();
|
||||
export const BasePathServiceConstructor = jest.fn().mockImplementation(() => MockBasePathService);
|
||||
jest.doMock('./base_path', () => ({
|
||||
BasePathService: BasePathServiceConstructor,
|
||||
}));
|
||||
|
||||
export const MockUiSettingsService = uiSettingsServiceMock.create();
|
||||
export const UiSettingsServiceConstructor = jest
|
||||
.fn()
|
||||
.mockImplementation(() => MockUiSettingsService);
|
||||
jest.doMock('./ui_settings', () => ({
|
||||
UiSettingsService: UiSettingsServiceConstructor,
|
||||
}));
|
||||
|
||||
export const MockChromeService = chromeServiceMock.create();
|
||||
export const ChromeServiceConstructor = jest.fn().mockImplementation(() => MockChromeService);
|
||||
jest.doMock('./chrome', () => ({
|
||||
ChromeService: ChromeServiceConstructor,
|
||||
}));
|
|
@ -17,73 +17,26 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
import { basePathServiceMock } from './base_path/base_path_service.mock';
|
||||
import { chromeServiceMock } from './chrome/chrome_service.mock';
|
||||
import { fatalErrorsServiceMock } from './fatal_errors/fatal_errors_service.mock';
|
||||
import { httpServiceMock } from './http/http_service.mock';
|
||||
import { i18nServiceMock } from './i18n/i18n_service.mock';
|
||||
import { injectedMetadataServiceMock } from './injected_metadata/injected_metadata_service.mock';
|
||||
import { legacyPlatformServiceMock } from './legacy/legacy_service.mock';
|
||||
import { notificationServiceMock } from './notifications/notifications_service.mock';
|
||||
import { uiSettingsServiceMock } from './ui_settings/ui_settings_service.mock';
|
||||
|
||||
const MockLegacyPlatformService = legacyPlatformServiceMock.create();
|
||||
const LegacyPlatformServiceConstructor = jest
|
||||
.fn()
|
||||
.mockImplementation(() => MockLegacyPlatformService);
|
||||
jest.mock('./legacy', () => ({
|
||||
LegacyPlatformService: LegacyPlatformServiceConstructor,
|
||||
}));
|
||||
|
||||
const MockInjectedMetadataService = injectedMetadataServiceMock.create();
|
||||
const InjectedMetadataServiceConstructor = jest
|
||||
.fn()
|
||||
.mockImplementation(() => MockInjectedMetadataService);
|
||||
jest.mock('./injected_metadata', () => ({
|
||||
InjectedMetadataService: InjectedMetadataServiceConstructor,
|
||||
}));
|
||||
|
||||
const MockFatalErrorsService = fatalErrorsServiceMock.create();
|
||||
const FatalErrorsServiceConstructor = jest.fn().mockImplementation(() => MockFatalErrorsService);
|
||||
jest.mock('./fatal_errors', () => ({
|
||||
FatalErrorsService: FatalErrorsServiceConstructor,
|
||||
}));
|
||||
|
||||
const MockI18nService = i18nServiceMock.create();
|
||||
const I18nServiceConstructor = jest.fn().mockImplementation(() => MockI18nService);
|
||||
jest.mock('./i18n', () => ({
|
||||
I18nService: I18nServiceConstructor,
|
||||
}));
|
||||
|
||||
const MockNotificationsService = notificationServiceMock.create();
|
||||
const NotificationServiceConstructor = jest.fn().mockImplementation(() => MockNotificationsService);
|
||||
jest.mock('./notifications', () => ({
|
||||
NotificationsService: NotificationServiceConstructor,
|
||||
}));
|
||||
|
||||
const MockHttpService = httpServiceMock.create();
|
||||
const HttpServiceConstructor = jest.fn().mockImplementation(() => MockHttpService);
|
||||
jest.mock('./http', () => ({
|
||||
HttpService: HttpServiceConstructor,
|
||||
}));
|
||||
|
||||
const MockBasePathService = basePathServiceMock.create();
|
||||
const BasePathServiceConstructor = jest.fn().mockImplementation(() => MockBasePathService);
|
||||
jest.mock('./base_path', () => ({
|
||||
BasePathService: BasePathServiceConstructor,
|
||||
}));
|
||||
|
||||
const MockUiSettingsService = uiSettingsServiceMock.create();
|
||||
const UiSettingsServiceConstructor = jest.fn().mockImplementation(() => MockUiSettingsService);
|
||||
jest.mock('./ui_settings', () => ({
|
||||
UiSettingsService: UiSettingsServiceConstructor,
|
||||
}));
|
||||
|
||||
const MockChromeService = chromeServiceMock.create();
|
||||
const ChromeServiceConstructor = jest.fn().mockImplementation(() => MockChromeService);
|
||||
jest.mock('./chrome', () => ({
|
||||
ChromeService: ChromeServiceConstructor,
|
||||
}));
|
||||
import {
|
||||
BasePathServiceConstructor,
|
||||
ChromeServiceConstructor,
|
||||
FatalErrorsServiceConstructor,
|
||||
HttpServiceConstructor,
|
||||
I18nServiceConstructor,
|
||||
InjectedMetadataServiceConstructor,
|
||||
LegacyPlatformServiceConstructor,
|
||||
MockBasePathService,
|
||||
MockChromeService,
|
||||
MockFatalErrorsService,
|
||||
MockHttpService,
|
||||
MockI18nService,
|
||||
MockInjectedMetadataService,
|
||||
MockLegacyPlatformService,
|
||||
MockNotificationsService,
|
||||
MockUiSettingsService,
|
||||
NotificationServiceConstructor,
|
||||
UiSettingsServiceConstructor,
|
||||
} from './core_system.test.mocks';
|
||||
|
||||
import { CoreSystem } from './core_system';
|
||||
jest.spyOn(CoreSystem.prototype, 'stop');
|
||||
|
|
|
@ -53,8 +53,7 @@ exports[`rendering render matches snapshot 1`] = `
|
|||
body={
|
||||
<p>
|
||||
<FormattedMessage
|
||||
defaultMessage="Try refreshing the page. If that doesn't work, go back to the previous page or
|
||||
clear your session data."
|
||||
defaultMessage="Try refreshing the page. If that doesn't work, go back to the previous page or clear your session data."
|
||||
id="core.fatalErrors.tryRefreshingPageDescription"
|
||||
values={Object {}}
|
||||
/>
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
export const mockRender = jest.fn();
|
||||
jest.mock('react-dom', () => {
|
||||
return {
|
||||
render: mockRender,
|
||||
};
|
||||
});
|
|
@ -24,12 +24,7 @@ expect.addSnapshotSerializer({
|
|||
print: () => `Rx.Observable`,
|
||||
});
|
||||
|
||||
const mockRender = jest.fn();
|
||||
jest.mock('react-dom', () => {
|
||||
return {
|
||||
render: mockRender,
|
||||
};
|
||||
});
|
||||
import { mockRender } from './fatal_errors_service.test.mocks';
|
||||
|
||||
import { FatalErrorsService } from './fatal_errors_service';
|
||||
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
export const mockReactDomRender = jest.fn();
|
||||
export const mockReactDomUnmount = jest.fn();
|
||||
jest.mock('react-dom', () => ({
|
||||
render: mockReactDomRender,
|
||||
unmountComponentAtNode: mockReactDomUnmount,
|
||||
}));
|
|
@ -17,12 +17,7 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
const mockReactDomRender = jest.fn();
|
||||
const mockReactDomUnmount = jest.fn();
|
||||
jest.mock('react-dom', () => ({
|
||||
render: mockReactDomRender,
|
||||
unmountComponentAtNode: mockReactDomUnmount,
|
||||
}));
|
||||
import { mockReactDomRender, mockReactDomUnmount } from './toasts_service.test.mocks';
|
||||
|
||||
import { ToastsService } from './toasts_service';
|
||||
import { ToastsSetup } from './toasts_start';
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
/*
|
||||
* 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 mockClass<T>(
|
||||
module: string,
|
||||
Class: { new (...args: any[]): T },
|
||||
setup: (instance: any, args: any[]) => void
|
||||
) {
|
||||
const MockClass = jest.fn(function(this: any, ...args: any[]) {
|
||||
setup(this, args);
|
||||
});
|
||||
|
||||
// define the mock name which is used in some snapshots
|
||||
MockClass.mockName(`Mock${Class.name}`);
|
||||
|
||||
// define the class name for the MockClass which is used in other snapshots
|
||||
Object.defineProperty(MockClass, 'name', {
|
||||
value: `Mock${Class.name}`,
|
||||
});
|
||||
|
||||
jest.doMock(module, () => ({
|
||||
[Class.name]: MockClass,
|
||||
}));
|
||||
|
||||
return MockClass;
|
||||
}
|
||||
|
||||
// Mock the UiSettingsApi class
|
||||
import { UiSettingsApi } from './ui_settings_api';
|
||||
export const MockUiSettingsApi = mockClass('./ui_settings_api', UiSettingsApi, inst => {
|
||||
inst.stop = jest.fn();
|
||||
inst.getLoadingCount$ = jest.fn().mockReturnValue({
|
||||
loadingCountObservable: true,
|
||||
});
|
||||
});
|
||||
|
||||
// Mock the UiSettingsClient class
|
||||
import { UiSettingsClient } from './ui_settings_client';
|
||||
export const MockUiSettingsClient = mockClass('./ui_settings_client', UiSettingsClient, inst => {
|
||||
inst.stop = jest.fn();
|
||||
});
|
|
@ -17,44 +17,7 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
function mockClass<T>(
|
||||
module: string,
|
||||
Class: { new (...args: any[]): T },
|
||||
setup: (instance: any, args: any[]) => void
|
||||
) {
|
||||
const MockClass = jest.fn(function(this: any, ...args: any[]) {
|
||||
setup(this, args);
|
||||
});
|
||||
|
||||
// define the mock name which is used in some snapshots
|
||||
MockClass.mockName(`Mock${Class.name}`);
|
||||
|
||||
// define the class name for the MockClass which is used in other snapshots
|
||||
Object.defineProperty(MockClass, 'name', {
|
||||
value: `Mock${Class.name}`,
|
||||
});
|
||||
|
||||
jest.mock(module, () => ({
|
||||
[Class.name]: MockClass,
|
||||
}));
|
||||
|
||||
return MockClass;
|
||||
}
|
||||
|
||||
// Mock the UiSettingsApi class
|
||||
import { UiSettingsApi } from './ui_settings_api';
|
||||
const MockUiSettingsApi = mockClass('./ui_settings_api', UiSettingsApi, inst => {
|
||||
inst.stop = jest.fn();
|
||||
inst.getLoadingCount$ = jest.fn().mockReturnValue({
|
||||
loadingCountObservable: true,
|
||||
});
|
||||
});
|
||||
|
||||
// Mock the UiSettingsClient class
|
||||
import { UiSettingsClient } from './ui_settings_client';
|
||||
const MockUiSettingsClient = mockClass('./ui_settings_client', UiSettingsClient, inst => {
|
||||
inst.stop = jest.fn();
|
||||
});
|
||||
import { MockUiSettingsApi, MockUiSettingsClient } from './ui_settings_service.test.mocks';
|
||||
|
||||
import { basePathServiceMock } from '../base_path/base_path_service.mock';
|
||||
import { httpServiceMock } from '../http/http_service.mock';
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
import { BehaviorSubject } from 'rxjs';
|
||||
import { ObjectToConfigAdapter } from './object_to_config_adapter';
|
||||
|
||||
|
|
21
src/core/server/config/config_service.test.mocks.ts
Normal file
21
src/core/server/config/config_service.test.mocks.ts
Normal file
|
@ -0,0 +1,21 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
export const mockPackage = new Proxy({ raw: {} as any }, { get: (obj, prop) => obj.raw[prop] });
|
||||
jest.mock('../../../../package.json', () => mockPackage);
|
|
@ -22,8 +22,7 @@
|
|||
import { BehaviorSubject } from 'rxjs';
|
||||
import { first } from 'rxjs/operators';
|
||||
|
||||
const mockPackage = new Proxy({ raw: {} as any }, { get: (obj, prop) => obj.raw[prop] });
|
||||
jest.mock('../../../../package.json', () => mockPackage);
|
||||
import { mockPackage } from './config_service.test.mocks';
|
||||
|
||||
import { schema, Type, TypeOf } from '@kbn/config-schema';
|
||||
|
||||
|
|
33
src/core/server/config/env.test.mocks.ts
Normal file
33
src/core/server/config/env.test.mocks.ts
Normal file
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
jest.mock('process', () => ({
|
||||
cwd() {
|
||||
return '/test/cwd';
|
||||
},
|
||||
}));
|
||||
|
||||
jest.mock('path', () => ({
|
||||
resolve(...pathSegments: string[]) {
|
||||
return pathSegments.join('/');
|
||||
},
|
||||
}));
|
||||
|
||||
export const mockPackage = new Proxy({ raw: {} as any }, { get: (obj, prop) => obj.raw[prop] });
|
||||
jest.mock('../../../../package.json', () => mockPackage);
|
|
@ -17,20 +17,7 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
jest.mock('process', () => ({
|
||||
cwd() {
|
||||
return '/test/cwd';
|
||||
},
|
||||
}));
|
||||
|
||||
jest.mock('path', () => ({
|
||||
resolve(...pathSegments: string[]) {
|
||||
return pathSegments.join('/');
|
||||
},
|
||||
}));
|
||||
|
||||
const mockPackage = new Proxy({ raw: {} as any }, { get: (obj, prop) => obj.raw[prop] });
|
||||
jest.mock('../../../../package.json', () => mockPackage);
|
||||
import { mockPackage } from './env.test.mocks';
|
||||
|
||||
import { Env } from '.';
|
||||
import { getEnvOptions } from './__mocks__/env';
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue