rescript-polished 1.15.0 โ 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/dependabot.yml +26 -0
- package/.github/workflows/release.yml +23 -20
- package/.husky/commit-msg +4 -0
- package/.husky/pre-commit +1 -0
- package/.releaserc.json +79 -0
- package/README.md +1 -1
- package/__tests__/PolishedCssTest.res +66 -77
- package/__tests__/PolishedTest.res +231 -237
- package/__tests__/RunTests.res +5 -0
- package/__tests__/TestFramework.res +170 -0
- package/commitlint.config.js +0 -0
- package/package.json +24 -20
- package/{bsconfig.json โ rescript.json} +7 -3
- package/src/PolishedCss__Color.res +16 -16
- package/src/Polished__Color.res +14 -14
- package/src/Polished__Mixins.res +12 -12
- package/lib/js/__tests__/PolishedCssTest.js +0 -171
- package/lib/js/__tests__/PolishedTest.js +0 -183
- package/lib/js/__tests__/__snapshots__/PolishedTest.js.snap +0 -63
- package/lib/js/src/Polished.js +0 -14
- package/lib/js/src/PolishedCss.js +0 -8
- package/lib/js/src/PolishedCss__Color.js +0 -140
- package/lib/js/src/Polished__Color.js +0 -144
- package/lib/js/src/Polished__Math.js +0 -11
- package/lib/js/src/Polished__Mixins.js +0 -51
|
@@ -1,245 +1,239 @@
|
|
|
1
|
-
open
|
|
2
|
-
open Expect
|
|
1
|
+
open TestFramework
|
|
3
2
|
open Polished
|
|
4
3
|
|
|
5
|
-
let
|
|
6
|
-
|
|
7
|
-
describe("Color", () => {
|
|
4
|
+
let colorTests = () => {
|
|
8
5
|
open Color
|
|
9
6
|
|
|
10
|
-
|
|
11
|
-
"
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
"
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
"
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
"
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
"
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
"
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
test("saturate", () => {
|
|
164
|
-
"#ed5051"->saturate(~amount=0.5)->expect |> toBe("#ff3e3f")
|
|
165
|
-
})
|
|
166
|
-
|
|
167
|
-
test("setHue", () => {
|
|
168
|
-
"#CCCD64"->setHue(~hue=42)->expect |> toBe("#cdae64")
|
|
169
|
-
})
|
|
170
|
-
|
|
171
|
-
test("setLightness", () => {
|
|
172
|
-
"#CCCD64"->setLightness(~lightness=0.2)->expect |> toBe("#4d4d19")
|
|
173
|
-
})
|
|
174
|
-
|
|
175
|
-
test("setSaturation", () => {
|
|
176
|
-
"#CCCD64"->setSaturation(~saturation=0.2)->expect |> toBe("#adad84")
|
|
177
|
-
})
|
|
178
|
-
})
|
|
179
|
-
|
|
180
|
-
describe("Math", () => {
|
|
7
|
+
[
|
|
8
|
+
test("shade", () => {
|
|
9
|
+
assertEqual("#ed5051"->shade(~amount=0.25), "#b13c3c")
|
|
10
|
+
}),
|
|
11
|
+
test("tint", () => {
|
|
12
|
+
assertEqual("#ed5051"->tint(~amount=0.25), "#f17b7c")
|
|
13
|
+
}),
|
|
14
|
+
test("lighten", () => {
|
|
15
|
+
assertEqual("#ed5051"->lighten(~amount=0.25), "#f9c4c4")
|
|
16
|
+
}),
|
|
17
|
+
test("darken", () => {
|
|
18
|
+
assertEqual("#ed5051"->darken(~amount=0.25), "#ac1213")
|
|
19
|
+
}),
|
|
20
|
+
test("hsl", () => {
|
|
21
|
+
assertEqual(hsl(~hue=30., ~saturation=0.5, ~lightness=0.3), "#734d26")
|
|
22
|
+
}),
|
|
23
|
+
test("adjustHue", () => {
|
|
24
|
+
assertEqual("#ed5051"->adjustHue(~degree=30.5), "#ed9f50")
|
|
25
|
+
}),
|
|
26
|
+
test("complement", () => {
|
|
27
|
+
assertEqual("#ed5051"->complement, "#50edec")
|
|
28
|
+
}),
|
|
29
|
+
test("desaturate", () => {
|
|
30
|
+
assertEqual("#ed5051"->desaturate(~amount=25.5), "#9f9f9f")
|
|
31
|
+
}),
|
|
32
|
+
test("getContrast", () => {
|
|
33
|
+
assertEqual("#ed5051"->getContrast("#fff"), 3.58)
|
|
34
|
+
}),
|
|
35
|
+
test("getLuminance", () => {
|
|
36
|
+
assertEqual("#ed5051"->getLuminance, 0.243)
|
|
37
|
+
}),
|
|
38
|
+
test("grayscale", () => {
|
|
39
|
+
assertEqual("#ed5051"->grayscale, "#9f9f9f")
|
|
40
|
+
}),
|
|
41
|
+
test("hsla", () => {
|
|
42
|
+
assertEqual(
|
|
43
|
+
hsla(~hue=130., ~saturation=0.25, ~lightness=0.5, ~alpha=0.5),
|
|
44
|
+
"rgba(96,159,106,0.5)",
|
|
45
|
+
)
|
|
46
|
+
}),
|
|
47
|
+
test("invert", () => {
|
|
48
|
+
assertEqual("#ed5951"->invert, "#12a6ae")
|
|
49
|
+
}),
|
|
50
|
+
test("meetsContrastGuidelines", () => {
|
|
51
|
+
let expected: contrastScores = {
|
|
52
|
+
"AA": true,
|
|
53
|
+
"AALarge": true,
|
|
54
|
+
"AAA": true,
|
|
55
|
+
"AAALarge": true,
|
|
56
|
+
}
|
|
57
|
+
assertEqual("#000000"->meetsContrastGuidelines("#ffffff"), expected)
|
|
58
|
+
}),
|
|
59
|
+
test("transparentize", () => {
|
|
60
|
+
assertEqual("#ed5051"->transparentize(~amount=0.5), "rgba(237,80,81,0.5)")
|
|
61
|
+
}),
|
|
62
|
+
test("hslToColorString", () => {
|
|
63
|
+
let hsl = {
|
|
64
|
+
"hue": 240.,
|
|
65
|
+
"lightness": 1.0,
|
|
66
|
+
"saturation": 0.5,
|
|
67
|
+
}
|
|
68
|
+
assertEqual(hsl->hslToColorString, "#fff")
|
|
69
|
+
}),
|
|
70
|
+
test("mix", () => {
|
|
71
|
+
assertEqual("#ed5051"->mix("#bc9090", ~weight=0.2), "#c58383")
|
|
72
|
+
}),
|
|
73
|
+
test("opacify", () => {
|
|
74
|
+
assertEqual("#ed505100"->opacify(~amount=0.5), "rgba(237,80,81,0.5)")
|
|
75
|
+
}),
|
|
76
|
+
test("parseToHsl", () => {
|
|
77
|
+
let expected: hslColor = {
|
|
78
|
+
"hue": 0.0,
|
|
79
|
+
"lightness": 0.5,
|
|
80
|
+
"saturation": 1.0,
|
|
81
|
+
}
|
|
82
|
+
assertEqual("#FF0000"->parseToHsl, expected)
|
|
83
|
+
}),
|
|
84
|
+
test("parseToRgb", () => {
|
|
85
|
+
let expected: rgbColor = {
|
|
86
|
+
"red": 237,
|
|
87
|
+
"green": 80,
|
|
88
|
+
"blue": 81,
|
|
89
|
+
}
|
|
90
|
+
assertEqual("#ed5051"->parseToRgb, expected)
|
|
91
|
+
}),
|
|
92
|
+
test("readableColor", () => {
|
|
93
|
+
combineResults([
|
|
94
|
+
assertEqual("#ed5051"->readableColor(~strict=false, ()), "#000"),
|
|
95
|
+
assertEqual("#000"->readableColor(), "#fff"),
|
|
96
|
+
assertEqual("black"->readableColor(~darkReturnColor="#ff8", ()), "#ff8"),
|
|
97
|
+
assertEqual("white"->readableColor(~lightReturnColor="#001", ()), "#001"),
|
|
98
|
+
assertEqual(
|
|
99
|
+
"red"->readableColor(
|
|
100
|
+
~lightReturnColor="#333",
|
|
101
|
+
~darkReturnColor="#ddd",
|
|
102
|
+
~strict=true,
|
|
103
|
+
(),
|
|
104
|
+
),
|
|
105
|
+
"#000",
|
|
106
|
+
),
|
|
107
|
+
assertEqual(
|
|
108
|
+
"yellow"->readableColor(
|
|
109
|
+
~lightReturnColor="#333",
|
|
110
|
+
~darkReturnColor="#ddd",
|
|
111
|
+
~strict=true,
|
|
112
|
+
(),
|
|
113
|
+
),
|
|
114
|
+
"#333",
|
|
115
|
+
),
|
|
116
|
+
assertEqual(
|
|
117
|
+
"blue"->readableColor(
|
|
118
|
+
~lightReturnColor="#333",
|
|
119
|
+
~darkReturnColor="#ddd",
|
|
120
|
+
~strict=true,
|
|
121
|
+
(),
|
|
122
|
+
),
|
|
123
|
+
"#ddd",
|
|
124
|
+
),
|
|
125
|
+
])
|
|
126
|
+
}),
|
|
127
|
+
test("rgb", () => {
|
|
128
|
+
let subject: rgbColor = {
|
|
129
|
+
"red": 255,
|
|
130
|
+
"green": 255,
|
|
131
|
+
"blue": 255,
|
|
132
|
+
}
|
|
133
|
+
assertEqual(subject->rgb, "#fff")
|
|
134
|
+
}),
|
|
135
|
+
test("rgba", () => {
|
|
136
|
+
let subject: rgbaColor = {
|
|
137
|
+
"red": 255,
|
|
138
|
+
"green": 205,
|
|
139
|
+
"blue": 100,
|
|
140
|
+
"alpha": 0.7,
|
|
141
|
+
}
|
|
142
|
+
assertEqual(subject->rgba, "rgba(255,205,100,0.7)")
|
|
143
|
+
}),
|
|
144
|
+
test("saturate", () => {
|
|
145
|
+
assertEqual("#ed5051"->saturate(~amount=0.5), "#ff3e3f")
|
|
146
|
+
}),
|
|
147
|
+
test("setHue", () => {
|
|
148
|
+
assertEqual("#CCCD64"->setHue(~hue=42), "#cdae64")
|
|
149
|
+
}),
|
|
150
|
+
test("setLightness", () => {
|
|
151
|
+
assertEqual("#CCCD64"->setLightness(~lightness=0.2), "#4d4d19")
|
|
152
|
+
}),
|
|
153
|
+
test("setSaturation", () => {
|
|
154
|
+
assertEqual("#CCCD64"->setSaturation(~saturation=0.2), "#adad84")
|
|
155
|
+
}),
|
|
156
|
+
]
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
let mathTests = () => {
|
|
181
160
|
open Math
|
|
182
161
|
|
|
183
|
-
|
|
184
|
-
"
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
162
|
+
[
|
|
163
|
+
test("math", () => {
|
|
164
|
+
combineResults([
|
|
165
|
+
assertEqual("12px + 8px"->math(), "20px"),
|
|
166
|
+
assertEqual("12rem + 8rem"->math(), "20rem"),
|
|
167
|
+
{
|
|
168
|
+
let result = try {
|
|
169
|
+
let _ = math("10px + 8rem", ())
|
|
170
|
+
Fail("Expected exception to be thrown")
|
|
171
|
+
} catch {
|
|
172
|
+
| _ => Pass
|
|
173
|
+
}
|
|
174
|
+
result
|
|
175
|
+
},
|
|
176
|
+
])
|
|
177
|
+
}),
|
|
178
|
+
]
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
let mixinTests = () => {
|
|
193
182
|
open Mixins
|
|
194
183
|
|
|
195
|
-
|
|
196
|
-
between(
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
{
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
184
|
+
[
|
|
185
|
+
test("between", () => {
|
|
186
|
+
let result = between(
|
|
187
|
+
~fromSize=Size.makeString("16px"),
|
|
188
|
+
~toSize=Size.makeString("100px"),
|
|
189
|
+
~minScreen="400px",
|
|
190
|
+
~maxScreen="1000px",
|
|
191
|
+
(),
|
|
192
|
+
)
|
|
193
|
+
assertTrue(result != "", ~message="between should return non-empty string")
|
|
194
|
+
}),
|
|
195
|
+
test("clearfix", () => {
|
|
196
|
+
let result = clearFix(~parent="div")
|
|
197
|
+
assertTrue(result != "", ~message="clearFix should return non-empty string")
|
|
198
|
+
}),
|
|
199
|
+
test("cover", () => {
|
|
200
|
+
let result = cover(~offset=Size.makeString("16px"), ())
|
|
201
|
+
assertTrue(result != "", ~message="cover should return non-empty string")
|
|
202
|
+
}),
|
|
203
|
+
test("ellipsis", () => {
|
|
204
|
+
let result = ellipsis(~width=Size.makeString("16px"), ~lines=10, ())
|
|
205
|
+
assertTrue(result != "", ~message="ellipsis should return non-empty string")
|
|
206
|
+
}),
|
|
207
|
+
test("fluidRange", () => {
|
|
208
|
+
let result =
|
|
209
|
+
{
|
|
210
|
+
prop: "padding",
|
|
211
|
+
fromSize: Size.makeString("20px"),
|
|
212
|
+
toSize: Size.makeString("20px"),
|
|
213
|
+
}->fluidRange(~minScreen="320px", ~maxScreen="1024px")
|
|
214
|
+
assertTrue(result != "", ~message="fluidRange should return non-empty string")
|
|
215
|
+
}),
|
|
216
|
+
test("fluidRangeWithArray", () => {
|
|
217
|
+
let result =
|
|
218
|
+
[
|
|
219
|
+
{
|
|
220
|
+
prop: "padding",
|
|
221
|
+
fromSize: Size.makeString("16px"),
|
|
222
|
+
toSize: Size.makeString("32px"),
|
|
223
|
+
},
|
|
224
|
+
{
|
|
225
|
+
prop: "margin",
|
|
226
|
+
fromSize: Size.makeString("16px"),
|
|
227
|
+
toSize: Size.makeString("32px"),
|
|
228
|
+
},
|
|
229
|
+
]->fluidRangeWithArray(~minScreen="320px", ~maxScreen="1024px")
|
|
230
|
+
assertTrue(result != "", ~message="fluidRangeWithArray should return non-empty string")
|
|
231
|
+
}),
|
|
232
|
+
]
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
let suites = [
|
|
236
|
+
suite("Color", colorTests()),
|
|
237
|
+
suite("Math", mathTests()),
|
|
238
|
+
suite("Mixins", mixinTests()),
|
|
239
|
+
]
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
// Simple test framework
|
|
2
|
+
|
|
3
|
+
type testResult = Pass | Fail(string)
|
|
4
|
+
|
|
5
|
+
type testCase = {
|
|
6
|
+
name: string,
|
|
7
|
+
run: unit => testResult,
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
type testSuite = {
|
|
11
|
+
name: string,
|
|
12
|
+
tests: array<testCase>,
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
let test = (name: string, run: unit => testResult): testCase => {
|
|
16
|
+
{name, run}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
let suite = (name: string, tests: array<testCase>): testSuite => {
|
|
20
|
+
{name, tests}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
let assertEqual = (actual: 'a, expected: 'a, ~message: option<string>=?): testResult => {
|
|
24
|
+
if actual == expected {
|
|
25
|
+
Pass
|
|
26
|
+
} else {
|
|
27
|
+
let msg = switch message {
|
|
28
|
+
| Some(m) => m
|
|
29
|
+
| None => `Expected ${String.make(expected)}, got ${String.make(actual)}`
|
|
30
|
+
}
|
|
31
|
+
Fail(msg)
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
let assertNotEqual = (actual: 'a, expected: 'a, ~message: option<string>=?): testResult => {
|
|
36
|
+
if actual != expected {
|
|
37
|
+
Pass
|
|
38
|
+
} else {
|
|
39
|
+
let msg = switch message {
|
|
40
|
+
| Some(m) => m
|
|
41
|
+
| None => `Expected values to not be equal`
|
|
42
|
+
}
|
|
43
|
+
Fail(msg)
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
let assertTrue = (condition: bool, ~message: option<string>=?): testResult => {
|
|
48
|
+
if condition {
|
|
49
|
+
Pass
|
|
50
|
+
} else {
|
|
51
|
+
let msg = switch message {
|
|
52
|
+
| Some(m) => m
|
|
53
|
+
| None => "Expected true, got false"
|
|
54
|
+
}
|
|
55
|
+
Fail(msg)
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
let assertFalse = (condition: bool, ~message: option<string>=?): testResult => {
|
|
60
|
+
if !condition {
|
|
61
|
+
Pass
|
|
62
|
+
} else {
|
|
63
|
+
let msg = switch message {
|
|
64
|
+
| Some(m) => m
|
|
65
|
+
| None => "Expected false, got true"
|
|
66
|
+
}
|
|
67
|
+
Fail(msg)
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
let combineResults = (results: array<testResult>): testResult => {
|
|
72
|
+
let failures = results->Array.filter(r =>
|
|
73
|
+
switch r {
|
|
74
|
+
| Fail(_) => true
|
|
75
|
+
| Pass => false
|
|
76
|
+
}
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
if Array.length(failures) > 0 {
|
|
80
|
+
failures->Array.get(0)->Option.getOr(Pass)
|
|
81
|
+
} else {
|
|
82
|
+
Pass
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
let runSuite = (suite: testSuite): unit => {
|
|
87
|
+
Console.log(`\n๐ฆ Running test suite: ${suite.name}`)
|
|
88
|
+
Console.log("=" ++ String.repeat("-", String.length(suite.name) + 23))
|
|
89
|
+
|
|
90
|
+
let passed = ref(0)
|
|
91
|
+
let failed = ref(0)
|
|
92
|
+
|
|
93
|
+
suite.tests->Array.forEach(testCase => {
|
|
94
|
+
switch testCase.run() {
|
|
95
|
+
| Pass => {
|
|
96
|
+
Console.log(` โ ${testCase.name}`)
|
|
97
|
+
passed := passed.contents + 1
|
|
98
|
+
}
|
|
99
|
+
| Fail(message) => {
|
|
100
|
+
Console.log(` โ ${testCase.name}`)
|
|
101
|
+
Console.log(` ${message}`)
|
|
102
|
+
failed := failed.contents + 1
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
Console.log("")
|
|
108
|
+
Console.log(
|
|
109
|
+
`Results: ${Int.toString(passed.contents)} passed, ${Int.toString(failed.contents)} failed`,
|
|
110
|
+
)
|
|
111
|
+
|
|
112
|
+
if failed.contents > 0 {
|
|
113
|
+
Console.log("โ Some tests failed")
|
|
114
|
+
} else {
|
|
115
|
+
Console.log("โ
All tests passed!")
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
let runSuites = (suites: array<testSuite>): unit => {
|
|
120
|
+
Console.log("\n๐งช Running all test suites")
|
|
121
|
+
Console.log("========================\n")
|
|
122
|
+
|
|
123
|
+
let totalPassed = ref(0)
|
|
124
|
+
let totalFailed = ref(0)
|
|
125
|
+
|
|
126
|
+
suites->Array.forEach(suite => {
|
|
127
|
+
Console.log(`\n๐ฆ ${suite.name}`)
|
|
128
|
+
Console.log("-" ++ String.repeat("-", String.length(suite.name) + 3))
|
|
129
|
+
|
|
130
|
+
let suitePassed = ref(0)
|
|
131
|
+
let suiteFailed = ref(0)
|
|
132
|
+
|
|
133
|
+
suite.tests->Array.forEach(testCase => {
|
|
134
|
+
switch testCase.run() {
|
|
135
|
+
| Pass => {
|
|
136
|
+
Console.log(` โ ${testCase.name}`)
|
|
137
|
+
suitePassed := suitePassed.contents + 1
|
|
138
|
+
totalPassed := totalPassed.contents + 1
|
|
139
|
+
}
|
|
140
|
+
| Fail(message) => {
|
|
141
|
+
Console.log(` โ ${testCase.name}`)
|
|
142
|
+
Console.log(` ${message}`)
|
|
143
|
+
suiteFailed := suiteFailed.contents + 1
|
|
144
|
+
totalFailed := totalFailed.contents + 1
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
})
|
|
148
|
+
|
|
149
|
+
Console.log(
|
|
150
|
+
` ${Int.toString(suitePassed.contents)} passed, ${Int.toString(
|
|
151
|
+
suiteFailed.contents,
|
|
152
|
+
)} failed`,
|
|
153
|
+
)
|
|
154
|
+
})
|
|
155
|
+
|
|
156
|
+
Console.log("\n" ++ String.repeat("=", 50))
|
|
157
|
+
Console.log(
|
|
158
|
+
`Total: ${Int.toString(totalPassed.contents)} passed, ${Int.toString(
|
|
159
|
+
totalFailed.contents,
|
|
160
|
+
)} failed`,
|
|
161
|
+
)
|
|
162
|
+
|
|
163
|
+
if totalFailed.contents > 0 {
|
|
164
|
+
Console.log("โ Some tests failed\n")
|
|
165
|
+
%raw(`process.exit(1)`)
|
|
166
|
+
} else {
|
|
167
|
+
Console.log("โ
All tests passed!\n")
|
|
168
|
+
%raw(`process.exit(0)`)
|
|
169
|
+
}
|
|
170
|
+
}
|
|
File without changes
|