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

feat(packages/lint-repository-sui): Add jest adoption rule to lint #1844

Merged
merged 1 commit into from
Oct 15, 2024
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
4 changes: 3 additions & 1 deletion packages/lint-repository-sui/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const TSvsJS = require('./rules/ts-vs-js-files.js')
const Sass = require('./rules/sass-files.js')
const Spark = require('./rules/spark-adoption.js')
const ComponentsLocation = require('./rules/components-location.js')
const JestAdoption = require('./rules/jest-adoption.js')

// ------------------------------------------------------------------------------
// Plugin Definition
Expand All @@ -31,6 +32,7 @@ module.exports = {
'ts-vs-js-files': TSvsJS,
'sass-files': Sass,
'spark-adoption': Spark,
'components-location': ComponentsLocation
'components-location': ComponentsLocation,
'jest-adoption': JestAdoption
}
}
45 changes: 45 additions & 0 deletions packages/lint-repository-sui/src/rules/jest-adoption.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
const dedent = require('string-dedent')

module.exports = {
meta: {
type: 'problem',
docs: {
description: 'This metric reports the number component that use Jest',
recommended: true,
url: null
},
fixable: null,
schema: [],
messages: {
percentage: dedent`
Currently, {{percentage}}% of your components use Jest. We have {{totalKarmaTests}}% tests in Karma and {{totalJestTests}}% in Jest
`
}
},

create: function (context) {
return {
'components/**/(test|__tests__)/*.(j|t)s(x)?': matches => {
const totalTests = matches.length
const totalJestTests = matches.filter(({fullPath}) => fullPath.includes('__tests__')).length
const totalKarmaTests = totalTests - totalJestTests
let percentage = (totalJestTests * 100) / totalTests
percentage = Math.round((percentage + Number.EPSILON) * 100) / 100

context.report({
messageId: 'percentage',
data: {percentage, totalKarmaTests, totalJestTests}
})
return context.monitoring(percentage)
},

missmatch: key => {
context.report({
messageId: 'percentage',
data: {percentage: 0}
})
context.monitoring(0)
}
}
}
}