Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migration to Babel7 and @babel/preset-typescript #33093

Merged
merged 68 commits into from
Mar 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
da72230
chore(NA): first changes on every package.json order to support new b…
mistic Feb 28, 2019
8e8a4f6
chore(NA): patch babel register to load typescrit
mistic Feb 28, 2019
5f46073
chore(NA): first working version with babel 7 replacing typescript co…
mistic Feb 28, 2019
12e320a
fix(NA): common preset declaration in order to make it work with babe…
mistic Feb 28, 2019
1005dbb
chore(na): organizing babel preset env package json.
mistic Feb 28, 2019
5c652e3
chore(NA): mocha tests enabled.
mistic Mar 1, 2019
d4865f0
fix(NA): typo on importing
mistic Mar 1, 2019
76af703
test(NA): start fixing tests.
mistic Mar 1, 2019
916e670
test(NA): majority of x-pack tests ported to use babel-jest
mistic Mar 1, 2019
d0cd8bb
fix(NA): report info button test with babel-jest.
mistic Mar 2, 2019
0913814
fix(NA): polling service tests.
mistic Mar 2, 2019
d981ab5
test(na): fix server plugins plugin tests.
mistic Mar 4, 2019
a2ba6de
test(NA): batch of test fixs for jest tests under babel-jest hoisting.
mistic Mar 5, 2019
84acbf5
chore(NA): add babel plugin to hoist mock prefixed vars on jest tests.
mistic Mar 7, 2019
55c8ede
chore(NA): update yarn.lock file.
mistic Mar 7, 2019
e436b53
chore(NA): tests passing.
mistic Mar 8, 2019
9d6ee23
chore(NA): remove wrong dep
mistic Mar 8, 2019
47468e8
chore(NA): fix tsconfig
mistic Mar 8, 2019
1d5a660
chore(NA): merge and solve conflicts with master.
mistic Mar 8, 2019
a00837b
chore(NA): merge and solve conflicts with master.
mistic Mar 8, 2019
bd02df2
chore(NA): skip babel for ts-jest.
mistic Mar 8, 2019
cdc09b7
chore(NA): selectively apply the plugin to strip off namespace from t…
mistic Mar 8, 2019
bf633c6
chore(NA): remove not needed changes from ts tests
mistic Mar 8, 2019
f919236
chore(NA): removed ts-jest dependency. chore(NA): migrate ts tests on…
mistic Mar 13, 2019
aabbf13
chore(NA): migrate kibana default distribution typescript tests to ru…
mistic Mar 13, 2019
9eb7b65
Merge branch 'master' into migrate-to-babel-7
mistic Mar 13, 2019
4ccc57e
chore(NA): merge and solve conflicts with master.
mistic Mar 13, 2019
9bef952
chore(NA): fix problems reported by eslint
mistic Mar 13, 2019
39ce5a7
Merge branch 'master' into migrate-to-babel-7
mistic Mar 13, 2019
f4d0fc4
chore(NA): fix license ovveride for babel-plugin-mock-imports
mistic Mar 13, 2019
4f0908a
chore(NA): update jest integration tests for kbn pm
mistic Mar 13, 2019
7297b95
Merge branch 'master' into migrate-to-babel-7
mistic Mar 13, 2019
3af1ad1
chore(NA): update babel jest integration tests for kbn pm.
mistic Mar 13, 2019
78b1ab0
test(NA): update jest integration snapshot for kbn pm.
mistic Mar 13, 2019
804b8bc
chore(NA): apply changes according to the pull request reviews.
mistic Mar 13, 2019
7482127
chore(NA): apply changes according to the pull request reviews.
mistic Mar 13, 2019
1a1d6d1
refact(NA): migrate jest tests to the new pattern.
mistic Mar 14, 2019
577e165
fix(NA): babel 7 polyfill in the tests bundle.
mistic Mar 14, 2019
1a14a64
chore(NA): restore needed step in order to compile x-pack with typesc…
mistic Mar 14, 2019
2707d53
chore(NA): change build to compile typescript with babel for the oss …
mistic Mar 15, 2019
892960b
Revert "chore(NA): change build to compile typescript with babel for …
mistic Mar 15, 2019
5ae437e
chore(NA): merge and solve conflicts with master.
mistic Mar 15, 2019
70fb9cc
Merge branch 'master' into migrate-to-babel-7
mistic Mar 16, 2019
1f7e0cd
fix(NA): import paths for tabConfigConst
mistic Mar 16, 2019
ac14ae6
chore(NA): fix transpiling error on browser tests
mistic Mar 16, 2019
f1ce0cc
chore(NA): simplify kbn babel preset package.
mistic Mar 16, 2019
4c7cd62
chore(NA): migrate build to use babel transpiler for typescript exclu…
mistic Mar 16, 2019
8016903
fix(NA): introduced error on test quick task.
mistic Mar 16, 2019
e07ebea
fix(NA): fix preset for client side code on build.
mistic Mar 17, 2019
4fbc302
fix(NA): build with babel
mistic Mar 18, 2019
32b6c1a
fix(NA): negated patterns in the end.
mistic Mar 18, 2019
f0027e1
fix(NA): kbn_tp_sample_panel_action creation.
mistic Mar 18, 2019
8d18cda
chore(NA): merge and solve conflicts with last master.
mistic Mar 18, 2019
63cb45d
fix(NA): babel typescript transform plugin workaround when exporting …
mistic Mar 18, 2019
c8a3ff4
chore(NA): merge and solve conflicts with master.
mistic Mar 20, 2019
5af493b
refact(NA): remove not needed type cast to any on jest test.
mistic Mar 20, 2019
0e735d5
docs(NA): add developement documentation about jest mocks test pattern.
mistic Mar 21, 2019
d28b124
chore(NA): merge and solve conflicts with last master.
mistic Mar 26, 2019
0678b30
chore(NA): missing unmerged path.
mistic Mar 26, 2019
c366662
chore(NA): fix jest tests for template.
mistic Mar 26, 2019
67acefc
[CCR] Client integration tests (table lists) (#33525)
sebelga Mar 26, 2019
961f791
Force user to re-authenticate if token refresh fails with `400` statu…
azasypkin Mar 26, 2019
2f9ad0a
Improve performance of the Logstash Pipeline Viewer (#33793)
ycombinator Mar 26, 2019
e247609
[Maps] split settings into layer and source panels (#33788)
nreese Mar 26, 2019
369f0f2
[env] exit if starting as root (#21563)
jbudz Mar 26, 2019
f5010cc
Typescript sample panel action (#33602)
stacey-gammon Mar 26, 2019
57c7572
Home page "recent links" should communicate saved object type #21896 …
PhilippBaranovskiy Mar 26, 2019
41ba9f0
chore(NA): merge and solve conflicts with last master.
mistic Mar 26, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/development/core-development.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ include::core/development-modules.asciidoc[]

include::core/development-elasticsearch.asciidoc[]

include::core/development-unit-tests.asciidoc[]

include::core/development-functional-tests.asciidoc[]
80 changes: 80 additions & 0 deletions docs/development/core/development-unit-tests.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
[[development-unit-tests]]
=== Unit Testing

We use unit tests to make sure that individual software units of Kibana perform as they were designed to.

[float]
==== Current Frameworks

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

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

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


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

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


42 changes: 19 additions & 23 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -264,7 +263,7 @@
"@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",
Expand All @@ -276,7 +275,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",
Expand Down Expand Up @@ -321,8 +320,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",
Expand All @@ -336,17 +335,17 @@
"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",
"eslint-plugin-prettier": "^3.0.1",
"eslint-plugin-react": "^7.12.4",
"faker": "1.1.0",
"fetch-mock": "7.3.0",
"geckodriver": "1.12.2",
Expand All @@ -357,7 +356,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",
Expand Down Expand Up @@ -403,9 +402,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",
Expand Down
23 changes: 13 additions & 10 deletions packages/elastic-datemath/.babelrc
Original file line number Diff line number Diff line change
@@ -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"]
}
}
6 changes: 3 additions & 3 deletions packages/elastic-datemath/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
16 changes: 8 additions & 8 deletions packages/eslint-config-kibana/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
},
"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"
}
}
2 changes: 1 addition & 1 deletion packages/kbn-babel-code-parser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
25 changes: 19 additions & 6 deletions packages/kbn-babel-preset/common_preset.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
],
]
}
]
};
39 changes: 0 additions & 39 deletions packages/kbn-babel-preset/common_preset_7.js

This file was deleted.

Loading