Skip to content

Commit

Permalink
feat(packages/lint-repository-sui): Create rule to check the Cypress …
Browse files Browse the repository at this point in the history
…version
  • Loading branch information
carlosvillu committed Apr 3, 2024
1 parent a4bbed9 commit 852df2e
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 2 deletions.
2 changes: 2 additions & 0 deletions packages/lint-repository-sui/src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const NodeVersion = require('./rules/node-version.js')
const ReactVersion = require('./rules/react-version.js')
const CypressVersion = require('./rules/cypress-version.js')
const PackageLock = require('./rules/package-lock.js')
const GithubAction = require('./rules/github-action.js')
const TypeScript = require('./rules/typescript.js')
Expand All @@ -16,6 +17,7 @@ module.exports = {
rules: {
'node-version': NodeVersion,
'react-version': ReactVersion,
'cypress-version': CypressVersion,
'package-lock': PackageLock,
'github-action': GithubAction,
typescript: TypeScript,
Expand Down
3 changes: 2 additions & 1 deletion packages/lint-repository-sui/src/rules/adv-tools-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ const dedent = require('string-dedent')

const ADV_TOOLS_VERSIONS = {
logger: '2',
'lint-reporters': '1'
'lint-reporters': '1',
'vendor-by-consents-loader': '1'
}

module.exports = {
Expand Down
64 changes: 64 additions & 0 deletions packages/lint-repository-sui/src/rules/cypress-version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
const dedent = require('string-dedent')

const CYPRESS_VERSION = '10'

module.exports = {
meta: {
type: 'problem',
docs: {
description: 'Check that your repository use the latest Cypress version',
recommended: true,
url: null
},
fixable: null,
schema: [],
messages: {
badCypressVersion: dedent`
Please be sure that your repository use the latest Cypress Version ${CYPRESS_VERSION}.
Your current version is {{version}}.
If you are not sure about how do it, please contact with Platform Web.
`,
missingCypressDependencie: dedent`
Your project doesnt have installed Cypress.
Please install at least the version ${CYPRESS_VERSION}.
If you are not sure about how do it, please contact with Platform Web.
`,
missingPackageLock: dedent`
To calculate the cypress version first we need to have a package-lock.json in the root
If you are not sure about how do it, please contact with Platform Web.
`
}
},
create: function (context) {
return {
'package-lock.json': matches => {
const [packageLock] = matches
let version = packageLock?.parsed?.packages?.['node_modules/cypress']?.version

if (!version) {
context.report({
messageId: 'missingCypressDependencie'
})
return context.monitoring(0)
}

version = version.split('.')[0]

if (version !== CYPRESS_VERSION) {
context.report({
messageId: 'badCypressVersion',
data: {version}
})
}
return context.monitoring(version)
},

missmatch: key => {
context.report({
messageId: 'missingPackageLock'
})
context.monitoring(0)
}
}
}
}
4 changes: 3 additions & 1 deletion packages/lint-repository-sui/src/rules/sui-tools-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ const SUI_TOOLS_VERSIONS = {
pde: '2',
test: '8',
theme: '8',
domain: '2'
domain: '2',
'react-web-vitals': '2',
'segment-wrapper': '3'
}

module.exports = {
Expand Down
44 changes: 44 additions & 0 deletions packages/lint-repository-sui/test/server/cypress-versionSpec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import dedent from 'dedent'

import handler from '../../src/rules/cypress-version.js'
import {MatchStub, RuleTester} from '../TestHelpers.js'

RuleTester.create('cypress-version', handler).run({
valid: [
{
'package-lock.json': [MatchStub.create({parsed: {packages: {'node_modules/cypress': {version: '10.0.0'}}}})],
name: 'Cypress 10 installed',
monitoring: '10'
}
],
invalid: [
{
'package-lock.json': [MatchStub.create({parsed: {packages: {}}})],
name: 'Cypress not installed',
report: dedent`
Your project doesnt have installed Cypress.
Please install at least the version 10.
If you are not sure about how do it, please contact with Platform Web.
`,
monitoring: 0
},
{
'package-lock.json': [MatchStub.create({parsed: {packages: {'node_modules/cypress': {version: '17.0.0'}}}})],
name: 'Cypress wrong version',
report: dedent`
Please be sure that your repository use the latest Cypress Version 10.
Your current version is 17.
If you are not sure about how do it, please contact with Platform Web.
`,
monitoring: '17'
},
{
missmatch: '',
report: dedent`
To calculate the cypress version first we need to have a package-lock.json in the root
If you are not sure about how do it, please contact with Platform Web.
`,
monitoring: 0
}
]
})

0 comments on commit 852df2e

Please sign in to comment.