Skip to content

Commit

Permalink
chore: improve support for mjs file extension (#70186) (#70325)
Browse files Browse the repository at this point in the history
  • Loading branch information
watson authored Jul 2, 2020
1 parent ab17a8a commit e245673
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 45 deletions.
58 changes: 29 additions & 29 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,69 +64,69 @@ module.exports = {
* Temporarily disable some react rules for specific plugins, remove in separate PRs
*/
{
files: ['packages/kbn-ui-framework/**/*.{js,ts,tsx}'],
files: ['packages/kbn-ui-framework/**/*.{js,mjs,ts,tsx}'],
rules: {
'jsx-a11y/no-onchange': 'off',
},
},
{
files: ['src/plugins/es_ui_shared/**/*.{js,ts,tsx}'],
files: ['src/plugins/es_ui_shared/**/*.{js,mjs,ts,tsx}'],
rules: {
'react-hooks/exhaustive-deps': 'off',
},
},
{
files: ['src/plugins/eui_utils/**/*.{js,ts,tsx}'],
files: ['src/plugins/eui_utils/**/*.{js,mjs,ts,tsx}'],
rules: {
'react-hooks/exhaustive-deps': 'off',
},
},
{
files: ['src/plugins/kibana_react/**/*.{js,ts,tsx}'],
files: ['src/plugins/kibana_react/**/*.{js,mjs,ts,tsx}'],
rules: {
'react-hooks/rules-of-hooks': 'off',
'react-hooks/exhaustive-deps': 'off',
},
},
{
files: ['src/plugins/kibana_utils/**/*.{js,ts,tsx}'],
files: ['src/plugins/kibana_utils/**/*.{js,mjs,ts,tsx}'],
rules: {
'react-hooks/exhaustive-deps': 'off',
},
},
{
files: ['x-pack/plugins/canvas/**/*.{js,ts,tsx}'],
files: ['x-pack/plugins/canvas/**/*.{js,mjs,ts,tsx}'],
rules: {
'jsx-a11y/click-events-have-key-events': 'off',
},
},
{
files: ['x-pack/plugins/cross_cluster_replication/**/*.{js,ts,tsx}'],
files: ['x-pack/plugins/cross_cluster_replication/**/*.{js,mjs,ts,tsx}'],
rules: {
'jsx-a11y/click-events-have-key-events': 'off',
},
},
{
files: ['x-pack/legacy/plugins/index_management/**/*.{js,ts,tsx}'],
files: ['x-pack/legacy/plugins/index_management/**/*.{js,mjs,ts,tsx}'],
rules: {
'react-hooks/exhaustive-deps': 'off',
'react-hooks/rules-of-hooks': 'off',
},
},
{
files: ['x-pack/plugins/lens/**/*.{js,ts,tsx}'],
files: ['x-pack/plugins/lens/**/*.{js,mjs,ts,tsx}'],
rules: {
'react-hooks/exhaustive-deps': 'off',
},
},
{
files: ['x-pack/plugins/ml/**/*.{js,ts,tsx}'],
files: ['x-pack/plugins/ml/**/*.{js,mjs,ts,tsx}'],
rules: {
'react-hooks/exhaustive-deps': 'off',
},
},
{
files: ['x-pack/legacy/plugins/snapshot_restore/**/*.{js,ts,tsx}'],
files: ['x-pack/legacy/plugins/snapshot_restore/**/*.{js,mjs,ts,tsx}'],
rules: {
'react-hooks/exhaustive-deps': 'off',
},
Expand All @@ -138,7 +138,7 @@ module.exports = {
* Licence headers
*/
{
files: ['**/*.{js,ts,tsx}', '!plugins/**/*'],
files: ['**/*.{js,mjs,ts,tsx}', '!plugins/**/*'],
rules: {
'@kbn/eslint/require-license-header': [
'error',
Expand All @@ -159,7 +159,7 @@ module.exports = {
* New Platform client-side
*/
{
files: ['{src,x-pack}/plugins/*/public/**/*.{js,ts,tsx}'],
files: ['{src,x-pack}/plugins/*/public/**/*.{js,mjs,ts,tsx}'],
rules: {
'import/no-commonjs': 'error',
},
Expand All @@ -169,7 +169,7 @@ module.exports = {
* Files that require Elastic license headers instead of Apache 2.0 header
*/
{
files: ['x-pack/**/*.{js,ts,tsx}'],
files: ['x-pack/**/*.{js,mjs,ts,tsx}'],
rules: {
'@kbn/eslint/require-license-header': [
'error',
Expand All @@ -190,7 +190,7 @@ module.exports = {
* Restricted paths
*/
{
files: ['**/*.{js,ts,tsx}'],
files: ['**/*.{js,mjs,ts,tsx}'],
rules: {
'@kbn/eslint/no-restricted-paths': [
'error',
Expand Down Expand Up @@ -257,8 +257,8 @@ module.exports = {
],
from: [
'(src|x-pack)/plugins/**/(public|server)/**/*',
'!(src|x-pack)/plugins/**/(public|server)/mocks/index.{js,ts}',
'!(src|x-pack)/plugins/**/(public|server)/(index|mocks).{js,ts,tsx}',
'!(src|x-pack)/plugins/**/(public|server)/mocks/index.{js,mjs,ts}',
'!(src|x-pack)/plugins/**/(public|server)/(index|mocks).{js,mjs,ts,tsx}',
],
allowSameFolder: true,
errorMessage: 'Plugins may only import from top-level public and server modules.',
Expand All @@ -270,11 +270,11 @@ module.exports = {

'src/legacy/core_plugins/**/*',
'!src/legacy/core_plugins/**/server/**/*',
'!src/legacy/core_plugins/**/index.{js,ts,tsx}',
'!src/legacy/core_plugins/**/index.{js,mjs,ts,tsx}',

'x-pack/legacy/plugins/**/*',
'!x-pack/legacy/plugins/**/server/**/*',
'!x-pack/legacy/plugins/**/index.{js,ts,tsx}',
'!x-pack/legacy/plugins/**/index.{js,mjs,ts,tsx}',

'examples/**/*',
'!examples/**/server/**/*',
Expand Down Expand Up @@ -535,7 +535,7 @@ module.exports = {
* Jest specific rules
*/
{
files: ['**/*.test.{js,ts,tsx}'],
files: ['**/*.test.{js,mjs,ts,tsx}'],
rules: {
'jest/valid-describe': 'error',
},
Expand Down Expand Up @@ -600,8 +600,8 @@ module.exports = {
{
// front end and common typescript and javascript files only
files: [
'x-pack/plugins/security_solution/public/**/*.{js,ts,tsx}',
'x-pack/plugins/security_solution/common/**/*.{js,ts,tsx}',
'x-pack/plugins/security_solution/public/**/*.{js,mjs,ts,tsx}',
'x-pack/plugins/security_solution/common/**/*.{js,mjs,ts,tsx}',
],
rules: {
'import/no-nodejs-modules': 'error',
Expand Down Expand Up @@ -651,7 +651,7 @@ module.exports = {
// {
// // will introduced after the other warns are fixed
// // typescript and javascript for front end react performance
// files: ['x-pack/plugins/security_solution/public/**/!(*.test).{js,ts,tsx}'],
// files: ['x-pack/plugins/security_solution/public/**/!(*.test).{js,mjs,ts,tsx}'],
// plugins: ['react-perf'],
// rules: {
// // 'react-perf/jsx-no-new-object-as-prop': 'error',
Expand All @@ -662,7 +662,7 @@ module.exports = {
// },
{
// typescript and javascript for front and back end
files: ['x-pack/{,legacy/}plugins/security_solution/**/*.{js,ts,tsx}'],
files: ['x-pack/{,legacy/}plugins/security_solution/**/*.{js,mjs,ts,tsx}'],
plugins: ['eslint-plugin-node', 'react'],
env: {
mocha: true,
Expand Down Expand Up @@ -781,8 +781,8 @@ module.exports = {
{
// front end and common typescript and javascript files only
files: [
'x-pack/plugins/lists/public/**/*.{js,ts,tsx}',
'x-pack/plugins/lists/common/**/*.{js,ts,tsx}',
'x-pack/plugins/lists/public/**/*.{js,mjs,ts,tsx}',
'x-pack/plugins/lists/common/**/*.{js,mjs,ts,tsx}',
],
rules: {
'import/no-nodejs-modules': 'error',
Expand All @@ -797,7 +797,7 @@ module.exports = {
},
{
// typescript and javascript for front and back end
files: ['x-pack/plugins/lists/**/*.{js,ts,tsx}'],
files: ['x-pack/plugins/lists/**/*.{js,mjs,ts,tsx}'],
plugins: ['eslint-plugin-node'],
env: {
mocha: true,
Expand Down Expand Up @@ -1025,8 +1025,8 @@ module.exports = {
*/
{
files: [
'src/plugins/vis_type_timeseries/**/*.{js,ts,tsx}',
'src/legacy/core_plugins/vis_type_timeseries/**/*.{js,ts,tsx}',
'src/plugins/vis_type_timeseries/**/*.{js,mjs,ts,tsx}',
'src/legacy/core_plugins/vis_type_timeseries/**/*.{js,mjs,ts,tsx}',
],
rules: {
'import/no-default-export': 'error',
Expand Down
2 changes: 1 addition & 1 deletion docs/developer/core/development-unit-tests.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ yarn test:mocha

[float]
==== Jest
Jest tests are stored in the same directory as source code files with the `.test.{js,ts,tsx}` suffix.
Jest tests are stored in the same directory as source code files with the `.test.{js,mjs,ts,tsx}` suffix.

*Running Jest Unit Tests*

Expand Down
4 changes: 2 additions & 2 deletions packages/eslint-config-kibana/jest.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ module.exports = {
overrides: [
{
files: [
'**/*.{test,test.mocks,mock}.{js,ts,tsx}',
'**/__mocks__/**/*.{js,ts,tsx}',
'**/*.{test,test.mocks,mock}.{js,mjs,ts,tsx}',
'**/__mocks__/**/*.{js,mjs,ts,tsx}',
],
plugins: [
'jest',
Expand Down
4 changes: 2 additions & 2 deletions src/dev/jest/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export default {
'packages/kbn-ui-framework/src/services/**/*.js',
'!packages/kbn-ui-framework/src/services/index.js',
'!packages/kbn-ui-framework/src/services/**/*/index.js',
'src/legacy/core_plugins/**/*.{js,jsx,ts,tsx}',
'src/legacy/core_plugins/**/*.{js,mjs,jsx,ts,tsx}',
'!src/legacy/core_plugins/**/{__test__,__snapshots__}/**/*',
],
moduleNameMapper: {
Expand Down Expand Up @@ -77,7 +77,7 @@ export default {
],
coverageDirectory: '<rootDir>/target/kibana-coverage/jest',
coverageReporters: ['html', 'text'],
moduleFileExtensions: ['js', 'json', 'ts', 'tsx', 'node'],
moduleFileExtensions: ['js', 'mjs', 'json', 'ts', 'tsx', 'node'],
modulePathIgnorePatterns: ['__fixtures__/', 'target/'],
testEnvironment: 'jest-environment-jsdom-thirteen',
testMatch: ['**/*.test.{js,ts,tsx}'],
Expand Down
2 changes: 1 addition & 1 deletion src/dev/run_eslint.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ if (!process.argv.includes('--no-cache')) {
}

if (!process.argv.includes('--ext')) {
process.argv.push('--ext', '.js,.ts,.tsx');
process.argv.push('--ext', '.js,.mjs,.ts,.tsx');
}

// common-js is required so that logic before this executes before loading eslint
Expand Down
12 changes: 6 additions & 6 deletions x-pack/dev-tools/jest/create_jest_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export function createJestConfig({ kibanaDirectory, rootDir, xPackKibanaDirector
return {
rootDir,
roots: ['<rootDir>/plugins', '<rootDir>/legacy/plugins', '<rootDir>/legacy/server'],
moduleFileExtensions: ['js', 'json', 'ts', 'tsx', 'node'],
moduleFileExtensions: ['js', 'mjs', 'json', 'ts', 'tsx', 'node'],
moduleNameMapper: {
'@elastic/eui$': `${kibanaDirectory}/node_modules/@elastic/eui/test-env`,
'@elastic/eui/lib/(.*)?': `${kibanaDirectory}/node_modules/@elastic/eui/test-env/$1`,
Expand All @@ -34,11 +34,11 @@ export function createJestConfig({ kibanaDirectory, rootDir, xPackKibanaDirector
coverageDirectory: `${kibanaDirectory}/target/kibana-coverage/jest`,
coverageReporters: ['html'],
collectCoverageFrom: [
'legacy/plugins/**/*.{js,jsx,ts,tsx}',
'legacy/server/**/*.{js,jsx,ts,tsx}',
'plugins/**/*.{js,jsx,ts,tsx}',
'legacy/plugins/**/*.{js,mjs,jsx,ts,tsx}',
'legacy/server/**/*.{js,mjs,jsx,ts,tsx}',
'plugins/**/*.{js,mjs,jsx,ts,tsx}',
'!**/{__test__,__snapshots__,__examples__,integration_tests,tests}/**',
'!**/*.test.{js,ts,tsx}',
'!**/*.test.{js,mjs,ts,tsx}',
'!**/flot-charts/**',
'!**/test/**',
'!**/build/**',
Expand All @@ -58,7 +58,7 @@ export function createJestConfig({ kibanaDirectory, rootDir, xPackKibanaDirector
`${kibanaDirectory}/src/dev/jest/setup/react_testing_library.js`,
],
testEnvironment: 'jest-environment-jsdom-thirteen',
testMatch: ['**/*.test.{js,ts,tsx}'],
testMatch: ['**/*.test.{js,mjs,ts,tsx}'],
testRunner: 'jest-circus/runner',
transform: {
'^.+\\.(js|tsx?)$': `${kibanaDirectory}/src/dev/jest/babel_transform.js`,
Expand Down
4 changes: 2 additions & 2 deletions x-pack/test_utils/jest/config.integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import config from './config';
export default {
...config,
testMatch: [
`**/${RESERVED_DIR_JEST_INTEGRATION_TESTS}/**/*.test.{js,ts,tsx}`,
`**/${RESERVED_DIR_JEST_INTEGRATION_TESTS}/**/*.test.{js,mjs,ts,tsx}`,
// Tests within `__jest__` directories should be treated as regular unit tests.
`!**/__jest__/${RESERVED_DIR_JEST_INTEGRATION_TESTS}/**/*.test.{js,ts,tsx}`,
`!**/__jest__/${RESERVED_DIR_JEST_INTEGRATION_TESTS}/**/*.test.{js,mjs,ts,tsx}`,
],
testPathIgnorePatterns: config.testPathIgnorePatterns.filter(
(pattern) => !pattern.includes(RESERVED_DIR_JEST_INTEGRATION_TESTS)
Expand Down
4 changes: 2 additions & 2 deletions x-pack/test_utils/jest/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ export default {
],
coverageDirectory: '<rootDir>/../target/kibana-coverage/jest',
coverageReporters: ['html'],
moduleFileExtensions: ['js', 'json', 'ts', 'tsx', 'node'],
moduleFileExtensions: ['js', 'mjs', 'json', 'ts', 'tsx', 'node'],
modulePathIgnorePatterns: ['__fixtures__/', 'target/'],
testEnvironment: 'jest-environment-jsdom-thirteen',
testMatch: ['**/*.test.{js,ts,tsx}'],
testMatch: ['**/*.test.{js,mjs,ts,tsx}'],
testPathIgnorePatterns: [
'<rootDir>/packages/kbn-ui-framework/(dist|doc_site|generator-kui)/',
'<rootDir>/packages/kbn-pm/dist/',
Expand Down

0 comments on commit e245673

Please sign in to comment.