Skip to content

Commit 80784cc

Browse files
Test command (#98)
Fixes #61.
1 parent a5807eb commit 80784cc

File tree

29 files changed

+3991
-46
lines changed

29 files changed

+3991
-46
lines changed

bin/index.js

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -176,27 +176,30 @@ server.post("withCreateProcess", (request) => {
176176
tmp.file((err, path, fd) => {
177177
if (err) throw err;
178178

179-
nextCounter += 1;
179+
nextCounter += 1;
180180

181181
fs.createReadStream(path)
182182
.on("data", (chunk) => {
183-
processes[nextCounter].stdin.end(chunk);
183+
processes[nextCounter].stdin.write(chunk);
184+
})
185+
.on("close", () => {
186+
processes[nextCounter].stdin.end();
184187
});
185188

186-
processes[nextCounter] = child_process.spawn(
187-
createProcess.cmdspec.cmd,
188-
createProcess.cmdspec.args,
189-
{
190-
stdio: [
191-
createProcess.stdin,
192-
createProcess.stdout,
193-
createProcess.stderr,
194-
],
195-
}
196-
);
197-
198-
request.respond(200, null, JSON.stringify({ stdinHandle: fd, ph: nextCounter }));
199-
});
189+
processes[nextCounter] = child_process.spawn(
190+
createProcess.cmdspec.cmd,
191+
createProcess.cmdspec.args,
192+
{
193+
stdio: [
194+
createProcess.stdin,
195+
createProcess.stdout,
196+
createProcess.stderr,
197+
],
198+
}
199+
);
200+
201+
request.respond(200, null, JSON.stringify({ stdinHandle: fd, ph: nextCounter }));
202+
});
200203
});
201204

