-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(packages/lint-repository-sui): Add jest adoption rule to lint
- Loading branch information
Jenifer López
committed
Oct 15, 2024
1 parent
99f2ea1
commit b631c23
Showing
2 changed files
with
48 additions
and
1 deletion.
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
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) | ||
} | ||
} | ||
} | ||
} |