Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Converts some Mocha unit tests to Jest #85514

Merged
merged 3 commits into from
Dec 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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);
Expand All @@ -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');
});
});

Expand All @@ -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');
});
});

Expand All @@ -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 () => {
Expand All @@ -114,16 +113,16 @@ 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', () => {
it('no debug logging', async () => {
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');
});
});
});
Expand All @@ -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 () => {
Expand All @@ -148,16 +147,16 @@ 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', () => {
it('no debug logging', async () => {
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');
});
});
});
Expand All @@ -166,21 +165,21 @@ 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);
});
});

describe('#archivedDoc(index)', () => {
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);
});
});

Expand All @@ -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());
Expand Down
24 changes: 24 additions & 0 deletions packages/kbn-eslint-plugin-eslint/jest.config.js
Original file line number Diff line number Diff line change
@@ -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'],
};
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
Loading