202205
server.post("hClose", (request) => {
@@ -428,6 +431,15 @@ server.post("putMVar", (request) => {
428431
}
429432
});
430433

434+
// NODE.JS SPECIFIC
435+
server.post("nodeGetDirname", (request) => {
436+
request.respond(200, null, __dirname);
437+
});
438+
439+
server.post("nodeMathRandom", (request) => {
440+
request.respond(200, null, Math.random());
441+
});
442+
431443
server.setDefaultHandler((request) => {
432444
const url = new URL(request.url);
433445
const client = url.protocol == "https:" ? https : http;

elm.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"elm/core": "1.0.5",
1313
"elm/http": "2.0.0",
1414
"elm/json": "1.1.3",
15+
"elm/regex": "1.0.0",
1516
"elm/time": "1.0.0",
1617
"elm/url": "1.0.0",
1718
"elm-community/array-extra": "2.6.0",
@@ -33,7 +34,6 @@
3334
"andre-dietrich/parser-combinators": "4.1.0",
3435
"elm/file": "1.0.5",
3536
"elm/parser": "1.1.0",
36-
"elm/regex": "1.0.0",
3737
"fredcy/elm-parseint": "2.0.1",
3838
"miniBill/elm-unicode": "1.1.1",
3939
"pilatch/flip": "1.0.0",

libraries/test/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# node-test-runner
2+
3+
Copied from [v0.19.1-revision15](https://github.com/rtfeldman/node-test-runner/tree/0.19.1-revision15).

libraries/test/src/Console/Text.elm

Lines changed: 217 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,217 @@
1+
module Console.Text exposing
2+
( Color
3+
, ColorModifier
4+
, Style
5+
, Text
6+
, UseColor(..)
7+
, concat
8+
, dark
9+
, green
10+
, plain
11+
, red
12+
, render
13+
, underline
14+
, yellow
15+
)
16+
17+
import Test.Runner.Node.Vendor.Console as Console
18+
19+
20+
type Text
21+
= Text { background : Color, foreground : Color, style : Style, modifiers : List ColorModifier } String
22+
| Texts (List Text)
23+
24+
25+
type UseColor
26+
= UseColor
27+
| Monochrome
28+
29+
30+
type Color
31+
= Default
32+
| Red
33+
| Green
34+
| Yellow
35+
| Black
36+
| Blue
37+
| Magenta
38+
| Cyan
39+
| White
40+
41+
42+
type ColorModifier
43+
= Inverted
44+
| Dark
45+
46+
47+
type Style
48+
= Normal
49+
| Bold
50+
| Underline
51+
52+
53+
render : UseColor -> Text -> String
54+
render useColor txt =
55+
case txt of
56+
Text attrs str ->
57+
case useColor of
58+
UseColor ->
59+
str
60+
|> colorizeBackground attrs.background
61+
|> colorizeForeground attrs.foreground
62+
|> applyModifiers attrs.modifiers
63+
|> applyStyle attrs.style
64+
65+
Monochrome ->
66+
str
67+
68+
Texts texts ->
69+
List.map (render useColor) texts
70+
|> String.join ""
71+
72+
73+
concat : List Text -> Text
74+
concat =
75+
Texts
76+
77+
78+
plain : String -> Text
79+
plain =
80+
Text { foreground = Default, background = Default, style = Normal, modifiers = [] }
81+
82+
83+
84+
-- FOREGROUND COLORS --
85+
86+
87+
red : String -> Text
88+
red =
89+
Text { foreground = Red, background = Default, style = Normal, modifiers = [] }
90+
91+
92+
green : String -> Text
93+
green =
94+
Text { foreground = Green, background = Default, style = Normal, modifiers = [] }
95+
96+
97+
yellow : String -> Text
98+
yellow =
99+
Text { foreground = Yellow, background = Default, style = Normal, modifiers = [] }
100+
101+
102+
dark : Text -> Text
103+
dark txt =
104+
case txt of
105+
Text styles str ->
106+
Text { styles | modifiers = Dark :: styles.modifiers } str
107+
108+
Texts texts ->
109+
Texts (List.map dark texts)
110+
111+
112+
113+
-- STYLES --
114+
115+
116+
underline : Text -> Text
117+
underline txt =
118+
case txt of
119+
Text styles str ->
120+
Text { styles | style = Underline } str
121+
122+
Texts texts ->
123+
Texts (List.map dark texts)
124+
125+
126+
127+
-- INTERNAL HELPERS --
128+
129+
130+
colorizeForeground : Color -> String -> String
131+
colorizeForeground color str =
132+
case color of
133+
Default ->
134+
str
135+
136+
Red ->
137+
Console.red str
138+
139+
Green ->
140+
Console.green str
141+
142+
Yellow ->
143+
Console.yellow str
144+
145+
Black ->
146+
Console.black str
147+
148+
Blue ->
149+
Console.blue str
150+
151+
Magenta ->
152+
Console.magenta str
153+
154+
Cyan ->
155+
Console.cyan str
156+
157+
White ->
158+
Console.white str
159+
160+
161+
colorizeBackground : Color -> String -> String
162+
colorizeBackground color str =
163+
case color of
164+
Default ->
165+
str
166+
167+
Red ->
168+
Console.bgRed str
169+
170+
Green ->
171+
Console.bgGreen str
172+
173+
Yellow ->
174+
Console.bgYellow str
175+
176+
Black ->
177+
Console.bgBlack str
178+
179+
Blue ->
180+
Console.bgBlue str
181+
182+
Magenta ->
183+
Console.bgMagenta str
184+
185+
Cyan ->
186+
Console.bgCyan str
187+
188+
White ->
189+
Console.bgWhite str
190+
191+
192+
applyStyle : Style -> String -> String
193+
applyStyle style str =
194+
case style of
195+
Normal ->
196+
str
197+
198+
Bold ->
199+
Console.bold str
200+
201+
Underline ->
202+
Console.underline str
203+
204+
205+
applyModifiers : List ColorModifier -> String -> String
206+
applyModifiers modifiers str =
207+
List.foldl applyModifiersHelp str modifiers
208+
209+
210+
applyModifiersHelp : ColorModifier -> String -> String
211+
applyModifiersHelp modifier str =
212+
case modifier of
213+
Inverted ->
214+
Console.colorsInverted str
215+
216+
Dark ->
217+
Console.dark str

0 commit comments

Comments
 (0)