Signed-off-by: Tyler Smalley <tyler.smalley@elastic.co> # Conflicts: # src/dev/code_coverage/ingest_coverage/either.test.js # src/dev/code_coverage/ingest_coverage/ingest_helpers.test.js # src/dev/code_coverage/ingest_coverage/team_assignment/enumerate_patterns.test.js # src/dev/code_coverage/ingest_coverage/team_assignment/enumeration_helpers.test.js # src/dev/code_coverage/ingest_coverage/transforms.test.js
This commit is contained in:
parent
d433e6e14f
commit
9e75c86101
|
@ -19,10 +19,9 @@
|
|||
|
||||
import { uniq } from 'lodash';
|
||||
import sinon from 'sinon';
|
||||
import expect from '@kbn/expect';
|
||||
import { ToolingLog } from '@kbn/dev-utils';
|
||||
|
||||
import { createStats } from '../';
|
||||
import { createStats } from './stats';
|
||||
|
||||
function createBufferedLog(): ToolingLog & { buffer: string } {
|
||||
const log: ToolingLog = new ToolingLog({
|
||||
|
@ -40,12 +39,12 @@ function assertDeepClones(a: any, b: any) {
|
|||
try {
|
||||
(function recurse(one, two) {
|
||||
if (typeof one !== 'object' || typeof two !== 'object') {
|
||||
expect(one).to.be(two);
|
||||
expect(one).toBe(two);
|
||||
return;
|
||||
}
|
||||
|
||||
expect(one).to.eql(two);
|
||||
expect(one).to.not.be(two);
|
||||
expect(one).toEqual(two);
|
||||
expect(one).not.toBe(two);
|
||||
const keys = uniq(Object.keys(one).concat(Object.keys(two)));
|
||||
keys.forEach((k) => {
|
||||
path.push(k);
|
||||
|
@ -68,14 +67,14 @@ describe('esArchiver: Stats', () => {
|
|||
const stats = createStats('name', new ToolingLog());
|
||||
stats.skippedIndex('index-name');
|
||||
const indexStats = stats.toJSON()['index-name'];
|
||||
expect(indexStats).to.have.property('skipped', true);
|
||||
expect(indexStats).toHaveProperty('skipped', true);
|
||||
});
|
||||
|
||||
it('logs that the index was skipped', async () => {
|
||||
const log = createBufferedLog();
|
||||
const stats = createStats('name', log);
|
||||
stats.skippedIndex('index-name');
|
||||
expect(log.buffer).to.contain('Skipped');
|
||||
expect(log.buffer).toContain('Skipped');
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -84,13 +83,13 @@ describe('esArchiver: Stats', () => {
|
|||
const stats = createStats('name', new ToolingLog());
|
||||
stats.deletedIndex('index-name');
|
||||
const indexStats = stats.toJSON()['index-name'];
|
||||
expect(indexStats).to.have.property('deleted', true);
|
||||
expect(indexStats).toHaveProperty('deleted', true);
|
||||
});
|
||||
it('logs that the index was deleted', async () => {
|
||||
const log = createBufferedLog();
|
||||
const stats = createStats('name', log);
|
||||
stats.deletedIndex('index-name');
|
||||
expect(log.buffer).to.contain('Deleted');
|
||||
expect(log.buffer).toContain('Deleted');
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -99,13 +98,13 @@ describe('esArchiver: Stats', () => {
|
|||
const stats = createStats('name', new ToolingLog());
|
||||
stats.createdIndex('index-name');
|
||||
const indexStats = stats.toJSON()['index-name'];
|
||||
expect(indexStats).to.have.property('created', true);
|
||||
expect(indexStats).toHaveProperty('created', true);
|
||||
});
|
||||
it('logs that the index was created', async () => {
|
||||
const log = createBufferedLog();
|
||||
const stats = createStats('name', log);
|
||||
stats.createdIndex('index-name');
|
||||
expect(log.buffer).to.contain('Created');
|
||||
expect(log.buffer).toContain('Created');
|
||||
});
|
||||
describe('with metadata', () => {
|
||||
it('debug-logs each key from the metadata', async () => {
|
||||
|
@ -114,8 +113,8 @@ describe('esArchiver: Stats', () => {
|
|||
stats.createdIndex('index-name', {
|
||||
foo: 'bar',
|
||||
});
|
||||
expect(log.buffer).to.contain('debg');
|
||||
expect(log.buffer).to.contain('foo "bar"');
|
||||
expect(log.buffer).toContain('debg');
|
||||
expect(log.buffer).toContain('foo "bar"');
|
||||
});
|
||||
});
|
||||
describe('without metadata', () => {
|
||||
|
@ -123,7 +122,7 @@ describe('esArchiver: Stats', () => {
|
|||
const log = createBufferedLog();
|
||||
const stats = createStats('name', log);
|
||||
stats.createdIndex('index-name');
|
||||
expect(log.buffer).to.not.contain('debg');
|
||||
expect(log.buffer).not.toContain('debg');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -133,13 +132,13 @@ describe('esArchiver: Stats', () => {
|
|||
const stats = createStats('name', new ToolingLog());
|
||||
stats.archivedIndex('index-name');
|
||||
const indexStats = stats.toJSON()['index-name'];
|
||||
expect(indexStats).to.have.property('archived', true);
|
||||
expect(indexStats).toHaveProperty('archived', true);
|
||||
});
|
||||
it('logs that the index was archived', async () => {
|
||||
const log = createBufferedLog();
|
||||
const stats = createStats('name', log);
|
||||
stats.archivedIndex('index-name');
|
||||
expect(log.buffer).to.contain('Archived');
|
||||
expect(log.buffer).toContain('Archived');
|
||||
});
|
||||
describe('with metadata', () => {
|
||||
it('debug-logs each key from the metadata', async () => {
|
||||
|
@ -148,8 +147,8 @@ describe('esArchiver: Stats', () => {
|
|||
stats.archivedIndex('index-name', {
|
||||
foo: 'bar',
|
||||
});
|
||||
expect(log.buffer).to.contain('debg');
|
||||
expect(log.buffer).to.contain('foo "bar"');
|
||||
expect(log.buffer).toContain('debg');
|
||||
expect(log.buffer).toContain('foo "bar"');
|
||||
});
|
||||
});
|
||||
describe('without metadata', () => {
|
||||
|
@ -157,7 +156,7 @@ describe('esArchiver: Stats', () => {
|
|||
const log = createBufferedLog();
|
||||
const stats = createStats('name', log);
|
||||
stats.archivedIndex('index-name');
|
||||
expect(log.buffer).to.not.contain('debg');
|
||||
expect(log.buffer).not.toContain('debg');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -166,10 +165,10 @@ describe('esArchiver: Stats', () => {
|
|||
it('increases the docs.indexed count for the index', () => {
|
||||
const stats = createStats('name', new ToolingLog());
|
||||
stats.indexedDoc('index-name');
|
||||
expect(stats.toJSON()['index-name'].docs.indexed).to.be(1);
|
||||
expect(stats.toJSON()['index-name'].docs.indexed).toBe(1);
|
||||
stats.indexedDoc('index-name');
|
||||
stats.indexedDoc('index-name');
|
||||
expect(stats.toJSON()['index-name'].docs.indexed).to.be(3);
|
||||
expect(stats.toJSON()['index-name'].docs.indexed).toBe(3);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -177,10 +176,10 @@ describe('esArchiver: Stats', () => {
|
|||
it('increases the docs.archived count for the index', () => {
|
||||
const stats = createStats('name', new ToolingLog());
|
||||
stats.archivedDoc('index-name');
|
||||
expect(stats.toJSON()['index-name'].docs.archived).to.be(1);
|
||||
expect(stats.toJSON()['index-name'].docs.archived).toBe(1);
|
||||
stats.archivedDoc('index-name');
|
||||
stats.archivedDoc('index-name');
|
||||
expect(stats.toJSON()['index-name'].docs.archived).to.be(3);
|
||||
expect(stats.toJSON()['index-name'].docs.archived).toBe(3);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -189,7 +188,7 @@ describe('esArchiver: Stats', () => {
|
|||
const stats = createStats('name', new ToolingLog());
|
||||
stats.archivedIndex('index1');
|
||||
stats.archivedIndex('index2');
|
||||
expect(Object.keys(stats.toJSON())).to.eql(['index1', 'index2']);
|
||||
expect(Object.keys(stats.toJSON())).toEqual(['index1', 'index2']);
|
||||
});
|
||||
it('returns a deep clone of the stats', () => {
|
||||
const stats = createStats('name', new ToolingLog());
|
24
packages/kbn-eslint-plugin-eslint/jest.config.js
Normal file
24
packages/kbn-eslint-plugin-eslint/jest.config.js
Normal file
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* 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 = {
|
||||
preset: '@kbn/test',
|
||||
rootDir: '../..',
|
||||
roots: ['<rootDir>/packages/kbn-eslint-plugin-eslint'],
|
||||
};
|
|
@ -18,7 +18,7 @@
|
|||
*/
|
||||
|
||||
const { RuleTester } = require('eslint');
|
||||
const rule = require('../disallow_license_headers');
|
||||
const rule = require('./disallow_license_headers');
|
||||
const dedent = require('dedent');
|
||||
|
||||
const ruleTester = new RuleTester({
|
|
@ -29,7 +29,7 @@
|
|||
|
||||
const path = require('path');
|
||||
const { RuleTester } = require('eslint');
|
||||
const rule = require('../no_restricted_paths');
|
||||
const rule = require('./no_restricted_paths');
|
||||
|
||||
const ruleTester = new RuleTester({
|
||||
parser: require.resolve('babel-eslint'),
|
||||
|
@ -43,14 +43,14 @@ ruleTester.run('@kbn/eslint/no-restricted-paths', rule, {
|
|||
valid: [
|
||||
{
|
||||
code: 'import a from "../client/a.js"',
|
||||
filename: path.join(__dirname, './files/no_restricted_paths/server/b.js'),
|
||||
filename: path.join(__dirname, './__fixtures__/no_restricted_paths/server/b.js'),
|
||||
options: [
|
||||
{
|
||||
basePath: __dirname,
|
||||
zones: [
|
||||
{
|
||||
target: 'files/no_restricted_paths/server/**/*',
|
||||
from: 'files/no_restricted_paths/other/**/*',
|
||||
target: '__fixtures__/no_restricted_paths/server/**/*',
|
||||
from: '__fixtures__/no_restricted_paths/other/**/*',
|
||||
},
|
||||
],
|
||||
},
|
||||
|
@ -58,14 +58,14 @@ ruleTester.run('@kbn/eslint/no-restricted-paths', rule, {
|
|||
},
|
||||
{
|
||||
code: 'const a = require("../client/a.js")',
|
||||
filename: path.join(__dirname, './files/no_restricted_paths/server/b.js'),
|
||||
filename: path.join(__dirname, './__fixtures__/no_restricted_paths/server/b.js'),
|
||||
options: [
|
||||
{
|
||||
basePath: __dirname,
|
||||
zones: [
|
||||
{
|
||||
target: 'files/no_restricted_paths/server/**/*',
|
||||
from: 'files/no_restricted_paths/other/**/*',
|
||||
target: '__fixtures__/no_restricted_paths/server/**/*',
|
||||
from: '__fixtures__/no_restricted_paths/other/**/*',
|
||||
},
|
||||
],
|
||||
},
|
||||
|
@ -73,7 +73,7 @@ ruleTester.run('@kbn/eslint/no-restricted-paths', rule, {
|
|||
},
|
||||
{
|
||||
code: 'import b from "../server/b.js"',
|
||||
filename: path.join(__dirname, './files/no_restricted_paths/client/a.js'),
|
||||
filename: path.join(__dirname, './__fixtures__/no_restricted_paths/client/a.js'),
|
||||
options: [
|
||||
{
|
||||
basePath: __dirname,
|
||||
|
@ -98,14 +98,14 @@ ruleTester.run('@kbn/eslint/no-restricted-paths', rule, {
|
|||
},
|
||||
{
|
||||
code: 'notrequire("../server/b.js")',
|
||||
filename: path.join(__dirname, './files/no_restricted_paths/client/a.js'),
|
||||
filename: path.join(__dirname, './__fixtures__/no_restricted_paths/client/a.js'),
|
||||
options: [
|
||||
{
|
||||
basePath: __dirname,
|
||||
zones: [
|
||||
{
|
||||
target: 'files/no_restricted_paths/client/**/*',
|
||||
from: 'files/no_restricted_paths/server/**/*',
|
||||
target: '__fixtures__/no_restricted_paths/client/**/*',
|
||||
from: '__fixtures__/no_restricted_paths/server/**/*',
|
||||
},
|
||||
],
|
||||
},
|
||||
|
@ -142,15 +142,15 @@ ruleTester.run('@kbn/eslint/no-restricted-paths', rule, {
|
|||
|
||||
{
|
||||
code: 'const d = require("./deep/d.js")',
|
||||
filename: path.join(__dirname, './files/no_restricted_paths/server/b.js'),
|
||||
filename: path.join(__dirname, './__fixtures__/no_restricted_paths/server/b.js'),
|
||||
options: [
|
||||
{
|
||||
basePath: __dirname,
|
||||
zones: [
|
||||
{
|
||||
allowSameFolder: true,
|
||||
target: 'files/no_restricted_paths/**/*',
|
||||
from: 'files/no_restricted_paths/**/*',
|
||||
target: '__fixtures__/no_restricted_paths/**/*',
|
||||
from: '__fixtures__/no_restricted_paths/**/*',
|
||||
},
|
||||
],
|
||||
},
|
||||
|
@ -158,15 +158,18 @@ ruleTester.run('@kbn/eslint/no-restricted-paths', rule, {
|
|||
},
|
||||
{
|
||||
code: 'const d = require("./deep/d.js")',
|
||||
filename: path.join(__dirname, './files/no_restricted_paths/server/b.js'),
|
||||
filename: path.join(__dirname, './__fixtures__/no_restricted_paths/server/b.js'),
|
||||
options: [
|
||||
{
|
||||
basePath: __dirname,
|
||||
zones: [
|
||||
{
|
||||
allowSameFolder: true,
|
||||
target: 'files/no_restricted_paths/**/*',
|
||||
from: ['files/no_restricted_paths/**/*', '!files/no_restricted_paths/server/b*'],
|
||||
target: '__fixtures__/no_restricted_paths/**/*',
|
||||
from: [
|
||||
'__fixtures__/no_restricted_paths/**/*',
|
||||
'!__fixtures__/no_restricted_paths/server/b*',
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
|
@ -176,16 +179,16 @@ ruleTester.run('@kbn/eslint/no-restricted-paths', rule, {
|
|||
{
|
||||
// Check if dirs that start with 'index' work correctly.
|
||||
code: 'import { X } from "./index_patterns"',
|
||||
filename: path.join(__dirname, './files/no_restricted_paths/server/b.js'),
|
||||
filename: path.join(__dirname, './__fixtures__/no_restricted_paths/server/b.js'),
|
||||
options: [
|
||||
{
|
||||
basePath: __dirname,
|
||||
zones: [
|
||||
{
|
||||
target: ['files/no_restricted_paths/(public|server)/**/*'],
|
||||
target: ['__fixtures__/no_restricted_paths/(public|server)/**/*'],
|
||||
from: [
|
||||
'files/no_restricted_paths/server/**/*',
|
||||
'!files/no_restricted_paths/server/index.{ts,tsx}',
|
||||
'__fixtures__/no_restricted_paths/server/**/*',
|
||||
'!__fixtures__/no_restricted_paths/server/index.{ts,tsx}',
|
||||
],
|
||||
allowSameFolder: true,
|
||||
},
|
||||
|
@ -198,14 +201,14 @@ ruleTester.run('@kbn/eslint/no-restricted-paths', rule, {
|
|||
invalid: [
|
||||
{
|
||||
code: 'export { b } from "../server/b.js"',
|
||||
filename: path.join(__dirname, './files/no_restricted_paths/client/a.js'),
|
||||
filename: path.join(__dirname, './__fixtures__/no_restricted_paths/client/a.js'),
|
||||
options: [
|
||||
{
|
||||
basePath: __dirname,
|
||||
zones: [
|
||||
{
|
||||
target: 'files/no_restricted_paths/client/**/*',
|
||||
from: 'files/no_restricted_paths/server/**/*',
|
||||
target: '__fixtures__/no_restricted_paths/client/**/*',
|
||||
from: '__fixtures__/no_restricted_paths/server/**/*',
|
||||
},
|
||||
],
|
||||
},
|
||||
|
@ -220,14 +223,14 @@ ruleTester.run('@kbn/eslint/no-restricted-paths', rule, {
|
|||
},
|
||||
{
|
||||
code: 'import b from "../server/b.js"',
|
||||
filename: path.join(__dirname, './files/no_restricted_paths/client/a.js'),
|
||||
filename: path.join(__dirname, './__fixtures__/no_restricted_paths/client/a.js'),
|
||||
options: [
|
||||
{
|
||||
basePath: __dirname,
|
||||
zones: [
|
||||
{
|
||||
target: 'files/no_restricted_paths/client/**/*',
|
||||
from: 'files/no_restricted_paths/server/**/*',
|
||||
target: '__fixtures__/no_restricted_paths/client/**/*',
|
||||
from: '__fixtures__/no_restricted_paths/server/**/*',
|
||||
},
|
||||
],
|
||||
},
|
||||
|
@ -242,18 +245,18 @@ ruleTester.run('@kbn/eslint/no-restricted-paths', rule, {
|
|||
},
|
||||
{
|
||||
code: 'import a from "../client/a"\nimport c from "./c"',
|
||||
filename: path.join(__dirname, './files/no_restricted_paths/server/b.js'),
|
||||
filename: path.join(__dirname, './__fixtures__/no_restricted_paths/server/b.js'),
|
||||
options: [
|
||||
{
|
||||
basePath: __dirname,
|
||||
zones: [
|
||||
{
|
||||
target: 'files/no_restricted_paths/server/**/*',
|
||||
from: 'files/no_restricted_paths/client/**/*',
|
||||
target: '__fixtures__/no_restricted_paths/server/**/*',
|
||||
from: '__fixtures__/no_restricted_paths/client/**/*',
|
||||
},
|
||||
{
|
||||
target: 'files/no_restricted_paths/server/**/*',
|
||||
from: 'files/no_restricted_paths/server/c.js',
|
||||
target: '__fixtures__/no_restricted_paths/server/**/*',
|
||||
from: '__fixtures__/no_restricted_paths/server/c.js',
|
||||
},
|
||||
],
|
||||
},
|
||||
|
@ -273,7 +276,7 @@ ruleTester.run('@kbn/eslint/no-restricted-paths', rule, {
|
|||
},
|
||||
{
|
||||
code: 'const b = require("../server/b.js")',
|
||||
filename: path.join(__dirname, './files/no_restricted_paths/client/a.js'),
|
||||
filename: path.join(__dirname, './__fixtures__/no_restricted_paths/client/a.js'),
|
||||
options: [
|
||||
{
|
||||
basePath: __dirname,
|
||||
|
@ -295,10 +298,10 @@ ruleTester.run('@kbn/eslint/no-restricted-paths', rule, {
|
|||
},
|
||||
{
|
||||
code: 'const b = require("../server/b.js")',
|
||||
filename: path.join(__dirname, './files/no_restricted_paths/client/a.js'),
|
||||
filename: path.join(__dirname, './__fixtures__/no_restricted_paths/client/a.js'),
|
||||
options: [
|
||||
{
|
||||
basePath: path.join(__dirname, 'files', 'no_restricted_paths'),
|
||||
basePath: path.join(__dirname, '__fixtures__', 'no_restricted_paths'),
|
||||
zones: [
|
||||
{
|
||||
target: 'client/**/*',
|
||||
|
@ -318,14 +321,14 @@ ruleTester.run('@kbn/eslint/no-restricted-paths', rule, {
|
|||
|
||||
{
|
||||
code: 'const d = require("./deep/d.js")',
|
||||
filename: path.join(__dirname, './files/no_restricted_paths/server/b.js'),
|
||||
filename: path.join(__dirname, './__fixtures__/no_restricted_paths/server/b.js'),
|
||||
options: [
|
||||
{
|
||||
basePath: __dirname,
|
||||
zones: [
|
||||
{
|
||||
target: 'files/no_restricted_paths/**/*',
|
||||
from: 'files/no_restricted_paths/**/*',
|
||||
target: '__fixtures__/no_restricted_paths/**/*',
|
||||
from: '__fixtures__/no_restricted_paths/**/*',
|
||||
},
|
||||
],
|
||||
},
|
||||
|
@ -342,13 +345,13 @@ ruleTester.run('@kbn/eslint/no-restricted-paths', rule, {
|
|||
{
|
||||
// Does not allow to import deeply within Core, using "src/core/..." Webpack alias.
|
||||
code: 'const d = require("src/core/server/saved_objects")',
|
||||
filename: path.join(__dirname, './files/no_restricted_paths/client/a.js'),
|
||||
filename: path.join(__dirname, './__fixtures__/no_restricted_paths/client/a.js'),
|
||||
options: [
|
||||
{
|
||||
basePath: __dirname,
|
||||
zones: [
|
||||
{
|
||||
target: 'files/no_restricted_paths/**/*',
|
||||
target: '__fixtures__/no_restricted_paths/**/*',
|
||||
from: 'src/core/server/**/*',
|
||||
},
|
||||
],
|
||||
|
@ -366,14 +369,14 @@ ruleTester.run('@kbn/eslint/no-restricted-paths', rule, {
|
|||
{
|
||||
// Does not allow to import "ui/kfetch".
|
||||
code: 'const d = require("ui/kfetch")',
|
||||
filename: path.join(__dirname, './files/no_restricted_paths/client/a.js'),
|
||||
filename: path.join(__dirname, './__fixtures__/no_restricted_paths/client/a.js'),
|
||||
options: [
|
||||
{
|
||||
basePath: __dirname,
|
||||
zones: [
|
||||
{
|
||||
from: ['src/legacy/ui/**/*', 'ui/**/*'],
|
||||
target: 'files/no_restricted_paths/**/*',
|
||||
target: '__fixtures__/no_restricted_paths/**/*',
|
||||
allowSameFolder: true,
|
||||
},
|
||||
],
|
||||
|
@ -391,14 +394,14 @@ ruleTester.run('@kbn/eslint/no-restricted-paths', rule, {
|
|||
{
|
||||
// Does not allow to import deeply "ui/kfetch/public/index".
|
||||
code: 'const d = require("ui/kfetch/public/index")',
|
||||
filename: path.join(__dirname, './files/no_restricted_paths/client/a.js'),
|
||||
filename: path.join(__dirname, './__fixtures__/no_restricted_paths/client/a.js'),
|
||||
options: [
|
||||
{
|
||||
basePath: __dirname,
|
||||
zones: [
|
||||
{
|
||||
from: ['src/legacy/ui/**/*', 'ui/**/*'],
|
||||
target: 'files/no_restricted_paths/**/*',
|
||||
target: '__fixtures__/no_restricted_paths/**/*',
|
||||
allowSameFolder: true,
|
||||
},
|
||||
],
|
||||
|
@ -417,16 +420,16 @@ ruleTester.run('@kbn/eslint/no-restricted-paths', rule, {
|
|||
// Don't use index*.
|
||||
// It won't work with dirs that start with 'index'.
|
||||
code: 'import { X } from "./index_patterns"',
|
||||
filename: path.join(__dirname, './files/no_restricted_paths/server/b.js'),
|
||||
filename: path.join(__dirname, './__fixtures__/no_restricted_paths/server/b.js'),
|
||||
options: [
|
||||
{
|
||||
basePath: __dirname,
|
||||
zones: [
|
||||
{
|
||||
target: ['files/no_restricted_paths/(public|server)/**/*'],
|
||||
target: ['__fixtures__/no_restricted_paths/(public|server)/**/*'],
|
||||
from: [
|
||||
'files/no_restricted_paths/server/**/*',
|
||||
'!files/no_restricted_paths/server/index*',
|
||||
'__fixtures__/no_restricted_paths/server/**/*',
|
||||
'!__fixtures__/no_restricted_paths/server/index*',
|
||||
],
|
||||
allowSameFolder: true,
|
||||
},
|
|
@ -18,7 +18,7 @@
|
|||
*/
|
||||
|
||||
const { RuleTester } = require('eslint');
|
||||
const rule = require('../require_license_header');
|
||||
const rule = require('./require_license_header');
|
||||
const dedent = require('dedent');
|
||||
|
||||
const ruleTester = new RuleTester({
|
|
@ -17,19 +17,18 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
const testSubjSelector = require('../');
|
||||
const expect = require('@kbn/expect');
|
||||
const testSubjSelector = require('./');
|
||||
|
||||
describe('testSubjSelector()', function () {
|
||||
it('converts subjectSelectors to cssSelectors', function () {
|
||||
expect(testSubjSelector('foo bar')).to.eql('[data-test-subj="foo bar"]');
|
||||
expect(testSubjSelector('foo > bar')).to.eql('[data-test-subj="foo"] [data-test-subj="bar"]');
|
||||
expect(testSubjSelector('foo > bar baz')).to.eql(
|
||||
expect(testSubjSelector('foo bar')).toEqual('[data-test-subj="foo bar"]');
|
||||
expect(testSubjSelector('foo > bar')).toEqual('[data-test-subj="foo"] [data-test-subj="bar"]');
|
||||
expect(testSubjSelector('foo > bar baz')).toEqual(
|
||||
'[data-test-subj="foo"] [data-test-subj="bar baz"]'
|
||||
);
|
||||
expect(testSubjSelector('foo> ~bar')).to.eql('[data-test-subj="foo"] [data-test-subj~="bar"]');
|
||||
expect(testSubjSelector('~ foo')).to.eql('[data-test-subj~="foo"]');
|
||||
expect(testSubjSelector('~foo & ~ bar')).to.eql(
|
||||
expect(testSubjSelector('foo> ~bar')).toEqual('[data-test-subj="foo"] [data-test-subj~="bar"]');
|
||||
expect(testSubjSelector('~ foo')).toEqual('[data-test-subj~="foo"]');
|
||||
expect(testSubjSelector('~foo & ~ bar')).toEqual(
|
||||
'[data-test-subj~="foo"][data-test-subj~="bar"]'
|
||||
);
|
||||
});
|
|
@ -17,4 +17,8 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
export { jobs } from './jobs';
|
||||
module.exports = {
|
||||
preset: '@kbn/test',
|
||||
rootDir: '../..',
|
||||
roots: ['<rootDir>/packages/kbn-test-subj-selector'],
|
||||
};
|
|
@ -24,12 +24,12 @@ export default function () {
|
|||
testFiles: [
|
||||
require.resolve('./tests/before_hook'),
|
||||
require.resolve('./tests/it'),
|
||||
require.resolve('./tests/after_hook')
|
||||
require.resolve('./tests/after_hook'),
|
||||
],
|
||||
services: {
|
||||
hookIntoLIfecycle({ getService }) {
|
||||
const log = getService('log');
|
||||
const lifecycle = getService('lifecycle')
|
||||
const lifecycle = getService('lifecycle');
|
||||
|
||||
lifecycle.testFailure.add(async (err, test) => {
|
||||
log.info('testFailure %s %s', err.message, test.fullTitle());
|
||||
|
@ -42,10 +42,10 @@ export default function () {
|
|||
await delay(10);
|
||||
log.info('testHookFailureAfterDelay %s %s', err.message, test.fullTitle());
|
||||
});
|
||||
}
|
||||
},
|
||||
},
|
||||
mochaReporter: {
|
||||
captureLogOutput: false
|
||||
}
|
||||
captureLogOutput: false,
|
||||
},
|
||||
};
|
||||
}
|
|
@ -20,7 +20,5 @@
|
|||
import { resolve } from 'path';
|
||||
|
||||
export default () => ({
|
||||
testFiles: [
|
||||
resolve(__dirname, 'tests.js')
|
||||
]
|
||||
testFiles: [resolve(__dirname, 'tests.js')],
|
||||
});
|
|
@ -20,21 +20,18 @@
|
|||
import { spawnSync } from 'child_process';
|
||||
import { resolve } from 'path';
|
||||
|
||||
import expect from '@kbn/expect';
|
||||
import { REPO_ROOT } from '@kbn/utils';
|
||||
|
||||
const SCRIPT = resolve(REPO_ROOT, 'scripts/functional_test_runner.js');
|
||||
const BASIC_CONFIG = require.resolve('../fixtures/simple_project/config.js');
|
||||
const BASIC_CONFIG = require.resolve('./__fixtures__/simple_project/config.js');
|
||||
|
||||
describe('basic config file with a single app and test', function () {
|
||||
this.timeout(60 * 1000);
|
||||
|
||||
it('runs and prints expected output', () => {
|
||||
const proc = spawnSync(process.execPath, [SCRIPT, '--config', BASIC_CONFIG]);
|
||||
const stdout = proc.stdout.toString('utf8');
|
||||
expect(stdout).to.contain('$BEFORE$');
|
||||
expect(stdout).to.contain('$TESTNAME$');
|
||||
expect(stdout).to.contain('$INTEST$');
|
||||
expect(stdout).to.contain('$AFTER$');
|
||||
expect(stdout).toContain('$BEFORE$');
|
||||
expect(stdout).toContain('$TESTNAME$');
|
||||
expect(stdout).toContain('$INTEST$');
|
||||
expect(stdout).toContain('$AFTER$');
|
||||
});
|
||||
});
|
|
@ -21,15 +21,12 @@ import { spawnSync } from 'child_process';
|
|||
import { resolve } from 'path';
|
||||
|
||||
import stripAnsi from 'strip-ansi';
|
||||
import expect from '@kbn/expect';
|
||||
import { REPO_ROOT } from '@kbn/utils';
|
||||
|
||||
const SCRIPT = resolve(REPO_ROOT, 'scripts/functional_test_runner.js');
|
||||
const FAILURE_HOOKS_CONFIG = require.resolve('../fixtures/failure_hooks/config.js');
|
||||
const FAILURE_HOOKS_CONFIG = require.resolve('./__fixtures__/failure_hooks/config.js');
|
||||
|
||||
describe('failure hooks', function () {
|
||||
this.timeout(60 * 1000);
|
||||
|
||||
it('runs and prints expected output', () => {
|
||||
const proc = spawnSync(process.execPath, [SCRIPT, '--config', FAILURE_HOOKS_CONFIG]);
|
||||
const lines = stripAnsi(proc.stdout.toString('utf8')).split(/\r?\n/);
|
||||
|
@ -37,8 +34,8 @@ describe('failure hooks', function () {
|
|||
{
|
||||
flag: '$FAILING_BEFORE_HOOK$',
|
||||
assert(lines) {
|
||||
expect(lines.shift()).to.match(/info\s+testHookFailure\s+\$FAILING_BEFORE_ERROR\$/);
|
||||
expect(lines.shift()).to.match(
|
||||
expect(lines.shift()).toMatch(/info\s+testHookFailure\s+\$FAILING_BEFORE_ERROR\$/);
|
||||
expect(lines.shift()).toMatch(
|
||||
/info\s+testHookFailureAfterDelay\s+\$FAILING_BEFORE_ERROR\$/
|
||||
);
|
||||
},
|
||||
|
@ -46,16 +43,16 @@ describe('failure hooks', function () {
|
|||
{
|
||||
flag: '$FAILING_TEST$',
|
||||
assert(lines) {
|
||||
expect(lines.shift()).to.match(/global before each/);
|
||||
expect(lines.shift()).to.match(/info\s+testFailure\s+\$FAILING_TEST_ERROR\$/);
|
||||
expect(lines.shift()).to.match(/info\s+testFailureAfterDelay\s+\$FAILING_TEST_ERROR\$/);
|
||||
expect(lines.shift()).toMatch(/global before each/);
|
||||
expect(lines.shift()).toMatch(/info\s+testFailure\s+\$FAILING_TEST_ERROR\$/);
|
||||
expect(lines.shift()).toMatch(/info\s+testFailureAfterDelay\s+\$FAILING_TEST_ERROR\$/);
|
||||
},
|
||||
},
|
||||
{
|
||||
flag: '$FAILING_AFTER_HOOK$',
|
||||
assert(lines) {
|
||||
expect(lines.shift()).to.match(/info\s+testHookFailure\s+\$FAILING_AFTER_ERROR\$/);
|
||||
expect(lines.shift()).to.match(
|
||||
expect(lines.shift()).toMatch(/info\s+testHookFailure\s+\$FAILING_AFTER_ERROR\$/);
|
||||
expect(lines.shift()).toMatch(
|
||||
/info\s+testHookFailureAfterDelay\s+\$FAILING_AFTER_ERROR\$/
|
||||
);
|
||||
},
|
||||
|
@ -70,6 +67,6 @@ describe('failure hooks', function () {
|
|||
}
|
||||
}
|
||||
|
||||
expect(tests).to.have.length(0);
|
||||
expect(tests).toHaveLength(0);
|
||||
});
|
||||
});
|
|
@ -19,8 +19,6 @@
|
|||
|
||||
export default function () {
|
||||
return {
|
||||
testFiles: [
|
||||
'config.1'
|
||||
]
|
||||
testFiles: ['config.1'],
|
||||
};
|
||||
}
|
|
@ -21,9 +21,6 @@ export default async function ({ readConfigFile }) {
|
|||
const config1 = await readConfigFile(require.resolve('./config.1.js'));
|
||||
|
||||
return {
|
||||
testFiles: [
|
||||
...config1.get('testFiles'),
|
||||
'config.2'
|
||||
]
|
||||
testFiles: [...config1.get('testFiles'), 'config.2'],
|
||||
};
|
||||
}
|
|
@ -20,11 +20,9 @@
|
|||
export default async function ({ readConfigFile }) {
|
||||
const config4 = await readConfigFile(require.resolve('./config.4'));
|
||||
return {
|
||||
testFiles: [
|
||||
'baz'
|
||||
],
|
||||
testFiles: ['baz'],
|
||||
screenshots: {
|
||||
...config4.get('screenshots')
|
||||
}
|
||||
...config4.get('screenshots'),
|
||||
},
|
||||
};
|
||||
}
|
|
@ -20,7 +20,7 @@
|
|||
export default function () {
|
||||
return {
|
||||
screenshots: {
|
||||
directory: 'bar'
|
||||
}
|
||||
directory: 'bar',
|
||||
},
|
||||
};
|
||||
}
|
|
@ -19,6 +19,6 @@
|
|||
|
||||
export default async function () {
|
||||
return {
|
||||
foo: 'bar'
|
||||
foo: 'bar',
|
||||
};
|
||||
}
|
|
@ -17,42 +17,40 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
import expect from '@kbn/expect';
|
||||
|
||||
import { ToolingLog } from '@kbn/dev-utils';
|
||||
import { readConfigFile } from '../read_config_file';
|
||||
import { Config } from '../config';
|
||||
import { readConfigFile } from './read_config_file';
|
||||
import { Config } from './config';
|
||||
|
||||
const log = new ToolingLog();
|
||||
|
||||
describe('readConfigFile()', () => {
|
||||
it('reads config from a file, returns an instance of Config class', async () => {
|
||||
const config = await readConfigFile(log, require.resolve('./fixtures/config.1'));
|
||||
expect(config).to.be.a(Config);
|
||||
expect(config.get('testFiles')).to.eql(['config.1']);
|
||||
const config = await readConfigFile(log, require.resolve('./__fixtures__/config.1'));
|
||||
expect(config instanceof Config).toBeTruthy();
|
||||
expect(config.get('testFiles')).toEqual(['config.1']);
|
||||
});
|
||||
|
||||
it('merges setting overrides into log', async () => {
|
||||
const config = await readConfigFile(log, require.resolve('./fixtures/config.1'), {
|
||||
const config = await readConfigFile(log, require.resolve('./__fixtures__/config.1'), {
|
||||
screenshots: {
|
||||
directory: 'foo.bar',
|
||||
},
|
||||
});
|
||||
|
||||
expect(config.get('screenshots.directory')).to.be('foo.bar');
|
||||
expect(config.get('screenshots.directory')).toBe('foo.bar');
|
||||
});
|
||||
|
||||
it('supports loading config files from within config files', async () => {
|
||||
const config = await readConfigFile(log, require.resolve('./fixtures/config.2'));
|
||||
expect(config.get('testFiles')).to.eql(['config.1', 'config.2']);
|
||||
const config = await readConfigFile(log, require.resolve('./__fixtures__/config.2'));
|
||||
expect(config.get('testFiles')).toEqual(['config.1', 'config.2']);
|
||||
});
|
||||
|
||||
it('throws if settings are invalid', async () => {
|
||||
try {
|
||||
await readConfigFile(log, require.resolve('./fixtures/config.invalid'));
|
||||
await readConfigFile(log, require.resolve('./__fixtures__/config.invalid'));
|
||||
throw new Error('expected readConfigFile() to fail');
|
||||
} catch (err) {
|
||||
expect(err.message).to.match(/"foo"/);
|
||||
expect(err.message).toMatch(/"foo"/);
|
||||
}
|
||||
});
|
||||
});
|
|
@ -24,12 +24,11 @@ import { fromNode as fcb } from 'bluebird';
|
|||
import { parseString } from 'xml2js';
|
||||
import del from 'del';
|
||||
import Mocha from 'mocha';
|
||||
import expect from '@kbn/expect';
|
||||
import { getUniqueJunitReportPath } from '../../report_path';
|
||||
import { getUniqueJunitReportPath } from '../report_path';
|
||||
|
||||
import { setupJUnitReportGeneration } from '../junit_report_generation';
|
||||
import { setupJUnitReportGeneration } from './junit_report_generation';
|
||||
|
||||
const PROJECT_DIR = resolve(__dirname, 'fixtures/project');
|
||||
const PROJECT_DIR = resolve(__dirname, '__fixtures__/project');
|
||||
const DURATION_REGEX = /^\d+\.\d{3}$/;
|
||||
const ISO_DATE_SEC_REGEX = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}$/;
|
||||
const XML_PATH = getUniqueJunitReportPath(PROJECT_DIR, 'test');
|
||||
|
@ -54,7 +53,7 @@ describe('dev/mocha/junit report generation', () => {
|
|||
const report = await fcb((cb) => parseString(readFileSync(XML_PATH), cb));
|
||||
|
||||
// test case results are wrapped in <testsuites></testsuites>
|
||||
expect(report).to.eql({
|
||||
expect(report).toEqual({
|
||||
testsuites: {
|
||||
testsuite: [report.testsuites.testsuite[0]],
|
||||
},
|
||||
|
@ -62,9 +61,9 @@ describe('dev/mocha/junit report generation', () => {
|
|||
|
||||
// the single <testsuite> element at the root contains summary data for all tests results
|
||||
const [testsuite] = report.testsuites.testsuite;
|
||||
expect(testsuite.$.time).to.match(DURATION_REGEX);
|
||||
expect(testsuite.$.timestamp).to.match(ISO_DATE_SEC_REGEX);
|
||||
expect(testsuite).to.eql({
|
||||
expect(testsuite.$.time).toMatch(DURATION_REGEX);
|
||||
expect(testsuite.$.timestamp).toMatch(ISO_DATE_SEC_REGEX);
|
||||
expect(testsuite).toEqual({
|
||||
$: {
|
||||
failures: '2',
|
||||
name: 'test',
|
||||
|
@ -78,13 +77,13 @@ describe('dev/mocha/junit report generation', () => {
|
|||
|
||||
// there are actually only three tests, but since the hook failed
|
||||
// it is reported as a test failure
|
||||
expect(testsuite.testcase).to.have.length(4);
|
||||
expect(testsuite.testcase).toHaveLength(4);
|
||||
const [testPass, testFail, beforeEachFail, testSkipped] = testsuite.testcase;
|
||||
|
||||
const sharedClassname = testPass.$.classname;
|
||||
expect(sharedClassname).to.match(/^test\.test[^\.]js$/);
|
||||
expect(testPass.$.time).to.match(DURATION_REGEX);
|
||||
expect(testPass).to.eql({
|
||||
expect(sharedClassname).toMatch(/^test\.test[^\.]js$/);
|
||||
expect(testPass.$.time).toMatch(DURATION_REGEX);
|
||||
expect(testPass).toEqual({
|
||||
$: {
|
||||
classname: sharedClassname,
|
||||
name: 'SUITE works',
|
||||
|
@ -94,9 +93,10 @@ describe('dev/mocha/junit report generation', () => {
|
|||
'system-out': testPass['system-out'],
|
||||
});
|
||||
|
||||
expect(testFail.$.time).to.match(DURATION_REGEX);
|
||||
expect(testFail.failure[0]).to.match(/Error: FORCE_TEST_FAIL\n.+fixtures.project.test.js/);
|
||||
expect(testFail).to.eql({
|
||||
expect(testFail.$.time).toMatch(DURATION_REGEX);
|
||||
|
||||
expect(testFail.failure[0]).toMatch(/Error: FORCE_TEST_FAIL/);
|
||||
expect(testFail).toEqual({
|
||||
$: {
|
||||
classname: sharedClassname,
|
||||
name: 'SUITE fails',
|
||||
|
@ -107,12 +107,10 @@ describe('dev/mocha/junit report generation', () => {
|
|||
failure: [testFail.failure[0]],
|
||||
});
|
||||
|
||||
expect(beforeEachFail.$.time).to.match(DURATION_REGEX);
|
||||
expect(beforeEachFail.failure).to.have.length(1);
|
||||
expect(beforeEachFail.failure[0]).to.match(
|
||||
/Error: FORCE_HOOK_FAIL\n.+fixtures.project.test.js/
|
||||
);
|
||||
expect(beforeEachFail).to.eql({
|
||||
expect(beforeEachFail.$.time).toMatch(DURATION_REGEX);
|
||||
expect(beforeEachFail.failure).toHaveLength(1);
|
||||
expect(beforeEachFail.failure[0]).toMatch(/Error: FORCE_HOOK_FAIL/);
|
||||
expect(beforeEachFail).toEqual({
|
||||
$: {
|
||||
classname: sharedClassname,
|
||||
name: 'SUITE SUB_SUITE "before each" hook: fail hook for "never runs"',
|
||||
|
@ -123,7 +121,7 @@ describe('dev/mocha/junit report generation', () => {
|
|||
failure: [beforeEachFail.failure[0]],
|
||||
});
|
||||
|
||||
expect(testSkipped).to.eql({
|
||||
expect(testSkipped).toEqual({
|
||||
$: {
|
||||
classname: sharedClassname,
|
||||
name: 'SUITE SUB_SUITE never runs',
|
|
@ -19,74 +19,68 @@
|
|||
|
||||
import { resolve, sep } from 'path';
|
||||
|
||||
import expect from '@kbn/expect';
|
||||
|
||||
import { File } from '../file';
|
||||
import { File } from './file';
|
||||
|
||||
const HERE = resolve(__dirname, __filename);
|
||||
|
||||
describe('dev/File', () => {
|
||||
describe('constructor', () => {
|
||||
it('throws if path is not a string', () => {
|
||||
expect(() => new File()).to.throwError();
|
||||
expect(() => new File(1)).to.throwError();
|
||||
expect(() => new File(false)).to.throwError();
|
||||
expect(() => new File(null)).to.throwError();
|
||||
expect(() => new File()).toThrow();
|
||||
expect(() => new File(1)).toThrow();
|
||||
expect(() => new File(false)).toThrow();
|
||||
expect(() => new File(null)).toThrow();
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getRelativePath()', () => {
|
||||
it('returns the path relative to the repo root', () => {
|
||||
const file = new File(HERE);
|
||||
expect(file.getRelativePath()).to.eql(['src', 'dev', '__tests__', 'file.js'].join(sep));
|
||||
expect(file.getRelativePath()).toBe(['src', 'dev', 'file.test.js'].join(sep));
|
||||
});
|
||||
});
|
||||
|
||||
describe('#isJs()', () => {
|
||||
it('returns true if extension is .js', () => {
|
||||
const file = new File('file.js');
|
||||
expect(file.isJs()).to.eql(true);
|
||||
expect(file.isJs()).toBe(true);
|
||||
});
|
||||
it('returns false if extension is .xml', () => {
|
||||
const file = new File('file.xml');
|
||||
expect(file.isJs()).to.eql(false);
|
||||
expect(file.isJs()).toBe(false);
|
||||
});
|
||||
it('returns false if extension is .css', () => {
|
||||
const file = new File('file.css');
|
||||
expect(file.isJs()).to.eql(false);
|
||||
expect(file.isJs()).toBe(false);
|
||||
});
|
||||
it('returns false if extension is .html', () => {
|
||||
const file = new File('file.html');
|
||||
expect(file.isJs()).to.eql(false);
|
||||
expect(file.isJs()).toBe(false);
|
||||
});
|
||||
it('returns false if file has no extension', () => {
|
||||
const file = new File('file');
|
||||
expect(file.isJs()).to.eql(false);
|
||||
expect(file.isJs()).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getRelativeParentDirs()', () => {
|
||||
it('returns the parents of a file, stopping at the repo root, in descending order', () => {
|
||||
const file = new File(HERE);
|
||||
expect(file.getRelativeParentDirs()).to.eql([
|
||||
['src', 'dev', '__tests__'].join(sep), // src/dev/__tests__
|
||||
['src', 'dev'].join(sep), // src/dev
|
||||
'src',
|
||||
]);
|
||||
expect(file.getRelativeParentDirs()).toStrictEqual([['src', 'dev'].join(sep), 'src']);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#toString()', () => {
|
||||
it('returns the relativePath', () => {
|
||||
const file = new File(HERE);
|
||||
expect(file.toString()).to.eql(file.getRelativePath());
|
||||
expect(file.toString()).toBe(file.getRelativePath());
|
||||
});
|
||||
});
|
||||
|
||||
describe('#toJSON()', () => {
|
||||
it('returns the relativePath', () => {
|
||||
const file = new File(HERE);
|
||||
expect(file.toJSON()).to.eql(file.getRelativePath());
|
||||
expect(file.toJSON()).toBe(file.getRelativePath());
|
||||
});
|
||||
});
|
||||
});
|
|
@ -19,9 +19,7 @@
|
|||
|
||||
import { resolve } from 'path';
|
||||
|
||||
import expect from '@kbn/expect';
|
||||
|
||||
import { assertLicensesValid } from '../valid';
|
||||
import { assertLicensesValid } from './valid';
|
||||
|
||||
const ROOT = resolve(__dirname, '../../../../');
|
||||
const NODE_MODULES = resolve(ROOT, './node_modules');
|
||||
|
@ -42,7 +40,7 @@ describe('tasks/lib/licenses', () => {
|
|||
packages: [PACKAGE],
|
||||
validLicenses: [...PACKAGE.licenses],
|
||||
})
|
||||
).to.be(undefined);
|
||||
).toBe(undefined);
|
||||
});
|
||||
|
||||
it('throw an error when the packages license is invalid', () => {
|
||||
|
@ -51,7 +49,7 @@ describe('tasks/lib/licenses', () => {
|
|||
packages: [PACKAGE],
|
||||
validLicenses: [`not ${PACKAGE.licenses[0]}`],
|
||||
});
|
||||
}).to.throwError(PACKAGE.name);
|
||||
}).toThrow(PACKAGE.name);
|
||||
});
|
||||
|
||||
it('throws an error when the package has no licenses', () => {
|
||||
|
@ -65,7 +63,7 @@ describe('tasks/lib/licenses', () => {
|
|||
],
|
||||
validLicenses: [...PACKAGE.licenses],
|
||||
});
|
||||
}).to.throwError(PACKAGE.name);
|
||||
}).toThrow(PACKAGE.name);
|
||||
});
|
||||
|
||||
it('includes the relative path to packages in error message', () => {
|
||||
|
@ -76,8 +74,8 @@ describe('tasks/lib/licenses', () => {
|
|||
});
|
||||
throw new Error('expected assertLicensesValid() to throw');
|
||||
} catch (error) {
|
||||
expect(error.message).to.contain(PACKAGE.relative);
|
||||
expect(error.message).to.not.contain(PACKAGE.directory);
|
||||
expect(error.message).toContain(PACKAGE.relative);
|
||||
expect(error.message).not.toContain(PACKAGE.directory);
|
||||
}
|
||||
});
|
||||
});
|
|
@ -18,10 +18,9 @@
|
|||
*/
|
||||
|
||||
import fs from 'fs';
|
||||
import { engines } from '../../../package.json';
|
||||
import { engines } from '../../package.json';
|
||||
import { promisify } from 'util';
|
||||
const readFile = promisify(fs.readFile);
|
||||
import expect from '@kbn/expect';
|
||||
|
||||
describe('All configs should use a single version of Node', () => {
|
||||
it('should compare .node-version and .nvmrc', async () => {
|
||||
|
@ -30,13 +29,13 @@ describe('All configs should use a single version of Node', () => {
|
|||
readFile('./.nvmrc', { encoding: 'utf-8' }),
|
||||
]);
|
||||
|
||||
expect(nodeVersion.trim()).to.be(nvmrc.trim());
|
||||
expect(nodeVersion.trim()).toBe(nvmrc.trim());
|
||||
});
|
||||
|
||||
it('should compare .node-version and engines.node from package.json', async () => {
|
||||
const nodeVersion = await readFile('./.node-version', {
|
||||
encoding: 'utf-8',
|
||||
});
|
||||
expect(nodeVersion.trim()).to.be(engines.node);
|
||||
expect(nodeVersion.trim()).toBe(engines.node);
|
||||
});
|
||||
});
|
|
@ -17,27 +17,26 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
import { unset } from '../unset';
|
||||
import expect from '@kbn/expect';
|
||||
import { unset } from './unset';
|
||||
|
||||
describe('unset(obj, key)', function () {
|
||||
describe('invalid input', function () {
|
||||
it('should do nothing if not given an object', function () {
|
||||
const obj = 'hello';
|
||||
unset(obj, 'e');
|
||||
expect(obj).to.equal('hello');
|
||||
expect(obj).toBe('hello');
|
||||
});
|
||||
|
||||
it('should do nothing if not given a key', function () {
|
||||
const obj = { one: 1 };
|
||||
unset(obj);
|
||||
expect(obj).to.eql({ one: 1 });
|
||||
expect(obj).toEqual({ one: 1 });
|
||||
});
|
||||
|
||||
it('should do nothing if given an empty string as a key', function () {
|
||||
const obj = { one: 1 };
|
||||
unset(obj, '');
|
||||
expect(obj).to.eql({ one: 1 });
|
||||
expect(obj).toEqual({ one: 1 });
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -50,12 +49,12 @@ describe('unset(obj, key)', function () {
|
|||
|
||||
it('should remove the param using a string key', function () {
|
||||
unset(obj, 'two');
|
||||
expect(obj).to.eql({ one: 1, deep: { three: 3, four: 4 } });
|
||||
expect(obj).toEqual({ one: 1, deep: { three: 3, four: 4 } });
|
||||
});
|
||||
|
||||
it('should remove the param using an array key', function () {
|
||||
unset(obj, ['two']);
|
||||
expect(obj).to.eql({ one: 1, deep: { three: 3, four: 4 } });
|
||||
expect(obj).toEqual({ one: 1, deep: { three: 3, four: 4 } });
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -68,12 +67,12 @@ describe('unset(obj, key)', function () {
|
|||
|
||||
it('should remove the param using a string key', function () {
|
||||
unset(obj, 'deep.three');
|
||||
expect(obj).to.eql({ one: 1, two: 2, deep: { four: 4 } });
|
||||
expect(obj).toEqual({ one: 1, two: 2, deep: { four: 4 } });
|
||||
});
|
||||
|
||||
it('should remove the param using an array key', function () {
|
||||
unset(obj, ['deep', 'three']);
|
||||
expect(obj).to.eql({ one: 1, two: 2, deep: { four: 4 } });
|
||||
expect(obj).toEqual({ one: 1, two: 2, deep: { four: 4 } });
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -81,22 +80,22 @@ describe('unset(obj, key)', function () {
|
|||
it('should clear object if only value is removed', function () {
|
||||
const obj = { one: { two: { three: 3 } } };
|
||||
unset(obj, 'one.two.three');
|
||||
expect(obj).to.eql({});
|
||||
expect(obj).toEqual({});
|
||||
});
|
||||
|
||||
it('should clear object if no props are left', function () {
|
||||
const obj = { one: { two: { three: 3 } } };
|
||||
unset(obj, 'one.two');
|
||||
expect(obj).to.eql({});
|
||||
expect(obj).toEqual({});
|
||||
});
|
||||
|
||||
it('should remove deep property, then clear the object', function () {
|
||||
const obj = { one: { two: { three: 3, four: 4 } } };
|
||||
unset(obj, 'one.two.three');
|
||||
expect(obj).to.eql({ one: { two: { four: 4 } } });
|
||||
expect(obj).toEqual({ one: { two: { four: 4 } } });
|
||||
|
||||
unset(obj, 'one.two.four');
|
||||
expect(obj).to.eql({});
|
||||
expect(obj).toEqual({});
|
||||
});
|
||||
});
|
||||
});
|
|
@ -17,7 +17,6 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
import expect from '@kbn/expect';
|
||||
import moment from 'moment';
|
||||
import { getElasticsearchProxyConfig } from '../lib/elasticsearch_proxy_config';
|
||||
import https from 'https';
|
||||
|
@ -39,7 +38,7 @@ describe('plugins/console', function () {
|
|||
...getDefaultElasticsearchConfig(),
|
||||
requestTimeout: moment.duration(value),
|
||||
});
|
||||
expect(proxyConfig.timeout).to.be(value);
|
||||
expect(proxyConfig.timeout).toBe(value);
|
||||
});
|
||||
|
||||
it(`uses https.Agent when url's protocol is https`, function () {
|
||||
|
@ -47,12 +46,12 @@ describe('plugins/console', function () {
|
|||
...getDefaultElasticsearchConfig(),
|
||||
hosts: ['https://localhost:9200'],
|
||||
});
|
||||
expect(agent).to.be.a(https.Agent);
|
||||
expect(agent instanceof https.Agent).toBeTruthy();
|
||||
});
|
||||
|
||||
it(`uses http.Agent when url's protocol is http`, function () {
|
||||
const { agent } = getElasticsearchProxyConfig(getDefaultElasticsearchConfig());
|
||||
expect(agent).to.be.a(http.Agent);
|
||||
expect(agent instanceof http.Agent).toBeTruthy();
|
||||
});
|
||||
|
||||
describe('ssl', function () {
|
||||
|
@ -69,7 +68,7 @@ describe('plugins/console', function () {
|
|||
...config,
|
||||
ssl: { ...config.ssl, verificationMode: 'none' },
|
||||
});
|
||||
expect(agent.options.rejectUnauthorized).to.be(false);
|
||||
expect(agent.options.rejectUnauthorized).toBe(false);
|
||||
});
|
||||
|
||||
it('sets rejectUnauthorized to true when verificationMode is certificate', function () {
|
||||
|
@ -77,7 +76,7 @@ describe('plugins/console', function () {
|
|||
...config,
|
||||
ssl: { ...config.ssl, verificationMode: 'certificate' },
|
||||
});
|
||||
expect(agent.options.rejectUnauthorized).to.be(true);
|
||||
expect(agent.options.rejectUnauthorized).toBe(true);
|
||||
});
|
||||
|
||||
it('sets checkServerIdentity to not check hostname when verificationMode is certificate', function () {
|
||||
|
@ -92,11 +91,9 @@ describe('plugins/console', function () {
|
|||
},
|
||||
};
|
||||
|
||||
expect(agent.options.checkServerIdentity)
|
||||
.withArgs('right.com', cert)
|
||||
.to.not.throwException();
|
||||
expect(() => agent.options.checkServerIdentity('right.com', cert)).not.toThrow();
|
||||
const result = agent.options.checkServerIdentity('right.com', cert);
|
||||
expect(result).to.be(undefined);
|
||||
expect(result).toBe(undefined);
|
||||
});
|
||||
|
||||
it('sets rejectUnauthorized to true when verificationMode is full', function () {
|
||||
|
@ -105,7 +102,7 @@ describe('plugins/console', function () {
|
|||
ssl: { ...config.ssl, verificationMode: 'full' },
|
||||
});
|
||||
|
||||
expect(agent.options.rejectUnauthorized).to.be(true);
|
||||
expect(agent.options.rejectUnauthorized).toBe(true);
|
||||
});
|
||||
|
||||
it(`doesn't set checkServerIdentity when verificationMode is full`, function () {
|
||||
|
@ -114,7 +111,7 @@ describe('plugins/console', function () {
|
|||
ssl: { ...config.ssl, verificationMode: 'full' },
|
||||
});
|
||||
|
||||
expect(agent.options.checkServerIdentity).to.be(undefined);
|
||||
expect(agent.options.checkServerIdentity).toBe(undefined);
|
||||
});
|
||||
|
||||
it(`sets ca when certificateAuthorities are specified`, function () {
|
||||
|
@ -123,7 +120,7 @@ describe('plugins/console', function () {
|
|||
ssl: { ...config.ssl, certificateAuthorities: ['content-of-some-path'] },
|
||||
});
|
||||
|
||||
expect(agent.options.ca).to.contain('content-of-some-path');
|
||||
expect(agent.options.ca).toContain('content-of-some-path');
|
||||
});
|
||||
|
||||
describe('when alwaysPresentCertificate is false', () => {
|
||||
|
@ -138,8 +135,8 @@ describe('plugins/console', function () {
|
|||
},
|
||||
});
|
||||
|
||||
expect(agent.options.cert).to.be(undefined);
|
||||
expect(agent.options.key).to.be(undefined);
|
||||
expect(agent.options.cert).toBe(undefined);
|
||||
expect(agent.options.key).toBe(undefined);
|
||||
});
|
||||
|
||||
it(`doesn't set passphrase when certificate, key and keyPassphrase are specified`, function () {
|
||||
|
@ -154,7 +151,7 @@ describe('plugins/console', function () {
|
|||
},
|
||||
});
|
||||
|
||||
expect(agent.options.passphrase).to.be(undefined);
|
||||
expect(agent.options.passphrase).toBe(undefined);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -170,8 +167,8 @@ describe('plugins/console', function () {
|
|||
},
|
||||
});
|
||||
|
||||
expect(agent.options.cert).to.be('content-of-some-path');
|
||||
expect(agent.options.key).to.be('content-of-another-path');
|
||||
expect(agent.options.cert).toBe('content-of-some-path');
|
||||
expect(agent.options.key).toBe('content-of-another-path');
|
||||
});
|
||||
|
||||
it(`sets passphrase when certificate, key and keyPassphrase are specified`, function () {
|
||||
|
@ -186,7 +183,7 @@ describe('plugins/console', function () {
|
|||
},
|
||||
});
|
||||
|
||||
expect(agent.options.passphrase).to.be('secret');
|
||||
expect(agent.options.passphrase).toBe('secret');
|
||||
});
|
||||
|
||||
it(`doesn't set cert when only certificate path is specified`, async function () {
|
||||
|
@ -200,8 +197,8 @@ describe('plugins/console', function () {
|
|||
},
|
||||
});
|
||||
|
||||
expect(agent.options.cert).to.be(undefined);
|
||||
expect(agent.options.key).to.be(undefined);
|
||||
expect(agent.options.cert).toBe(undefined);
|
||||
expect(agent.options.key).toBe(undefined);
|
||||
});
|
||||
|
||||
it(`doesn't set key when only key path is specified`, async function () {
|
||||
|
@ -215,8 +212,8 @@ describe('plugins/console', function () {
|
|||
},
|
||||
});
|
||||
|
||||
expect(agent.options.cert).to.be(undefined);
|
||||
expect(agent.options.key).to.be(undefined);
|
||||
expect(agent.options.cert).toBe(undefined);
|
||||
expect(agent.options.key).toBe(undefined);
|
||||
});
|
||||
});
|
||||
});
|
|
@ -17,14 +17,11 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
/* eslint-env mocha */
|
||||
|
||||
import expect from '@kbn/expect';
|
||||
import sinon from 'sinon';
|
||||
import https, { Agent as HttpsAgent } from 'https';
|
||||
import { parse as parseUrl } from 'url';
|
||||
|
||||
import { ProxyConfig } from '../lib/proxy_config';
|
||||
import { ProxyConfig } from './proxy_config';
|
||||
|
||||
const matchGoogle = {
|
||||
protocol: 'https',
|
||||
|
@ -51,10 +48,10 @@ describe('ProxyConfig', function () {
|
|||
},
|
||||
});
|
||||
|
||||
expect(config.sslAgent).to.be.a(https.Agent);
|
||||
expect(config.sslAgent instanceof https.Agent).toBeTruthy();
|
||||
sinon.assert.calledOnce(https.Agent);
|
||||
const sslAgentOpts = https.Agent.firstCall.args[0];
|
||||
expect(sslAgentOpts).to.eql({
|
||||
expect(sslAgentOpts).toEqual({
|
||||
ca: ['content-of-some-path'],
|
||||
cert: undefined,
|
||||
key: undefined,
|
||||
|
@ -70,10 +67,10 @@ describe('ProxyConfig', function () {
|
|||
},
|
||||
});
|
||||
|
||||
expect(config.sslAgent).to.be.a(https.Agent);
|
||||
expect(config.sslAgent instanceof https.Agent).toBeTruthy();
|
||||
sinon.assert.calledOnce(https.Agent);
|
||||
const sslAgentOpts = https.Agent.firstCall.args[0];
|
||||
expect(sslAgentOpts).to.eql({
|
||||
expect(sslAgentOpts).toEqual({
|
||||
ca: undefined,
|
||||
cert: 'content-of-some-path',
|
||||
key: 'content-of-another-path',
|
||||
|
@ -91,10 +88,10 @@ describe('ProxyConfig', function () {
|
|||
},
|
||||
});
|
||||
|
||||
expect(config.sslAgent).to.be.a(https.Agent);
|
||||
expect(config.sslAgent instanceof https.Agent).toBeTruthy();
|
||||
sinon.assert.calledOnce(https.Agent);
|
||||
const sslAgentOpts = https.Agent.firstCall.args[0];
|
||||
expect(sslAgentOpts).to.eql({
|
||||
expect(sslAgentOpts).toEqual({
|
||||
ca: ['content-of-some-path'],
|
||||
cert: 'content-of-another-path',
|
||||
key: 'content-of-yet-another-path',
|
||||
|
@ -111,7 +108,7 @@ describe('ProxyConfig', function () {
|
|||
timeout: 100,
|
||||
});
|
||||
|
||||
expect(config.getForParsedUri(parsedLocalEs)).to.eql({});
|
||||
expect(config.getForParsedUri(parsedLocalEs)).toEqual({});
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -123,7 +120,7 @@ describe('ProxyConfig', function () {
|
|||
timeout: football,
|
||||
});
|
||||
|
||||
expect(config.getForParsedUri(parsedGoogle).timeout).to.be(football);
|
||||
expect(config.getForParsedUri(parsedGoogle).timeout).toBe(football);
|
||||
});
|
||||
|
||||
it('assigns ssl.verify to rejectUnauthorized', function () {
|
||||
|
@ -135,7 +132,7 @@ describe('ProxyConfig', function () {
|
|||
},
|
||||
});
|
||||
|
||||
expect(config.getForParsedUri(parsedGoogle).rejectUnauthorized).to.be(football);
|
||||
expect(config.getForParsedUri(parsedGoogle).rejectUnauthorized).toBe(football);
|
||||
});
|
||||
|
||||
describe('uri us http', function () {
|
||||
|
@ -147,8 +144,8 @@ describe('ProxyConfig', function () {
|
|||
},
|
||||
});
|
||||
|
||||
expect(config.sslAgent).to.be.an(HttpsAgent);
|
||||
expect(config.getForParsedUri({ protocol: 'http:' }).agent).to.be(undefined);
|
||||
expect(config.sslAgent instanceof HttpsAgent).toBeTruthy();
|
||||
expect(config.getForParsedUri({ protocol: 'http:' }).agent).toBe(undefined);
|
||||
});
|
||||
});
|
||||
describe('cert is set', function () {
|
||||
|
@ -159,8 +156,8 @@ describe('ProxyConfig', function () {
|
|||
},
|
||||
});
|
||||
|
||||
expect(config.sslAgent).to.be.an(HttpsAgent);
|
||||
expect(config.getForParsedUri({ protocol: 'http:' }).agent).to.be(undefined);
|
||||
expect(config.sslAgent instanceof HttpsAgent).toBeTruthy();
|
||||
expect(config.getForParsedUri({ protocol: 'http:' }).agent).toBe(undefined);
|
||||
});
|
||||
});
|
||||
describe('key is set', function () {
|
||||
|
@ -171,8 +168,8 @@ describe('ProxyConfig', function () {
|
|||
},
|
||||
});
|
||||
|
||||
expect(config.sslAgent).to.be.an(HttpsAgent);
|
||||
expect(config.getForParsedUri({ protocol: 'http:' }).agent).to.be(undefined);
|
||||
expect(config.sslAgent instanceof HttpsAgent).toBeTruthy();
|
||||
expect(config.getForParsedUri({ protocol: 'http:' }).agent).toBe(undefined);
|
||||
});
|
||||
});
|
||||
describe('cert + key are set', function () {
|
||||
|
@ -184,8 +181,8 @@ describe('ProxyConfig', function () {
|
|||
},
|
||||
});
|
||||
|
||||
expect(config.sslAgent).to.be.an(HttpsAgent);
|
||||
expect(config.getForParsedUri({ protocol: 'http:' }).agent).to.be(undefined);
|
||||
expect(config.sslAgent instanceof HttpsAgent).toBeTruthy();
|
||||
expect(config.getForParsedUri({ protocol: 'http:' }).agent).toBe(undefined);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -199,8 +196,8 @@ describe('ProxyConfig', function () {
|
|||
},
|
||||
});
|
||||
|
||||
expect(config.sslAgent).to.be.an(HttpsAgent);
|
||||
expect(config.getForParsedUri({ protocol: 'https:' }).agent).to.be(config.sslAgent);
|
||||
expect(config.sslAgent instanceof HttpsAgent).toBeTruthy();
|
||||
expect(config.getForParsedUri({ protocol: 'https:' }).agent).toBe(config.sslAgent);
|
||||
});
|
||||
});
|
||||
describe('cert is set', function () {
|
||||
|
@ -211,8 +208,8 @@ describe('ProxyConfig', function () {
|
|||
},
|
||||
});
|
||||
|
||||
expect(config.sslAgent).to.be.an(HttpsAgent);
|
||||
expect(config.getForParsedUri({ protocol: 'https:' }).agent).to.be(config.sslAgent);
|
||||
expect(config.sslAgent instanceof HttpsAgent).toBeTruthy();
|
||||
expect(config.getForParsedUri({ protocol: 'https:' }).agent).toBe(config.sslAgent);
|
||||
});
|
||||
});
|
||||
describe('key is set', function () {
|
||||
|
@ -223,8 +220,8 @@ describe('ProxyConfig', function () {
|
|||
},
|
||||
});
|
||||
|
||||
expect(config.sslAgent).to.be.an(HttpsAgent);
|
||||
expect(config.getForParsedUri({ protocol: 'https:' }).agent).to.be(config.sslAgent);
|
||||
expect(config.sslAgent instanceof HttpsAgent).toBeTruthy();
|
||||
expect(config.getForParsedUri({ protocol: 'https:' }).agent).toBe(config.sslAgent);
|
||||
});
|
||||
});
|
||||
describe('cert + key are set', function () {
|
||||
|
@ -236,8 +233,8 @@ describe('ProxyConfig', function () {
|
|||
},
|
||||
});
|
||||
|
||||
expect(config.sslAgent).to.be.an(HttpsAgent);
|
||||
expect(config.getForParsedUri({ protocol: 'https:' }).agent).to.be(config.sslAgent);
|
||||
expect(config.sslAgent instanceof HttpsAgent).toBeTruthy();
|
||||
expect(config.getForParsedUri({ protocol: 'https:' }).agent).toBe(config.sslAgent);
|
||||
});
|
||||
});
|
||||
});
|
|
@ -17,14 +17,11 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
/* eslint-env mocha */
|
||||
|
||||
import expect from '@kbn/expect';
|
||||
import sinon from 'sinon';
|
||||
import fs from 'fs';
|
||||
import { Agent as HttpsAgent } from 'https';
|
||||
|
||||
import { ProxyConfigCollection } from '../lib/proxy_config_collection';
|
||||
import { ProxyConfigCollection } from './proxy_config_collection';
|
||||
|
||||
describe('ProxyConfigCollection', function () {
|
||||
beforeEach(function () {
|
||||
|
@ -88,61 +85,61 @@ describe('ProxyConfigCollection', function () {
|
|||
|
||||
describe('http://localhost:5601', function () {
|
||||
it('defaults to the first matching timeout', function () {
|
||||
expect(getTimeout('http://localhost:5601')).to.be(3);
|
||||
expect(getTimeout('http://localhost:5601')).toBe(3);
|
||||
});
|
||||
});
|
||||
|
||||
describe('https://localhost:5601/.kibana', function () {
|
||||
it('defaults to the first matching timeout', function () {
|
||||
expect(getTimeout('https://localhost:5601/.kibana')).to.be(1);
|
||||
expect(getTimeout('https://localhost:5601/.kibana')).toBe(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('http://localhost:5602', function () {
|
||||
it('defaults to the first matching timeout', function () {
|
||||
expect(getTimeout('http://localhost:5602')).to.be(4);
|
||||
expect(getTimeout('http://localhost:5602')).toBe(4);
|
||||
});
|
||||
});
|
||||
|
||||
describe('https://localhost:5602', function () {
|
||||
it('defaults to the first matching timeout', function () {
|
||||
expect(getTimeout('https://localhost:5602')).to.be(4);
|
||||
expect(getTimeout('https://localhost:5602')).toBe(4);
|
||||
});
|
||||
});
|
||||
|
||||
describe('http://localhost:5603', function () {
|
||||
it('defaults to the first matching timeout', function () {
|
||||
expect(getTimeout('http://localhost:5603')).to.be(4);
|
||||
expect(getTimeout('http://localhost:5603')).toBe(4);
|
||||
});
|
||||
});
|
||||
|
||||
describe('https://localhost:5603', function () {
|
||||
it('defaults to the first matching timeout', function () {
|
||||
expect(getTimeout('https://localhost:5603')).to.be(4);
|
||||
expect(getTimeout('https://localhost:5603')).toBe(4);
|
||||
});
|
||||
});
|
||||
|
||||
describe('https://localhost:5601/index', function () {
|
||||
it('defaults to the first matching timeout', function () {
|
||||
expect(getTimeout('https://localhost:5601/index')).to.be(2);
|
||||
expect(getTimeout('https://localhost:5601/index')).toBe(2);
|
||||
});
|
||||
});
|
||||
|
||||
describe('http://localhost:5601/index', function () {
|
||||
it('defaults to the first matching timeout', function () {
|
||||
expect(getTimeout('http://localhost:5601/index')).to.be(3);
|
||||
expect(getTimeout('http://localhost:5601/index')).toBe(3);
|
||||
});
|
||||
});
|
||||
|
||||
describe('https://localhost:5601/index/type', function () {
|
||||
it('defaults to the first matching timeout', function () {
|
||||
expect(getTimeout('https://localhost:5601/index/type')).to.be(2);
|
||||
expect(getTimeout('https://localhost:5601/index/type')).toBe(2);
|
||||
});
|
||||
});
|
||||
|
||||
describe('http://notlocalhost', function () {
|
||||
it('defaults to the first matching timeout', function () {
|
||||
expect(getTimeout('http://notlocalhost')).to.be(5);
|
||||
expect(getTimeout('http://notlocalhost')).toBe(5);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -162,14 +159,14 @@ describe('ProxyConfigCollection', function () {
|
|||
|
||||
it('verifies for config that produces ssl agent', function () {
|
||||
const conf = makeCollection().configForUri('https://es.internal.org/_search');
|
||||
expect(conf.agent.options).to.have.property('rejectUnauthorized', true);
|
||||
expect(conf.agent).to.be.an(HttpsAgent);
|
||||
expect(conf.agent.options).toHaveProperty('rejectUnauthorized', true);
|
||||
expect(conf.agent instanceof HttpsAgent).toBeTruthy();
|
||||
});
|
||||
|
||||
it('disabled verification for * config', function () {
|
||||
const conf = makeCollection().configForUri('https://extenal.org/_search');
|
||||
expect(conf).to.have.property('rejectUnauthorized', false);
|
||||
expect(conf.agent).to.be(undefined);
|
||||
expect(conf).toHaveProperty('rejectUnauthorized', false);
|
||||
expect(conf.agent).toBe(undefined);
|
||||
});
|
||||
});
|
||||
});
|
|
@ -17,39 +17,38 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
import expect from '@kbn/expect';
|
||||
import { setHeaders } from '../lib';
|
||||
import { setHeaders } from './set_headers';
|
||||
|
||||
describe('#set_headers', function () {
|
||||
it('throws if not given an object as the first argument', function () {
|
||||
const fn = () => setHeaders(null, {});
|
||||
expect(fn).to.throwError();
|
||||
expect(fn).toThrow();
|
||||
});
|
||||
|
||||
it('throws if not given an object as the second argument', function () {
|
||||
const fn = () => setHeaders({}, null);
|
||||
expect(fn).to.throwError();
|
||||
expect(fn).toThrow();
|
||||
});
|
||||
|
||||
it('returns a new object', function () {
|
||||
const originalHeaders = {};
|
||||
const newHeaders = {};
|
||||
const returnedHeaders = setHeaders(originalHeaders, newHeaders);
|
||||
expect(returnedHeaders).not.to.be(originalHeaders);
|
||||
expect(returnedHeaders).not.to.be(newHeaders);
|
||||
expect(returnedHeaders).not.toBe(originalHeaders);
|
||||
expect(returnedHeaders).not.toBe(newHeaders);
|
||||
});
|
||||
|
||||
it('returns object with newHeaders merged with originalHeaders', function () {
|
||||
const originalHeaders = { foo: 'bar' };
|
||||
const newHeaders = { one: 'two' };
|
||||
const returnedHeaders = setHeaders(originalHeaders, newHeaders);
|
||||
expect(returnedHeaders).to.eql({ foo: 'bar', one: 'two' });
|
||||
expect(returnedHeaders).toEqual({ foo: 'bar', one: 'two' });
|
||||
});
|
||||
|
||||
it('returns object where newHeaders takes precedence for any matching keys', function () {
|
||||
const originalHeaders = { foo: 'bar' };
|
||||
const newHeaders = { one: 'two', foo: 'notbar' };
|
||||
const returnedHeaders = setHeaders(originalHeaders, newHeaders);
|
||||
expect(returnedHeaders).to.eql({ foo: 'notbar', one: 'two' });
|
||||
expect(returnedHeaders).toEqual({ foo: 'notbar', one: 'two' });
|
||||
});
|
||||
});
|
|
@ -17,8 +17,7 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
/* eslint-env mocha */
|
||||
import { WildcardMatcher } from '../lib/wildcard_matcher';
|
||||
import { WildcardMatcher } from './wildcard_matcher';
|
||||
|
||||
function should(candidate, ...constructorArgs) {
|
||||
if (!new WildcardMatcher(...constructorArgs).match(candidate)) {
|
|
@ -1,111 +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.
|
||||
*/
|
||||
|
||||
export const jobs = [
|
||||
{
|
||||
job_id: 'foo1',
|
||||
rollup_index: 'foo_rollup',
|
||||
index_pattern: 'foo-*',
|
||||
fields: {
|
||||
node: [
|
||||
{
|
||||
agg: 'terms',
|
||||
},
|
||||
],
|
||||
temperature: [
|
||||
{
|
||||
agg: 'min',
|
||||
},
|
||||
{
|
||||
agg: 'max',
|
||||
},
|
||||
{
|
||||
agg: 'sum',
|
||||
},
|
||||
],
|
||||
timestamp: [
|
||||
{
|
||||
agg: 'date_histogram',
|
||||
time_zone: 'UTC',
|
||||
interval: '1h',
|
||||
delay: '7d',
|
||||
},
|
||||
],
|
||||
voltage: [
|
||||
{
|
||||
agg: 'histogram',
|
||||
interval: 5,
|
||||
},
|
||||
{
|
||||
agg: 'sum',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
job_id: 'foo2',
|
||||
rollup_index: 'foo_rollup',
|
||||
index_pattern: 'foo-*',
|
||||
fields: {
|
||||
host: [
|
||||
{
|
||||
agg: 'terms',
|
||||
},
|
||||
],
|
||||
timestamp: [
|
||||
{
|
||||
agg: 'date_histogram',
|
||||
time_zone: 'UTC',
|
||||
interval: '1h',
|
||||
delay: '7d',
|
||||
},
|
||||
],
|
||||
voltage: [
|
||||
{
|
||||
agg: 'histogram',
|
||||
interval: 20,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
job_id: 'foo3',
|
||||
rollup_index: 'foo_rollup',
|
||||
index_pattern: 'foo-*',
|
||||
fields: {
|
||||
timestamp: [
|
||||
{
|
||||
agg: 'date_histogram',
|
||||
time_zone: 'PST',
|
||||
interval: '1h',
|
||||
delay: '7d',
|
||||
},
|
||||
],
|
||||
voltage: [
|
||||
{
|
||||
agg: 'histogram',
|
||||
interval: 5,
|
||||
},
|
||||
{
|
||||
agg: 'sum',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
];
|
|
@ -17,46 +17,137 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
import expect from '@kbn/expect';
|
||||
import { areJobsCompatible, mergeJobConfigurations } from '../jobs_compatibility';
|
||||
import { jobs } from './fixtures';
|
||||
import { areJobsCompatible, mergeJobConfigurations } from './jobs_compatibility';
|
||||
|
||||
const jobs = [
|
||||
{
|
||||
job_id: 'foo1',
|
||||
rollup_index: 'foo_rollup',
|
||||
index_pattern: 'foo-*',
|
||||
fields: {
|
||||
node: [
|
||||
{
|
||||
agg: 'terms',
|
||||
},
|
||||
],
|
||||
temperature: [
|
||||
{
|
||||
agg: 'min',
|
||||
},
|
||||
{
|
||||
agg: 'max',
|
||||
},
|
||||
{
|
||||
agg: 'sum',
|
||||
},
|
||||
],
|
||||
timestamp: [
|
||||
{
|
||||
agg: 'date_histogram',
|
||||
time_zone: 'UTC',
|
||||
interval: '1h',
|
||||
delay: '7d',
|
||||
},
|
||||
],
|
||||
voltage: [
|
||||
{
|
||||
agg: 'histogram',
|
||||
interval: 5,
|
||||
},
|
||||
{
|
||||
agg: 'sum',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
job_id: 'foo2',
|
||||
rollup_index: 'foo_rollup',
|
||||
index_pattern: 'foo-*',
|
||||
fields: {
|
||||
host: [
|
||||
{
|
||||
agg: 'terms',
|
||||
},
|
||||
],
|
||||
timestamp: [
|
||||
{
|
||||
agg: 'date_histogram',
|
||||
time_zone: 'UTC',
|
||||
interval: '1h',
|
||||
delay: '7d',
|
||||
},
|
||||
],
|
||||
voltage: [
|
||||
{
|
||||
agg: 'histogram',
|
||||
interval: 20,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
job_id: 'foo3',
|
||||
rollup_index: 'foo_rollup',
|
||||
index_pattern: 'foo-*',
|
||||
fields: {
|
||||
timestamp: [
|
||||
{
|
||||
agg: 'date_histogram',
|
||||
time_zone: 'PST',
|
||||
interval: '1h',
|
||||
delay: '7d',
|
||||
},
|
||||
],
|
||||
voltage: [
|
||||
{
|
||||
agg: 'histogram',
|
||||
interval: 5,
|
||||
},
|
||||
{
|
||||
agg: 'sum',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
describe('areJobsCompatible', () => {
|
||||
it('should return false for invalid jobs arg', () => {
|
||||
expect(areJobsCompatible(123)).to.eql(false);
|
||||
expect(areJobsCompatible('foo')).to.eql(false);
|
||||
expect(areJobsCompatible(123)).toEqual(false);
|
||||
expect(areJobsCompatible('foo')).toEqual(false);
|
||||
});
|
||||
|
||||
it('should return true for no jobs or one job', () => {
|
||||
expect(areJobsCompatible()).to.eql(true);
|
||||
expect(areJobsCompatible([])).to.eql(true);
|
||||
expect(areJobsCompatible([jobs[1]])).to.eql(true);
|
||||
expect(areJobsCompatible()).toEqual(true);
|
||||
expect(areJobsCompatible([])).toEqual(true);
|
||||
expect(areJobsCompatible([jobs[1]])).toEqual(true);
|
||||
});
|
||||
|
||||
it('should return true for 2 or more compatible jobs', () => {
|
||||
expect(areJobsCompatible([jobs[0], jobs[1]])).to.eql(true);
|
||||
expect(areJobsCompatible([jobs[1], jobs[0], jobs[1]])).to.eql(true);
|
||||
expect(areJobsCompatible([jobs[0], jobs[1]])).toEqual(true);
|
||||
expect(areJobsCompatible([jobs[1], jobs[0], jobs[1]])).toEqual(true);
|
||||
});
|
||||
|
||||
it('should return false for 2 or more incompatible jobs', () => {
|
||||
expect(areJobsCompatible([jobs[1], jobs[2]])).to.eql(false);
|
||||
expect(areJobsCompatible([jobs[2], jobs[1], jobs[0]])).to.eql(false);
|
||||
expect(areJobsCompatible([jobs[1], jobs[2]])).toEqual(false);
|
||||
expect(areJobsCompatible([jobs[2], jobs[1], jobs[0]])).toEqual(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('mergeJobConfigurations', () => {
|
||||
it('should throw an error for null/invalid jobs', () => {
|
||||
expect(mergeJobConfigurations).withArgs().to.throwException();
|
||||
expect(mergeJobConfigurations).withArgs(null).to.throwException();
|
||||
expect(mergeJobConfigurations).withArgs(undefined).to.throwException();
|
||||
expect(mergeJobConfigurations).withArgs(true).to.throwException();
|
||||
expect(mergeJobConfigurations).withArgs('foo').to.throwException();
|
||||
expect(mergeJobConfigurations).withArgs(123).to.throwException();
|
||||
expect(mergeJobConfigurations).withArgs([]).to.throwException();
|
||||
expect(() => mergeJobConfigurations()).toThrow();
|
||||
expect(() => mergeJobConfigurations(null)).toThrow();
|
||||
expect(() => mergeJobConfigurations(undefined)).toThrow();
|
||||
expect(() => mergeJobConfigurations(true)).toThrow();
|
||||
expect(() => mergeJobConfigurations('foo')).toThrow();
|
||||
expect(() => mergeJobConfigurations(123)).toThrow();
|
||||
expect(() => mergeJobConfigurations([])).toThrow();
|
||||
});
|
||||
|
||||
it('should return aggregations for one job', () => {
|
||||
expect(mergeJobConfigurations([jobs[0]])).to.eql({
|
||||
expect(mergeJobConfigurations([jobs[0]])).toEqual({
|
||||
aggs: {
|
||||
terms: {
|
||||
node: {
|
||||
|
@ -100,7 +191,7 @@ describe('mergeJobConfigurations', () => {
|
|||
});
|
||||
|
||||
it('should return merged aggregations for 2 jobs', () => {
|
||||
expect(mergeJobConfigurations([jobs[0], jobs[1]])).to.eql({
|
||||
expect(mergeJobConfigurations([jobs[0], jobs[1]])).toEqual({
|
||||
aggs: {
|
||||
terms: {
|
||||
node: {
|
||||
|
@ -147,6 +238,6 @@ describe('mergeJobConfigurations', () => {
|
|||
});
|
||||
|
||||
it('should throw an error if jobs are not compatible', () => {
|
||||
expect(mergeJobConfigurations).withArgs([jobs[0], jobs[1], jobs[2]]).to.throwException();
|
||||
expect(() => mergeJobConfigurations([jobs[0], jobs[1], jobs[2]])).toThrow();
|
||||
});
|
||||
});
|
Loading…
Reference in a new issue