-
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): Create rule to check the Cypress …
…version
- Loading branch information
1 parent
a4bbed9
commit 852df2e
Showing
5 changed files
with
115 additions
and
2 deletions.
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
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,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) | ||
} | ||
} | ||
} | ||
} |
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
44 changes: 44 additions & 0 deletions
44
packages/lint-repository-sui/test/server/cypress-versionSpec.js
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,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 | ||
} | ||
] | ||
}) |