-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch upstream/7.x
- Loading branch information
Showing
277 changed files
with
5,585 additions
and
1,944 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
import { commonBasePath } from './run'; | ||
|
||
describe('commonBasePath', () => { | ||
it('returns a common path', () => { | ||
expect(commonBasePath(['foo/bar/baz', 'foo/bar/quux', 'foo/bar'])).toBe('foo/bar'); | ||
}); | ||
|
||
it('handles an empty array', () => { | ||
expect(commonBasePath([])).toBe(''); | ||
}); | ||
|
||
it('handles no common path', () => { | ||
expect(commonBasePath(['foo', 'bar'])).toBe(''); | ||
}); | ||
|
||
it('matches full paths', () => { | ||
expect(commonBasePath(['foo/bar', 'foo/bar_baz'])).toBe('foo'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
// Run Jest tests | ||
// | ||
// Provides Jest with `--config` to the first jest.config.js file found in the current | ||
// directory, or while going up in the directory chain. If the current working directory | ||
// is nested under the config path, a pattern will be provided to Jest to only run the | ||
// tests within that directory. | ||
// | ||
// Any additional options passed will be forwarded to Jest. | ||
// | ||
// See all cli options in https://facebook.github.io/jest/docs/cli.html | ||
|
||
import { resolve, relative, sep as osSep } from 'path'; | ||
import { existsSync } from 'fs'; | ||
import { run } from 'jest'; | ||
import { buildArgv } from 'jest-cli/build/cli'; | ||
import { ToolingLog } from '@kbn/dev-utils'; | ||
|
||
// yarn test:jest src/core/server/saved_objects | ||
// yarn test:jest src/core/public/core_system.test.ts | ||
// :kibana/src/core/server/saved_objects yarn test:jest | ||
|
||
export function runJest(configName = 'jest.config.js') { | ||
const argv = buildArgv(process.argv); | ||
|
||
const log = new ToolingLog({ | ||
level: argv.verbose ? 'verbose' : 'info', | ||
writeTo: process.stdout, | ||
}); | ||
|
||
if (!argv.config) { | ||
const cwd = process.env.INIT_CWD || process.cwd(); | ||
const testFiles = argv._.splice(2).map((p) => resolve(cwd, p)); | ||
const commonTestFiles = commonBasePath(testFiles); | ||
const testFilesProvided = testFiles.length > 0; | ||
|
||
log.verbose('cwd:', cwd); | ||
log.verbose('testFiles:', testFiles.join(', ')); | ||
log.verbose('commonTestFiles:', commonTestFiles); | ||
|
||
let configPath; | ||
|
||
// sets the working directory to the cwd or the common | ||
// base directory of the provided test files | ||
let wd = testFilesProvided ? commonTestFiles : cwd; | ||
|
||
configPath = resolve(wd, configName); | ||
|
||
while (!existsSync(configPath)) { | ||
wd = resolve(wd, '..'); | ||
configPath = resolve(wd, configName); | ||
} | ||
|
||
log.verbose(`no config provided, found ${configPath}`); | ||
process.argv.push('--config', configPath); | ||
|
||
if (!testFilesProvided) { | ||
log.verbose(`no test files provided, setting to current directory`); | ||
process.argv.push(relative(wd, cwd)); | ||
} | ||
|
||
log.info('yarn jest', process.argv.slice(2).join(' ')); | ||
} | ||
|
||
if (process.env.NODE_ENV == null) { | ||
process.env.NODE_ENV = 'test'; | ||
} | ||
|
||
run(); | ||
} | ||
|
||
/** | ||
* Finds the common basePath by sorting the array | ||
* and comparing the first and last element | ||
*/ | ||
export function commonBasePath(paths: string[] = [], sep = osSep) { | ||
if (paths.length === 0) return ''; | ||
|
||
paths = paths.concat().sort(); | ||
|
||
const first = paths[0].split(sep); | ||
const last = paths[paths.length - 1].split(sep); | ||
|
||
const length = first.length; | ||
let i = 0; | ||
|
||
while (i < length && first[i] === last[i]) { | ||
i++; | ||
} | ||
|
||
return first.slice(0, i).join(sep); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.