-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Init tests * Add more tests * Tests * Add coverage
- Loading branch information
1 parent
8b04cc4
commit 1a437f8
Showing
21 changed files
with
1,997 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
name: Tests | ||
|
||
on: | ||
push: | ||
branches: [ master ] | ||
pull_request: | ||
branches: [ master ] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-20.04 | ||
strategy: | ||
matrix: | ||
node-version: [16.x, 18.x, 20.x] | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
- uses: actions/cache@v3 | ||
id: yarn-cache | ||
with: | ||
path: .yarn/cache | ||
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} | ||
restore-keys: | | ||
${{ runner.os }}-yarn- | ||
- name: Install Dependencies | ||
run: yarn install | ||
- name: Run tests | ||
run: yarn test -- --ci --coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,5 @@ node_modules | |
.yarn/local | ||
.pnp.* | ||
**/dist/* | ||
**/.turbo/* | ||
**/.turbo/* | ||
**/coverage/* |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { JSDOM } from "jsdom" | ||
const dom = new JSDOM() | ||
global.document = dom.window.document | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
global.window = dom.window |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
export default { | ||
preset: 'ts-jest', | ||
testEnvironment: 'node', | ||
setupFiles: ['./jest.client.ts'], | ||
coverageThreshold: { | ||
global: { | ||
branches: 90, | ||
functions: 90, | ||
lines: 90, | ||
statements: 90, | ||
}, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { describe, expect, test } from '@jest/globals' | ||
import { stylis, compile } from './css' | ||
import { Style } from '.' | ||
|
||
describe('stylis', () => { | ||
test('should return an empty array if the CSS string is empty', () => { | ||
const css = '' | ||
const results = stylis(css) | ||
expect(results).toHaveLength(0) | ||
}) | ||
|
||
test('should return an array of CSS strings with comments removed', () => { | ||
const css = '/* This is a comment */ p { color: red; } /* This is another comment */' | ||
const results = stylis(css) | ||
expect(results).toHaveLength(1) | ||
expect(results.at(0)).toBe('p{color:red;}') | ||
}) | ||
|
||
test('should return button with hover from nasted selector ', () => { | ||
const css = 'button { color: blue; &:hover: { color: red; } }' | ||
const results = stylis(css) | ||
expect(results).toHaveLength(2) | ||
expect(results).toEqual(['button{color:blue;}', 'button:hover:{color:red;}']) | ||
}) | ||
}) | ||
|
||
describe('compile', () => { | ||
test('without props', () => { | ||
const style: Style<{}> = [['color: blue;'], []] | ||
const compiled = compile<{}>([style], {}) | ||
|
||
expect(compiled).toEqual([{ id: '1r77qux', name: 'teiler-1r77qux', css: 'color: blue;' }]) | ||
}) | ||
|
||
test('with props', () => { | ||
type Props = { color: string } | ||
|
||
const style: Style<Props> = [['color: ', ';'], [({ color }) => color]] | ||
const compiled = compile<Props>([style], { color: 'red' }) | ||
|
||
expect(compiled).toEqual([{ id: 'wq229y', name: 'teiler-wq229y', css: 'color: red;' }]) | ||
}) | ||
|
||
test('with object', () => { | ||
const keyframes = { | ||
css: '@keyframes test { from { background-color: yellow; } to { background-color: red; } }', | ||
id: '14uknit', | ||
name: 'teiler-keyframes-14uknit', | ||
} | ||
|
||
const style: Style<{}> = [['animation: ', ' 5s;'], [keyframes]] | ||
const compiled = compile<{}>([style], {}) | ||
|
||
expect(compiled).toEqual([ | ||
keyframes, | ||
{ | ||
id: 'd18jjz', | ||
name: 'teiler-d18jjz', | ||
css: 'animation: teiler-keyframes-14uknit 5s;', | ||
}, | ||
]) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { describe, expect, test } from '@jest/globals' | ||
import hash from './hash' | ||
|
||
describe('hash', () => { | ||
test('create hash', () => { | ||
const styles = ` | ||
color: red; | ||
background: blue; | ||
` | ||
|
||
const generated = hash(styles) | ||
expect(generated).toEqual('1a6449z') | ||
}) | ||
|
||
test('compare hashe of styles', () => { | ||
const styles = ` | ||
color: red; | ||
background: blue; | ||
` | ||
|
||
const hash1 = hash(styles) | ||
const hash2 = hash(styles) | ||
|
||
expect(hash1).toEqual(hash2) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
import type { Compile, Style, TeilerComponent } from '.' | ||
|
||
import { describe, jest, expect, test } from '@jest/globals' | ||
import styled, { component, global, keyframes, createStyleSheet } from '.' | ||
|
||
const createComponent = <Target, Props>(compile: Compile, tag: Target, styles: Array<Style<Props>>): TeilerComponent<Target, Props> => { | ||
return { | ||
tag, | ||
styles, | ||
} | ||
} | ||
|
||
describe('styled', () => { | ||
test('should create component', () => { | ||
const createComponentBinded = createComponent.bind(null, null, 'div') | ||
const template = ['color: red;'] | ||
const test = jest.fn(styled) | ||
|
||
test(createComponentBinded, template) | ||
|
||
expect(test).toHaveReturnedWith({ styles: [[['color: red;'], []]], tag: 'div' }) | ||
}) | ||
|
||
test('should extend component', () => { | ||
const createComponentBinded = createComponent.bind(null, null, 'div') | ||
const template = ['background: blue;'] | ||
const component: TeilerComponent<'div', {}> = { tag: 'div', styles: [[['color: red;'], []]] } | ||
|
||
const extend = styled(createComponentBinded, component) | ||
|
||
type Callable = Extract<typeof extend, Function> | ||
|
||
const test = jest.fn(extend as Callable) | ||
|
||
test(template) | ||
|
||
expect(test).toHaveReturnedWith({ | ||
styles: [ | ||
[['color: red;'], []], | ||
[['background: blue;'], []], | ||
], | ||
tag: 'div', | ||
}) | ||
}) | ||
}) | ||
|
||
describe('component', () => { | ||
test('should create style from styles', () => { | ||
const styleSheet = createStyleSheet({}) | ||
const test = jest.fn(component) | ||
|
||
test(styleSheet, [[['color: red;'], []]], []) | ||
|
||
expect(test).toHaveReturnedWith(['teiler-wq229y']) | ||
}) | ||
|
||
test('should create style from styles with props', () => { | ||
const styleSheet = createStyleSheet({}) | ||
const test = jest.fn(component) | ||
|
||
test(styleSheet, [[['color: ', ';'], [({ color }) => color]]], [{ color: 'red' }]) | ||
|
||
expect(test).toHaveReturnedWith(['teiler-10upe3l']) | ||
}) | ||
}) | ||
|
||
describe('global', () => { | ||
test('should create style from styles', () => { | ||
const styleSheet = createStyleSheet({}) | ||
const test = jest.fn(global) | ||
|
||
test(styleSheet, [[['body { color: red; }'], []]], {}) | ||
|
||
expect(test).toHaveReturnedWith(undefined) | ||
expect(styleSheet.dump()).toContain(' body{color:red;}') | ||
}) | ||
|
||
test('should create style from styles with props', () => { | ||
const styleSheet = createStyleSheet({}) | ||
const test = jest.fn(global) | ||
|
||
test(styleSheet, [[['body { color: ', '; }'], [({ color }) => color]]], { color: 'blue' }) | ||
|
||
expect(test).toHaveReturnedWith(undefined) | ||
expect(styleSheet.dump()).toContain(' body{color:blue;}') | ||
}) | ||
}) | ||
|
||
describe('keyframes', () => { | ||
test('should create a keyframes definition with the given strings and properties', () => { | ||
const keyframesDefinition = keyframes`from { background-color: red; } to { background-color: green; }` | ||
|
||
expect(keyframesDefinition).toStrictEqual({ | ||
css: `@keyframes teiler-keyframes-1ep7axc { from { background-color: red; } to { background-color: green; } }`, | ||
id: '1ep7axc', | ||
name: 'teiler-keyframes-1ep7axc', | ||
}) | ||
}) | ||
|
||
test('should allow passing properties to the keyframes definition', () => { | ||
const props = { | ||
from: 'yellow', | ||
to: 'red', | ||
} | ||
|
||
const keyframesDefinition = keyframes`from { background-color: ${props.from}; } to { background-color: ${props.to}; }` | ||
|
||
expect(keyframesDefinition).toEqual({ | ||
css: '@keyframes teiler-keyframes-14uknit { from { background-color: yellow; } to { background-color: red; } }', | ||
id: '14uknit', | ||
name: 'teiler-keyframes-14uknit', | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.