mirror of
https://github.com/elastic/kibana.git
synced 2025-06-27 18:51:07 -04:00
## Dearest Reviewers 👋 I've been working on this branch with @mistic and @tylersmalley and we're really confident in these changes. Additionally, this changes code in nearly every package in the repo so we don't plan to wait for reviews to get in before merging this. If you'd like to have a concern addressed, please feel free to leave a review, but assuming that nobody raises a blocker in the next 24 hours we plan to merge this EOD pacific tomorrow, 12/22. We'll be paying close attention to any issues this causes after merging and work on getting those fixed ASAP. 🚀 --- The operations team is not confident that we'll have the time to achieve what we originally set out to accomplish by moving to Bazel with the time and resources we have available. We have also bought ourselves some headroom with improvements to babel-register, optimizer caching, and typescript project structure. In order to make sure we deliver packages as quickly as possible (many teams really want them), with a usable and familiar developer experience, this PR removes Bazel for building packages in favor of using the same JIT transpilation we use for plugins. Additionally, packages now use `kbn_references` (again, just copying the dx from plugins to packages). Because of the complex relationships between packages/plugins and in order to prepare ourselves for automatic dependency detection tools we plan to use in the future, this PR also introduces a "TS Project Linter" which will validate that every tsconfig.json file meets a few requirements: 1. the chain of base config files extended by each config includes `tsconfig.base.json` and not `tsconfig.json` 1. the `include` config is used, and not `files` 2. the `exclude` config includes `target/**/*` 3. the `outDir` compiler option is specified as `target/types` 1. none of these compiler options are specified: `declaration`, `declarationMap`, `emitDeclarationOnly`, `skipLibCheck`, `target`, `paths` 4. all references to other packages/plugins use their pkg id, ie: ```js // valid { "kbn_references": ["@kbn/core"] } // not valid { "kbn_references": [{ "path": "../../../src/core/tsconfig.json" }] } ``` 5. only packages/plugins which are imported somewhere in the ts code are listed in `kbn_references` This linter is not only validating all of the tsconfig.json files, but it also will fix these config files to deal with just about any violation that can be produced. Just run `node scripts/ts_project_linter --fix` locally to apply these fixes, or let CI take care of automatically fixing things and pushing the changes to your PR. > **Example:** [` |
||
---|---|---|
.. | ||
expect.d.ts | ||
expect.js | ||
kibana.jsonc | ||
LICENSE.txt | ||
package.json | ||
README.mdx | ||
tsconfig.json |
--- id: kibDevDocsOpsExpect slug: /kibana-dev-docs/ops/expect title: "@kbn/expect" description: An assertion toolkit based on should.js date: 2022-05-17 tags: ['kibana', 'dev', 'contributor', 'operations', '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); ``` > NOTE: This is a local fork of https://github.com/Automattic/expect.js ## 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.