1
1
mirror of https://github.com/primer/css.git synced 2024-12-10 23:26:59 +03:00
css/__tests__/css.test.js

60 lines
2.4 KiB
JavaScript
Raw Normal View History

2021-04-01 09:11:55 +03:00
const {
getCurrentVersion,
getDeprecatedSelectors,
getDeprecatedVariables,
getSelectorDiff,
getVariableDiff
} = require('./utils/css')
const semver = require('semver')
2021-04-01 00:53:15 +03:00
2021-04-01 09:11:55 +03:00
let selectorsDiff, variablesDiff, version
2021-04-09 05:34:17 +03:00
// Because of a change in analyzer this was incorrectly in the list
const variableAllowList = ['$marketing-all-spacers']
2021-04-01 09:11:55 +03:00
beforeAll(async () => {
selectorsDiff = getSelectorDiff()
variablesDiff = getVariableDiff()
version = getCurrentVersion()
})
describe('deprecations', () => {
it('A selector was marked as deprecated but not removed from the codebase', () => {
const removed = selectorsDiff['removed']
const deprecations = getDeprecatedSelectors(version)
if (deprecations.length) {
// Selectors were marked to be deprecated in this version,
// but were not removed from the codebase. Please remove these selectors.
2021-04-01 20:56:12 +03:00
expect(deprecations.sort()).toEqual(removed.sort()) // eslint-disable-line jest/no-conditional-expect
2021-04-01 09:11:55 +03:00
}
})
2021-04-07 22:38:58 +03:00
it('A selector was removed from the codebase but not added to upcoming major release deprecations file.', () => {
2021-04-01 09:11:55 +03:00
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))
})
it('A variable was marked as deprecated but not removed from the codebase', () => {
const removed = variablesDiff.removed
const deprecations = getDeprecatedVariables(version)
if (deprecations.length) {
// Variables were marked to be deprecated in this version,
// but were not removed from the codebase. Please remove these variables.
2021-04-01 20:56:12 +03:00
expect(deprecations.sort()).toEqual(removed.sort()) // eslint-disable-line jest/no-conditional-expect
2021-04-01 09:11:55 +03:00
}
})
it('A variable was removed from the codebase and added to upcoming major release deprecations file.', () => {
2021-04-09 05:34:17 +03:00
const removed = variablesDiff.removed.filter(v => !variableAllowList.includes(v))
2021-04-01 09:11:55 +03:00
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))
2021-04-01 00:53:15 +03:00
})
})