1
1
mirror of https://github.com/primer/css.git synced 2024-11-12 22:06:08 +03:00

Fixing deprecation test

This commit is contained in:
Jon Rohan 2021-05-05 14:10:15 -07:00
parent 82e575f625
commit 49026e74bb
No known key found for this signature in database
GPG Key ID: B0BBE304A9A0AECB
2 changed files with 21 additions and 15 deletions

View File

@ -21,7 +21,7 @@ beforeAll(async () => {
describe('deprecations', () => {
it('A selector was marked as deprecated but not removed from the codebase', () => {
const removed = selectorsDiff['removed']
const deprecations = getDeprecatedSelectors(version)
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.
@ -31,16 +31,19 @@ describe('deprecations', () => {
it('A selector was removed from the codebase but not added to upcoming major release deprecations file.', () => {
const removedSelectors = selectorsDiff['removed']
const nextMajor = semver.inc(version, 'major')
const deprecations = getDeprecatedSelectors(nextMajor)
// Some classes were removed from the codebase, but not found
// in the next upcoming major release deprecation.json
expect(deprecations).toEqual(expect.arrayContaining(removedSelectors))
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)
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.
@ -50,10 +53,12 @@ describe('deprecations', () => {
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))
const nextMajor = semver.inc(version, '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))
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
}
})
})

View File

@ -1,10 +1,11 @@
const {join} = require('path')
const currentPath = join(__dirname, '../../')
const lastPath = join(__dirname, '../../tmp/node_modules/@primer/css')
const semver = require('semver')
function diffLists(before, after) {
const added = after.filter(value => !before.includes(value))
const removed = before.filter(value => !after.includes(value))
const added = [...new Set(after.filter(value => !before.includes(value)))]
const removed = [...new Set(before.filter(value => !after.includes(value)))]
return {
changed: added.length + removed.length,
added,
@ -24,7 +25,7 @@ function getVariables(versionPath) {
function getCurrentVersion() {
const pkg = require(join(currentPath, './package.json'))
return pkg.version
return semver.parse(pkg.version)
}
function getDeprecatedSelectors(version) {