forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ci] Splits Jest integration tests (elastic#125454) (elastic#125533)
(cherry picked from commit 435b772) Co-authored-by: Tyler Smalley <[email protected]>
- Loading branch information
1 parent
61274ee
commit 25f4f43
Showing
27 changed files
with
467 additions
and
62 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
module.exports = { | ||
preset: '@kbn/test/jest_integration', | ||
rootDir: '../..', | ||
roots: ['<rootDir>/packages/kbn-es'], | ||
}; |
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,13 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
module.exports = { | ||
preset: '@kbn/test/jest_integration', | ||
rootDir: '../..', | ||
roots: ['<rootDir>/packages/kbn-optimizer'], | ||
}; |
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,13 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
module.exports = { | ||
preset: '@kbn/test/jest_integration', | ||
rootDir: '../..', | ||
roots: ['<rootDir>/packages/kbn-plugin-generator'], | ||
}; |
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,13 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
module.exports = { | ||
preset: '@kbn/test/jest_integration', | ||
rootDir: '../..', | ||
roots: ['<rootDir>/packages/kbn-plugin-helpers'], | ||
}; |
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,13 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
module.exports = { | ||
preset: '@kbn/test/jest_integration', | ||
rootDir: '../..', | ||
roots: ['<rootDir>/packages/kbn-test'], | ||
}; |
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
3 changes: 3 additions & 0 deletions
3
packages/kbn-test/src/jest/configs/__snapshots__/jest_configs.test.ts.snap
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,9 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
export * from './jest_configs'; |
116 changes: 116 additions & 0 deletions
116
packages/kbn-test/src/jest/configs/jest_configs.test.ts
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,116 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import mockFs from 'mock-fs'; | ||
import fs from 'fs'; | ||
|
||
import { JestConfigs } from './jest_configs'; | ||
|
||
describe('jestConfigs', () => { | ||
let jestConfigs: JestConfigs; | ||
|
||
beforeEach(async () => { | ||
mockFs({ | ||
'/kbn-test/packages': { | ||
a: { | ||
'jest.config.js': '', | ||
'a_first.test.js': '', | ||
'a_second.test.js': '', | ||
}, | ||
b: { | ||
'b.test.js': '', | ||
integration_tests: { | ||
'b_integration.test.js': '', | ||
}, | ||
nested: { | ||
d: { | ||
'd.test.js': '', | ||
}, | ||
}, | ||
}, | ||
c: { | ||
'jest.integration.config.js': '', | ||
integration_tests: { | ||
'c_integration.test.js': '', | ||
}, | ||
}, | ||
}, | ||
}); | ||
jestConfigs = new JestConfigs('/kbn-test', ['packages/b/nested', 'packages']); | ||
}); | ||
|
||
afterEach(mockFs.restore); | ||
|
||
describe('#files', () => { | ||
it('lists unit test files', async () => { | ||
const files = await jestConfigs.files('unit'); | ||
expect(files).toEqual([ | ||
'packages/a/a_first.test.js', | ||
'packages/a/a_second.test.js', | ||
'packages/b/b.test.js', | ||
'packages/b/nested/d/d.test.js', | ||
]); | ||
}); | ||
|
||
it('lists integration test files', async () => { | ||
const files = await jestConfigs.files('integration'); | ||
expect(files).toEqual([ | ||
'packages/b/integration_tests/b_integration.test.js', | ||
'packages/c/integration_tests/c_integration.test.js', | ||
]); | ||
}); | ||
}); | ||
|
||
describe('#expected', () => { | ||
it('expects unit config files', async () => { | ||
const files = await jestConfigs.expected('unit'); | ||
expect(files).toEqual([ | ||
'packages/a/jest.config.js', | ||
'packages/b/jest.config.js', | ||
'packages/b/nested/d/jest.config.js', | ||
]); | ||
}); | ||
|
||
it('expects integration config files', async () => { | ||
const files = await jestConfigs.expected('integration'); | ||
expect(files).toEqual([ | ||
'packages/b/jest.integration.config.js', | ||
'packages/c/jest.integration.config.js', | ||
]); | ||
}); | ||
|
||
it('throws if test file outside root', async () => { | ||
fs.writeFileSync('/kbn-test/bad.test.js', ''); | ||
await expect(() => jestConfigs.expected('unit')).rejects.toMatchSnapshot(); | ||
}); | ||
}); | ||
|
||
describe('#existing', () => { | ||
it('lists existing unit test config files', async () => { | ||
const files = await jestConfigs.existing('unit'); | ||
expect(files).toEqual(['packages/a/jest.config.js']); | ||
}); | ||
|
||
it('lists existing integration test config files', async () => { | ||
const files = await jestConfigs.existing('integration'); | ||
expect(files).toEqual(['packages/c/jest.integration.config.js']); | ||
}); | ||
}); | ||
|
||
describe('#missing', () => { | ||
it('lists existing unit test config files', async () => { | ||
const files = await jestConfigs.missing('unit'); | ||
expect(files).toEqual(['packages/b/jest.config.js', 'packages/b/nested/d/jest.config.js']); | ||
}); | ||
|
||
it('lists existing integration test config files', async () => { | ||
const files = await jestConfigs.missing('integration'); | ||
expect(files).toEqual(['packages/b/jest.integration.config.js']); | ||
}); | ||
}); | ||
}); |
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,85 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import path from 'path'; | ||
import globby from 'globby'; | ||
|
||
// @ts-ignore | ||
import { testMatch } from '../../../jest-preset'; | ||
|
||
export const CONFIG_NAMES = { | ||
unit: 'jest.config.js', | ||
integration: 'jest.integration.config.js', | ||
}; | ||
|
||
export class JestConfigs { | ||
cwd: string; | ||
roots: string[]; | ||
allFiles: string[] | undefined; | ||
|
||
constructor(cwd: string, roots: string[]) { | ||
this.cwd = cwd; | ||
this.roots = roots; | ||
} | ||
|
||
async files(type: 'unit' | 'integration') { | ||
if (!this.allFiles) { | ||
this.allFiles = await globby(testMatch, { | ||
gitignore: true, | ||
cwd: this.cwd, | ||
}); | ||
} | ||
|
||
return this.allFiles.filter((f) => | ||
type === 'integration' ? f.includes('integration_tests') : !f.includes('integration_tests') | ||
); | ||
} | ||
|
||
async expected(type: 'unit' | 'integration') { | ||
const filesForType = await this.files(type); | ||
const directories: Set<string> = new Set(); | ||
|
||
filesForType.forEach((file) => { | ||
const root = this.roots.find((r) => file.startsWith(r)); | ||
|
||
if (root) { | ||
const splitPath = file.substring(root.length).split(path.sep); | ||
|
||
if (splitPath.length > 2) { | ||
const name = splitPath[1]; | ||
directories.add([root, name].join(path.sep)); | ||
} | ||
} else { | ||
throw new Error( | ||
`Test file (${file}) can not exist outside roots (${this.roots.join( | ||
', ' | ||
)}). Move it to a root or configure additional root.` | ||
); | ||
} | ||
}); | ||
|
||
return [...directories].map((d) => [d, CONFIG_NAMES[type]].join(path.sep)); | ||
} | ||
|
||
async existing(type: 'unit' | 'integration') { | ||
return await globby(`**/${CONFIG_NAMES[type]}`, { | ||
gitignore: true, | ||
cwd: this.cwd, | ||
}); | ||
} | ||
|
||
async missing(type: 'unit' | 'integration') { | ||
const expectedConfigs = await this.expected(type); | ||
const existingConfigs = await this.existing(type); | ||
return await expectedConfigs.filter((x) => !existingConfigs.includes(x)); | ||
} | ||
|
||
async allMissing() { | ||
return (await this.missing('unit')).concat(await this.missing('integration')); | ||
} | ||
} |
Oops, something went wrong.