Skip to content

Commit

Permalink
chore(NA): move reporting plugin test fixtures out of __tests__ folder (
Browse files Browse the repository at this point in the history
#87888) (#87963)

* chore(NA): move reporting plugin test fixtures out of __tests__ folder

* fix(NA): fix a test import
  • Loading branch information
mistic authored Jan 12, 2021
1 parent 1729061 commit 9922002
Show file tree
Hide file tree
Showing 12 changed files with 48 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@

import fs from 'fs';
import crypto from 'crypto';
import expect from '@kbn/expect';
import { resolve } from 'path';

import { extract } from '../extract';
import { ExtractError } from '../extract_error';
import { extract } from './extract';
import { ExtractError } from './extract_error';
import { promisify } from 'util';

const FIXTURES_FOLDER = resolve(__dirname, '__fixtures__');
Expand Down Expand Up @@ -71,18 +70,18 @@ describe('extract', () => {
thrownException = e;
}

expect(thrownException).to.be.an(ExtractError);
expect(thrownException).toBeInstanceOf(ExtractError);
});

it('successfully extracts a valid zip file to the given target', async () => {
await extract(SRC_FILE_COMPRESSED_ZIP, EXTRACT_TARGET_FOLDER);

const stats = fs.statSync(EXTRACT_TARGET_FILE);
expect(stats).to.be.an(Object);
expect(stats).toBeInstanceOf(fs.Stats);

const srcFileHash = await fileHash(SRC_FILE_UNCOMPRESSED);
const targetFileHash = await fileHash(EXTRACT_TARGET_FILE);
expect(targetFileHash).to.eql(srcFileHash);
expect(targetFileHash).toEqual(srcFileHash);
});

if (isWindows) {
Expand All @@ -100,8 +99,8 @@ describe('extract', () => {
thrownException = e;
}

expect(thrownException).to.be.an(ExtractError);
expect(thrownException.cause.code).to.eql('EACCES');
expect(thrownException).toBeInstanceOf(ExtractError);
expect(thrownException.cause.code).toEqual('EACCES');
});
}
});
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/reporting/server/lib/create_worker.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { createWorkerFactory } from './create_worker';
// @ts-ignore
import { Esqueue } from './esqueue';
// @ts-ignore
import { ClientMock } from './esqueue/__tests__/fixtures/legacy_elasticsearch';
import { ClientMock } from './esqueue/__fixtures__/legacy_elasticsearch';
import { ExportTypesRegistry } from './export_types_registry';

const logger = createMockLevelLogger();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,54 +4,53 @@
* you may not use this file except in compliance with the Elastic License.
*/

import expect from '@kbn/expect';
import { WorkerTimeoutError, UnspecifiedWorkerError } from '../../helpers/errors';
import { WorkerTimeoutError, UnspecifiedWorkerError } from './errors';

