Skip to content

Commit

Permalink
feat(packages/lint-repository-sui): Add jest adoption rule to lint
Browse files Browse the repository at this point in the history
  • Loading branch information
Jenifer López committed Oct 15, 2024
1 parent 99f2ea1 commit b631c23
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
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)
}
}
}
}

0 comments on commit b631c23

Please sign in to comment.