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

Chore/migrate mocha tests #1553

Merged
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 @@ -28,10 +28,10 @@
* under the License.
*/

const dateMath = require('../index');
const moment = require('moment');
const sinon = require('sinon');
const expect = require('@osd/expect');
import dateMath from './index';
import moment from 'moment';
import sinon from 'sinon';
import expect from '@osd/expect';

/**
* Require a new instance of the moment library, bypassing the require cache.
Expand All @@ -43,6 +43,7 @@ const expect = require('@osd/expect');
* of moment, by deleting the require cache and require the library again.
*/
function momentClone() {
jest.resetModules();
delete require.cache[require.resolve('moment')];
return require('moment');
}
Expand All @@ -58,7 +59,7 @@ describe('dateMath', function () {

describe('errors', function () {
it('should return undefined if passed something falsy', function () {
expect(dateMath.parse()).to.be(undefined);
expect(dateMath.parse('')).to.be(undefined);
});

it('should return undefined if I pass an operator besides [+-/]', function () {
Expand All @@ -82,11 +83,13 @@ describe('dateMath', function () {

describe('forceNow', function () {
it('should throw an Error if passed a string', function () {
// @ts-ignore bad arg
const fn = () => dateMath.parse('now', { forceNow: '2000-01-01T00:00:00.000Z' });
expect(fn).to.throwError();
});

it('should throw an Error if passed a moment', function () {
// @ts-ignore bad arg
expect(() => dateMath.parse('now', { forceNow: moment() })).to.throwError();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,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
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,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'),
Expand All @@ -54,37 +54,37 @@ ruleTester.run('@osd/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, './testfiles/no_restricted_paths/server/b.js'),
options: [
{
basePath: __dirname,
zones: [
{
target: 'files/no_restricted_paths/server/**/*',
from: 'files/no_restricted_paths/other/**/*',
target: 'testfiles/no_restricted_paths/server/**/*',
from: 'testfiles/no_restricted_paths/other/**/*',
},
],
},
],
},
{
code: 'const a = require("../client/a.js")',
filename: path.join(__dirname, './files/no_restricted_paths/server/b.js'),
filename: path.join(__dirname, './testfiles/no_restricted_paths/server/b.js'),
options: [
{
basePath: __dirname,
zones: [
{
target: 'files/no_restricted_paths/server/**/*',
from: 'files/no_restricted_paths/other/**/*',
target: 'testfiles/no_restricted_paths/server/**/*',
from: 'testfiles/no_restricted_paths/other/**/*',
},
],
},
],
},
{
code: 'import b from "../server/b.js"',
filename: path.join(__dirname, './files/no_restricted_paths/client/a.js'),
filename: path.join(__dirname, './testfiles/no_restricted_paths/client/a.js'),
options: [
{
basePath: __dirname,
Expand All @@ -109,14 +109,14 @@ ruleTester.run('@osd/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, './testfiles/no_restricted_paths/client/a.js'),
options: [
{
basePath: __dirname,
zones: [
{
target: 'files/no_restricted_paths/client/**/*',
from: 'files/no_restricted_paths/server/**/*',
target: 'testfiles/no_restricted_paths/client/**/*',
from: 'testfiles/no_restricted_paths/server/**/*',
},
],
},
Expand Down Expand Up @@ -153,31 +153,34 @@ ruleTester.run('@osd/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, './testfiles/no_restricted_paths/server/b.js'),
options: [
{
basePath: __dirname,
zones: [
{
allowSameFolder: true,
target: 'files/no_restricted_paths/**/*',
from: 'files/no_restricted_paths/**/*',
target: 'testfiles/no_restricted_paths/**/*',
from: 'testfiles/no_restricted_paths/**/*',
},
],
},
],
},
{
code: 'const d = require("./deep/d.js")',
filename: path.join(__dirname, './files/no_restricted_paths/server/b.js'),
filename: path.join(__dirname, './testfiles/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: 'testfiles/no_restricted_paths/**/*',
from: [
'testfiles/no_restricted_paths/**/*',
'!testfiles/no_restricted_paths/server/b*',
],
},
],
},
Expand All @@ -187,16 +190,16 @@ ruleTester.run('@osd/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, './testfiles/no_restricted_paths/server/b.js'),
options: [
{
basePath: __dirname,
zones: [
{
target: ['files/no_restricted_paths/(public|server)/**/*'],
target: ['testfiles/no_restricted_paths/(public|server)/**/*'],
from: [
'files/no_restricted_paths/server/**/*',
'!files/no_restricted_paths/server/index.{ts,tsx}',
'testfiles/no_restricted_paths/server/**/*',
'!testfiles/no_restricted_paths/server/index.{ts,tsx}',
],
allowSameFolder: true,
},
Expand All @@ -209,14 +212,14 @@ ruleTester.run('@osd/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, './testfiles/no_restricted_paths/client/a.js'),
options: [
{
basePath: __dirname,
zones: [
{
target: 'files/no_restricted_paths/client/**/*',
from: 'files/no_restricted_paths/server/**/*',
target: 'testfiles/no_restricted_paths/client/**/*',
from: 'testfiles/no_restricted_paths/server/**/*',
},
],
},
Expand All @@ -231,14 +234,14 @@ ruleTester.run('@osd/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, './testfiles/no_restricted_paths/client/a.js'),
options: [
{
basePath: __dirname,
zones: [
{
target: 'files/no_restricted_paths/client/**/*',
from: 'files/no_restricted_paths/server/**/*',
target: 'testfiles/no_restricted_paths/client/**/*',
from: 'testfiles/no_restricted_paths/server/**/*',
},
],
},
Expand All @@ -253,18 +256,18 @@ ruleTester.run('@osd/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, './testfiles/no_restricted_paths/server/b.js'),
options: [
{
basePath: __dirname,
zones: [
{
target: 'files/no_restricted_paths/server/**/*',
from: 'files/no_restricted_paths/client/**/*',
target: 'testfiles/no_restricted_paths/server/**/*',
from: 'testfiles/no_restricted_paths/client/**/*',
},
{
target: 'files/no_restricted_paths/server/**/*',
from: 'files/no_restricted_paths/server/c.js',
target: 'testfiles/no_restricted_paths/server/**/*',
from: 'testfiles/no_restricted_paths/server/c.js',
},
],
},
Expand All @@ -284,7 +287,7 @@ ruleTester.run('@osd/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, './testfiles/no_restricted_paths/client/a.js'),
options: [
{
basePath: __dirname,
Expand All @@ -306,10 +309,10 @@ ruleTester.run('@osd/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, './testfiles/no_restricted_paths/client/a.js'),
options: [
{
basePath: path.join(__dirname, 'files', 'no_restricted_paths'),
basePath: path.join(__dirname, 'testfiles', 'no_restricted_paths'),
zones: [
{
target: 'client/**/*',
Expand All @@ -329,14 +332,14 @@ ruleTester.run('@osd/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, './testfiles/no_restricted_paths/server/b.js'),
options: [
{
basePath: __dirname,
zones: [
{
target: 'files/no_restricted_paths/**/*',
from: 'files/no_restricted_paths/**/*',
target: 'testfiles/no_restricted_paths/**/*',
from: 'testfiles/no_restricted_paths/**/*',
},
],
},
Expand All @@ -353,13 +356,13 @@ ruleTester.run('@osd/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, './testfiles/no_restricted_paths/client/a.js'),
options: [
{
basePath: __dirname,
zones: [
{
target: 'files/no_restricted_paths/**/*',
target: 'testfiles/no_restricted_paths/**/*',
from: 'src/core/server/**/*',
},
],
Expand All @@ -377,14 +380,14 @@ ruleTester.run('@osd/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, './testfiles/no_restricted_paths/client/a.js'),
options: [
{
basePath: __dirname,
zones: [
{
from: ['src/legacy/ui/**/*', 'ui/**/*'],
target: 'files/no_restricted_paths/**/*',
target: 'testfiles/no_restricted_paths/**/*',
allowSameFolder: true,
},
],
Expand All @@ -402,14 +405,14 @@ ruleTester.run('@osd/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, './testfiles/no_restricted_paths/client/a.js'),
options: [
{
basePath: __dirname,
zones: [
{
from: ['src/legacy/ui/**/*', 'ui/**/*'],
target: 'files/no_restricted_paths/**/*',
target: 'testfiles/no_restricted_paths/**/*',
allowSameFolder: true,
},
],
Expand All @@ -428,16 +431,16 @@ ruleTester.run('@osd/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, './testfiles/no_restricted_paths/server/b.js'),
options: [
{
basePath: __dirname,
zones: [
{
target: ['files/no_restricted_paths/(public|server)/**/*'],
target: ['testfiles/no_restricted_paths/(public|server)/**/*'],
from: [
'files/no_restricted_paths/server/**/*',
'!files/no_restricted_paths/server/index*',
'testfiles/no_restricted_paths/server/**/*',
'!testfiles/no_restricted_paths/server/index*',
],
allowSameFolder: true,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,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({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ import { createGunzip } from 'zlib';

import expect from '@osd/expect';

import { createListStream, createPromiseFromStreams, createConcatStream } from '../../streams';
import { createListStream, createPromiseFromStreams, createConcatStream } from '../streams';

import { createFormatArchiveStreams } from '../format';
import { createFormatArchiveStreams } from './format';

const INPUTS = [1, 2, { foo: 'bar' }, [1, 2]];
const INPUT_JSON = INPUTS.map((i) => JSON.stringify(i, null, 2)).join('\n\n');
Expand Down
Loading