describe('custom errors', function () {
describe('WorkerTimeoutError', function () {
it('should be function', () => {
expect(WorkerTimeoutError).to.be.a('function');
expect(typeof WorkerTimeoutError).toBe('function');
});

it('should have a name', function () {
const err = new WorkerTimeoutError('timeout error');
expect(err).to.have.property('name', 'WorkerTimeoutError');
expect(err).toHaveProperty('name', 'WorkerTimeoutError');
});

it('should take a jobId property', function () {
const err = new WorkerTimeoutError('timeout error', { jobId: 'il7hl34rqlo8ro' });
expect(err).to.have.property('jobId', 'il7hl34rqlo8ro');
expect(err).toHaveProperty('jobId', 'il7hl34rqlo8ro');
});

it('should take a timeout property', function () {
const err = new WorkerTimeoutError('timeout error', { timeout: 15000 });
expect(err).to.have.property('timeout', 15000);
expect(err).toHaveProperty('timeout', 15000);
});

it('should be stringifyable', function () {
const err = new WorkerTimeoutError('timeout error');
expect(`${err}`).to.equal('WorkerTimeoutError: timeout error');
expect(`${err}`).toEqual('WorkerTimeoutError: timeout error');
});
});

describe('UnspecifiedWorkerError', function () {
it('should be function', () => {
expect(UnspecifiedWorkerError).to.be.a('function');
expect(typeof UnspecifiedWorkerError).toBe('function');
});

it('should have a name', function () {
const err = new UnspecifiedWorkerError('unspecified error');
expect(err).to.have.property('name', 'UnspecifiedWorkerError');
expect(err).toHaveProperty('name', 'UnspecifiedWorkerError');
});

it('should take a jobId property', function () {
const err = new UnspecifiedWorkerError('unspecified error', { jobId: 'il7hl34rqlo8ro' });
expect(err).to.have.property('jobId', 'il7hl34rqlo8ro');
expect(err).toHaveProperty('jobId', 'il7hl34rqlo8ro');
});

it('should be stringifyable', function () {
const err = new UnspecifiedWorkerError('unspecified error');
expect(`${err}`).to.equal('UnspecifiedWorkerError: unspecified error');
expect(`${err}`).toEqual('UnspecifiedWorkerError: unspecified error');
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,18 @@ import expect from '@kbn/expect';
import sinon from 'sinon';
import proxyquire from 'proxyquire';
import { noop, times } from 'lodash';
import { constants } from '../constants';
import { ClientMock } from './fixtures/legacy_elasticsearch';
import { JobMock } from './fixtures/job';
import { WorkerMock } from './fixtures/worker';
import { constants } from './constants';
import { ClientMock } from './__fixtures__/legacy_elasticsearch';
import { JobMock } from './__fixtures__/job';
import { WorkerMock } from './__fixtures__/worker';

const { Esqueue } = proxyquire.noPreserveCache()('../index', {
const { Esqueue } = proxyquire.noPreserveCache()('./index', {
'./job': { Job: JobMock },
'./worker': { Worker: WorkerMock },
});

describe('Esqueue class', function () {
// TODO: tests were not running and are not up to date
describe.skip('Esqueue class', function () {
let client;

beforeEach(function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import expect from '@kbn/expect';
import sinon from 'sinon';
import moment from 'moment';
import { noop, random, get, find, identity } from 'lodash';
import { ClientMock } from './fixtures/legacy_elasticsearch';
import { QueueMock } from './fixtures/queue';
import { formatJobObject, getUpdatedDocPath, Worker } from '../worker';
import { constants } from '../constants';
import { ClientMock } from './__fixtures__/legacy_elasticsearch';
import { QueueMock } from './__fixtures__/queue';
import { formatJobObject, getUpdatedDocPath, Worker } from './worker';
import { constants } from './constants';

const anchor = '2016-04-02T01:02:03.456'; // saturday
const defaults = {
Expand All @@ -26,9 +26,10 @@ const defaultWorkerOptions = {
intervalErrorMultiplier: 10,
};

describe('Worker class', function () {
// TODO: tests were not running and are not up to date
describe.skip('Worker class', function () {
// some of these tests might be a little slow, give them a little extra time
this.timeout(10000);
jest.setTimeout(10000);

let anchorMoment;
let clock;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import expect from '@kbn/expect';
import { ExportTypesRegistry } from '../export_types_registry';
import { ExportTypesRegistry } from './export_types_registry';

describe('ExportTypesRegistry', function () {
let exportTypesRegistry;
Expand All @@ -17,30 +16,30 @@ describe('ExportTypesRegistry', function () {
it(`doesn't throw an Error when using a new type with a string id`, function () {
expect(() => {
exportTypesRegistry.register({ id: 'foo' });
}).to.not.throwError();
}).not.toThrow();
});

it('throws an Error when registering a type without an id', function () {
expect(() => {
exportTypesRegistry.register({});
}).to.throwError();
}).toThrow();
});

it('throws an Error when registering a type with an integer id', function () {
expect(() => {
exportTypesRegistry.register({ id: 1 });
}).to.throwError();
}).toThrow();
});

it('throws an Error when registering the same id twice', function () {
const id = 'foo';
expect(() => {
exportTypesRegistry.register({ id });
}).to.not.throwError();
}).not.toThrow();

expect(() => {
exportTypesRegistry.register({ id });
}).to.throwError();
}).toThrow();
});
});

Expand All @@ -50,20 +49,20 @@ describe('ExportTypesRegistry', function () {
const obj = { id };
exportTypesRegistry.register(obj);
exportTypesRegistry.register({ id: 'bar' });
expect(exportTypesRegistry.getById(id)).to.be(obj);
expect(exportTypesRegistry.getById(id)).toBe(obj);
});

it(`throws an Error if the id isn't found`, function () {
expect(() => {
exportTypesRegistry.getById('foo');
}).to.throwError();
}).toThrow();
});
});

describe('getAll', function () {
it('returns an empty Iterator if no objects have been registered', function () {
const array = Array.from(exportTypesRegistry.getAll());
expect(array.length).to.be(0);
expect(array.length).toBe(0);
});

it('returns all objects that have been registered', function () {
Expand All @@ -72,23 +71,23 @@ describe('ExportTypesRegistry', function () {
const objs = [obj1, obj2];
objs.forEach((obj) => exportTypesRegistry.register(obj));
const all = Array.from(exportTypesRegistry.getAll());
expect(all).to.contain(obj1);
expect(all).to.contain(obj2);
expect(all).toContain(obj1);
expect(all).toContain(obj2);
});
});

describe('getSize', function () {
it('returns 0 initially', function () {
const size = exportTypesRegistry.getSize();
expect(size).to.be(0);
expect(size).toBe(0);
});

it('returns the number of objects that have been added', function () {
exportTypesRegistry.register({ id: 'foo' });
exportTypesRegistry.register({ id: 'bar' });
exportTypesRegistry.register({ id: 'baz' });
const size = exportTypesRegistry.getSize();
expect(size).to.be(3);
expect(size).toBe(3);
});
});

Expand All @@ -97,7 +96,7 @@ describe('ExportTypesRegistry', function () {
const prop = 'fooProp';
const match = { id: 'foo', prop };
[match, { id: 'bar' }, { id: 'baz' }].forEach((obj) => exportTypesRegistry.register(obj));
expect(exportTypesRegistry.get((item) => item.prop === prop)).to.be(match);
expect(exportTypesRegistry.get((item) => item.prop === prop)).toBe(match);
});

it('throws Error if multiple items match predicate', function () {
Expand All @@ -108,7 +107,7 @@ describe('ExportTypesRegistry', function () {
].forEach((obj) => exportTypesRegistry.register(obj));
expect(() => {
exportTypesRegistry.get((item) => item.prop === prop);
}).to.throwError();
}).toThrow();
});

it('throws Error if no items match predicate', function () {
Expand All @@ -119,7 +118,7 @@ describe('ExportTypesRegistry', function () {
].forEach((obj) => exportTypesRegistry.register(obj));
expect(() => {
exportTypesRegistry.get((item) => item.prop !== prop);
}).to.throwError();
}).toThrow();
});
});
});

0 comments on commit 9922002

Please sign in to comment.