This repository was archived by the owner on Jan 30, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 6 files changed +114
-0
lines changed
Expand file tree Collapse file tree 6 files changed +114
-0
lines changed Original file line number Diff line number Diff line change 1+ import { exec } from 'child_process' ;
2+ import { promisify } from 'util' ;
3+ import path from 'path' ;
4+
5+ const execPromise = promisify ( exec ) ;
6+
7+ test ( 'CSS compilation logs contain expected output' , async ( ) => {
8+ const { stdout } = await execPromise ( 'npm run compile' , {
9+ cwd : path . join ( __dirname , '../e2e/site' ) ,
10+ } ) ;
11+
12+ console . log ( 'stdout:' , stdout ) ;
13+ expect ( stdout ) . toContain ( 'Generating module static css' ) ;
14+ expect ( stdout ) . toContain ( '.e2e_' ) ;
15+ expect ( stdout ) . toContain ( 'color: pink;' ) ;
16+ expect ( stdout ) . toContain ( '@media (max-width: 1024px)' ) ;
17+ expect ( stdout ) . toContain ( 'color: aqua;' ) ;
18+ } ) ;
Original file line number Diff line number Diff line change 1+ import { create } from '../src/core/method/create' ;
2+
3+ test ( 'Style.create returns an object with string values' , ( ) => {
4+ const styleObject = {
5+ test : {
6+ color : 'red' ,
7+ fontSize : '16px' ,
8+ } ,
9+ } ;
10+
11+ const styles = create ( styleObject ) ;
12+ expect ( typeof styles ) . toBe ( 'object' ) ;
13+ expect ( typeof styles . test ) . toBe ( 'string' ) ;
14+
15+ const styleElement = document . createElement ( 'style' ) ;
16+ styleElement . textContent = `.${ styles . test } { color: ${ styleObject . test . color } ; font-size: ${ styleObject . test . fontSize } ; }` ;
17+ document . head . appendChild ( styleElement ) ;
18+
19+ document . body . innerHTML = `<div class="${ styles . test } ">Test Element</div>` ;
20+ const element = document . querySelector ( `.${ styles . test } ` ) as HTMLElement ;
21+ const computedStyle = window . getComputedStyle ( element ) ;
22+ expect ( computedStyle . color ) . toBe ( 'red' ) ;
23+ expect ( computedStyle . fontSize ) . toBe ( '16px' ) ;
24+ } ) ;
Original file line number Diff line number Diff line change 1+ import { global } from '../src/core/method/global' ;
2+
3+ test ( 'Style.global insert style into the head with data-scope="global"' , ( ) => {
4+ global ( {
5+ h1 : {
6+ fontSize : 24 ,
7+ } ,
8+ } ) ;
9+
10+ const styleElements = document . head . querySelectorAll ( 'style[data-scope="global"]' ) ;
11+ expect ( styleElements . length ) . toBeGreaterThan ( 0 ) ;
12+
13+ const styleContent = styleElements [ 0 ] . textContent ;
14+ expect ( styleContent ) . toContain ( 'h1' ) ;
15+ expect ( styleContent ) . toContain ( 'font-size: 24px' ) ;
16+ } ) ;
Original file line number Diff line number Diff line change 1+ import { root } from '../src/core/method/root' ;
2+
3+ test ( 'Style.root insert style into the head with data-scope="root"' , ( ) => {
4+ root ( {
5+ '--color-heading' : '#333' ,
6+ } ) ;
7+
8+ const styleElements = document . head . querySelectorAll ( 'style[data-scope="root"]' ) ;
9+ expect ( styleElements . length ) . toBeGreaterThan ( 0 ) ;
10+
11+ const styleContent = styleElements [ 0 ] . textContent ;
12+ expect ( styleContent ) . toContain ( '--color-heading: #333' ) ;
13+ } ) ;
Original file line number Diff line number Diff line change 1+ import { set } from '../src/core/method/set' ;
2+
3+ test ( 'Style.set creates a class with correct styles' , ( ) => {
4+ const styleObject = {
5+ color : 'blue' ,
6+ margin : '10px' ,
7+ } ;
8+
9+ const style = set ( styleObject ) ;
10+ expect ( typeof style ) . toBe ( 'string' ) ;
11+
12+ const styleElement = document . createElement ( 'style' ) ;
13+ styleElement . textContent = `.${ style } { color: ${ styleObject . color } ; margin: ${ styleObject . margin } ; }` ;
14+ document . head . appendChild ( styleElement ) ;
15+
16+ document . body . innerHTML = `<div class="${ style } ">Test Element</div>` ;
17+ const element = document . querySelector ( `.${ style } ` ) as HTMLElement ;
18+ const computedStyle = window . getComputedStyle ( element ) ;
19+ expect ( computedStyle . color ) . toBe ( 'blue' ) ;
20+ expect ( computedStyle . margin ) . toBe ( '10px' ) ;
21+ } ) ;
Original file line number Diff line number Diff line change 1+ import Style from '../src/core' ;
2+
3+ test ( 'Style.create returns an object with string values' , ( ) => {
4+ const styles = Style . create ( { test : { color : 'aqua' } } ) ;
5+ expect ( typeof styles ) . toBe ( 'object' ) ;
6+ expect ( typeof styles . test ) . toBe ( 'string' ) ;
7+ } ) ;
8+
9+ test ( 'Style.set returns a string' , ( ) => {
10+ const styleClass = Style . set ( { color : 'aqua' } ) ;
11+ expect ( typeof styleClass ) . toBe ( 'string' ) ;
12+ } ) ;
13+
14+ test ( 'Style.global returns undefined' , ( ) => {
15+ const result = Style . global ( { } ) ;
16+ expect ( result ) . toBeUndefined ( ) ;
17+ } ) ;
18+
19+ test ( 'Style.root returns undefined' , ( ) => {
20+ const result = Style . root ( { } ) ;
21+ expect ( result ) . toBeUndefined ( ) ;
22+ } ) ;
You can’t perform that action at this time.
0 commit comments