Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
1aron committed Nov 6, 2023
1 parent 3272ad7 commit 41b96f6
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 53 deletions.
3 changes: 2 additions & 1 deletion packages/css/src/config/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import type { Rule } from '../rule'

const functions = {
$: {
colored: true,
transform(value) {
return [{ type: 'variable', name: value }]
}
},
},
calc: {
transform(value, bypassVariableNames) {
Expand Down
7 changes: 7 additions & 0 deletions packages/css/tests/config/variables/color.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { testProp } from '../../css'

test('with fallback color', () => {
testProp('background-color:$(primary,white/.1)', 'background:var(rgb(0 0 0),rgb(255 255 255/.1))', {
variables: { primary: '#000000' }
})
})
22 changes: 22 additions & 0 deletions packages/css/tests/config/variables/number.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,25 @@ test('number with themes using variable function', () => {
}
})
})

test('variables', () => {
testCSS('m:$(spacing-x1)', '.m\\:\\$\\(spacing-x1\\){margin:1rem}', {
variables: {
spacing: { x1: 16, x2: 32 },
}
})
})

test('negative variables', () => {
testCSS('m:$(-spacing-x1)', '.m\\:\\$\\(-spacing-x1\\){margin:-1rem}', {
variables: {
spacing: { x1: 16, x2: 32 }
}
})

testCSS('w:-11x', '.w\\:-11x{width:-3.75rem}', {
variables: {
width: { '11x': 60 }
}
})
})
78 changes: 27 additions & 51 deletions packages/css/tests/config/variables/test.ts
Original file line number Diff line number Diff line change
@@ -1,58 +1,34 @@
import { testCSS } from '../../css'
import config from '../../config'

// it('uses with $ function', () => {
// testCSS('font-weight:$(fontWeight-thin)', '.font-weight\\:\\$\\(fontWeight-thin\\){font-weight:100}')
// })

// test('variables', () => {
// testCSS('m:$(spacing-x1)', '.m\\:\\$\\(spacing-x1\\){margin:1rem}', {
// variables: {
// spacing: { x1: 16, x2: 32 },
// }
// })
// })
it('uses with $ function', () => {
testCSS('font-weight:$(fontWeight-thin)', '.font-weight\\:\\$\\(fontWeight-thin\\){font-weight:100}')
})

test('negative variables', () => {
testCSS('m:$(-spacing-x1)', '.m\\:\\$\\(-spacing-x1\\){margin:-1rem}', {
test('rule variables', () => {
testCSS('font:sm', '.font\\:sm{font-size:1rem}', config)
testCSS('font-size:sm', '.font-size\\:sm{font-size:1rem}', config)
testCSS('ls:wide', '.ls\\:wide{letter-spacing:0.025em}', config)
testCSS('letter-spacing:wide', '.letter-spacing\\:wide{letter-spacing:0.025em}', config)
testCSS('shadow:x2', '.shadow\\:x2{box-shadow:0rem 25px 50px -12px rgb(0 0 0 / 25%)}', config)
testCSS('inset:sm|md|md|sm', '.inset\\:sm\\|md\\|md\\|sm{inset:0.625rem 1.25rem 1.25rem 0.625rem}', config)
testCSS('b:inputborder', '.b\\:inputborder{border:0.125rem solid rgb(209 26 30)}', config)
testCSS('content:delimiter', '.content\\:delimiter{content:"123"}', {
variables: {
spacing: { x1: 16, x2: 32 }
content: { delimiter: '"123"' }
}
})
})

// test('rule variables', () => {
// testCSS('font:sm', '.font\\:sm{font-size:1rem}', config)
// testCSS('font-size:sm', '.font-size\\:sm{font-size:1rem}', config)
// testCSS('ls:wide', '.ls\\:wide{letter-spacing:0.025em}', config)
// testCSS('letter-spacing:wide', '.letter-spacing\\:wide{letter-spacing:0.025em}', config)
// testCSS('shadow:x2', '.shadow\\:x2{box-shadow:0rem 25px 50px -12px rgb(0 0 0 / 25%)}', config)
// testCSS('inset:sm|md|md|sm', '.inset\\:sm\\|md\\|md\\|sm{inset:0.625rem 1.25rem 1.25rem 0.625rem}', config)
// testCSS('b:inputborder', '.b\\:inputborder{border:0.125rem solid rgb(209 26 30)}', config)
// testCSS('content:delimiter', '.content\\:delimiter{content:"123"}', {
// variables: {
// content: { delimiter: '"123"' }
// }
// })
// testCSS('content:delimiter', '.content\\:delimiter{content:"|"}', {
// variables: {
// content: { delimiter: '"|"' }
// }
// })
// testCSS('b:input', '.b\\:input{border:0.0625rem solid rgb(0 0 0)}', {
// variables: {
// border: {
// input: '1|solid|test-70'
// },
// test: { 70: '#000' }
// }
// })
// })

// it('negative variables', () => {
// testCSS('w:-11x', '.w\\:-11x{width:-3.75rem}', {
// variables: {
// width: { '11x': 60 }
// }
// })
// })
testCSS('content:delimiter', '.content\\:delimiter{content:"|"}', {
variables: {
content: { delimiter: '"|"' }
}
})
testCSS('b:input', '.b\\:input{border:0.0625rem solid rgb(0 0 0)}', {
variables: {
border: {
input: '1|solid|test-70'
},
test: { 70: '#000' }
}
})
})
1 change: 0 additions & 1 deletion packages/css/tests/variables.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import puppeteer, { Browser, ElementHandle, Page } from 'puppeteer-core'
import path from 'path'
import type { MasterCSS } from '../src'

const variables = {
first: {
Expand Down

0 comments on commit 41b96f6

Please sign in to comment.