Skip to content

Commit

Permalink
Updating deprecations.js file to be more straightforward (#1581)
Browse files Browse the repository at this point in the history
* Updating deprecations.js file to be more straightforward

* Create poor-coins-fix.md

* Remove tests

* Adding more info about the deprecation to the doc

* Title section

* Moving data to deprecations.json

* Moving data to deprecations.json

* Lint only scss files
  • Loading branch information
jonrohan authored Sep 10, 2021
1 parent c3b4a0c commit be518b8
Show file tree
Hide file tree
Showing 9 changed files with 570 additions and 922 deletions.
5 changes: 5 additions & 0 deletions .changeset/poor-coins-fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@primer/css": minor
---

Updating deprecations.js file to be more straightforward
58 changes: 0 additions & 58 deletions __tests__/css.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import {
getCurrentVersion,
getDeprecatedSelectors,
getDeprecatedVariables,
getPackageStats,
getSelectorDiff,
getVariableDiff
Expand All @@ -10,17 +8,6 @@ import semver from 'semver'

let selectorsDiff, variablesDiff, version

// Because of a change in analyzer this was incorrectly in the list
const variableAllowList = ['$marketing-all-spacers']
const selectorAllowList = [
'.Truncate .Truncate-text',
'.Truncate .Truncate-text+.Truncate-text',
'.Truncate .Truncate-text.Truncate-text--expandable:active',
'.Truncate .Truncate-text.Truncate-text--expandable:focus',
'.Truncate .Truncate-text.Truncate-text--expandable:hover',
'.Truncate .Truncate-text.Truncate-text--primary'
]

beforeAll(async () => {
selectorsDiff = getSelectorDiff()
variablesDiff = getVariableDiff()
Expand All @@ -33,48 +20,3 @@ describe('css', () => {
expect(supportStats.size).toEqual(0)
})
})

describe('deprecations', () => {
it('A selector was marked as deprecated but not removed from the codebase', () => {
const removed = selectorsDiff['removed']
const deprecations = getDeprecatedSelectors(version.raw)
if (deprecations.length) {
// Selectors were marked to be deprecated in this version,
// but were not removed from the codebase. Please remove these selectors.
expect(deprecations.sort()).toEqual(removed.sort()) // eslint-disable-line jest/no-conditional-expect
}
})

it('A selector was removed from the codebase but not added to upcoming major release deprecations file.', () => {
const removedSelectors = selectorsDiff['removed'].filter(v => !selectorAllowList.includes(v))

if (version.minor !== 0 && version.patch !== 0) {
const nextMajor = semver.inc(version.raw, 'major')
const deprecations = getDeprecatedSelectors(nextMajor)
// Some classes were removed from the codebase, but not found
// in the next upcoming major release deprecation.js
expect(deprecations.sort()).toEqual(expect.arrayContaining(removedSelectors.sort())) // eslint-disable-line jest/no-conditional-expect
}
})

it('A variable was marked as deprecated but not removed from the codebase', () => {
const removed = variablesDiff.removed
const deprecations = getDeprecatedVariables(version.raw)
if (deprecations.length) {
// Variables were marked to be deprecated in this version,
// but were not removed from the codebase. Please remove these variables.
expect(deprecations.sort()).toEqual(removed.sort()) // eslint-disable-line jest/no-conditional-expect
}
})

it('A variable was removed from the codebase and added to upcoming major release deprecations file.', () => {
const removed = variablesDiff.removed.filter(v => !variableAllowList.includes(v))
if (version.minor !== 0 && version.patch !== 0) {
const nextMajor = semver.inc(version.raw, 'major')
const deprecations = getDeprecatedVariables(nextMajor)
// Some variables were removed from the codebase, but not found
// in the next upcoming major release deprecation.json
expect(deprecations).toEqual(expect.arrayContaining(removed)) // eslint-disable-line jest/no-conditional-expect
}
})
})
14 changes: 0 additions & 14 deletions __tests__/utils/css.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,6 @@ export function getCurrentVersion() {
return semver.parse(pkg.version)
}

export function getDeprecatedSelectors(version) {
if (getCurrentVersion().raw === version) return []
let deprecations = JSON.parse(fs.readFileSync(join(currentPath, './dist/deprecations.json')))
deprecations = deprecations.versions[version] || []
return deprecations.reduce((list, deprecation) => list.concat(deprecation.selectors), []).filter(v => v)
}

export function getDeprecatedVariables(version) {
if (getCurrentVersion().raw === version) return []
let deprecations = JSON.parse(fs.readFileSync(join(currentPath, './dist/deprecations.json')))
deprecations = deprecations.versions[version] || []
return deprecations.reduce((list, deprecation) => list.concat(deprecation.variables), []).filter(v => v)
}

export function getPackageStats(packageName) {
const stats = JSON.parse(fs.readFileSync(join(currentPath, './dist', `./stats/${packageName}.json`)))
return stats
Expand Down
Loading

0 comments on commit be518b8

Please sign in to comment.