| 1 | let { parse } = require('postcss') |
| 2 | let { test } = require('uvu') |
| 3 | let { equal, is, type } = require('uvu/assert') |
| 4 | |
| 5 | let Prefixer = require('../lib/prefixer') |
| 6 | |
| 7 | let css, prefix |
| 8 | test.before.each(() => { |
| 9 | prefix = new Prefixer() |
| 10 | css = parse( |
| 11 | '@-ms-keyframes a { to { } } ' + |
| 12 | ':-moz-full-screen { } a { } ' + |
| 13 | '@-dev-keyframes s { to { } }' |
| 14 | ) |
| 15 | }) |
| 16 | |
| 17 | test('registers hacks for subclasses', () => { |
| 18 | class A extends Prefixer {} |
| 19 | class Hack extends A {} |
| 20 | Hack.names = ['a', 'b'] |
| 21 | |
| 22 | A.hack(Hack) |
| 23 | |
| 24 | equal(A.hacks, { a: Hack, b: Hack }) |
| 25 | type(Prefixer.hacks, 'undefined') |
| 26 | }) |
| 27 | |
| 28 | test('loads hacks', () => { |
| 29 | class A extends Prefixer { |
| 30 | constructor() { |
| 31 | super() |
| 32 | this.klass = 'a' |
| 33 | } |
| 34 | } |
| 35 | class Hack extends A { |
| 36 | constructor() { |
| 37 | super() |
| 38 | this.klass = 'hack' |
| 39 | } |
| 40 | } |
| 41 | A.hacks = { hacked: Hack } |
| 42 | |
| 43 | equal(A.load('hacked').klass, 'hack') |
| 44 | equal(A.load('a').klass, 'a') |
| 45 | }) |
| 46 | |
| 47 | test('cleans custom properties', () => { |
| 48 | let rule = css.first.first |
| 49 | rule._autoprefixerPrefix = '-ms-' |
| 50 | rule._autoprefixerValues = { '-ms-': 1 } |
| 51 | |
| 52 | let cloned = Prefixer.clone(rule, { selector: 'from' }) |
| 53 | equal(cloned.selector, 'from') |
| 54 | |
| 55 | type(cloned._autoprefixerPrefix, 'undefined') |
| 56 | type(cloned._autoprefixerValues, 'undefined') |
| 57 | }) |
| 58 | |
| 59 | test('fixed declaration between', () => { |
| 60 | let parsed = parse('a { color : black }') |
| 61 | let cloned = Prefixer.clone(parsed.first.first) |
| 62 | equal(cloned.raws.between, ' : ') |
| 63 | }) |
| 64 | |
| 65 | test('works with root node', () => { |
| 66 | is(prefix.parentPrefix(css), false) |
| 67 | }) |
| 68 | |
| 69 | test('finds in at-rules', () => { |
| 70 | equal(prefix.parentPrefix(css.first), '-ms-') |
| 71 | }) |
| 72 | |
| 73 | test('finds in selectors', () => { |
| 74 | equal(prefix.parentPrefix(css.nodes[1]), '-moz-') |
| 75 | }) |
| 76 | |
| 77 | test('finds in parents', () => { |
| 78 | let decl = css.first.first |
| 79 | equal(prefix.parentPrefix(decl), '-ms-') |
| 80 | is(prefix.parentPrefix(css.nodes[2]), false) |
| 81 | }) |
| 82 | |
| 83 | test('caches prefix', () => { |
| 84 | prefix.parentPrefix(css.first) |
| 85 | equal(css.first._autoprefixerPrefix, '-ms-') |
| 86 | |
| 87 | css.first._autoprefixerPrefix = false |
| 88 | is(prefix.parentPrefix(css.first), false) |
| 89 | }) |
| 90 | |
| 91 | test('finds only browsers prefixes', () => { |
| 92 | is(prefix.parentPrefix(css.nodes[2]), false) |
| 93 | }) |
| 94 | |
| 95 | test('works with selector contained --', () => { |
| 96 | let parsed = parse(':--a { color: black }') |
| 97 | is(prefix.parentPrefix(parsed.first.first), false) |
| 98 | }) |
| 99 | |
| 100 | test.run() |