1
- import { expect } from 'chai' ;
2
1
import * as cheerio from 'cheerio' ;
2
+ import assert from 'node:assert/strict' ;
3
+ import { before , describe , it } from 'node:test' ;
3
4
import { loadFixture } from './test-utils.js' ;
4
5
5
6
describe ( '<Code>' , ( ) => {
@@ -13,33 +14,35 @@ describe('<Code>', () => {
13
14
it ( '<Code> without lang or theme' , async ( ) => {
14
15
let html = await fixture . readFile ( '/no-lang/index.html' ) ;
15
16
const $ = cheerio . load ( html ) ;
16
- expect ( $ ( 'pre' ) ) . to . have . lengthOf ( 1 ) ;
17
- expect ( $ ( 'pre' ) . attr ( 'style' ) ) . to . equal (
17
+ assert . equal ( $ ( 'pre' ) . length , 1 ) ;
18
+ assert . equal (
19
+ $ ( 'pre' ) . attr ( 'style' ) ,
18
20
'background-color:#24292e;color:#e1e4e8; overflow-x: auto;' ,
19
21
'applies default and overflow'
20
22
) ;
21
- expect ( $ ( 'pre > code' ) ) . to . have . lengthOf ( 1 ) ;
23
+ assert . equal ( $ ( 'pre > code' ) . length , 1 ) ;
22
24
23
25
// test: contains some generated spans
24
- expect ( $ ( 'pre > code span' ) . length ) . to . be . greaterThan ( 1 ) ;
26
+ assert . equal ( $ ( 'pre > code span' ) . length > 1 , true ) ;
25
27
} ) ;
26
28
27
29
it ( '<Code lang="...">' , async ( ) => {
28
30
let html = await fixture . readFile ( '/basic/index.html' ) ;
29
31
const $ = cheerio . load ( html ) ;
30
- expect ( $ ( 'pre' ) ) . to . have . lengthOf ( 1 ) ;
31
- expect ( $ ( 'pre' ) . attr ( 'class' ) , 'astro-code nord ' ) ;
32
- expect ( $ ( 'pre > code' ) ) . to . have . lengthOf ( 1 ) ;
32
+ assert . equal ( $ ( 'pre' ) . length , 1 ) ;
33
+ assert . equal ( $ ( 'pre' ) . attr ( 'class' ) , 'astro-code github-dark ' ) ;
34
+ assert . equal ( $ ( 'pre > code' ) . length , 1 ) ;
33
35
// test: contains many generated spans
34
- expect ( $ ( 'pre > code span' ) . length ) . to . be . greaterThanOrEqual ( 6 ) ;
36
+ assert . equal ( $ ( 'pre > code span' ) . length >= 6 , true ) ;
35
37
} ) ;
36
38
37
39
it ( '<Code theme="...">' , async ( ) => {
38
40
let html = await fixture . readFile ( '/custom-theme/index.html' ) ;
39
41
const $ = cheerio . load ( html ) ;
40
- expect ( $ ( 'pre' ) ) . to . have . lengthOf ( 1 ) ;
41
- expect ( $ ( 'pre' ) . attr ( 'class' ) ) . to . equal ( 'astro-code nord' ) ;
42
- expect ( $ ( 'pre' ) . attr ( 'style' ) ) . to . equal (
42
+ assert . equal ( $ ( 'pre' ) . length , 1 ) ;
43
+ assert . equal ( $ ( 'pre' ) . attr ( 'class' ) , 'astro-code nord' ) ;
44
+ assert . equal (
45
+ $ ( 'pre' ) . attr ( 'style' ) ,
43
46
'background-color:#2e3440ff;color:#d8dee9ff; overflow-x: auto;' ,
44
47
'applies custom theme'
45
48
) ;
@@ -49,67 +52,73 @@ describe('<Code>', () => {
49
52
{
50
53
let html = await fixture . readFile ( '/wrap-true/index.html' ) ;
51
54
const $ = cheerio . load ( html ) ;
52
- expect ( $ ( 'pre' ) ) . to . have . lengthOf ( 1 ) ;
55
+ assert . equal ( $ ( 'pre' ) . length , 1 ) ;
53
56
// test: applies wrap overflow
54
- expect ( $ ( 'pre' ) . attr ( 'style' ) ) . to . equal (
57
+ assert . equal (
58
+ $ ( 'pre' ) . attr ( 'style' ) ,
55
59
'background-color:#24292e;color:#e1e4e8; overflow-x: auto; white-space: pre-wrap; word-wrap: break-word;'
56
60
) ;
57
61
}
58
62
{
59
63
let html = await fixture . readFile ( '/wrap-false/index.html' ) ;
60
64
const $ = cheerio . load ( html ) ;
61
- expect ( $ ( 'pre' ) ) . to . have . lengthOf ( 1 ) ;
65
+ assert . equal ( $ ( 'pre' ) . length , 1 ) ;
62
66
// test: applies wrap overflow
63
- expect ( $ ( 'pre' ) . attr ( 'style' ) ) . to . equal (
67
+ assert . equal (
68
+ $ ( 'pre' ) . attr ( 'style' ) ,
64
69
'background-color:#24292e;color:#e1e4e8; overflow-x: auto;'
65
70
) ;
66
71
}
67
72
{
68
73
let html = await fixture . readFile ( '/wrap-null/index.html' ) ;
69
74
const $ = cheerio . load ( html ) ;
70
- expect ( $ ( 'pre' ) ) . to . have . lengthOf ( 1 ) ;
75
+ assert . equal ( $ ( 'pre' ) . length , 1 ) ;
71
76
// test: applies wrap overflow
72
- expect ( $ ( 'pre' ) . attr ( 'style' ) ) . to . equal ( 'background-color:#24292e;color:#e1e4e8' ) ;
77
+ assert . equal ( $ ( 'pre' ) . attr ( 'style' ) , 'background-color:#24292e;color:#e1e4e8' ) ;
73
78
}
74
79
} ) ;
75
80
76
81
it ( '<Code lang="..." theme="css-variables">' , async ( ) => {
77
82
let html = await fixture . readFile ( '/css-theme/index.html' ) ;
78
83
const $ = cheerio . load ( html ) ;
79
- expect ( $ ( 'pre' ) ) . to . have . lengthOf ( 1 ) ;
80
- expect ( $ ( 'pre' ) . attr ( 'class' ) ) . to . equal ( 'astro-code css-variables' ) ;
81
- expect (
84
+ assert . equal ( $ ( 'pre' ) . length , 1 ) ;
85
+ assert . equal ( $ ( 'pre' ) . attr ( 'class' ) , 'astro-code css-variables' ) ;
86
+ assert . deepEqual (
82
87
$ ( 'pre, pre span' )
83
88
. map ( ( i , f ) => ( f . attribs ? f . attribs . style : 'no style found' ) )
84
- . toArray ( )
85
- ) . to . deep . equal ( [
86
- 'background-color:var(--astro-code-color-background);color:var(--astro-code-color-text); overflow-x: auto;' ,
87
- 'color:var(--astro-code-token-constant)' ,
88
- 'color:var(--astro-code-token-function)' ,
89
- 'color:var(--astro-code-color-text)' ,
90
- 'color:var(--astro-code-token-string-expression)' ,
91
- 'color:var(--astro-code-color-text)' ,
92
- ] ) ;
89
+ . toArray ( ) ,
90
+ [
91
+ 'background-color:var(--astro-code-color-background);color:var(--astro-code-color-text); overflow-x: auto;' ,
92
+ 'color:var(--astro-code-token-constant)' ,
93
+ 'color:var(--astro-code-token-function)' ,
94
+ 'color:var(--astro-code-color-text)' ,
95
+ 'color:var(--astro-code-token-string-expression)' ,
96
+ 'color:var(--astro-code-color-text)' ,
97
+ ]
98
+ ) ;
93
99
} ) ;
94
100
95
101
it ( '<Code> with custom theme and lang' , async ( ) => {
96
102
let html = await fixture . readFile ( '/imported/index.html' ) ;
97
103
const $ = cheerio . load ( html ) ;
98
104
99
- expect ( $ ( '#theme > pre' ) ) . to . have . lengthOf ( 1 ) ;
100
- expect ( $ ( '#theme > pre' ) . attr ( 'style' ) , 'background-color: #FDFDFE; overflow-x: auto;' ) ;
105
+ assert . equal ( $ ( '#theme > pre' ) . length , 1 ) ;
106
+ assert . equal (
107
+ $ ( '#theme > pre' ) . attr ( 'style' ) ,
108
+ 'background-color:#FDFDFE;color:#4E5377; overflow-x: auto;'
109
+ ) ;
101
110
102
- expect ( $ ( '#lang > pre' ) ) . to . have . lengthOf ( 1 ) ;
103
- expect ( $ ( '#lang > pre > code span' ) . length ) . to . equal ( 3 ) ;
111
+ assert . equal ( $ ( '#lang > pre' ) . length , 1 ) ;
112
+ assert . equal ( $ ( '#lang > pre > code span' ) . length , 3 ) ;
104
113
} ) ;
105
114
106
115
it ( '<Code inline> has no pre tag' , async ( ) => {
107
116
let html = await fixture . readFile ( '/inline/index.html' ) ;
108
117
const $ = cheerio . load ( html ) ;
109
118
const codeEl = $ ( '.astro-code' ) ;
110
119
111
- expect ( codeEl . prop ( 'tagName' ) ) . to . eq ( 'CODE' ) ;
112
- expect ( codeEl . attr ( 'style' ) ) . to . include ( ' background-color:' ) ;
113
- expect ( $ ( 'pre' ) ) . to . have . lengthOf ( 0 ) ;
120
+ assert . equal ( codeEl . prop ( 'tagName' ) , 'CODE' ) ;
121
+ assert . match ( codeEl . attr ( 'style' ) , / b a c k g r o u n d - c o l o r : / ) ;
122
+ assert . equal ( $ ( 'pre' ) . length , 0 ) ;
114
123
} ) ;
115
124
} ) ;
0 commit comments