Skip to content

Commit

Permalink
[yarn] remove typings-tester, use @ts-expect-error
Browse files Browse the repository at this point in the history
  • Loading branch information
spalger committed Aug 31, 2020
1 parent a8b2810 commit ee58d46
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 116 deletions.
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
"test:ftr:server": "node scripts/functional_tests_server",
"test:ftr:runner": "node scripts/functional_test_runner",
"test:coverage": "grunt test:coverage",
"typespec": "typings-tester --config x-pack/plugins/canvas/public/lib/aeroelastic/tsconfig.json x-pack/plugins/canvas/public/lib/aeroelastic/__fixtures__/typescript/typespec_tests.ts",
"checkLicenses": "node scripts/check_licenses --dev",
"build": "node scripts/build --all-platforms",
"start": "node scripts/kibana --dev",
Expand Down Expand Up @@ -473,7 +472,6 @@
"topojson-client": "3.0.0",
"tree-kill": "^1.2.2",
"typescript": "4.0.2",
"typings-tester": "^0.3.2",
"ui-select": "0.19.8",
"vega": "^5.13.0",
"vega-lite": "^4.13.1",
Expand Down
21 changes: 0 additions & 21 deletions x-pack/plugins/canvas/public/lib/aeroelastic/tsconfig.json

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,49 +4,47 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { select } from '../../select';
import { Json, Selector, Vector2d, Vector3d, TransformMatrix2d, TransformMatrix3d } from '../..';
import { select } from './select';
import { Json, Selector, Vector2d, Vector3d, TransformMatrix2d, TransformMatrix3d } from './index';
import {
mvMultiply as mult2d,
ORIGIN as UNIT2D,
UNITMATRIX as UNITMATRIX2D,
add as add2d,
} from '../../matrix2d';
} from './matrix2d';
import {
mvMultiply as mult3d,
ORIGIN as UNIT3D,
NANMATRIX as NANMATRIX3D,
add as add3d,
} from '../../matrix';
} from './matrix';

/*
// helper to mark variables as "used" so they don't trigger errors
const use = (...vars: any[]) => vars.includes(null);

/*
Type checking isn't too useful if future commits can accidentally weaken the type constraints, because a
TypeScript linter will not complain - everything that passed before will continue to pass. The coder
will not have feedback that the original intent with the typing got compromised. To declare the intent
via passing and failing type checks, test cases are needed, some of which designed to expect a TS pass,
some of them to expect a TS complaint. It documents intent for peers too, as type specs are a tough read.
Run compile-time type specification tests in the `kibana` root with:
yarn typespec
Test "cases" expecting to pass TS checks are not annotated, while ones we want TS to complain about
are prepended with the comment
// typings:expect-error
// @ts-expect-error
The test "suite" and "cases" are wrapped in IIFEs to prevent linters from complaining about the unused
binding. It can be structured internally as desired.
*/

