Skip to content

Commit

Permalink
Clean up tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ai committed Jul 10, 2023
1 parent b65ebd3 commit cb807a9
Showing 1 changed file with 27 additions and 31 deletions.
58 changes: 27 additions & 31 deletions index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,72 +4,68 @@ let postcss = require('postcss')

let plugin = require('./')

async function run(input, output, opts = {}) {
function run(input, output, opts = {}) {
let result = postcss([plugin(opts)]).process(input, { from: undefined })
equal(result.css, output)
equal(result.warnings().length, 0)
}

test('adds focus selector', async () => {
await run('a:hover, b {}', 'a:hover, b, a:focus-visible {}', {
splitRules: false,
test('adds focus selector', () => {
run('a:hover, b {}', 'a:hover, b {}a:focus-visible {}')
})

test('supports old focus', () => {
run('a:hover, b {}', 'a:hover, b {}a:focus {}', {
oldFocus: true
})
})

test('supports old focus', async () => {
await run('a:hover, b {}', 'a:hover, b, a:focus {}', {
oldFocus: true,
splitRules: false,
test('supports non-splitting', () => {
run('a:hover, b {}', 'a:hover, b, a:focus-visible {}', {
splitRules: false
})
})

test('supports split rules', async () => {
await run('a:hover, b {}', 'a:hover, b {}a:focus-visible {}')
test('supports split rules', () => {
run('a:hover, b {}', 'a:hover, b {}a:focus-visible {}')
})

test('supports split rules and old focus', async () => {
await run('a:hover, b {}', 'a:hover, b {}a:focus {}', {
test('supports split rules and old focus', () => {
run('a:hover, b {}', 'a:hover, b, a:focus {}', {
oldFocus: true,
splitRules: true,
splitRules: false
})
})

test('adds focus selectors', async () => {
await run(
test('adds focus selectors', () => {
run(
'a:hover, b:hover {}',
'a:hover, b:hover, a:focus-visible, b:focus-visible {}',
{
splitRules: false,
}
'a:hover, b:hover {}a:focus-visible, b:focus-visible {}'
)
})

test('ignores hover selector because of focus', async () => {
await run(
test('ignores hover selector because of focus', () => {
run(
'.foo:hover {} .foo:focus-visible {} ' +
'a:hover, b:hover {} ' +
'b:focus-visible {} ' +
'@media { b:hover {} }',
'.foo:hover {} .foo:focus-visible {} ' +
'a:hover, b:hover, a:focus-visible {} ' +
'a:hover, b:hover {} a:focus-visible {} ' +
'b:focus-visible {} ' +
'@media { b:hover, b:focus-visible {} }',
{
splitRules: false,
}
'@media { b:hover {} b:focus-visible {} }'
)
await run(
run(
'.foo:hover {} .foo:focus {} ' +
'a:hover, b:hover {} ' +
'b:focus {} ' +
'@media { b:hover {} }',
'.foo:hover {} .foo:focus {} ' +
'a:hover, b:hover, a:focus {} ' +
'a:hover, b:hover {} a:focus {} ' +
'b:focus {} ' +
'@media { b:hover, b:focus {} }',
'@media { b:hover {} b:focus {} }',
{
oldFocus: true,
splitRules: false,
oldFocus: true
}
)
})
Expand Down

0 comments on commit cb807a9

Please sign in to comment.