((): void => {
/**
* TYPE TEST SUITE
*/
describe('vector array creation', () => {
it('passes typechecking', () => {
let vec2d: Vector2d = UNIT2D;
let vec3d: Vector3d = UNIT3D;

use(vec2d, vec3d);

(function vectorArrayCreationTests(vec2d: Vector2d, vec3d: Vector3d): void {
// 2D vector OK
vec2d = [0, 0, 0] as Vector2d; // OK
vec2d = [-0, NaN, -Infinity] as Vector2d; // IEEE 754 values are OK
Expand All @@ -57,30 +55,35 @@ import {

// 2D vector not OK

// typings:expect-error
// @ts-expect-error
vec2d = 3; // not even an array
// typings:expect-error
// @ts-expect-error
vec2d = [] as Vector2d; // no elements
// typings:expect-error
// @ts-expect-error
vec2d = [0, 0] as Vector2d; // too few elements
// typings:expect-error
// @ts-expect-error
vec2d = [0, 0, 0, 0] as Vector2d; // too many elements

// 3D vector not OK

// typings:expect-error
// @ts-expect-error
vec3d = 3; // not even an array
// typings:expect-error
// @ts-expect-error
vec3d = [] as Vector3d; // no elements
// typings:expect-error
// @ts-expect-error
vec3d = [0, 0, 0] as Vector3d; // too few elements
// typings:expect-error
// @ts-expect-error
vec3d = [0, 0, 0, 0, 0] as Vector3d; // too many elements
});
});

describe('matrix array creation', () => {
it('passes typechecking', () => {
let mat2d: TransformMatrix2d = UNITMATRIX2D;
let mat3d: TransformMatrix3d = NANMATRIX3D;

return; // arrayCreationTests
})(UNIT2D, UNIT3D);
use(mat2d, mat3d);

(function matrixArrayCreationTests(mat2d: TransformMatrix2d, mat3d: TransformMatrix3d): void {
// 2D matrix OK
mat2d = [0, 1, 2, 3, 4, 5, 6, 7, 8] as TransformMatrix2d; // OK
mat2d = [-0, NaN, -Infinity, 3, 4, 5, 6, 7, 8] as TransformMatrix2d; // IEEE 754 values are OK
Expand All @@ -91,80 +94,87 @@ import {

// 2D matrix not OK

// typings:expect-error
// @ts-expect-error
mat2d = 3; // not even an array
// typings:expect-error
// @ts-expect-error
mat2d = [] as TransformMatrix2d; // no elements
// typings:expect-error
// @ts-expect-error
mat2d = [0, 1, 2, 3, 4, 5, 6, 7] as TransformMatrix2d; // too few elements
// typings:expect-error
// @ts-expect-error
mat2d = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] as TransformMatrix2d; // too many elements

// 3D vector not OK

// typings:expect-error
// @ts-expect-error
mat3d = 3; // not even an array
// typings:expect-error
// @ts-expect-error
mat3d = [] as TransformMatrix3d; // no elements
// typings:expect-error
// @ts-expect-error
mat3d = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14] as TransformMatrix3d; // too few elements
// typings:expect-error
// @ts-expect-error
mat3d = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16] as TransformMatrix3d; // too many elements

// Matrix modification should NOT be OK
mat3d[3] = 100; // too bad the ReadOnly part appears not to be enforced so can't precede it with typings:expect-error
// @ts-expect-error
mat3d[3] = 100; // Matrix modification is NOT OK
});
});

return; // arrayCreationTests
})(UNITMATRIX2D, NANMATRIX3D);
describe('matrix addition', () => {
it('passes typecheck', () => {
const mat2d: TransformMatrix2d = UNITMATRIX2D;
const mat3d: TransformMatrix3d = NANMATRIX3D;

(function matrixMatrixAdditionTests(mat2d: TransformMatrix2d, mat3d: TransformMatrix3d): void {
add2d(mat2d, mat2d); // OK
add3d(mat3d, mat3d); // OK

// typings:expect-error
// @ts-expect-error
add2d(mat2d, mat3d); // at least one arg doesn't comply
// typings:expect-error
// @ts-expect-error
add2d(mat3d, mat2d); // at least one arg doesn't comply
// typings:expect-error
// @ts-expect-error
add2d(mat3d, mat3d); // at least one arg doesn't comply
// typings:expect-error
// @ts-expect-error
add3d(mat2d, mat3d); // at least one arg doesn't comply
// typings:expect-error
// @ts-expect-error
add3d(mat3d, mat2d); // at least one arg doesn't comply
// typings:expect-error
// @ts-expect-error
add3d(mat2d, mat2d); // at least one arg doesn't comply
});
});

return; // matrixMatrixAdditionTests
})(UNITMATRIX2D, NANMATRIX3D);
describe('matric vector multiplication', () => {
it('passes typecheck', () => {
const vec2d: Vector2d = UNIT2D;
const mat2d: TransformMatrix2d = UNITMATRIX2D;
const vec3d: Vector3d = UNIT3D;
const mat3d: TransformMatrix3d = NANMATRIX3D;

(function matrixVectorMultiplicationTests(
vec2d: Vector2d,
mat2d: TransformMatrix2d,
vec3d: Vector3d,
mat3d: TransformMatrix3d
): void {
mult2d(mat2d, vec2d); // OK
mult3d(mat3d, vec3d); // OK

// typings:expect-error
// @ts-expect-error
mult3d(mat2d, vec2d); // trying to use a 3d fun for 2d args
// typings:expect-error
// @ts-expect-error
mult2d(mat3d, vec3d); // trying to use a 2d fun for 3d args

// typings:expect-error
// @ts-expect-error
mult2d(mat3d, vec2d); // 1st arg is a mismatch
// typings:expect-error
// @ts-expect-error
mult2d(mat2d, vec3d); // 2nd arg is a mismatch

// typings:expect-error
// @ts-expect-error
mult3d(mat2d, vec3d); // 1st arg is a mismatch
// typings:expect-error
// @ts-expect-error
mult3d(mat3d, vec2d); // 2nd arg is a mismatch
});
});

return; // matrixVectorTests
})(UNIT2D, UNITMATRIX2D, UNIT3D, NANMATRIX3D);
describe('json', () => {
it('passes typecheck', () => {
let plain: Json = null;

use(plain);

(function jsonTests(plain: Json): void {
// numbers are OK
plain = 1;
plain = NaN;
Expand All @@ -182,37 +192,37 @@ import {
plain = [0, null, false, NaN, 3.14, 'one more'];
plain = { a: { b: 5, c: { d: [1, 'a', -Infinity, null], e: -1 }, f: 'b' }, g: false };

// typings:expect-error
// @ts-expect-error
plain = undefined; // it's undefined
// typings:expect-error
// @ts-expect-error
plain = (a) => a; // it's a function
// typings:expect-error
// @ts-expect-error
plain = [new Date()]; // it's a time
// typings:expect-error
// @ts-expect-error
plain = { a: Symbol('haha') }; // symbol isn't permitted either
// typings:expect-error
// @ts-expect-error
plain = window || void 0;
// typings:expect-error
// @ts-expect-error
plain = { a: { b: 5, c: { d: [1, 'a', undefined, null] } } }; // going deep into the structure
});
});

return; // jsonTests
})(null);
describe('select', () => {
it('passes typecheck', () => {
let selector: Selector;

(function selectTests(selector: Selector): void {
selector = select((a: Json) => a); // one arg
selector = select((a: Json, b: Json): Json => `${a} and ${b}`); // more args
selector = select(() => 1); // zero arg
selector = select((...args: Json[]) => args); // variadic

// typings:expect-error
// @ts-expect-error
selector = (a: Json) => a; // not a selector
// typings:expect-error
// @ts-expect-error
selector = select(() => {}); // should yield a JSON value, but it returns void
// typings:expect-error
// @ts-expect-error
selector = select((x: Json) => ({ a: x, b: undefined })); // should return a Json

return; // selectTests
})(select((a: Json) => a));

return; // test suite
})();
use(selector);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"exclude": [
"test/**/*",
"**/__fixtures__/**/*",
"plugins/security_solution/cypress/**/*",
"**/typespec_tests.ts"
"plugins/security_solution/cypress/**/*"
]
}
3 changes: 1 addition & 2 deletions x-pack/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
"test/**/*",
"plugins/security_solution/cypress/**/*",
"plugins/apm/e2e/cypress/**/*",
"plugins/apm/scripts/**/*",
"**/typespec_tests.ts"
"plugins/apm/scripts/**/*"
],
"compilerOptions": {
"outDir": ".",
Expand Down
9 changes: 1 addition & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9035,7 +9035,7 @@ comma-separated-tokens@^1.0.1:
resolved "https://registry.yarnpkg.com/comma-separated-tokens/-/comma-separated-tokens-1.0.8.tgz#632b80b6117867a158f1080ad498b2fbe7e3f5ea"
integrity sha512-GHuDRO12Sypu2cV70d1dkA2EUmXHgntrzbpvOB+Qy+49ypNfGgFQIC2fhhXbnyrJRynDCAARsT7Ou0M6hirpfw==

commander@2, commander@2.19.0, commander@^2.11.0, commander@^2.12.2:
commander@2, commander@2.19.0, commander@^2.11.0:
version "2.19.0"
resolved "https://registry.yarnpkg.com/commander/-/commander-2.19.0.tgz#f6198aa84e5b83c46054b94ddedbfed5ee9ff12a"
integrity sha512-6tvAOO+D6OENvRAh524Dh9jcfKTYDQAqvqezbCW82xj5X0pSrcpxtvRKHLG0yBY6SD7PSDrJaj+0AiOcKVd1Xg==
Expand Down Expand Up @@ -28434,13 +28434,6 @@ typescript@4.0.2, typescript@^3.0.1, typescript@^3.0.3, typescript@^3.2.2, types
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.0.2.tgz#7ea7c88777c723c681e33bf7988be5d008d05ac2"
integrity sha512-e4ERvRV2wb+rRZ/IQeb3jm2VxBsirQLpQhdxplZ2MEzGvDkkMmPglecnNDfSUBivMjP93vRbngYYDQqQ/78bcQ==

typings-tester@^0.3.2:
version "0.3.2"
resolved "https://registry.yarnpkg.com/typings-tester/-/typings-tester-0.3.2.tgz#04cc499d15ab1d8b2d14dd48415a13d01333bc5b"
integrity sha512-HjGoAM2UoGhmSKKy23TYEKkxlphdJFdix5VvqWFLzH1BJVnnwG38tpC6SXPgqhfFGfHY77RlN1K8ts0dbWBQ7A==
dependencies:
commander "^2.12.2"

ua-parser-js@^0.7.18:
version "0.7.21"
resolved "https://registry.yarnpkg.com/ua-parser-js/-/ua-parser-js-0.7.21.tgz#853cf9ce93f642f67174273cc34565ae6f308777"
Expand Down

0 comments on commit ee58d46

Please sign in to comment.